mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[feature] Read + Write tombstones for deleted Actors (#1005)
* [feature] Read + Write tombstones for deleted Actors * copyTombstone * update to use resultcache instead of old ttl cache Signed-off-by: kim <grufwub@gmail.com> * update go-cache library to fix result cache capacity / ordering bugs Signed-off-by: kim <grufwub@gmail.com> * bump go-cache/v3 to v3.1.6 to fix bugs Signed-off-by: kim <grufwub@gmail.com> * switch on status code * better explain ErrGone reasoning Signed-off-by: kim <grufwub@gmail.com> Co-authored-by: kim <grufwub@gmail.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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))
|
||||
|
Reference in New Issue
Block a user