mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[feature] Allow exposing allows, implement /api/v1/domain_blocks
and /api/v1/domain_allows
(#4169)
- adds config flags `instance-expose-allowlist` and `instance-expose-allowlist-web` to allow instance admins to expose their allowlist via the web + api. - renames `instance-expose-suspended` and `instance-expose-suspended-web` to `instance-expose-blocklist` and `instance-expose-blocklist-web`. - deprecates the `suspended` filter on `/api/v1/instance/peers` endpoint and adds `blocked` and `allowed` filters - adds the `flat` query param to `/api/v1/instance/peers` to allow forcing return of a flat list of domains - implements `/api/v1/instance/domain_blocks` and `/api/v1/instance/domain_allows` endpoints with or without auth depending on config - rejigs the instance about page to include a general section on domain permissions, with block and allow subsections (and appropriate links) Closes https://codeberg.org/superseriousbusiness/gotosocial/issues/3847 Closes https://codeberg.org/superseriousbusiness/gotosocial/issues/4150 Prerequisite to https://codeberg.org/superseriousbusiness/gotosocial/issues/3711 Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4169 Co-authored-by: tobi <tobi.smethurst@protonmail.com> Co-committed-by: tobi <tobi.smethurst@protonmail.com>
This commit is contained in:
@ -136,13 +136,14 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetOnlySuspended() {
|
||||
{
|
||||
"domain": "replyguys.com",
|
||||
"suspended_at": "2020-05-13T13:29:12.000Z",
|
||||
"comment": "reply-guying to tech posts"
|
||||
"comment": "reply-guying to tech posts",
|
||||
"severity": "suspend"
|
||||
}
|
||||
]`, dst.String())
|
||||
}
|
||||
|
||||
func (suite *InstancePeersGetTestSuite) TestInstancePeersGetOnlySuspendedUnauthorized() {
|
||||
config.SetInstanceExposeSuspended(false)
|
||||
config.SetInstanceExposeBlocklist(false)
|
||||
|
||||
recorder := httptest.NewRecorder()
|
||||
baseURI := fmt.Sprintf("%s://%s", config.GetProtocol(), config.GetHost())
|
||||
@ -159,11 +160,11 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetOnlySuspendedUnautho
|
||||
b, err := io.ReadAll(result.Body)
|
||||
suite.NoError(err)
|
||||
|
||||
suite.Equal(`{"error":"Unauthorized: peers suspended query requires an authenticated account/user"}`, string(b))
|
||||
suite.Equal(`{"error":"Unauthorized: peers blocked query requires an authenticated account/user"}`, string(b))
|
||||
}
|
||||
|
||||
func (suite *InstancePeersGetTestSuite) TestInstancePeersGetOnlySuspendedAuthorized() {
|
||||
config.SetInstanceExposeSuspended(false)
|
||||
config.SetInstanceExposeBlocklist(false)
|
||||
|
||||
recorder := httptest.NewRecorder()
|
||||
baseURI := fmt.Sprintf("%s://%s", config.GetProtocol(), config.GetHost())
|
||||
@ -186,7 +187,8 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetOnlySuspendedAuthori
|
||||
{
|
||||
"domain": "replyguys.com",
|
||||
"suspended_at": "2020-05-13T13:29:12.000Z",
|
||||
"comment": "reply-guying to tech posts"
|
||||
"comment": "reply-guying to tech posts",
|
||||
"severity": "suspend"
|
||||
}
|
||||
]`, dst.String())
|
||||
}
|
||||
@ -219,11 +221,33 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetAll() {
|
||||
{
|
||||
"domain": "replyguys.com",
|
||||
"suspended_at": "2020-05-13T13:29:12.000Z",
|
||||
"comment": "reply-guying to tech posts"
|
||||
"comment": "reply-guying to tech posts",
|
||||
"severity": "suspend"
|
||||
}
|
||||
]`, dst.String())
|
||||
}
|
||||
|
||||
func (suite *InstancePeersGetTestSuite) TestInstancePeersGetAllowed() {
|
||||
recorder := httptest.NewRecorder()
|
||||
baseURI := fmt.Sprintf("%s://%s", config.GetProtocol(), config.GetHost())
|
||||
requestURI := fmt.Sprintf("%s/%s?filter=allowed", baseURI, instance.InstancePeersPath)
|
||||
ctx := suite.newContext(recorder, http.MethodGet, requestURI, nil, "", false)
|
||||
|
||||
suite.instanceModule.InstancePeersGETHandler(ctx)
|
||||
|
||||
suite.Equal(http.StatusOK, recorder.Code)
|
||||
|
||||
result := recorder.Result()
|
||||
defer result.Body.Close()
|
||||
|
||||
b, err := io.ReadAll(result.Body)
|
||||
suite.NoError(err)
|
||||
dst := new(bytes.Buffer)
|
||||
err = json.Indent(dst, b, "", " ")
|
||||
suite.NoError(err)
|
||||
suite.Equal(`[]`, dst.String())
|
||||
}
|
||||
|
||||
func (suite *InstancePeersGetTestSuite) TestInstancePeersGetAllWithObfuscated() {
|
||||
err := suite.db.Put(context.Background(), >smodel.DomainBlock{
|
||||
ID: "01G633XTNK51GBADQZFZQDP6WR",
|
||||
@ -263,16 +287,55 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetAllWithObfuscated()
|
||||
{
|
||||
"domain": "o*g.*u**.t**.*or*t.*r**ev**",
|
||||
"suspended_at": "2021-06-09T10:34:55.000Z",
|
||||
"comment": "just absolutely the worst, wowza"
|
||||
"comment": "just absolutely the worst, wowza",
|
||||
"severity": "suspend"
|
||||
},
|
||||
{
|
||||
"domain": "replyguys.com",
|
||||
"suspended_at": "2020-05-13T13:29:12.000Z",
|
||||
"comment": "reply-guying to tech posts"
|
||||
"comment": "reply-guying to tech posts",
|
||||
"severity": "suspend"
|
||||
}
|
||||
]`, dst.String())
|
||||
}
|
||||
|
||||
func (suite *InstancePeersGetTestSuite) TestInstancePeersGetAllWithObfuscatedFlat() {
|
||||
err := suite.db.Put(context.Background(), >smodel.DomainBlock{
|
||||
ID: "01G633XTNK51GBADQZFZQDP6WR",
|
||||
CreatedAt: testrig.TimeMustParse("2021-06-09T12:34:55+02:00"),
|
||||
UpdatedAt: testrig.TimeMustParse("2021-06-09T12:34:55+02:00"),
|
||||
Domain: "omg.just.the.worst.org.ever",
|
||||
CreatedByAccountID: "01F8MH17FWEB39HZJ76B6VXSKF",
|
||||
PublicComment: "just absolutely the worst, wowza",
|
||||
Obfuscate: util.Ptr(true),
|
||||
})
|
||||
suite.NoError(err)
|
||||
|
||||
recorder := httptest.NewRecorder()
|
||||
baseURI := fmt.Sprintf("%s://%s", config.GetProtocol(), config.GetHost())
|
||||
requestURI := fmt.Sprintf("%s/%s?filter=suspended,open&flat=true", baseURI, instance.InstancePeersPath)
|
||||
ctx := suite.newContext(recorder, http.MethodGet, requestURI, nil, "", false)
|
||||
|
||||
suite.instanceModule.InstancePeersGETHandler(ctx)
|
||||
|
||||
suite.Equal(http.StatusOK, recorder.Code)
|
||||
|
||||
result := recorder.Result()
|
||||
defer result.Body.Close()
|
||||
|
||||
b, err := io.ReadAll(result.Body)
|
||||
suite.NoError(err)
|
||||
dst := new(bytes.Buffer)
|
||||
err = json.Indent(dst, b, "", " ")
|
||||
suite.NoError(err)
|
||||
suite.Equal(`[
|
||||
"example.org",
|
||||
"fossbros-anonymous.io",
|
||||
"o*g.*u**.t**.*or*t.*r**ev**",
|
||||
"replyguys.com"
|
||||
]`, dst.String())
|
||||
}
|
||||
|
||||
func (suite *InstancePeersGetTestSuite) TestInstancePeersGetFunkyParams() {
|
||||
recorder := httptest.NewRecorder()
|
||||
baseURI := fmt.Sprintf("%s://%s", config.GetProtocol(), config.GetHost())
|
||||
@ -289,7 +352,7 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetFunkyParams() {
|
||||
b, err := io.ReadAll(result.Body)
|
||||
suite.NoError(err)
|
||||
|
||||
suite.Equal(`{"error":"Bad Request: filter aaaaaaaaaaaaaaaaa not recognized; accepted values are 'open', 'suspended'"}`, string(b))
|
||||
suite.Equal(`{"error":"Bad Request: filter aaaaaaaaaaaaaaaaa not recognized; accepted values are 'open', 'blocked', 'allowed', and 'suspended' (deprecated)"}`, string(b))
|
||||
}
|
||||
|
||||
func TestInstancePeersGetTestSuite(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user