diff options
Diffstat (limited to 'internal/api')
-rw-r--r-- | internal/api/activitypub/users/outboxget_test.go | 43 | ||||
-rw-r--r-- | internal/api/client/admin/emojicategoriesget_test.go | 17 | ||||
-rw-r--r-- | internal/api/client/admin/emojidelete_test.go | 20 | ||||
-rw-r--r-- | internal/api/client/admin/emojiget_test.go | 38 | ||||
-rw-r--r-- | internal/api/client/followrequests/authorize_test.go | 27 | ||||
-rw-r--r-- | internal/api/client/followrequests/get_test.go | 30 | ||||
-rw-r--r-- | internal/api/client/followrequests/reject_test.go | 25 | ||||
-rw-r--r-- | internal/api/client/instance/instancepatch_test.go | 425 | ||||
-rw-r--r-- | internal/api/client/instance/instancepeersget_test.go | 85 | ||||
-rw-r--r-- | internal/api/model/source.go | 8 | ||||
-rw-r--r-- | internal/api/wellknown/webfinger/webfingerget_test.go | 107 |
11 files changed, 760 insertions, 65 deletions
diff --git a/internal/api/activitypub/users/outboxget_test.go b/internal/api/activitypub/users/outboxget_test.go index 58c32760e..6e5c4e1e0 100644 --- a/internal/api/activitypub/users/outboxget_test.go +++ b/internal/api/activitypub/users/outboxget_test.go @@ -19,6 +19,7 @@ package users_test import ( + "bytes" "context" "encoding/json" "io/ioutil" @@ -76,7 +77,15 @@ func (suite *OutboxGetTestSuite) TestGetOutbox() { defer result.Body.Close() b, err := ioutil.ReadAll(result.Body) suite.NoError(err) - suite.Equal(`{"@context":"https://www.w3.org/ns/activitystreams","first":"http://localhost:8080/users/the_mighty_zork/outbox?page=true","id":"http://localhost:8080/users/the_mighty_zork/outbox","type":"OrderedCollection"}`, string(b)) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`{ + "@context": "https://www.w3.org/ns/activitystreams", + "first": "http://localhost:8080/users/the_mighty_zork/outbox?page=true", + "id": "http://localhost:8080/users/the_mighty_zork/outbox", + "type": "OrderedCollection" +}`, dst.String()) m := make(map[string]interface{}) err = json.Unmarshal(b, &m) @@ -135,7 +144,26 @@ func (suite *OutboxGetTestSuite) TestGetOutboxFirstPage() { defer result.Body.Close() b, err := ioutil.ReadAll(result.Body) suite.NoError(err) - suite.Equal(`{"@context":"https://www.w3.org/ns/activitystreams","id":"http://localhost:8080/users/the_mighty_zork/outbox?page=true","next":"http://localhost:8080/users/the_mighty_zork/outbox?page=true\u0026max_id=01F8MHAMCHF6Y650WCRSCP4WMY","orderedItems":{"actor":"http://localhost:8080/users/the_mighty_zork","cc":"http://localhost:8080/users/the_mighty_zork/followers","id":"http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY/activity","object":"http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY","published":"2021-10-20T10:40:37Z","to":"https://www.w3.org/ns/activitystreams#Public","type":"Create"},"partOf":"http://localhost:8080/users/the_mighty_zork/outbox","prev":"http://localhost:8080/users/the_mighty_zork/outbox?page=true\u0026min_id=01F8MHAMCHF6Y650WCRSCP4WMY","type":"OrderedCollectionPage"}`, string(b)) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`{ + "@context": "https://www.w3.org/ns/activitystreams", + "id": "http://localhost:8080/users/the_mighty_zork/outbox?page=true", + "next": "http://localhost:8080/users/the_mighty_zork/outbox?page=true\u0026max_id=01F8MHAMCHF6Y650WCRSCP4WMY", + "orderedItems": { + "actor": "http://localhost:8080/users/the_mighty_zork", + "cc": "http://localhost:8080/users/the_mighty_zork/followers", + "id": "http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY/activity", + "object": "http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY", + "published": "2021-10-20T10:40:37Z", + "to": "https://www.w3.org/ns/activitystreams#Public", + "type": "Create" + }, + "partOf": "http://localhost:8080/users/the_mighty_zork/outbox", + "prev": "http://localhost:8080/users/the_mighty_zork/outbox?page=true\u0026min_id=01F8MHAMCHF6Y650WCRSCP4WMY", + "type": "OrderedCollectionPage" +}`, dst.String()) m := make(map[string]interface{}) err = json.Unmarshal(b, &m) @@ -198,7 +226,16 @@ func (suite *OutboxGetTestSuite) TestGetOutboxNextPage() { defer result.Body.Close() b, err := ioutil.ReadAll(result.Body) suite.NoError(err) - suite.Equal(`{"@context":"https://www.w3.org/ns/activitystreams","id":"http://localhost:8080/users/the_mighty_zork/outbox?page=true\u0026maxID=01F8MHAMCHF6Y650WCRSCP4WMY","orderedItems":[],"partOf":"http://localhost:8080/users/the_mighty_zork/outbox","type":"OrderedCollectionPage"}`, string(b)) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`{ + "@context": "https://www.w3.org/ns/activitystreams", + "id": "http://localhost:8080/users/the_mighty_zork/outbox?page=true\u0026maxID=01F8MHAMCHF6Y650WCRSCP4WMY", + "orderedItems": [], + "partOf": "http://localhost:8080/users/the_mighty_zork/outbox", + "type": "OrderedCollectionPage" +}`, dst.String()) m := make(map[string]interface{}) err = json.Unmarshal(b, &m) diff --git a/internal/api/client/admin/emojicategoriesget_test.go b/internal/api/client/admin/emojicategoriesget_test.go index 3c7e8eb3d..c9deca1dd 100644 --- a/internal/api/client/admin/emojicategoriesget_test.go +++ b/internal/api/client/admin/emojicategoriesget_test.go @@ -19,6 +19,8 @@ package admin_test import ( + "bytes" + "encoding/json" "io" "net/http" "net/http/httptest" @@ -44,8 +46,19 @@ func (suite *EmojiCategoriesGetTestSuite) TestEmojiCategoriesGet() { b, err := io.ReadAll(recorder.Body) suite.NoError(err) suite.NotNil(b) - - suite.Equal(`[{"id":"01GGQ989PTT9PMRN4FZ1WWK2B9","name":"cute stuff"},{"id":"01GGQ8V4993XK67B2JB396YFB7","name":"reactions"}]`, string(b)) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`[ + { + "id": "01GGQ989PTT9PMRN4FZ1WWK2B9", + "name": "cute stuff" + }, + { + "id": "01GGQ8V4993XK67B2JB396YFB7", + "name": "reactions" + } +]`, dst.String()) } func TestEmojiCategoriesGetTestSuite(t *testing.T) { diff --git a/internal/api/client/admin/emojidelete_test.go b/internal/api/client/admin/emojidelete_test.go index e9eaa464c..e7e4a153b 100644 --- a/internal/api/client/admin/emojidelete_test.go +++ b/internal/api/client/admin/emojidelete_test.go @@ -19,7 +19,9 @@ package admin_test import ( + "bytes" "context" + "encoding/json" "io" "net/http" "net/http/httptest" @@ -48,8 +50,22 @@ func (suite *EmojiDeleteTestSuite) TestEmojiDelete1() { b, err := io.ReadAll(recorder.Body) suite.NoError(err) suite.NotNil(b) - - suite.Equal(`{"shortcode":"rainbow","url":"http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/original/01F8MH9H8E4VG3KDYJR9EGPXCQ.png","static_url":"http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/static/01F8MH9H8E4VG3KDYJR9EGPXCQ.png","visible_in_picker":true,"category":"reactions","id":"01F8MH9H8E4VG3KDYJR9EGPXCQ","disabled":false,"updated_at":"2021-09-20T10:40:37.000Z","total_file_size":47115,"content_type":"image/png","uri":"http://localhost:8080/emoji/01F8MH9H8E4VG3KDYJR9EGPXCQ"}`, string(b)) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`{ + "shortcode": "rainbow", + "url": "http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/original/01F8MH9H8E4VG3KDYJR9EGPXCQ.png", + "static_url": "http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/static/01F8MH9H8E4VG3KDYJR9EGPXCQ.png", + "visible_in_picker": true, + "category": "reactions", + "id": "01F8MH9H8E4VG3KDYJR9EGPXCQ", + "disabled": false, + "updated_at": "2021-09-20T10:40:37.000Z", + "total_file_size": 47115, + "content_type": "image/png", + "uri": "http://localhost:8080/emoji/01F8MH9H8E4VG3KDYJR9EGPXCQ" +}`, dst.String()) // emoji should no longer be in the db dbEmoji, err := suite.db.GetEmojiByID(context.Background(), testEmoji.ID) diff --git a/internal/api/client/admin/emojiget_test.go b/internal/api/client/admin/emojiget_test.go index fec555cee..41e96fd8e 100644 --- a/internal/api/client/admin/emojiget_test.go +++ b/internal/api/client/admin/emojiget_test.go @@ -19,6 +19,8 @@ package admin_test import ( + "bytes" + "encoding/json" "io" "net/http" "net/http/httptest" @@ -46,8 +48,22 @@ func (suite *EmojiGetTestSuite) TestEmojiGet1() { b, err := io.ReadAll(recorder.Body) suite.NoError(err) suite.NotNil(b) - - suite.Equal(`{"shortcode":"rainbow","url":"http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/original/01F8MH9H8E4VG3KDYJR9EGPXCQ.png","static_url":"http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/static/01F8MH9H8E4VG3KDYJR9EGPXCQ.png","visible_in_picker":true,"category":"reactions","id":"01F8MH9H8E4VG3KDYJR9EGPXCQ","disabled":false,"updated_at":"2021-09-20T10:40:37.000Z","total_file_size":47115,"content_type":"image/png","uri":"http://localhost:8080/emoji/01F8MH9H8E4VG3KDYJR9EGPXCQ"}`, string(b)) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`{ + "shortcode": "rainbow", + "url": "http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/original/01F8MH9H8E4VG3KDYJR9EGPXCQ.png", + "static_url": "http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/static/01F8MH9H8E4VG3KDYJR9EGPXCQ.png", + "visible_in_picker": true, + "category": "reactions", + "id": "01F8MH9H8E4VG3KDYJR9EGPXCQ", + "disabled": false, + "updated_at": "2021-09-20T10:40:37.000Z", + "total_file_size": 47115, + "content_type": "image/png", + "uri": "http://localhost:8080/emoji/01F8MH9H8E4VG3KDYJR9EGPXCQ" +}`, dst.String()) } func (suite *EmojiGetTestSuite) TestEmojiGet2() { @@ -64,8 +80,22 @@ func (suite *EmojiGetTestSuite) TestEmojiGet2() { b, err := io.ReadAll(recorder.Body) suite.NoError(err) suite.NotNil(b) - - suite.Equal(`{"shortcode":"yell","url":"http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/original/01GD5KP5CQEE1R3X43Y1EHS2CW.png","static_url":"http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/static/01GD5KP5CQEE1R3X43Y1EHS2CW.png","visible_in_picker":false,"id":"01GD5KP5CQEE1R3X43Y1EHS2CW","disabled":false,"domain":"fossbros-anonymous.io","updated_at":"2020-03-18T12:12:00.000Z","total_file_size":21697,"content_type":"image/png","uri":"http://fossbros-anonymous.io/emoji/01GD5KP5CQEE1R3X43Y1EHS2CW"}`, string(b)) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`{ + "shortcode": "yell", + "url": "http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/original/01GD5KP5CQEE1R3X43Y1EHS2CW.png", + "static_url": "http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/static/01GD5KP5CQEE1R3X43Y1EHS2CW.png", + "visible_in_picker": false, + "id": "01GD5KP5CQEE1R3X43Y1EHS2CW", + "disabled": false, + "domain": "fossbros-anonymous.io", + "updated_at": "2020-03-18T12:12:00.000Z", + "total_file_size": 21697, + "content_type": "image/png", + "uri": "http://fossbros-anonymous.io/emoji/01GD5KP5CQEE1R3X43Y1EHS2CW" +}`, dst.String()) } func (suite *EmojiGetTestSuite) TestEmojiGetNotFound() { diff --git a/internal/api/client/followrequests/authorize_test.go b/internal/api/client/followrequests/authorize_test.go index 4f2e69d49..e6ad1ff30 100644 --- a/internal/api/client/followrequests/authorize_test.go +++ b/internal/api/client/followrequests/authorize_test.go @@ -19,7 +19,9 @@ package followrequests_test import ( + "bytes" "context" + "encoding/json" "fmt" "io/ioutil" "net/http" @@ -28,7 +30,6 @@ import ( "time" "github.com/gin-gonic/gin" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/api/client/followrequests" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" @@ -77,9 +78,25 @@ func (suite *AuthorizeTestSuite) TestAuthorize() { // check the response b, err := ioutil.ReadAll(result.Body) - assert.NoError(suite.T(), err) - - suite.Equal(`{"id":"01FHMQX3GAABWSM0S2VZEC2SWC","following":false,"showing_reblogs":false,"notifying":false,"followed_by":true,"blocking":false,"blocked_by":false,"muting":false,"muting_notifications":false,"requested":false,"domain_blocking":false,"endorsed":false,"note":""}`, string(b)) + suite.NoError(err) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`{ + "id": "01FHMQX3GAABWSM0S2VZEC2SWC", + "following": false, + "showing_reblogs": false, + "notifying": false, + "followed_by": true, + "blocking": false, + "blocked_by": false, + "muting": false, + "muting_notifications": false, + "requested": false, + "domain_blocking": false, + "endorsed": false, + "note": "" +}`, dst.String()) } func (suite *AuthorizeTestSuite) TestAuthorizeNoFR() { @@ -105,7 +122,7 @@ func (suite *AuthorizeTestSuite) TestAuthorizeNoFR() { // check the response b, err := ioutil.ReadAll(result.Body) - assert.NoError(suite.T(), err) + suite.NoError(err) suite.Equal(`{"error":"Not Found"}`, string(b)) } diff --git a/internal/api/client/followrequests/get_test.go b/internal/api/client/followrequests/get_test.go index 077dfdc0a..5d7feb3bf 100644 --- a/internal/api/client/followrequests/get_test.go +++ b/internal/api/client/followrequests/get_test.go @@ -19,7 +19,9 @@ package followrequests_test import ( + "bytes" "context" + "encoding/json" "fmt" "io/ioutil" "net/http" @@ -69,8 +71,32 @@ func (suite *GetTestSuite) TestGet() { // check the response b, err := ioutil.ReadAll(result.Body) assert.NoError(suite.T(), err) - - suite.Equal(`[{"id":"01FHMQX3GAABWSM0S2VZEC2SWC","username":"Some_User","acct":"Some_User@example.org","display_name":"some user","locked":true,"bot":false,"created_at":"2020-08-10T12:13:28.000Z","note":"i'm a real son of a gun","url":"http://example.org/@Some_User","avatar":"","avatar_static":"","header":"http://localhost:8080/assets/default_header.png","header_static":"http://localhost:8080/assets/default_header.png","followers_count":0,"following_count":0,"statuses_count":0,"last_status_at":null,"emojis":[],"fields":[]}]`, string(b)) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`[ + { + "id": "01FHMQX3GAABWSM0S2VZEC2SWC", + "username": "Some_User", + "acct": "Some_User@example.org", + "display_name": "some user", + "locked": true, + "bot": false, + "created_at": "2020-08-10T12:13:28.000Z", + "note": "i'm a real son of a gun", + "url": "http://example.org/@Some_User", + "avatar": "", + "avatar_static": "", + "header": "http://localhost:8080/assets/default_header.png", + "header_static": "http://localhost:8080/assets/default_header.png", + "followers_count": 0, + "following_count": 0, + "statuses_count": 0, + "last_status_at": null, + "emojis": [], + "fields": [] + } +]`, dst.String()) } func TestGetTestSuite(t *testing.T) { diff --git a/internal/api/client/followrequests/reject_test.go b/internal/api/client/followrequests/reject_test.go index 439d7424f..758cd0448 100644 --- a/internal/api/client/followrequests/reject_test.go +++ b/internal/api/client/followrequests/reject_test.go @@ -19,7 +19,9 @@ package followrequests_test import ( + "bytes" "context" + "encoding/json" "fmt" "io/ioutil" "net/http" @@ -28,7 +30,6 @@ import ( "time" "github.com/gin-gonic/gin" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/api/client/followrequests" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" @@ -77,9 +78,25 @@ func (suite *RejectTestSuite) TestReject() { // check the response b, err := ioutil.ReadAll(result.Body) - assert.NoError(suite.T(), err) - - suite.Equal(`{"id":"01FHMQX3GAABWSM0S2VZEC2SWC","following":false,"showing_reblogs":false,"notifying":false,"followed_by":false,"blocking":false,"blocked_by":false,"muting":false,"muting_notifications":false,"requested":false,"domain_blocking":false,"endorsed":false,"note":""}`, string(b)) + suite.NoError(err) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`{ + "id": "01FHMQX3GAABWSM0S2VZEC2SWC", + "following": false, + "showing_reblogs": false, + "notifying": false, + "followed_by": false, + "blocking": false, + "blocked_by": false, + "muting": false, + "muting_notifications": false, + "requested": false, + "domain_blocking": false, + "endorsed": false, + "note": "" +}`, dst.String()) } func TestRejectTestSuite(t *testing.T) { diff --git a/internal/api/client/instance/instancepatch_test.go b/internal/api/client/instance/instancepatch_test.go index e57234654..0c209c78c 100644 --- a/internal/api/client/instance/instancepatch_test.go +++ b/internal/api/client/instance/instancepatch_test.go @@ -19,8 +19,9 @@ package instance_test import ( + "bytes" "context" - "fmt" + "encoding/json" "io" "net/http" "net/http/httptest" @@ -64,8 +65,87 @@ func (suite *InstancePatchTestSuite) TestInstancePatch1() { b, err := io.ReadAll(result.Body) suite.NoError(err) - - suite.Equal(`{"uri":"http://localhost:8080","account_domain":"localhost:8080","title":"Example Instance","description":"\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e","short_description":"\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e","email":"someone@example.org","version":"0.0.0-testrig","registrations":true,"approval_required":true,"invites_enabled":false,"configuration":{"statuses":{"max_characters":5000,"max_media_attachments":6,"characters_reserved_per_url":25},"media_attachments":{"supported_mime_types":["image/jpeg","image/gif","image/png","image/webp","video/mp4"],"image_size_limit":10485760,"image_matrix_limit":16777216,"video_size_limit":41943040,"video_frame_rate_limit":60,"video_matrix_limit":16777216},"polls":{"max_options":6,"max_characters_per_option":50,"min_expiration":300,"max_expiration":2629746},"accounts":{"allow_custom_css":true},"emojis":{"emoji_size_limit":51200}},"urls":{"streaming_api":"wss://localhost:8080"},"stats":{"domain_count":2,"status_count":16,"user_count":4},"thumbnail":"http://localhost:8080/assets/logo.png","contact_account":{"id":"01F8MH17FWEB39HZJ76B6VXSKF","username":"admin","acct":"admin","display_name":"","locked":false,"bot":false,"created_at":"2022-05-17T13:10:59.000Z","note":"","url":"http://localhost:8080/@admin","avatar":"","avatar_static":"","header":"http://localhost:8080/assets/default_header.png","header_static":"http://localhost:8080/assets/default_header.png","followers_count":1,"following_count":1,"statuses_count":4,"last_status_at":"2021-10-20T10:41:37.000Z","emojis":[],"fields":[],"enable_rss":true,"role":"admin"},"max_toot_chars":5000}`, string(b)) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`{ + "uri": "http://localhost:8080", + "account_domain": "localhost:8080", + "title": "Example Instance", + "description": "\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e", + "short_description": "\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e", + "email": "someone@example.org", + "version": "0.0.0-testrig", + "registrations": true, + "approval_required": true, + "invites_enabled": false, + "configuration": { + "statuses": { + "max_characters": 5000, + "max_media_attachments": 6, + "characters_reserved_per_url": 25 + }, + "media_attachments": { + "supported_mime_types": [ + "image/jpeg", + "image/gif", + "image/png", + "image/webp", + "video/mp4" + ], + "image_size_limit": 10485760, + "image_matrix_limit": 16777216, + "video_size_limit": 41943040, + "video_frame_rate_limit": 60, + "video_matrix_limit": 16777216 + }, + "polls": { + "max_options": 6, + "max_characters_per_option": 50, + "min_expiration": 300, + "max_expiration": 2629746 + }, + "accounts": { + "allow_custom_css": true + }, + "emojis": { + "emoji_size_limit": 51200 + } + }, + "urls": { + "streaming_api": "wss://localhost:8080" + }, + "stats": { + "domain_count": 2, + "status_count": 16, + "user_count": 4 + }, + "thumbnail": "http://localhost:8080/assets/logo.png", + "contact_account": { + "id": "01F8MH17FWEB39HZJ76B6VXSKF", + "username": "admin", + "acct": "admin", + "display_name": "", + "locked": false, + "bot": false, + "created_at": "2022-05-17T13:10:59.000Z", + "note": "", + "url": "http://localhost:8080/@admin", + "avatar": "", + "avatar_static": "", + "header": "http://localhost:8080/assets/default_header.png", + "header_static": "http://localhost:8080/assets/default_header.png", + "followers_count": 1, + "following_count": 1, + "statuses_count": 4, + "last_status_at": "2021-10-20T10:41:37.000Z", + "emojis": [], + "fields": [], + "enable_rss": true, + "role": "admin" + }, + "max_toot_chars": 5000 +}`, dst.String()) } func (suite *InstancePatchTestSuite) TestInstancePatch2() { @@ -94,8 +174,87 @@ func (suite *InstancePatchTestSuite) TestInstancePatch2() { b, err := io.ReadAll(result.Body) suite.NoError(err) - - suite.Equal(`{"uri":"http://localhost:8080","account_domain":"localhost:8080","title":"Geoff's Instance","description":"\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e","short_description":"\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e","email":"admin@example.org","version":"0.0.0-testrig","registrations":true,"approval_required":true,"invites_enabled":false,"configuration":{"statuses":{"max_characters":5000,"max_media_attachments":6,"characters_reserved_per_url":25},"media_attachments":{"supported_mime_types":["image/jpeg","image/gif","image/png","image/webp","video/mp4"],"image_size_limit":10485760,"image_matrix_limit":16777216,"video_size_limit":41943040,"video_frame_rate_limit":60,"video_matrix_limit":16777216},"polls":{"max_options":6,"max_characters_per_option":50,"min_expiration":300,"max_expiration":2629746},"accounts":{"allow_custom_css":true},"emojis":{"emoji_size_limit":51200}},"urls":{"streaming_api":"wss://localhost:8080"},"stats":{"domain_count":2,"status_count":16,"user_count":4},"thumbnail":"http://localhost:8080/assets/logo.png","contact_account":{"id":"01F8MH17FWEB39HZJ76B6VXSKF","username":"admin","acct":"admin","display_name":"","locked":false,"bot":false,"created_at":"2022-05-17T13:10:59.000Z","note":"","url":"http://localhost:8080/@admin","avatar":"","avatar_static":"","header":"http://localhost:8080/assets/default_header.png","header_static":"http://localhost:8080/assets/default_header.png","followers_count":1,"following_count":1,"statuses_count":4,"last_status_at":"2021-10-20T10:41:37.000Z","emojis":[],"fields":[],"enable_rss":true,"role":"admin"},"max_toot_chars":5000}`, string(b)) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`{ + "uri": "http://localhost:8080", + "account_domain": "localhost:8080", + "title": "Geoff's Instance", + "description": "\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e", + "short_description": "\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e", + "email": "admin@example.org", + "version": "0.0.0-testrig", + "registrations": true, + "approval_required": true, + "invites_enabled": false, + "configuration": { + "statuses": { + "max_characters": 5000, + "max_media_attachments": 6, + "characters_reserved_per_url": 25 + }, + "media_attachments": { + "supported_mime_types": [ + "image/jpeg", + "image/gif", + "image/png", + "image/webp", + "video/mp4" + ], + "image_size_limit": 10485760, + "image_matrix_limit": 16777216, + "video_size_limit": 41943040, + "video_frame_rate_limit": 60, + "video_matrix_limit": 16777216 + }, + "polls": { + "max_options": 6, + "max_characters_per_option": 50, + "min_expiration": 300, + "max_expiration": 2629746 + }, + "accounts": { + "allow_custom_css": true + }, + "emojis": { + "emoji_size_limit": 51200 + } + }, + "urls": { + "streaming_api": "wss://localhost:8080" + }, + "stats": { + "domain_count": 2, + "status_count": 16, + "user_count": 4 + }, + "thumbnail": "http://localhost:8080/assets/logo.png", + "contact_account": { + "id": "01F8MH17FWEB39HZJ76B6VXSKF", + "username": "admin", + "acct": "admin", + "display_name": "", + "locked": false, + "bot": false, + "created_at": "2022-05-17T13:10:59.000Z", + "note": "", + "url": "http://localhost:8080/@admin", + "avatar": "", + "avatar_static": "", + "header": "http://localhost:8080/assets/default_header.png", + "header_static": "http://localhost:8080/assets/default_header.png", + "followers_count": 1, + "following_count": 1, + "statuses_count": 4, + "last_status_at": "2021-10-20T10:41:37.000Z", + "emojis": [], + "fields": [], + "enable_rss": true, + "role": "admin" + }, + "max_toot_chars": 5000 +}`, dst.String()) } func (suite *InstancePatchTestSuite) TestInstancePatch3() { @@ -124,8 +283,87 @@ func (suite *InstancePatchTestSuite) TestInstancePatch3() { b, err := io.ReadAll(result.Body) suite.NoError(err) - - suite.Equal(`{"uri":"http://localhost:8080","account_domain":"localhost:8080","title":"GoToSocial Testrig Instance","description":"\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e","short_description":"\u003cp\u003eThis is some html, which is \u003cem\u003eallowed\u003c/em\u003e in short descriptions.\u003c/p\u003e","email":"admin@example.org","version":"0.0.0-testrig","registrations":true,"approval_required":true,"invites_enabled":false,"configuration":{"statuses":{"max_characters":5000,"max_media_attachments":6,"characters_reserved_per_url":25},"media_attachments":{"supported_mime_types":["image/jpeg","image/gif","image/png","image/webp","video/mp4"],"image_size_limit":10485760,"image_matrix_limit":16777216,"video_size_limit":41943040,"video_frame_rate_limit":60,"video_matrix_limit":16777216},"polls":{"max_options":6,"max_characters_per_option":50,"min_expiration":300,"max_expiration":2629746},"accounts":{"allow_custom_css":true},"emojis":{"emoji_size_limit":51200}},"urls":{"streaming_api":"wss://localhost:8080"},"stats":{"domain_count":2,"status_count":16,"user_count":4},"thumbnail":"http://localhost:8080/assets/logo.png","contact_account":{"id":"01F8MH17FWEB39HZJ76B6VXSKF","username":"admin","acct":"admin","display_name":"","locked":false,"bot":false,"created_at":"2022-05-17T13:10:59.000Z","note":"","url":"http://localhost:8080/@admin","avatar":"","avatar_static":"","header":"http://localhost:8080/assets/default_header.png","header_static":"http://localhost:8080/assets/default_header.png","followers_count":1,"following_count":1,"statuses_count":4,"last_status_at":"2021-10-20T10:41:37.000Z","emojis":[],"fields":[],"enable_rss":true,"role":"admin"},"max_toot_chars":5000}`, string(b)) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`{ + "uri": "http://localhost:8080", + "account_domain": "localhost:8080", + "title": "GoToSocial Testrig Instance", + "description": "\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e", + "short_description": "\u003cp\u003eThis is some html, which is \u003cem\u003eallowed\u003c/em\u003e in short descriptions.\u003c/p\u003e", + "email": "admin@example.org", + "version": "0.0.0-testrig", + "registrations": true, + "approval_required": true, + "invites_enabled": false, + "configuration": { + "statuses": { + "max_characters": 5000, + "max_media_attachments": 6, + "characters_reserved_per_url": 25 + }, + "media_attachments": { + "supported_mime_types": [ + "image/jpeg", + "image/gif", + "image/png", + "image/webp", + "video/mp4" + ], + "image_size_limit": 10485760, + "image_matrix_limit": 16777216, + "video_size_limit": 41943040, + "video_frame_rate_limit": 60, + "video_matrix_limit": 16777216 + }, + "polls": { + "max_options": 6, + "max_characters_per_option": 50, + "min_expiration": 300, + "max_expiration": 2629746 + }, + "accounts": { + "allow_custom_css": true + }, + "emojis": { + "emoji_size_limit": 51200 + } + }, + "urls": { + "streaming_api": "wss://localhost:8080" + }, + "stats": { + "domain_count": 2, + "status_count": 16, + "user_count": 4 + }, + "thumbnail": "http://localhost:8080/assets/logo.png", + "contact_account": { + "id": "01F8MH17FWEB39HZJ76B6VXSKF", + "username": "admin", + "acct": "admin", + "display_name": "", + "locked": false, + "bot": false, + "created_at": "2022-05-17T13:10:59.000Z", + "note": "", + "url": "http://localhost:8080/@admin", + "avatar": "", + "avatar_static": "", + "header": "http://localhost:8080/assets/default_header.png", + "header_static": "http://localhost:8080/assets/default_header.png", + "followers_count": 1, + "following_count": 1, + "statuses_count": 4, + "last_status_at": "2021-10-20T10:41:37.000Z", + "emojis": [], + "fields": [], + "enable_rss": true, + "role": "admin" + }, + "max_toot_chars": 5000 +}`, dst.String()) } func (suite *InstancePatchTestSuite) TestInstancePatch4() { @@ -215,8 +453,87 @@ func (suite *InstancePatchTestSuite) TestInstancePatch6() { b, err := io.ReadAll(result.Body) suite.NoError(err) - - suite.Equal(`{"uri":"http://localhost:8080","account_domain":"localhost:8080","title":"GoToSocial Testrig Instance","description":"\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e","short_description":"\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e","email":"","version":"0.0.0-testrig","registrations":true,"approval_required":true,"invites_enabled":false,"configuration":{"statuses":{"max_characters":5000,"max_media_attachments":6,"characters_reserved_per_url":25},"media_attachments":{"supported_mime_types":["image/jpeg","image/gif","image/png","image/webp","video/mp4"],"image_size_limit":10485760,"image_matrix_limit":16777216,"video_size_limit":41943040,"video_frame_rate_limit":60,"video_matrix_limit":16777216},"polls":{"max_options":6,"max_characters_per_option":50,"min_expiration":300,"max_expiration":2629746},"accounts":{"allow_custom_css":true},"emojis":{"emoji_size_limit":51200}},"urls":{"streaming_api":"wss://localhost:8080"},"stats":{"domain_count":2,"status_count":16,"user_count":4},"thumbnail":"http://localhost:8080/assets/logo.png","contact_account":{"id":"01F8MH17FWEB39HZJ76B6VXSKF","username":"admin","acct":"admin","display_name":"","locked":false,"bot":false,"created_at":"2022-05-17T13:10:59.000Z","note":"","url":"http://localhost:8080/@admin","avatar":"","avatar_static":"","header":"http://localhost:8080/assets/default_header.png","header_static":"http://localhost:8080/assets/default_header.png","followers_count":1,"following_count":1,"statuses_count":4,"last_status_at":"2021-10-20T10:41:37.000Z","emojis":[],"fields":[],"enable_rss":true,"role":"admin"},"max_toot_chars":5000}`, string(b)) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`{ + "uri": "http://localhost:8080", + "account_domain": "localhost:8080", + "title": "GoToSocial Testrig Instance", + "description": "\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e", + "short_description": "\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e", + "email": "", + "version": "0.0.0-testrig", + "registrations": true, + "approval_required": true, + "invites_enabled": false, + "configuration": { + "statuses": { + "max_characters": 5000, + "max_media_attachments": 6, + "characters_reserved_per_url": 25 + }, + "media_attachments": { + "supported_mime_types": [ + "image/jpeg", + "image/gif", + "image/png", + "image/webp", + "video/mp4" + ], + "image_size_limit": 10485760, + "image_matrix_limit": 16777216, + "video_size_limit": 41943040, + "video_frame_rate_limit": 60, + "video_matrix_limit": 16777216 + }, + "polls": { + "max_options": 6, + "max_characters_per_option": 50, + "min_expiration": 300, + "max_expiration": 2629746 + }, + "accounts": { + "allow_custom_css": true + }, + "emojis": { + "emoji_size_limit": 51200 + } + }, + "urls": { + "streaming_api": "wss://localhost:8080" + }, + "stats": { + "domain_count": 2, + "status_count": 16, + "user_count": 4 + }, + "thumbnail": "http://localhost:8080/assets/logo.png", + "contact_account": { + "id": "01F8MH17FWEB39HZJ76B6VXSKF", + "username": "admin", + "acct": "admin", + "display_name": "", + "locked": false, + "bot": false, + "created_at": "2022-05-17T13:10:59.000Z", + "note": "", + "url": "http://localhost:8080/@admin", + "avatar": "", + "avatar_static": "", + "header": "http://localhost:8080/assets/default_header.png", + "header_static": "http://localhost:8080/assets/default_header.png", + "followers_count": 1, + "following_count": 1, + "statuses_count": 4, + "last_status_at": "2021-10-20T10:41:37.000Z", + "emojis": [], + "fields": [], + "enable_rss": true, + "role": "admin" + }, + "max_toot_chars": 5000 +}`, dst.String()) } func (suite *InstancePatchTestSuite) TestInstancePatch7() { @@ -270,17 +587,97 @@ func (suite *InstancePatchTestSuite) TestInstancePatch8() { result := recorder.Result() defer result.Body.Close() - b, err := io.ReadAll(result.Body) - suite.NoError(err) - instanceAccount, err := suite.db.GetInstanceAccount(context.Background(), "") if err != nil { suite.FailNow(err.Error()) } suite.NotEmpty(instanceAccount.AvatarMediaAttachmentID) - expectedInstanceResponse := fmt.Sprintf(`{"uri":"http://localhost:8080","account_domain":"localhost:8080","title":"GoToSocial Testrig Instance","description":"\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e","short_description":"\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e","email":"admin@example.org","version":"0.0.0-testrig","registrations":true,"approval_required":true,"invites_enabled":false,"configuration":{"statuses":{"max_characters":5000,"max_media_attachments":6,"characters_reserved_per_url":25},"media_attachments":{"supported_mime_types":["image/jpeg","image/gif","image/png","image/webp","video/mp4"],"image_size_limit":10485760,"image_matrix_limit":16777216,"video_size_limit":41943040,"video_frame_rate_limit":60,"video_matrix_limit":16777216},"polls":{"max_options":6,"max_characters_per_option":50,"min_expiration":300,"max_expiration":2629746},"accounts":{"allow_custom_css":true},"emojis":{"emoji_size_limit":51200}},"urls":{"streaming_api":"wss://localhost:8080"},"stats":{"domain_count":2,"status_count":16,"user_count":4},"thumbnail":"http://localhost:8080/fileserver/%s/attachment/original/%s.gif","thumbnail_type":"image/gif","thumbnail_description":"A bouncing little green peglin.","contact_account":{"id":"01F8MH17FWEB39HZJ76B6VXSKF","username":"admin","acct":"admin","display_name":"","locked":false,"bot":false,"created_at":"2022-05-17T13:10:59.000Z","note":"","url":"http://localhost:8080/@admin","avatar":"","avatar_static":"","header":"http://localhost:8080/assets/default_header.png","header_static":"http://localhost:8080/assets/default_header.png","followers_count":1,"following_count":1,"statuses_count":4,"last_status_at":"2021-10-20T10:41:37.000Z","emojis":[],"fields":[],"enable_rss":true,"role":"admin"},"max_toot_chars":5000}`, instanceAccount.ID, instanceAccount.AvatarMediaAttachmentID) - suite.Equal(expectedInstanceResponse, string(b)) + b, err := io.ReadAll(result.Body) + suite.NoError(err) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`{ + "uri": "http://localhost:8080", + "account_domain": "localhost:8080", + "title": "GoToSocial Testrig Instance", + "description": "\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e", + "short_description": "\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e", + "email": "admin@example.org", + "version": "0.0.0-testrig", + "registrations": true, + "approval_required": true, + "invites_enabled": false, + "configuration": { + "statuses": { + "max_characters": 5000, + "max_media_attachments": 6, + "characters_reserved_per_url": 25 + }, + "media_attachments": { + "supported_mime_types": [ + "image/jpeg", + "image/gif", + "image/png", + "image/webp", + "video/mp4" + ], + "image_size_limit": 10485760, + "image_matrix_limit": 16777216, + "video_size_limit": 41943040, + "video_frame_rate_limit": 60, + "video_matrix_limit": 16777216 + }, + "polls": { + "max_options": 6, + "max_characters_per_option": 50, + "min_expiration": 300, + "max_expiration": 2629746 + }, + "accounts": { + "allow_custom_css": true + }, + "emojis": { + "emoji_size_limit": 51200 + } + }, + "urls": { + "streaming_api": "wss://localhost:8080" + }, + "stats": { + "domain_count": 2, + "status_count": 16, + "user_count": 4 + }, + "thumbnail": "http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/attachment/original/`+instanceAccount.AvatarMediaAttachment.ID+`.gif",`+` + "thumbnail_type": "image/gif", + "thumbnail_description": "A bouncing little green peglin.", + "contact_account": { + "id": "01F8MH17FWEB39HZJ76B6VXSKF", + "username": "admin", + "acct": "admin", + "display_name": "", + "locked": false, + "bot": false, + "created_at": "2022-05-17T13:10:59.000Z", + "note": "", + "url": "http://localhost:8080/@admin", + "avatar": "", + "avatar_static": "", + "header": "http://localhost:8080/assets/default_header.png", + "header_static": "http://localhost:8080/assets/default_header.png", + "followers_count": 1, + "following_count": 1, + "statuses_count": 4, + "last_status_at": "2021-10-20T10:41:37.000Z", + "emojis": [], + "fields": [], + "enable_rss": true, + "role": "admin" + }, + "max_toot_chars": 5000 +}`, dst.String()) } func TestInstancePatchTestSuite(t *testing.T) { diff --git a/internal/api/client/instance/instancepeersget_test.go b/internal/api/client/instance/instancepeersget_test.go index 560fedac4..519931528 100644 --- a/internal/api/client/instance/instancepeersget_test.go +++ b/internal/api/client/instance/instancepeersget_test.go @@ -19,7 +19,9 @@ package instance_test import ( + "bytes" "context" + "encoding/json" "fmt" "io" "net/http" @@ -56,8 +58,13 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetNoParams() { b, err := io.ReadAll(result.Body) suite.NoError(err) - - suite.Equal(`["example.org","fossbros-anonymous.io"]`, string(b)) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`[ + "example.org", + "fossbros-anonymous.io" +]`, dst.String()) } func (suite *InstancePeersGetTestSuite) TestInstancePeersGetNoParamsUnauthorized() { @@ -98,8 +105,13 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetNoParamsAuthorized() b, err := io.ReadAll(result.Body) suite.NoError(err) - - suite.Equal(`["example.org","fossbros-anonymous.io"]`, string(b)) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`[ + "example.org", + "fossbros-anonymous.io" +]`, dst.String()) } func (suite *InstancePeersGetTestSuite) TestInstancePeersGetOnlySuspended() { @@ -117,8 +129,16 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetOnlySuspended() { b, err := io.ReadAll(result.Body) suite.NoError(err) - - suite.Equal(`[{"domain":"replyguys.com","suspended_at":"2020-05-13T13:29:12.000Z","public_comment":"reply-guying to tech posts"}]`, string(b)) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`[ + { + "domain": "replyguys.com", + "suspended_at": "2020-05-13T13:29:12.000Z", + "public_comment": "reply-guying to tech posts" + } +]`, dst.String()) } func (suite *InstancePeersGetTestSuite) TestInstancePeersGetOnlySuspendedUnauthorized() { @@ -159,8 +179,16 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetOnlySuspendedAuthori b, err := io.ReadAll(result.Body) suite.NoError(err) - - suite.Equal(`[{"domain":"replyguys.com","suspended_at":"2020-05-13T13:29:12.000Z","public_comment":"reply-guying to tech posts"}]`, string(b)) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`[ + { + "domain": "replyguys.com", + "suspended_at": "2020-05-13T13:29:12.000Z", + "public_comment": "reply-guying to tech posts" + } +]`, dst.String()) } func (suite *InstancePeersGetTestSuite) TestInstancePeersGetAll() { @@ -178,8 +206,22 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetAll() { b, err := io.ReadAll(result.Body) suite.NoError(err) - - suite.Equal(`[{"domain":"example.org"},{"domain":"fossbros-anonymous.io"},{"domain":"replyguys.com","suspended_at":"2020-05-13T13:29:12.000Z","public_comment":"reply-guying to tech posts"}]`, string(b)) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`[ + { + "domain": "example.org" + }, + { + "domain": "fossbros-anonymous.io" + }, + { + "domain": "replyguys.com", + "suspended_at": "2020-05-13T13:29:12.000Z", + "public_comment": "reply-guying to tech posts" + } +]`, dst.String()) } func (suite *InstancePeersGetTestSuite) TestInstancePeersGetAllWithObfuscated() { @@ -208,8 +250,27 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetAllWithObfuscated() b, err := io.ReadAll(result.Body) suite.NoError(err) - - suite.Equal(`[{"domain":"example.org"},{"domain":"fossbros-anonymous.io"},{"domain":"o*g.*u**.t**.*or*t.*r**ev**","suspended_at":"2021-06-09T10:34:55.000Z","public_comment":"just absolutely the worst, wowza"},{"domain":"replyguys.com","suspended_at":"2020-05-13T13:29:12.000Z","public_comment":"reply-guying to tech posts"}]`, string(b)) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`[ + { + "domain": "example.org" + }, + { + "domain": "fossbros-anonymous.io" + }, + { + "domain": "o*g.*u**.t**.*or*t.*r**ev**", + "suspended_at": "2021-06-09T10:34:55.000Z", + "public_comment": "just absolutely the worst, wowza" + }, + { + "domain": "replyguys.com", + "suspended_at": "2020-05-13T13:29:12.000Z", + "public_comment": "reply-guying to tech posts" + } +]`, dst.String()) } func (suite *InstancePeersGetTestSuite) TestInstancePeersGetFunkyParams() { diff --git a/internal/api/model/source.go b/internal/api/model/source.go index f3b7beb49..9e2eafa0a 100644 --- a/internal/api/model/source.go +++ b/internal/api/model/source.go @@ -26,11 +26,11 @@ type Source struct { // unlisted = Unlisted post // private = Followers-only post // direct = Direct post - Privacy Visibility `json:"privacy,omitempty"` + Privacy Visibility `json:"privacy"` // Whether new statuses should be marked sensitive by default. - Sensitive bool `json:"sensitive,omitempty"` + Sensitive bool `json:"sensitive"` // The default posting language for new statuses. - Language string `json:"language,omitempty"` + Language string `json:"language"` // The default posting format for new statuses. StatusFormat string `json:"status_format"` // Profile bio. @@ -38,5 +38,5 @@ type Source struct { // Metadata about the account. Fields []Field `json:"fields"` // The number of pending follow requests. - FollowRequestsCount int `json:"follow_requests_count,omitempty"` + FollowRequestsCount int `json:"follow_requests_count"` } diff --git a/internal/api/wellknown/webfinger/webfingerget_test.go b/internal/api/wellknown/webfinger/webfingerget_test.go index cbc37dce1..7587dfee1 100644 --- a/internal/api/wellknown/webfinger/webfingerget_test.go +++ b/internal/api/wellknown/webfinger/webfingerget_test.go @@ -19,14 +19,15 @@ package webfinger_test import ( + "bytes" "context" + "encoding/json" "fmt" "io/ioutil" "net/http" "net/http/httptest" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/api/wellknown/webfinger" "github.com/superseriousbusiness/gotosocial/internal/concurrency" @@ -61,9 +62,29 @@ func (suite *WebfingerGetTestSuite) TestFingerUser() { result := recorder.Result() defer result.Body.Close() b, err := ioutil.ReadAll(result.Body) - assert.NoError(suite.T(), err) - - suite.Equal(`{"subject":"acct:the_mighty_zork@localhost:8080","aliases":["http://localhost:8080/users/the_mighty_zork","http://localhost:8080/@the_mighty_zork"],"links":[{"rel":"http://webfinger.net/rel/profile-page","type":"text/html","href":"http://localhost:8080/@the_mighty_zork"},{"rel":"self","type":"application/activity+json","href":"http://localhost:8080/users/the_mighty_zork"}]}`, string(b)) + suite.NoError(err) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`{ + "subject": "acct:the_mighty_zork@localhost:8080", + "aliases": [ + "http://localhost:8080/users/the_mighty_zork", + "http://localhost:8080/@the_mighty_zork" + ], + "links": [ + { + "rel": "http://webfinger.net/rel/profile-page", + "type": "text/html", + "href": "http://localhost:8080/@the_mighty_zork" + }, + { + "rel": "self", + "type": "application/activity+json", + "href": "http://localhost:8080/users/the_mighty_zork" + } + ] +}`, dst.String()) } func (suite *WebfingerGetTestSuite) TestFingerUserWithDifferentAccountDomainByHost() { @@ -98,9 +119,29 @@ func (suite *WebfingerGetTestSuite) TestFingerUserWithDifferentAccountDomainByHo result := recorder.Result() defer result.Body.Close() b, err := ioutil.ReadAll(result.Body) - assert.NoError(suite.T(), err) - - suite.Equal(`{"subject":"acct:aaaaa@example.org","aliases":["http://gts.example.org/users/aaaaa","http://gts.example.org/@aaaaa"],"links":[{"rel":"http://webfinger.net/rel/profile-page","type":"text/html","href":"http://gts.example.org/@aaaaa"},{"rel":"self","type":"application/activity+json","href":"http://gts.example.org/users/aaaaa"}]}`, string(b)) + suite.NoError(err) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`{ + "subject": "acct:aaaaa@example.org", + "aliases": [ + "http://gts.example.org/users/aaaaa", + "http://gts.example.org/@aaaaa" + ], + "links": [ + { + "rel": "http://webfinger.net/rel/profile-page", + "type": "text/html", + "href": "http://gts.example.org/@aaaaa" + }, + { + "rel": "self", + "type": "application/activity+json", + "href": "http://gts.example.org/users/aaaaa" + } + ] +}`, dst.String()) } func (suite *WebfingerGetTestSuite) TestFingerUserWithDifferentAccountDomainByAccountDomain() { @@ -135,9 +176,29 @@ func (suite *WebfingerGetTestSuite) TestFingerUserWithDifferentAccountDomainByAc result := recorder.Result() defer result.Body.Close() b, err := ioutil.ReadAll(result.Body) - assert.NoError(suite.T(), err) - - suite.Equal(`{"subject":"acct:aaaaa@example.org","aliases":["http://gts.example.org/users/aaaaa","http://gts.example.org/@aaaaa"],"links":[{"rel":"http://webfinger.net/rel/profile-page","type":"text/html","href":"http://gts.example.org/@aaaaa"},{"rel":"self","type":"application/activity+json","href":"http://gts.example.org/users/aaaaa"}]}`, string(b)) + suite.NoError(err) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`{ + "subject": "acct:aaaaa@example.org", + "aliases": [ + "http://gts.example.org/users/aaaaa", + "http://gts.example.org/@aaaaa" + ], + "links": [ + { + "rel": "http://webfinger.net/rel/profile-page", + "type": "text/html", + "href": "http://gts.example.org/@aaaaa" + }, + { + "rel": "self", + "type": "application/activity+json", + "href": "http://gts.example.org/users/aaaaa" + } + ] +}`, dst.String()) } func (suite *WebfingerGetTestSuite) TestFingerUserWithoutAcct() { @@ -161,9 +222,29 @@ func (suite *WebfingerGetTestSuite) TestFingerUserWithoutAcct() { result := recorder.Result() defer result.Body.Close() b, err := ioutil.ReadAll(result.Body) - assert.NoError(suite.T(), err) - - suite.Equal(`{"subject":"acct:the_mighty_zork@localhost:8080","aliases":["http://localhost:8080/users/the_mighty_zork","http://localhost:8080/@the_mighty_zork"],"links":[{"rel":"http://webfinger.net/rel/profile-page","type":"text/html","href":"http://localhost:8080/@the_mighty_zork"},{"rel":"self","type":"application/activity+json","href":"http://localhost:8080/users/the_mighty_zork"}]}`, string(b)) + suite.NoError(err) + dst := new(bytes.Buffer) + err = json.Indent(dst, b, "", " ") + suite.NoError(err) + suite.Equal(`{ + "subject": "acct:the_mighty_zork@localhost:8080", + "aliases": [ + "http://localhost:8080/users/the_mighty_zork", + "http://localhost:8080/@the_mighty_zork" + ], + "links": [ + { + "rel": "http://webfinger.net/rel/profile-page", + "type": "text/html", + "href": "http://localhost:8080/@the_mighty_zork" + }, + { + "rel": "self", + "type": "application/activity+json", + "href": "http://localhost:8080/users/the_mighty_zork" + } + ] +}`, dst.String()) } func TestWebfingerGetTestSuite(t *testing.T) { |