summaryrefslogtreecommitdiff
path: root/internal/federation
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-05-27 16:35:35 +0200
committerLibravatar GitHub <noreply@github.com>2022-05-27 16:35:35 +0200
commitdc8cc7e364de3342c84c2329da6a0addfcbba273 (patch)
tree2645e28ba4ba97014582075c577b011dafb79c16 /internal/federation
parent[performance] Don't retry/backoff invalid http requests that will never succe... (diff)
downloadgotosocial-dc8cc7e364de3342c84c2329da6a0addfcbba273.tar.xz
[chore] Add test for dereferencing Owncast service account (#613)
Diffstat (limited to 'internal/federation')
-rw-r--r--internal/federation/dereferencing/account_test.go20
-rw-r--r--internal/federation/dereferencing/dereferencer_test.go15
2 files changed, 35 insertions, 0 deletions
diff --git a/internal/federation/dereferencing/account_test.go b/internal/federation/dereferencing/account_test.go
index cb6f9588c..75c02af75 100644
--- a/internal/federation/dereferencing/account_test.go
+++ b/internal/federation/dereferencing/account_test.go
@@ -51,6 +51,26 @@ func (suite *AccountTestSuite) TestDereferenceGroup() {
suite.Equal(ap.ActorGroup, dbGroup.ActorType)
}
+func (suite *AccountTestSuite) TestDereferenceService() {
+ fetchingAccount := suite.testAccounts["local_account_1"]
+
+ serviceURL := testrig.URLMustParse("https://owncast.example.org/federation/user/rgh")
+ service, err := suite.dereferencer.GetRemoteAccount(context.Background(), fetchingAccount.Username, serviceURL, false, false)
+ suite.NoError(err)
+ suite.NotNil(service)
+ suite.NotNil(service)
+
+ // service values should be set
+ suite.Equal("https://owncast.example.org/federation/user/rgh", service.URI)
+ suite.Equal("https://owncast.example.org/federation/user/rgh", service.URL)
+
+ // service should be in the database
+ dbService, err := suite.db.GetAccountByURI(context.Background(), service.URI)
+ suite.NoError(err)
+ suite.Equal(service.ID, dbService.ID)
+ suite.Equal(ap.ActorService, dbService.ActorType)
+}
+
func TestAccountTestSuite(t *testing.T) {
suite.Run(t, new(AccountTestSuite))
}
diff --git a/internal/federation/dereferencing/dereferencer_test.go b/internal/federation/dereferencing/dereferencer_test.go
index 339490e5d..96ec7869f 100644
--- a/internal/federation/dereferencing/dereferencer_test.go
+++ b/internal/federation/dereferencing/dereferencer_test.go
@@ -46,6 +46,7 @@ type DereferencerStandardTestSuite struct {
testRemoteStatuses map[string]vocab.ActivityStreamsNote
testRemotePeople map[string]vocab.ActivityStreamsPerson
testRemoteGroups map[string]vocab.ActivityStreamsGroup
+ testRemoteServices map[string]vocab.ActivityStreamsService
testRemoteAttachments map[string]testrig.RemoteAttachmentFile
testAccounts map[string]*gtsmodel.Account
@@ -60,6 +61,7 @@ func (suite *DereferencerStandardTestSuite) SetupTest() {
suite.testRemoteStatuses = testrig.NewTestFediStatuses()
suite.testRemotePeople = testrig.NewTestFediPeople()
suite.testRemoteGroups = testrig.NewTestFediGroups()
+ suite.testRemoteServices = testrig.NewTestFediServices()
suite.testRemoteAttachments = testrig.NewTestFediAttachments("../../../testrig/media")
suite.db = testrig.NewTestDB()
@@ -126,6 +128,19 @@ func (suite *DereferencerStandardTestSuite) mockTransportController() transport.
responseType = "application/activity+json"
}
+ if service, ok := suite.testRemoteServices[req.URL.String()]; ok {
+ serviceI, err := streams.Serialize(service)
+ if err != nil {
+ panic(err)
+ }
+ serviceJson, err := json.Marshal(serviceI)
+ if err != nil {
+ panic(err)
+ }
+ responseBytes = serviceJson
+ responseType = "application/activity+json"
+ }
+
if attachment, ok := suite.testRemoteAttachments[req.URL.String()]; ok {
responseBytes = attachment.Data
responseType = attachment.ContentType