mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-18 09:27:34 -06:00
allow dereferencing of groups (#256)
This commit is contained in:
parent
231075f28d
commit
0cd2bd2960
4 changed files with 310 additions and 14 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
57
internal/federation/dereferencing/account_test.go
Normal file
57
internal/federation/dereferencing/account_test.go
Normal file
|
|
@ -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))
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue