diff options
Diffstat (limited to 'internal/federation')
-rw-r--r-- | internal/federation/dereferencing/account.go | 24 | ||||
-rw-r--r-- | internal/federation/dereferencing/account_test.go | 57 | ||||
-rw-r--r-- | internal/federation/dereferencing/dereferencer_test.go | 29 |
3 files changed, 96 insertions, 14 deletions
diff --git a/internal/federation/dereferencing/account.go b/internal/federation/dereferencing/account.go index b16b53fee..35ea2507d 100644 --- a/internal/federation/dereferencing/account.go +++ b/internal/federation/dereferencing/account.go @@ -165,18 +165,30 @@ func (d *deref) dereferenceAccountable(ctx context.Context, username string, rem } switch t.GetTypeName() { - case ap.ActorPerson: - p, ok := t.(vocab.ActivityStreamsPerson) - if !ok { - return nil, errors.New("DereferenceAccountable: error resolving type as activitystreams person") - } - return p, nil case ap.ActorApplication: p, ok := t.(vocab.ActivityStreamsApplication) if !ok { return nil, errors.New("DereferenceAccountable: error resolving type as activitystreams application") } return p, nil + case ap.ActorGroup: + p, ok := t.(vocab.ActivityStreamsGroup) + if !ok { + return nil, errors.New("DereferenceAccountable: error resolving type as activitystreams group") + } + return p, nil + case ap.ActorOrganization: + p, ok := t.(vocab.ActivityStreamsOrganization) + if !ok { + return nil, errors.New("DereferenceAccountable: error resolving type as activitystreams organization") + } + return p, nil + case ap.ActorPerson: + p, ok := t.(vocab.ActivityStreamsPerson) + if !ok { + return nil, errors.New("DereferenceAccountable: error resolving type as activitystreams person") + } + return p, nil case ap.ActorService: p, ok := t.(vocab.ActivityStreamsService) if !ok { diff --git a/internal/federation/dereferencing/account_test.go b/internal/federation/dereferencing/account_test.go new file mode 100644 index 000000000..04b455631 --- /dev/null +++ b/internal/federation/dereferencing/account_test.go @@ -0,0 +1,57 @@ +/* + GoToSocial + Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +package dereferencing_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/suite" + "github.com/superseriousbusiness/gotosocial/internal/ap" + "github.com/superseriousbusiness/gotosocial/testrig" +) + +type AccountTestSuite struct { + DereferencerStandardTestSuite +} + +func (suite *AccountTestSuite) TestDereferenceGroup() { + fetchingAccount := suite.testAccounts["local_account_1"] + + groupURL := testrig.URLMustParse("https://unknown-instance.com/groups/some_group") + group, new, err := suite.dereferencer.GetRemoteAccount(context.Background(), fetchingAccount.Username, groupURL, false) + suite.NoError(err) + suite.NotNil(group) + suite.NotNil(group) + suite.True(new) + + // group values should be set + suite.Equal("https://unknown-instance.com/groups/some_group", group.URI) + suite.Equal("https://unknown-instance.com/@some_group", group.URL) + + // group should be in the database + dbGroup, err := suite.db.GetAccountByURI(context.Background(), group.URI) + suite.NoError(err) + suite.Equal(group.ID, dbGroup.ID) + suite.Equal(ap.ActorGroup, dbGroup.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 41909ec4d..0eeabc64a 100644 --- a/internal/federation/dereferencing/dereferencer_test.go +++ b/internal/federation/dereferencing/dereferencer_test.go @@ -45,7 +45,8 @@ type DereferencerStandardTestSuite struct { storage *kv.KVStore testRemoteStatuses map[string]vocab.ActivityStreamsNote - testRemoteAccounts map[string]vocab.ActivityStreamsPerson + testRemotePeople map[string]vocab.ActivityStreamsPerson + testRemoteGroups map[string]vocab.ActivityStreamsGroup testRemoteAttachments map[string]testrig.RemoteAttachmentFile testAccounts map[string]*gtsmodel.Account @@ -55,7 +56,8 @@ type DereferencerStandardTestSuite struct { func (suite *DereferencerStandardTestSuite) SetupSuite() { suite.testAccounts = testrig.NewTestAccounts() suite.testRemoteStatuses = testrig.NewTestFediStatuses() - suite.testRemoteAccounts = testrig.NewTestFediPeople() + suite.testRemotePeople = testrig.NewTestFediPeople() + suite.testRemoteGroups = testrig.NewTestFediGroups() suite.testRemoteAttachments = testrig.NewTestFediAttachments("../../../testrig/media") } @@ -89,8 +91,7 @@ func (suite *DereferencerStandardTestSuite) mockTransportController() transport. responseType := "" responseLength := 0 - note, ok := suite.testRemoteStatuses[req.URL.String()] - if ok { + if note, ok := suite.testRemoteStatuses[req.URL.String()]; ok { // the request is for a note that we have stored noteI, err := streams.Serialize(note) if err != nil { @@ -104,8 +105,7 @@ func (suite *DereferencerStandardTestSuite) mockTransportController() transport. responseType = "application/activity+json" } - person, ok := suite.testRemoteAccounts[req.URL.String()] - if ok { + if person, ok := suite.testRemotePeople[req.URL.String()]; ok { // the request is for a person that we have stored personI, err := streams.Serialize(person) if err != nil { @@ -119,8 +119,21 @@ func (suite *DereferencerStandardTestSuite) mockTransportController() transport. responseType = "application/activity+json" } - attachment, ok := suite.testRemoteAttachments[req.URL.String()] - if ok { + if group, ok := suite.testRemoteGroups[req.URL.String()]; ok { + // the request is for a person that we have stored + groupI, err := streams.Serialize(group) + if err != nil { + panic(err) + } + groupJson, err := json.Marshal(groupI) + if err != nil { + panic(err) + } + responseBytes = groupJson + responseType = "application/activity+json" + } + + if attachment, ok := suite.testRemoteAttachments[req.URL.String()]; ok { responseBytes = attachment.Data responseType = attachment.ContentType } |