From 2e5dcc2929d6e6b22f370bf1b83c54d03ac1cd43 Mon Sep 17 00:00:00 2001
From: tobi <31960611+tsmethurst@users.noreply.github.com>
Date: Tue, 14 Sep 2021 12:23:56 +0200
Subject: [PATCH] Fix mentions not notifying (#230)
* set default privacy for new accounts
* teshts
* found it
* tiny change
* aaaa
---
internal/ap/extract_test.go | 100 +++++
internal/ap/extractattachments_test.go | 57 +--
internal/ap/extractmentions_test.go | 50 +++
internal/federation/dereference.go | 8 +-
internal/federation/dereferencing/announce.go | 2 +-
.../federation/dereferencing/dereferencer.go | 4 +-
internal/federation/dereferencing/status.go | 28 +-
.../federation/dereferencing/status_test.go | 4 +-
internal/federation/dereferencing/thread.go | 6 +-
internal/federation/federator.go | 4 +-
internal/processing/fromfederator.go | 2 +-
internal/processing/fromfederator_test.go | 70 ++++
internal/processing/search.go | 2 +-
internal/typeutils/astointernal_test.go | 361 +++---------------
internal/typeutils/converter_test.go | 327 +++++++++++++++-
internal/typeutils/internaltoas_test.go | 27 +-
16 files changed, 630 insertions(+), 422 deletions(-)
create mode 100644 internal/ap/extract_test.go
create mode 100644 internal/ap/extractmentions_test.go
diff --git a/internal/ap/extract_test.go b/internal/ap/extract_test.go
new file mode 100644
index 000000000..8753e8c24
--- /dev/null
+++ b/internal/ap/extract_test.go
@@ -0,0 +1,100 @@
+/*
+ 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
@the_mighty_zork nice there it is:
https://social.pixie.town/users/f0x/statuses/106221628567855262/activity
`, + Mentions: []*gtsmodel.Mention{ + { + TargetAccountURI: repliedAccount.URI, + NameString: "@the_mighty_zork@localhost:8080", + }, + }, + AccountID: replyingAccount.ID, + AccountURI: replyingAccount.URI, + InReplyToID: repliedStatus.ID, + InReplyToURI: repliedStatus.URI, + InReplyToAccountID: repliedAccount.ID, + Visibility: gtsmodel.VisibilityUnlocked, + ActivityStreamsType: ap.ObjectNote, + Federated: true, + Boostable: true, + Replyable: true, + Likeable: true, + } + + // id the status based on the time it was created + statusID, err := id.NewULIDFromTime(replyingStatus.CreatedAt) + suite.NoError(err) + replyingStatus.ID = statusID + + err = suite.db.PutStatus(context.Background(), replyingStatus) + suite.NoError(err) + + err = suite.processor.ProcessFromFederator(context.Background(), messages.FromFederator{ + APObjectType: ap.ObjectNote, + APActivityType: ap.ActivityCreate, + GTSModel: replyingStatus, + ReceivingAccount: suite.testAccounts["local_account_1"], + }) + suite.NoError(err) + + // side effects should be triggered + // 1. status should be in the database + suite.NotEmpty(replyingStatus.ID) + _, err = suite.db.GetStatusByID(context.Background(), replyingStatus.ID) + suite.NoError(err) + + // 2. a notification should exist for the mention + where := []db.Where{ + { + Key: "status_id", + Value: replyingStatus.ID, + }, + } + + notif := >smodel.Notification{} + err = suite.db.GetWhere(context.Background(), where, notif) + suite.NoError(err) + suite.Equal(gtsmodel.NotificationMention, notif.NotificationType) + suite.Equal(replyingStatus.InReplyToAccountID, notif.TargetAccountID) + suite.Equal(replyingStatus.AccountID, notif.OriginAccountID) + suite.Equal(replyingStatus.ID, notif.StatusID) + suite.False(notif.Read) +} + func TestFromFederatorTestSuite(t *testing.T) { suite.Run(t, &FromFederatorTestSuite{}) } diff --git a/internal/processing/search.go b/internal/processing/search.go index 85da0d83f..2fb1f6062 100644 --- a/internal/processing/search.go +++ b/internal/processing/search.go @@ -130,7 +130,7 @@ func (p *processor) searchStatusByURI(ctx context.Context, authed *oauth.Auth, u // we don't have it locally so dereference it if we're allowed to if resolve { - status, _, _, err := p.federator.GetRemoteStatus(ctx, authed.Account.Username, uri, true, false, false) + status, _, _, err := p.federator.GetRemoteStatus(ctx, authed.Account.Username, uri, true, true) if err == nil { if err := p.federator.DereferenceRemoteThread(ctx, authed.Account.Username, uri); err != nil { // try to deref the thread while we're here diff --git a/internal/typeutils/astointernal_test.go b/internal/typeutils/astointernal_test.go index 21b36a5c4..bc44ec2bd 100644 --- a/internal/typeutils/astointernal_test.go +++ b/internal/typeutils/astointernal_test.go @@ -25,328 +25,19 @@ "testing" "github.com/go-fed/activity/streams" + "github.com/go-fed/activity/streams/vocab" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/ap" - "github.com/superseriousbusiness/gotosocial/internal/typeutils" - "github.com/superseriousbusiness/gotosocial/testrig" + "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) type ASToInternalTestSuite struct { - ConverterStandardTestSuite -} - -const ( - statusWithMentionsActivityJson = `{ - "@context": [ - "https://www.w3.org/ns/activitystreams", - { - "ostatus": "http://ostatus.org#", - "atomUri": "ostatus:atomUri", - "inReplyToAtomUri": "ostatus:inReplyToAtomUri", - "conversation": "ostatus:conversation", - "sensitive": "as:sensitive", - "toot": "http://joinmastodon.org/ns#", - "votersCount": "toot:votersCount" - } - ], - "id": "https://ondergrond.org/users/dumpsterqueer/statuses/106221634728637552/activity", - "type": "Create", - "actor": "https://ondergrond.org/users/dumpsterqueer", - "published": "2021-05-12T09:58:38Z", - "to": [ - "https://ondergrond.org/users/dumpsterqueer/followers" - ], - "cc": [ - "https://www.w3.org/ns/activitystreams#Public", - "https://social.pixie.town/users/f0x" - ], - "object": { - "id": "https://ondergrond.org/users/dumpsterqueer/statuses/106221634728637552", - "type": "Note", - "summary": null, - "inReplyTo": "https://social.pixie.town/users/f0x/statuses/106221628567855262", - "published": "2021-05-12T09:58:38Z", - "url": "https://ondergrond.org/@dumpsterqueer/106221634728637552", - "attributedTo": "https://ondergrond.org/users/dumpsterqueer", - "to": [ - "https://ondergrond.org/users/dumpsterqueer/followers" - ], - "cc": [ - "https://www.w3.org/ns/activitystreams#Public", - "https://social.pixie.town/users/f0x" - ], - "sensitive": false, - "atomUri": "https://ondergrond.org/users/dumpsterqueer/statuses/106221634728637552", - "inReplyToAtomUri": "https://social.pixie.town/users/f0x/statuses/106221628567855262", - "conversation": "tag:ondergrond.org,2021-05-12:objectId=1132361:objectType=Conversation", - "content": "@f0x nice there it is:
https://social.pixie.town/users/f0x/statuses/106221628567855262/activity
", - "contentMap": { - "en": "@f0x nice there it is:
https://social.pixie.town/users/f0x/statuses/106221628567855262/activity
" - }, - "attachment": [], - "tag": [ - { - "type": "Mention", - "href": "https://social.pixie.town/users/f0x", - "name": "@f0x@pixie.town" - } - ], - "replies": { - "id": "https://ondergrond.org/users/dumpsterqueer/statuses/106221634728637552/replies", - "type": "Collection", - "first": { - "type": "CollectionPage", - "next": "https://ondergrond.org/users/dumpsterqueer/statuses/106221634728637552/replies?only_other_accounts=true&page=true", - "partOf": "https://ondergrond.org/users/dumpsterqueer/statuses/106221634728637552/replies", - "items": [] - } - } - } - }` - statusWithEmojisAndTagsAsActivityJson = `{ - "@context": [ - "https://www.w3.org/ns/activitystreams", - { - "ostatus": "http://ostatus.org#", - "atomUri": "ostatus:atomUri", - "inReplyToAtomUri": "ostatus:inReplyToAtomUri", - "conversation": "ostatus:conversation", - "sensitive": "as:sensitive", - "toot": "http://joinmastodon.org/ns#", - "votersCount": "toot:votersCount", - "Hashtag": "as:Hashtag", - "Emoji": "toot:Emoji", - "focalPoint": { - "@container": "@list", - "@id": "toot:focalPoint" - } - } - ], - "id": "https://ondergrond.org/users/dumpsterqueer/statuses/106221567884565704/activity", - "type": "Create", - "actor": "https://ondergrond.org/users/dumpsterqueer", - "published": "2021-05-12T09:41:38Z", - "to": [ - "https://ondergrond.org/users/dumpsterqueer/followers" - ], - "cc": [ - "https://www.w3.org/ns/activitystreams#Public" - ], - "object": { - "id": "https://ondergrond.org/users/dumpsterqueer/statuses/106221567884565704", - "type": "Note", - "summary": null, - "inReplyTo": null, - "published": "2021-05-12T09:41:38Z", - "url": "https://ondergrond.org/@dumpsterqueer/106221567884565704", - "attributedTo": "https://ondergrond.org/users/dumpsterqueer", - "to": [ - "https://ondergrond.org/users/dumpsterqueer/followers" - ], - "cc": [ - "https://www.w3.org/ns/activitystreams#Public" - ], - "sensitive": false, - "atomUri": "https://ondergrond.org/users/dumpsterqueer/statuses/106221567884565704", - "inReplyToAtomUri": null, - "conversation": "tag:ondergrond.org,2021-05-12:objectId=1132361:objectType=Conversation", - "content": "just testing activitypub representations of #tags and #emoji :party_parrot: :amaze: :blobsunglasses:
don't mind me....
", - "contentMap": { - "en": "just testing activitypub representations of #tags and #emoji :party_parrot: :amaze: :blobsunglasses:
don't mind me....
" - }, - "attachment": [], - "tag": [ - { - "type": "Hashtag", - "href": "https://ondergrond.org/tags/tags", - "name": "#tags" - }, - { - "type": "Hashtag", - "href": "https://ondergrond.org/tags/emoji", - "name": "#emoji" - }, - { - "id": "https://ondergrond.org/emojis/2390", - "type": "Emoji", - "name": ":party_parrot:", - "updated": "2020-11-06T13:42:11Z", - "icon": { - "type": "Image", - "mediaType": "image/gif", - "url": "https://ondergrond.org/system/custom_emojis/images/000/002/390/original/ef133aac7ab23341.gif" - } - }, - { - "id": "https://ondergrond.org/emojis/2395", - "type": "Emoji", - "name": ":amaze:", - "updated": "2020-09-26T12:29:56Z", - "icon": { - "type": "Image", - "mediaType": "image/png", - "url": "https://ondergrond.org/system/custom_emojis/images/000/002/395/original/2c7d9345e57367ed.png" - } - }, - { - "id": "https://ondergrond.org/emojis/764", - "type": "Emoji", - "name": ":blobsunglasses:", - "updated": "2020-09-26T12:13:23Z", - "icon": { - "type": "Image", - "mediaType": "image/png", - "url": "https://ondergrond.org/system/custom_emojis/images/000/000/764/original/3f8eef9de773c90d.png" - } - } - ], - "replies": { - "id": "https://ondergrond.org/users/dumpsterqueer/statuses/106221567884565704/replies", - "type": "Collection", - "first": { - "type": "CollectionPage", - "next": "https://ondergrond.org/users/dumpsterqueer/statuses/106221567884565704/replies?only_other_accounts=true&page=true", - "partOf": "https://ondergrond.org/users/dumpsterqueer/statuses/106221567884565704/replies", - "items": [] - } - } - } - }` - gargronAsActivityJson = `{ - "@context": [ - "https://www.w3.org/ns/activitystreams", - "https://w3id.org/security/v1", - { - "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", - "toot": "http://joinmastodon.org/ns#", - "featured": { - "@id": "toot:featured", - "@type": "@id" - }, - "featuredTags": { - "@id": "toot:featuredTags", - "@type": "@id" - }, - "alsoKnownAs": { - "@id": "as:alsoKnownAs", - "@type": "@id" - }, - "movedTo": { - "@id": "as:movedTo", - "@type": "@id" - }, - "schema": "http://schema.org#", - "PropertyValue": "schema:PropertyValue", - "value": "schema:value", - "IdentityProof": "toot:IdentityProof", - "discoverable": "toot:discoverable", - "Device": "toot:Device", - "Ed25519Signature": "toot:Ed25519Signature", - "Ed25519Key": "toot:Ed25519Key", - "Curve25519Key": "toot:Curve25519Key", - "EncryptedMessage": "toot:EncryptedMessage", - "publicKeyBase64": "toot:publicKeyBase64", - "deviceId": "toot:deviceId", - "claim": { - "@type": "@id", - "@id": "toot:claim" - }, - "fingerprintKey": { - "@type": "@id", - "@id": "toot:fingerprintKey" - }, - "identityKey": { - "@type": "@id", - "@id": "toot:identityKey" - }, - "devices": { - "@type": "@id", - "@id": "toot:devices" - }, - "messageFranking": "toot:messageFranking", - "messageType": "toot:messageType", - "cipherText": "toot:cipherText", - "suspended": "toot:suspended", - "focalPoint": { - "@container": "@list", - "@id": "toot:focalPoint" - } - } - ], - "id": "https://mastodon.social/users/Gargron", - "type": "Person", - "following": "https://mastodon.social/users/Gargron/following", - "followers": "https://mastodon.social/users/Gargron/followers", - "inbox": "https://mastodon.social/users/Gargron/inbox", - "outbox": "https://mastodon.social/users/Gargron/outbox", - "featured": "https://mastodon.social/users/Gargron/collections/featured", - "featuredTags": "https://mastodon.social/users/Gargron/collections/tags", - "preferredUsername": "Gargron", - "name": "Eugen", - "summary": "Developer of Mastodon and administrator of mastodon.social. I post service announcements, development updates, and personal stuff.
", - "url": "https://mastodon.social/@Gargron", - "manuallyApprovesFollowers": false, - "discoverable": true, - "devices": "https://mastodon.social/users/Gargron/collections/devices", - "alsoKnownAs": [ - "https://tooting.ai/users/Gargron" - ], - "publicKey": { - "id": "https://mastodon.social/users/Gargron#main-key", - "owner": "https://mastodon.social/users/Gargron", - "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvXc4vkECU2/CeuSo1wtn\nFoim94Ne1jBMYxTZ9wm2YTdJq1oiZKif06I2fOqDzY/4q/S9uccrE9Bkajv1dnkO\nVm31QjWlhVpSKynVxEWjVBO5Ienue8gND0xvHIuXf87o61poqjEoepvsQFElA5ym\novljWGSA/jpj7ozygUZhCXtaS2W5AD5tnBQUpcO0lhItYPYTjnmzcc4y2NbJV8hz\n2s2G8qKv8fyimE23gY1XrPJg+cRF+g4PqFXujjlJ7MihD9oqtLGxbu7o1cifTn3x\nBfIdPythWu5b4cujNsB3m3awJjVmx+MHQ9SugkSIYXV0Ina77cTNS0M2PYiH1PFR\nTwIDAQAB\n-----END PUBLIC KEY-----\n" - }, - "tag": [], - "attachment": [ - { - "type": "PropertyValue", - "name": "Patreon", - "value": "https://www.patreon.com/mastodon" - }, - { - "type": "PropertyValue", - "name": "Homepage", - "value": "https://zeonfederated.com" - }, - { - "type": "IdentityProof", - "name": "gargron", - "signatureAlgorithm": "keybase", - "signatureValue": "5cfc20c7018f2beefb42a68836da59a792e55daa4d118498c9b1898de7e845690f" - } - ], - "endpoints": { - "sharedInbox": "https://mastodon.social/inbox" - }, - "icon": { - "type": "Image", - "mediaType": "image/jpeg", - "url": "https://files.mastodon.social/accounts/avatars/000/000/001/original/d96d39a0abb45b92.jpg" - }, - "image": { - "type": "Image", - "mediaType": "image/png", - "url": "https://files.mastodon.social/accounts/headers/000/000/001/original/c91b871f294ea63e.png" - } - }` -) - -func (suite *ASToInternalTestSuite) SetupSuite() { - suite.config = testrig.NewTestConfig() - suite.db = testrig.NewTestDB() - suite.log = testrig.NewTestLog() - suite.accounts = testrig.NewTestAccounts() - suite.people = testrig.NewTestFediPeople() - suite.typeconverter = typeutils.NewConverter(suite.config, suite.db, suite.log) -} - -func (suite *ASToInternalTestSuite) SetupTest() { - testrig.StandardDBSetup(suite.db, nil) + TypeUtilsTestSuite } func (suite *ASToInternalTestSuite) TestParsePerson() { - testPerson := suite.people["https://unknown-instance.com/users/brand_new_person"] + testPerson := suite.testPeople["https://unknown-instance.com/users/brand_new_person"] acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), testPerson, false) assert.NoError(suite.T(), err) @@ -384,8 +75,48 @@ func (suite *ASToInternalTestSuite) TestParseGargron() { // TODO: write assertions here, rn we're just eyeballing the output } -func (suite *ASToInternalTestSuite) TearDownTest() { - testrig.StandardDBTeardown(suite.db) +func (suite *ASToInternalTestSuite) TestParseReplyWithMention() { + m := make(map[string]interface{}) + err := json.Unmarshal([]byte(statusWithMentionsActivityJson), &m) + assert.NoError(suite.T(), err) + + t, err := streams.ToType(context.Background(), m) + assert.NoError(suite.T(), err) + + create, ok := t.(vocab.ActivityStreamsCreate) + suite.True(ok) + + object := create.GetActivityStreamsObject() + var status *gtsmodel.Status + for i := object.Begin(); i != nil; i = i.Next() { + statusable := i.GetActivityStreamsNote() + s, err := suite.typeconverter.ASStatusToStatus(context.Background(), statusable) + suite.NoError(err) + status = s + break + } + suite.NotNil(status) + + postingAccount := suite.testAccounts["remote_account_1"] + inReplyToAccount := suite.testAccounts["local_account_1"] + inReplyToStatus := suite.testStatuses["local_account_1_status_1"] + + suite.Equal("http://fossbros-anonymous.io/users/foss_satan/statuses/106221634728637552", status.URI) + suite.Equal(postingAccount.ID, status.AccountID) + suite.Equal(postingAccount.URI, status.AccountURI) + suite.Equal(inReplyToAccount.ID, status.InReplyToAccountID) + suite.Equal(inReplyToStatus.ID, status.InReplyToID) + suite.Equal(inReplyToStatus.URI, status.InReplyToURI) + suite.True(status.Federated) + suite.True(status.Boostable) + suite.True(status.Replyable) + suite.True(status.Likeable) + suite.Equal(`@the_mighty_zork nice there it is:
https://social.pixie.town/users/f0x/statuses/106221628567855262/activity
`, status.Content) + suite.Len(status.Mentions, 1) + m1 := status.Mentions[0] + suite.Equal(inReplyToAccount.URI, m1.TargetAccountURI) + suite.Equal("@the_mighty_zork@localhost:8080", m1.NameString) + suite.Equal(gtsmodel.VisibilityUnlocked, status.Visibility) } func TestASToInternalTestSuite(t *testing.T) { diff --git a/internal/typeutils/converter_test.go b/internal/typeutils/converter_test.go index 63f3fe705..424b0de29 100644 --- a/internal/typeutils/converter_test.go +++ b/internal/typeutils/converter_test.go @@ -26,16 +26,329 @@ "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/typeutils" + "github.com/superseriousbusiness/gotosocial/testrig" ) -// nolint -type ConverterStandardTestSuite struct { +const ( + statusWithMentionsActivityJson = `{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + { + "ostatus": "http://ostatus.org#", + "atomUri": "ostatus:atomUri", + "inReplyToAtomUri": "ostatus:inReplyToAtomUri", + "conversation": "ostatus:conversation", + "sensitive": "as:sensitive", + "toot": "http://joinmastodon.org/ns#", + "votersCount": "toot:votersCount" + } + ], + "id": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221634728637552/activity", + "type": "Create", + "actor": "http://fossbros-anonymous.io/users/foss_satan", + "published": "2021-05-12T09:58:38Z", + "to": [ + "http://fossbros-anonymous.io/users/foss_satan/followers" + ], + "cc": [ + "https://www.w3.org/ns/activitystreams#Public", + "http://localhost:8080/users/the_mighty_zork" + ], + "object": { + "id": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221634728637552", + "type": "Note", + "summary": null, + "inReplyTo": "http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY", + "published": "2021-05-12T09:58:38Z", + "url": "https://ondergrond.org/@dumpsterqueer/106221634728637552", + "attributedTo": "http://fossbros-anonymous.io/users/foss_satan", + "to": [ + "http://fossbros-anonymous.io/users/foss_satan/followers" + ], + "cc": [ + "https://www.w3.org/ns/activitystreams#Public", + "http://localhost:8080/users/the_mighty_zork" + ], + "sensitive": false, + "conversation": "tag:ondergrond.org,2021-05-12:objectId=1132361:objectType=Conversation", + "content": "@the_mighty_zork nice there it is:
https://social.pixie.town/users/f0x/statuses/106221628567855262/activity
", + "contentMap": { + "en": "@the_mighty_zork nice there it is:
https://social.pixie.town/users/f0x/statuses/106221628567855262/activity
" + }, + "attachment": [], + "tag": [ + { + "type": "Mention", + "href": "http://localhost:8080/users/the_mighty_zork", + "name": "@the_mighty_zork@localhost:8080" + } + ], + "replies": { + "id": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221634728637552/replies", + "type": "Collection", + "first": { + "type": "CollectionPage", + "next": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221634728637552/replies?only_other_accounts=true&page=true", + "partOf": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221634728637552/replies", + "items": [] + } + } + } + }` + statusWithEmojisAndTagsAsActivityJson = `{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + { + "ostatus": "http://ostatus.org#", + "atomUri": "ostatus:atomUri", + "inReplyToAtomUri": "ostatus:inReplyToAtomUri", + "conversation": "ostatus:conversation", + "sensitive": "as:sensitive", + "toot": "http://joinmastodon.org/ns#", + "votersCount": "toot:votersCount", + "Hashtag": "as:Hashtag", + "Emoji": "toot:Emoji", + "focalPoint": { + "@container": "@list", + "@id": "toot:focalPoint" + } + } + ], + "id": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221567884565704/activity", + "type": "Create", + "actor": "http://fossbros-anonymous.io/users/foss_satan", + "published": "2021-05-12T09:41:38Z", + "to": [ + "http://fossbros-anonymous.io/users/foss_satan/followers" + ], + "cc": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "object": { + "id": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221567884565704", + "type": "Note", + "summary": null, + "inReplyTo": null, + "published": "2021-05-12T09:41:38Z", + "url": "https://ondergrond.org/@dumpsterqueer/106221567884565704", + "attributedTo": "http://fossbros-anonymous.io/users/foss_satan", + "to": [ + "http://fossbros-anonymous.io/users/foss_satan/followers" + ], + "cc": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "sensitive": false, + "atomUri": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221567884565704", + "inReplyToAtomUri": null, + "conversation": "tag:ondergrond.org,2021-05-12:objectId=1132361:objectType=Conversation", + "content": "just testing activitypub representations of #tags and #emoji :party_parrot: :amaze: :blobsunglasses:
don't mind me....
", + "contentMap": { + "en": "just testing activitypub representations of #tags and #emoji :party_parrot: :amaze: :blobsunglasses:
don't mind me....
" + }, + "attachment": [], + "tag": [ + { + "type": "Hashtag", + "href": "https://ondergrond.org/tags/tags", + "name": "#tags" + }, + { + "type": "Hashtag", + "href": "https://ondergrond.org/tags/emoji", + "name": "#emoji" + }, + { + "id": "https://ondergrond.org/emojis/2390", + "type": "Emoji", + "name": ":party_parrot:", + "updated": "2020-11-06T13:42:11Z", + "icon": { + "type": "Image", + "mediaType": "image/gif", + "url": "https://ondergrond.org/system/custom_emojis/images/000/002/390/original/ef133aac7ab23341.gif" + } + }, + { + "id": "https://ondergrond.org/emojis/2395", + "type": "Emoji", + "name": ":amaze:", + "updated": "2020-09-26T12:29:56Z", + "icon": { + "type": "Image", + "mediaType": "image/png", + "url": "https://ondergrond.org/system/custom_emojis/images/000/002/395/original/2c7d9345e57367ed.png" + } + }, + { + "id": "https://ondergrond.org/emojis/764", + "type": "Emoji", + "name": ":blobsunglasses:", + "updated": "2020-09-26T12:13:23Z", + "icon": { + "type": "Image", + "mediaType": "image/png", + "url": "https://ondergrond.org/system/custom_emojis/images/000/000/764/original/3f8eef9de773c90d.png" + } + } + ], + "replies": { + "id": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221567884565704/replies", + "type": "Collection", + "first": { + "type": "CollectionPage", + "next": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221567884565704/replies?only_other_accounts=true&page=true", + "partOf": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221567884565704/replies", + "items": [] + } + } + } + }` + gargronAsActivityJson = `{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "toot": "http://joinmastodon.org/ns#", + "featured": { + "@id": "toot:featured", + "@type": "@id" + }, + "featuredTags": { + "@id": "toot:featuredTags", + "@type": "@id" + }, + "alsoKnownAs": { + "@id": "as:alsoKnownAs", + "@type": "@id" + }, + "movedTo": { + "@id": "as:movedTo", + "@type": "@id" + }, + "schema": "http://schema.org#", + "PropertyValue": "schema:PropertyValue", + "value": "schema:value", + "IdentityProof": "toot:IdentityProof", + "discoverable": "toot:discoverable", + "Device": "toot:Device", + "Ed25519Signature": "toot:Ed25519Signature", + "Ed25519Key": "toot:Ed25519Key", + "Curve25519Key": "toot:Curve25519Key", + "EncryptedMessage": "toot:EncryptedMessage", + "publicKeyBase64": "toot:publicKeyBase64", + "deviceId": "toot:deviceId", + "claim": { + "@type": "@id", + "@id": "toot:claim" + }, + "fingerprintKey": { + "@type": "@id", + "@id": "toot:fingerprintKey" + }, + "identityKey": { + "@type": "@id", + "@id": "toot:identityKey" + }, + "devices": { + "@type": "@id", + "@id": "toot:devices" + }, + "messageFranking": "toot:messageFranking", + "messageType": "toot:messageType", + "cipherText": "toot:cipherText", + "suspended": "toot:suspended", + "focalPoint": { + "@container": "@list", + "@id": "toot:focalPoint" + } + } + ], + "id": "https://mastodon.social/users/Gargron", + "type": "Person", + "following": "https://mastodon.social/users/Gargron/following", + "followers": "https://mastodon.social/users/Gargron/followers", + "inbox": "https://mastodon.social/users/Gargron/inbox", + "outbox": "https://mastodon.social/users/Gargron/outbox", + "featured": "https://mastodon.social/users/Gargron/collections/featured", + "featuredTags": "https://mastodon.social/users/Gargron/collections/tags", + "preferredUsername": "Gargron", + "name": "Eugen", + "summary": "Developer of Mastodon and administrator of mastodon.social. I post service announcements, development updates, and personal stuff.
", + "url": "https://mastodon.social/@Gargron", + "manuallyApprovesFollowers": false, + "discoverable": true, + "devices": "https://mastodon.social/users/Gargron/collections/devices", + "alsoKnownAs": [ + "https://tooting.ai/users/Gargron" + ], + "publicKey": { + "id": "https://mastodon.social/users/Gargron#main-key", + "owner": "https://mastodon.social/users/Gargron", + "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvXc4vkECU2/CeuSo1wtn\nFoim94Ne1jBMYxTZ9wm2YTdJq1oiZKif06I2fOqDzY/4q/S9uccrE9Bkajv1dnkO\nVm31QjWlhVpSKynVxEWjVBO5Ienue8gND0xvHIuXf87o61poqjEoepvsQFElA5ym\novljWGSA/jpj7ozygUZhCXtaS2W5AD5tnBQUpcO0lhItYPYTjnmzcc4y2NbJV8hz\n2s2G8qKv8fyimE23gY1XrPJg+cRF+g4PqFXujjlJ7MihD9oqtLGxbu7o1cifTn3x\nBfIdPythWu5b4cujNsB3m3awJjVmx+MHQ9SugkSIYXV0Ina77cTNS0M2PYiH1PFR\nTwIDAQAB\n-----END PUBLIC KEY-----\n" + }, + "tag": [], + "attachment": [ + { + "type": "PropertyValue", + "name": "Patreon", + "value": "https://www.patreon.com/mastodon" + }, + { + "type": "PropertyValue", + "name": "Homepage", + "value": "https://zeonfederated.com" + }, + { + "type": "IdentityProof", + "name": "gargron", + "signatureAlgorithm": "keybase", + "signatureValue": "5cfc20c7018f2beefb42a68836da59a792e55daa4d118498c9b1898de7e845690f" + } + ], + "endpoints": { + "sharedInbox": "https://mastodon.social/inbox" + }, + "icon": { + "type": "Image", + "mediaType": "image/jpeg", + "url": "https://files.mastodon.social/accounts/avatars/000/000/001/original/d96d39a0abb45b92.jpg" + }, + "image": { + "type": "Image", + "mediaType": "image/png", + "url": "https://files.mastodon.social/accounts/headers/000/000/001/original/c91b871f294ea63e.png" + } + }` +) + +type TypeUtilsTestSuite struct { suite.Suite - config *config.Config - db db.DB - log *logrus.Logger - accounts map[string]*gtsmodel.Account - people map[string]vocab.ActivityStreamsPerson + config *config.Config + db db.DB + log *logrus.Logger + testAccounts map[string]*gtsmodel.Account + testStatuses map[string]*gtsmodel.Status + testPeople map[string]vocab.ActivityStreamsPerson typeconverter typeutils.TypeConverter } + +func (suite *TypeUtilsTestSuite) SetupSuite() { + suite.config = testrig.NewTestConfig() + suite.db = testrig.NewTestDB() + suite.log = testrig.NewTestLog() + suite.testAccounts = testrig.NewTestAccounts() + suite.testStatuses = testrig.NewTestStatuses() + suite.testPeople = testrig.NewTestFediPeople() + suite.typeconverter = typeutils.NewConverter(suite.config, suite.db, suite.log) +} + +func (suite *TypeUtilsTestSuite) SetupTest() { + testrig.StandardDBSetup(suite.db, nil) +} + +func (suite *TypeUtilsTestSuite) TearDownTest() { + testrig.StandardDBTeardown(suite.db) +} diff --git a/internal/typeutils/internaltoas_test.go b/internal/typeutils/internaltoas_test.go index de046fe0a..50f92e043 100644 --- a/internal/typeutils/internaltoas_test.go +++ b/internal/typeutils/internaltoas_test.go @@ -27,37 +27,14 @@ "github.com/go-fed/activity/streams" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" - - "github.com/superseriousbusiness/gotosocial/internal/typeutils" - "github.com/superseriousbusiness/gotosocial/testrig" ) type InternalToASTestSuite struct { - ConverterStandardTestSuite -} - -// SetupSuite sets some variables on the suite that we can use as consts (more or less) throughout -func (suite *InternalToASTestSuite) SetupSuite() { - // setup standard items - suite.config = testrig.NewTestConfig() - suite.db = testrig.NewTestDB() - suite.log = testrig.NewTestLog() - suite.accounts = testrig.NewTestAccounts() - suite.people = testrig.NewTestFediPeople() - suite.typeconverter = typeutils.NewConverter(suite.config, suite.db, suite.log) -} - -func (suite *InternalToASTestSuite) SetupTest() { - testrig.StandardDBSetup(suite.db, nil) -} - -// TearDownTest drops tables to make sure there's no data in the db -func (suite *InternalToASTestSuite) TearDownTest() { - testrig.StandardDBTeardown(suite.db) + TypeUtilsTestSuite } func (suite *InternalToASTestSuite) TestAccountToAS() { - testAccount := suite.accounts["local_account_1"] // take zork for this test + testAccount := suite.testAccounts["local_account_1"] // take zork for this test asPerson, err := suite.typeconverter.AccountToAS(context.Background(), testAccount) assert.NoError(suite.T(), err)