[chore] Add test for dereferencing Owncast service account (#613)

This commit is contained in:
tobi 2022-05-27 16:35:35 +02:00 committed by GitHub
commit dc8cc7e364
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 344 additions and 0 deletions

View file

@ -157,6 +157,49 @@ func (suite *ASToInternalTestSuite) TestParseReplyWithMention() {
suite.Equal(gtsmodel.VisibilityUnlocked, status.Visibility)
}
func (suite *ASToInternalTestSuite) TestParseOwncastService() {
m := make(map[string]interface{})
err := json.Unmarshal([]byte(owncastService), &m)
suite.NoError(err)
t, err := streams.ToType(context.Background(), m)
suite.NoError(err)
rep, ok := t.(ap.Accountable)
suite.True(ok)
acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), rep, false)
suite.NoError(err)
suite.Equal("rgh", acct.Username)
suite.Equal("owncast.example.org", acct.Domain)
suite.Equal("https://owncast.example.org/logo/external", acct.AvatarRemoteURL)
suite.Equal("https://owncast.example.org/logo/external", acct.HeaderRemoteURL)
suite.Equal("Rob's Owncast Server", acct.DisplayName)
suite.Equal("linux audio stuff ", acct.Note)
suite.True(acct.Bot)
suite.False(acct.Locked)
suite.True(acct.Discoverable)
suite.Equal("https://owncast.example.org/federation/user/rgh", acct.URI)
suite.Equal("https://owncast.example.org/federation/user/rgh", acct.URL)
suite.Equal("https://owncast.example.org/federation/user/rgh/inbox", acct.InboxURI)
suite.Equal("https://owncast.example.org/federation/user/rgh/outbox", acct.OutboxURI)
suite.Equal("https://owncast.example.org/federation/user/rgh/followers", acct.FollowersURI)
suite.Equal("Service", acct.ActorType)
suite.Equal("https://owncast.example.org/federation/user/rgh#main-key", acct.PublicKeyURI)
acct.ID = "01G42D57DTCJQE8XT9KD4K88RK"
apiAcct, err := suite.typeconverter.AccountToAPIAccountPublic(context.Background(), acct)
suite.NoError(err)
suite.NotNil(apiAcct)
b, err := json.Marshal(apiAcct)
suite.NoError(err)
fmt.Printf("\n\n\n%s\n\n\n", string(b))
}
func TestASToInternalTestSuite(t *testing.T) {
suite.Run(t, new(ASToInternalTestSuite))
}

View file

@ -414,6 +414,57 @@ const (
}
}
`
owncastService = `
{
"@context": [
"https://www.w3.org/ns/activitystreams",
"http://joinmastodon.org/ns",
"https://w3id.org/security/v1"
],
"attachment": {
"name": "Stream",
"type": "PropertyValue",
"value": "<a href=\"https://owncast.example.org\" rel=\"me nofollow noopener noreferrer\" target=\"_blank\">https://owncast.example.org</a>"
},
"discoverable": true,
"followers": "https://owncast.example.org/federation/user/rgh/followers",
"icon": {
"type": "Image",
"url": "https://owncast.example.org/logo/external"
},
"id": "https://owncast.example.org/federation/user/rgh",
"image": {
"type": "Image",
"url": "https://owncast.example.org/logo/external"
},
"inbox": "https://owncast.example.org/federation/user/rgh/inbox",
"manuallyApprovesFollowers": false,
"name": "Rob's Owncast Server",
"outbox": "https://owncast.example.org/federation/user/rgh/outbox",
"preferredUsername": "rgh",
"publicKey": {
"id": "https://owncast.example.org/federation/user/rgh#main-key",
"owner": "https://owncast.example.org/federation/user/rgh",
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAurN+lUNwcGV2poLNtaoT\naRtJzN6s4SDcBmIFk82lxhdMKC6/Nssm+hvDuxWGqL0+dHwSvrG11rA6irGuSzRk\niHjYyVwYe/p1CxqJxzUfZVJAWdsCFWy+HtDrTWs5sggj1MiL59uGxvkCep+OYBuG\nBI8CvSOMLrDp8soCg3EY+zSgpXtGMuRaaUukavsfuglApShB61ny7W8LG252iKC5\nmyO8L7l8TNa5BrIi/pRHLzvv9aWiCa8VKtvmqj+mClEhpkRhImSk5GPJXgouTTgl\ntT28NYYciSf9YYgZ0SNWHdLUCdkMF592j4+BbkPvdgzc70G4yyu2GcWnTzBuvF5X\nYwIDAQAB\n-----END PUBLIC KEY-----\n"
},
"published": "2022-05-22T18:44:57Z",
"summary": "linux audio stuff ",
"tag": [
{
"href": "https://directory.owncast.online/tags/owncast",
"name": "#owncast",
"type": "Hashtag"
},
{
"href": "https://directory.owncast.online/tags/streaming",
"name": "#streaming",
"type": "Hashtag"
}
],
"type": "Service",
"url": "https://owncast.example.org/federation/user/rgh"
}
`
)
type TypeUtilsTestSuite struct {