account_test.go (3178B)
1 // GoToSocial 2 // Copyright (C) GoToSocial Authors admin@gotosocial.org 3 // SPDX-License-Identifier: AGPL-3.0-or-later 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package processing_test 19 20 import ( 21 "context" 22 "encoding/json" 23 "fmt" 24 "testing" 25 "time" 26 27 "github.com/stretchr/testify/suite" 28 "github.com/superseriousbusiness/activity/pub" 29 "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" 30 "github.com/superseriousbusiness/gotosocial/testrig" 31 ) 32 33 type AccountTestSuite struct { 34 ProcessingStandardTestSuite 35 } 36 37 func (suite *AccountTestSuite) TestAccountDeleteLocal() { 38 ctx := context.Background() 39 deletingAccount := suite.testAccounts["local_account_1"] 40 followingAccount := suite.testAccounts["remote_account_1"] 41 42 // make the following account follow the deleting account so that a delete message will be sent to it via the federating API 43 follow := >smodel.Follow{ 44 ID: "01FJ1S8DX3STJJ6CEYPMZ1M0R3", 45 CreatedAt: time.Now(), 46 UpdatedAt: time.Now(), 47 URI: fmt.Sprintf("%s/follow/01FJ1S8DX3STJJ6CEYPMZ1M0R3", followingAccount.URI), 48 AccountID: followingAccount.ID, 49 TargetAccountID: deletingAccount.ID, 50 } 51 err := suite.db.Put(ctx, follow) 52 suite.NoError(err) 53 54 errWithCode := suite.processor.Account().DeleteSelf(ctx, suite.testAccounts["local_account_1"]) 55 suite.NoError(errWithCode) 56 57 // the delete should be federated outwards to the following account's inbox 58 var sent [][]byte 59 delete := new(struct { 60 Actor string `json:"actor"` 61 ID string `json:"id"` 62 Object string `json:"object"` 63 To string `json:"to"` 64 CC string `json:"cc"` 65 Type string `json:"type"` 66 }) 67 68 if !testrig.WaitFor(func() bool { 69 sentI, ok := suite.httpClient.SentMessages.Load(*followingAccount.SharedInboxURI) 70 if ok { 71 sent, ok = sentI.([][]byte) 72 if !ok { 73 panic("SentMessages entry was not [][]byte") 74 } 75 err = json.Unmarshal(sent[0], delete) 76 return err == nil 77 } 78 return false 79 }) { 80 suite.FailNow("timed out waiting for message") 81 } 82 83 suite.Equal(deletingAccount.URI, delete.Actor) 84 suite.Equal(deletingAccount.URI, delete.Object) 85 suite.Equal(deletingAccount.FollowersURI, delete.To) 86 suite.Equal(pub.PublicActivityPubIRI, delete.CC) 87 suite.Equal("Delete", delete.Type) 88 89 if !testrig.WaitFor(func() bool { 90 dbAccount, _ := suite.db.GetAccountByID(ctx, deletingAccount.ID) 91 return !dbAccount.SuspendedAt.IsZero() 92 }) { 93 suite.FailNow("timed out waiting for account to be deleted") 94 } 95 } 96 97 func TestAccountTestSuite(t *testing.T) { 98 suite.Run(t, &AccountTestSuite{}) 99 }