diff options
Diffstat (limited to 'testrig')
-rw-r--r-- | testrig/db.go | 7 | ||||
-rw-r--r-- | testrig/testmodels.go | 50 | ||||
-rw-r--r-- | testrig/transportcontroller.go | 8 |
3 files changed, 65 insertions, 0 deletions
diff --git a/testrig/db.go b/testrig/db.go index 88237d7d0..2e974f100 100644 --- a/testrig/db.go +++ b/testrig/db.go @@ -55,6 +55,7 @@ var testModels = []interface{}{ >smodel.RouterSession{}, >smodel.Token{}, >smodel.Client{}, + >smodel.Tombstone{}, } // NewTestDB returns a new initialized, empty database for testing. @@ -240,6 +241,12 @@ func StandardDBSetup(db db.DB, accounts map[string]*gtsmodel.Account) { } } + for _, v := range NewTestTombstones() { + if err := db.Put(ctx, v); err != nil { + log.Panic(err) + } + } + if err := db.CreateInstanceAccount(ctx); err != nil { log.Panic(err) } diff --git a/testrig/testmodels.go b/testrig/testmodels.go index fa2eabf04..9f987eeae 100644 --- a/testrig/testmodels.go +++ b/testrig/testmodels.go @@ -583,6 +583,18 @@ func NewTestAccounts() map[string]*gtsmodel.Account { return accounts } +func NewTestTombstones() map[string]*gtsmodel.Tombstone { + return map[string]*gtsmodel.Tombstone{ + "https://somewhere.mysterious/users/rest_in_piss#main-key": { + ID: "01GHBTVE9HQPPBDH2W5VH2DGN4", + CreatedAt: TimeMustParse("2021-11-09T19:33:45Z"), + UpdatedAt: TimeMustParse("2021-11-09T19:33:45Z"), + Domain: "somewhere.mysterious", + URI: "https://somewhere.mysterious/users/rest_in_piss#main-key", + }, + } +} + // NewTestAttachments returns a map of attachments keyed according to which account // and status they belong to, and which attachment number of that status they are. func NewTestAttachments() map[string]*gtsmodel.MediaAttachment { @@ -1835,6 +1847,16 @@ func NewTestActivities(accounts map[string]*gtsmodel.Account) map[string]Activit ) announceForwarded2ZorkSig, announceForwarded2ZorkDigest, announceForwarded2ZorkDate := GetSignatureForActivity(announceForwarded2Zork, accounts["remote_account_1"].PublicKeyURI, accounts["remote_account_1"].PrivateKey, URLMustParse(accounts["local_account_1"].InboxURI)) + deleteForRemoteAccount3 := newAPDelete( + URLMustParse("https://somewhere.mysterious/users/rest_in_piss"), + URLMustParse("https://somewhere.mysterious/users/rest_in_piss"), + TimeMustParse("2022-07-13T12:13:12+02:00"), + URLMustParse(accounts["local_account_1"].URI), + ) + // it doesn't really matter what key we use to sign this, since we're not going to be able to verify if anyway + keyToSignDelete := accounts["remote_account_1"].PrivateKey + deleteForRemoteAccount3Sig, deleteForRemoteAccount3Digest, deleteForRemoteAccount3Date := GetSignatureForActivity(deleteForRemoteAccount3, "https://somewhere.mysterious/users/rest_in_piss#main-key", keyToSignDelete, URLMustParse(accounts["local_account_1"].InboxURI)) + return map[string]ActivityWithSignature{ "dm_for_zork": { Activity: createDmForZork, @@ -1878,6 +1900,12 @@ func NewTestActivities(accounts map[string]*gtsmodel.Account) map[string]Activit DigestHeader: announceForwarded2ZorkDigest, DateHeader: announceForwarded2ZorkDate, }, + "delete_https://somewhere.mysterious/users/rest_in_piss#main-key": { + Activity: deleteForRemoteAccount3, + SignatureHeader: deleteForRemoteAccount3Sig, + DigestHeader: deleteForRemoteAccount3Digest, + DateHeader: deleteForRemoteAccount3Date, + }, } } @@ -3151,3 +3179,25 @@ func newAPAnnounce(announceID *url.URL, announceActor *url.URL, announcePublishe return announce } + +func newAPDelete(deleteTarget *url.URL, deleteActor *url.URL, deletePublished time.Time, deleteTo *url.URL) vocab.ActivityStreamsDelete { + delete := streams.NewActivityStreamsDelete() + + objectProp := streams.NewActivityStreamsObjectProperty() + objectProp.AppendIRI(deleteTarget) + delete.SetActivityStreamsObject(objectProp) + + to := streams.NewActivityStreamsToProperty() + to.AppendIRI(deleteTo) + delete.SetActivityStreamsTo(to) + + actor := streams.NewActivityStreamsActorProperty() + actor.AppendIRI(deleteActor) + delete.SetActivityStreamsActor(actor) + + published := streams.NewActivityStreamsPublishedProperty() + published.Set(deletePublished) + delete.SetActivityStreamsPublished(published) + + return delete +} diff --git a/testrig/transportcontroller.go b/testrig/transportcontroller.go index 70f2f0c61..18c3094d5 100644 --- a/testrig/transportcontroller.go +++ b/testrig/transportcontroller.go @@ -33,6 +33,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/concurrency" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/federation" + "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/log" "github.com/superseriousbusiness/gotosocial/internal/messages" "github.com/superseriousbusiness/gotosocial/internal/transport" @@ -65,6 +66,7 @@ type MockHTTPClient struct { testRemoteServices map[string]vocab.ActivityStreamsService testRemoteAttachments map[string]RemoteAttachmentFile testRemoteEmojis map[string]vocab.TootEmoji + testTombstones map[string]*gtsmodel.Tombstone SentMessages sync.Map } @@ -92,6 +94,7 @@ func NewMockHTTPClient(do func(req *http.Request) (*http.Response, error), relat mockHTTPClient.testRemoteServices = NewTestFediServices() mockHTTPClient.testRemoteAttachments = NewTestFediAttachments(relativeMediaPath) mockHTTPClient.testRemoteEmojis = NewTestFediEmojis() + mockHTTPClient.testTombstones = NewTestTombstones() mockHTTPClient.do = func(req *http.Request) (*http.Response, error) { responseCode := http.StatusNotFound @@ -193,6 +196,11 @@ func NewMockHTTPClient(do func(req *http.Request) (*http.Response, error), relat responseBytes = attachment.Data responseContentType = attachment.ContentType responseContentLength = len(attachment.Data) + } else if _, ok := mockHTTPClient.testTombstones[req.URL.String()]; ok { + responseCode = http.StatusGone + responseBytes = []byte{} + responseContentType = "text/html" + responseContentLength = 0 } log.Debugf("returning response %s", string(responseBytes)) |