diff options
author | 2023-03-31 15:01:29 +0200 | |
---|---|---|
committer | 2023-03-31 15:01:29 +0200 | |
commit | d9bbcc60a6cd32282de907a2090c674c4616219e (patch) | |
tree | c007cf145ebe24fcc3de420020722a4ea70fb803 /internal/typeutils | |
parent | [bugfix] Fix relationship not updating 'following' on accept follow request (... (diff) | |
download | gotosocial-d9bbcc60a6cd32282de907a2090c674c4616219e.tar.xz |
[bugfix] Fix report serialization errors caused by user delete (#1659)
* [bugfix] Fix report serialization errors caused by user delete
* fix tests
Diffstat (limited to 'internal/typeutils')
-rw-r--r-- | internal/typeutils/converter_test.go | 23 | ||||
-rw-r--r-- | internal/typeutils/internaltofrontend.go | 11 | ||||
-rw-r--r-- | internal/typeutils/internaltofrontend_test.go | 232 |
3 files changed, 254 insertions, 12 deletions
diff --git a/internal/typeutils/converter_test.go b/internal/typeutils/converter_test.go index 88c0256c8..d92a30c13 100644 --- a/internal/typeutils/converter_test.go +++ b/internal/typeutils/converter_test.go @@ -22,6 +22,7 @@ import ( "github.com/superseriousbusiness/activity/streams/vocab" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" + "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/state" "github.com/superseriousbusiness/gotosocial/internal/typeutils" "github.com/superseriousbusiness/gotosocial/testrig" @@ -482,13 +483,17 @@ type TypeUtilsTestSuite struct { typeconverter typeutils.TypeConverter } -func (suite *TypeUtilsTestSuite) SetupSuite() { +func (suite *TypeUtilsTestSuite) SetupTest() { suite.state.Caches.Init() testrig.InitTestConfig() testrig.InitTestLog() suite.db = testrig.NewTestDB(&suite.state) + suite.state.DB = suite.db + storage := testrig.NewInMemoryStorage() + suite.state.Storage = storage + suite.testAccounts = testrig.NewTestAccounts() suite.testStatuses = testrig.NewTestStatuses() suite.testAttachments = testrig.NewTestAttachments() @@ -497,13 +502,23 @@ func (suite *TypeUtilsTestSuite) SetupSuite() { suite.testReports = testrig.NewTestReports() suite.testMentions = testrig.NewTestMentions() suite.typeconverter = typeutils.NewConverter(suite.db) -} -func (suite *TypeUtilsTestSuite) SetupTest() { - suite.state.Caches.Init() // reset testrig.StandardDBSetup(suite.db, nil) } func (suite *TypeUtilsTestSuite) TearDownTest() { testrig.StandardDBTeardown(suite.db) + testrig.StopWorkers(&suite.state) +} + +// GetProcessor is a utility function that instantiates a processor. +// Useful when a test in the test suite needs to change some state. +func (suite *TypeUtilsTestSuite) GetProcessor() *processing.Processor { + testrig.StartWorkers(&suite.state) + httpClient := testrig.NewMockHTTPClient(nil, "../../testrig/media") + transportController := testrig.NewTestTransportController(&suite.state, httpClient) + mediaManager := testrig.NewTestMediaManager(&suite.state) + federator := testrig.NewTestFederator(&suite.state, transportController, mediaManager) + emailSender := testrig.NewEmailSender("../../web/template/", nil) + return testrig.NewTestProcessor(&suite.state, federator, emailSender, mediaManager) } diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go index 198bed099..74b061fb0 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -270,7 +270,7 @@ func (c *converter) AccountToAdminAPIAccount(ctx context.Context, a *gtsmodel.Ac ) // take user-level information if possible - if a.Domain != "" { + if a.IsRemote() { domain = &a.Domain } else { user, err := c.db.GetUserByAccountID(ctx, a.ID) @@ -289,7 +289,9 @@ func (c *converter) AccountToAdminAPIAccount(ctx context.Context, a *gtsmodel.Ac } locale = user.Locale - inviteRequest = &user.Account.Reason + if user.Account.Reason != "" { + inviteRequest = &user.Account.Reason + } if *user.Admin { role.Name = apimodel.AccountRoleAdmin } else if *user.Moderator { @@ -298,11 +300,12 @@ func (c *converter) AccountToAdminAPIAccount(ctx context.Context, a *gtsmodel.Ac confirmed = !user.ConfirmedAt.IsZero() approved = *user.Approved disabled = *user.Disabled - silenced = !user.Account.SilencedAt.IsZero() - suspended = !user.Account.SuspendedAt.IsZero() createdByApplicationID = user.CreatedByApplicationID } + silenced = !a.SilencedAt.IsZero() + suspended = !a.SuspendedAt.IsZero() + apiAccount, err := c.AccountToAPIAccountPublic(ctx, a) if err != nil { return nil, fmt.Errorf("AccountToAdminAPIAccount: error converting account to api account for account id %s: %w", a.ID, err) diff --git a/internal/typeutils/internaltofrontend_test.go b/internal/typeutils/internaltofrontend_test.go index 40e074fe3..993dc920b 100644 --- a/internal/typeutils/internaltofrontend_test.go +++ b/internal/typeutils/internaltofrontend_test.go @@ -26,6 +26,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" + "github.com/superseriousbusiness/gotosocial/testrig" ) type InternalToFrontendTestSuite struct { @@ -908,7 +909,7 @@ func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontend1() { "ip": "118.44.18.196", "ips": [], "locale": "en", - "invite_request": "", + "invite_request": null, "role": { "name": "user" }, @@ -953,7 +954,7 @@ func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontend1() { "ip": "89.122.255.1", "ips": [], "locale": "en", - "invite_request": "", + "invite_request": null, "role": { "name": "admin" }, @@ -999,7 +1000,7 @@ func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontend1() { "ip": "89.122.255.1", "ips": [], "locale": "en", - "invite_request": "", + "invite_request": null, "role": { "name": "admin" }, @@ -1068,7 +1069,7 @@ func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontend2() { "ip": "118.44.18.196", "ips": [], "locale": "en", - "invite_request": "", + "invite_request": null, "role": { "name": "user" }, @@ -1234,6 +1235,229 @@ func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontend2() { }`, string(b)) } +func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontendSuspendedLocalAccount() { + ctx := context.Background() + requestingAccount := suite.testAccounts["admin_account"] + reportedAccount := >smodel.Account{} + *reportedAccount = *suite.testAccounts["local_account_2"] + + // Suspend/delete the reported account. + if err := suite.GetProcessor().Account().Delete(ctx, reportedAccount, requestingAccount.ID); err != nil { + suite.FailNow(err.Error()) + } + + // Wait for the delete to process. Stubbifying + // the account is the last part of the delete, + // so once it's stubbified we know we're done. + if !testrig.WaitFor(func() bool { + dbAccount, err := suite.db.GetAccountByID(ctx, reportedAccount.ID) + if err != nil { + suite.FailNow(err.Error()) + } + return dbAccount.DisplayName == "" + }) { + suite.FailNow("timed out waiting for account delete") + } + + adminReport, err := suite.typeconverter.ReportToAdminAPIReport(context.Background(), suite.testReports["remote_account_1_report_local_account_2"], requestingAccount) + suite.NoError(err) + + b, err := json.MarshalIndent(adminReport, "", " ") + suite.NoError(err) + + suite.Equal(`{ + "id": "01GP3DFY9XQ1TJMZT5BGAZPXX7", + "action_taken": true, + "action_taken_at": "2022-05-15T15:01:56.000Z", + "category": "other", + "comment": "this is a turtle, not a person, therefore should not be a poster", + "forwarded": true, + "created_at": "2022-05-15T14:20:12.000Z", + "updated_at": "2022-05-15T14:20:12.000Z", + "account": { + "id": "01F8MH5ZK5VRH73AKHQM6Y9VNX", + "username": "foss_satan", + "domain": "fossbros-anonymous.io", + "created_at": "2021-09-26T10:52:36.000Z", + "email": "", + "ip": null, + "ips": [], + "locale": "", + "invite_request": null, + "role": { + "name": "user" + }, + "confirmed": false, + "approved": false, + "disabled": false, + "silenced": false, + "suspended": false, + "account": { + "id": "01F8MH5ZK5VRH73AKHQM6Y9VNX", + "username": "foss_satan", + "acct": "foss_satan@fossbros-anonymous.io", + "display_name": "big gerald", + "locked": false, + "discoverable": true, + "bot": false, + "created_at": "2021-09-26T10:52:36.000Z", + "note": "i post about like, i dunno, stuff, or whatever!!!!", + "url": "http://fossbros-anonymous.io/@foss_satan", + "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": 1, + "last_status_at": "2021-09-20T10:40:37.000Z", + "emojis": [], + "fields": [] + } + }, + "target_account": { + "id": "01F8MH5NBDF2MV7CTC4Q5128HF", + "username": "1happyturtle", + "domain": null, + "created_at": "2022-06-04T13:12:00.000Z", + "email": "tortle.dude@example.org", + "ip": "0.0.0.0", + "ips": [], + "locale": "", + "invite_request": null, + "role": { + "name": "user" + }, + "confirmed": true, + "approved": true, + "disabled": false, + "silenced": false, + "suspended": true, + "account": { + "id": "01F8MH5NBDF2MV7CTC4Q5128HF", + "username": "1happyturtle", + "acct": "1happyturtle", + "display_name": "", + "locked": true, + "discoverable": false, + "bot": false, + "created_at": "2022-06-04T13:12:00.000Z", + "note": "", + "url": "http://localhost:8080/@1happyturtle", + "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": [], + "suspended": true, + "role": { + "name": "user" + } + } + }, + "assigned_account": { + "id": "01F8MH17FWEB39HZJ76B6VXSKF", + "username": "admin", + "domain": null, + "created_at": "2022-05-17T13:10:59.000Z", + "email": "admin@example.org", + "ip": "89.122.255.1", + "ips": [], + "locale": "en", + "invite_request": null, + "role": { + "name": "admin" + }, + "confirmed": true, + "approved": true, + "disabled": false, + "silenced": false, + "suspended": false, + "account": { + "id": "01F8MH17FWEB39HZJ76B6VXSKF", + "username": "admin", + "acct": "admin", + "display_name": "", + "locked": false, + "discoverable": true, + "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": { + "name": "admin" + } + }, + "created_by_application_id": "01F8MGXQRHYF5QPMTMXP78QC2F" + }, + "action_taken_by_account": { + "id": "01F8MH17FWEB39HZJ76B6VXSKF", + "username": "admin", + "domain": null, + "created_at": "2022-05-17T13:10:59.000Z", + "email": "admin@example.org", + "ip": "89.122.255.1", + "ips": [], + "locale": "en", + "invite_request": null, + "role": { + "name": "admin" + }, + "confirmed": true, + "approved": true, + "disabled": false, + "silenced": false, + "suspended": false, + "account": { + "id": "01F8MH17FWEB39HZJ76B6VXSKF", + "username": "admin", + "acct": "admin", + "display_name": "", + "locked": false, + "discoverable": true, + "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": { + "name": "admin" + } + }, + "created_by_application_id": "01F8MGXQRHYF5QPMTMXP78QC2F" + }, + "statuses": [], + "rule_ids": [], + "action_taken_comment": "user was warned not to be a turtle anymore" +}`, string(b)) +} + func TestInternalToFrontendTestSuite(t *testing.T) { suite.Run(t, new(InternalToFrontendTestSuite)) } |