2023-03-12 15:00:57 +00:00
|
|
|
// GoToSocial
|
|
|
|
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
//
|
|
|
|
// 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/>.
|
2021-09-04 12:29:56 +01:00
|
|
|
|
|
|
|
package processing_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-10-01 18:08:50 +01:00
|
|
|
"encoding/json"
|
2021-09-30 09:56:02 +01:00
|
|
|
"fmt"
|
2021-09-04 12:29:56 +01:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
2023-01-02 12:10:50 +00:00
|
|
|
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
2021-09-04 12:29:56 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
2021-09-14 11:23:56 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/id"
|
2021-09-04 12:29:56 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
2021-11-22 18:03:21 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/stream"
|
2023-08-07 18:38:11 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/util"
|
2021-10-10 11:39:25 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/testrig"
|
2021-09-04 12:29:56 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type FromFederatorTestSuite struct {
|
|
|
|
ProcessingStandardTestSuite
|
|
|
|
}
|
|
|
|
|
|
|
|
// remote_account_1 boosts the first status of local_account_1
|
|
|
|
func (suite *FromFederatorTestSuite) TestProcessFederationAnnounce() {
|
|
|
|
boostedStatus := suite.testStatuses["local_account_1_status_1"]
|
|
|
|
boostingAccount := suite.testAccounts["remote_account_1"]
|
|
|
|
announceStatus := >smodel.Status{}
|
|
|
|
announceStatus.URI = "https://example.org/some-announce-uri"
|
|
|
|
announceStatus.BoostOf = >smodel.Status{
|
|
|
|
URI: boostedStatus.URI,
|
|
|
|
}
|
|
|
|
announceStatus.CreatedAt = time.Now()
|
|
|
|
announceStatus.UpdatedAt = time.Now()
|
|
|
|
announceStatus.AccountID = boostingAccount.ID
|
|
|
|
announceStatus.AccountURI = boostingAccount.URI
|
|
|
|
announceStatus.Account = boostingAccount
|
|
|
|
announceStatus.Visibility = boostedStatus.Visibility
|
|
|
|
|
|
|
|
err := suite.processor.ProcessFromFederator(context.Background(), messages.FromFederator{
|
|
|
|
APObjectType: ap.ActivityAnnounce,
|
|
|
|
APActivityType: ap.ActivityCreate,
|
|
|
|
GTSModel: announceStatus,
|
|
|
|
ReceivingAccount: suite.testAccounts["local_account_1"],
|
|
|
|
})
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
// side effects should be triggered
|
|
|
|
// 1. status should have an ID, and be in the database
|
|
|
|
suite.NotEmpty(announceStatus.ID)
|
|
|
|
_, err = suite.db.GetStatusByID(context.Background(), announceStatus.ID)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
// 2. a notification should exist for the announce
|
|
|
|
where := []db.Where{
|
|
|
|
{
|
|
|
|
Key: "status_id",
|
|
|
|
Value: announceStatus.ID,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
notif := >smodel.Notification{}
|
|
|
|
err = suite.db.GetWhere(context.Background(), where, notif)
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.Equal(gtsmodel.NotificationReblog, notif.NotificationType)
|
|
|
|
suite.Equal(boostedStatus.AccountID, notif.TargetAccountID)
|
|
|
|
suite.Equal(announceStatus.AccountID, notif.OriginAccountID)
|
|
|
|
suite.Equal(announceStatus.ID, notif.StatusID)
|
2022-08-15 11:35:05 +01:00
|
|
|
suite.False(*notif.Read)
|
2021-09-04 12:29:56 +01:00
|
|
|
}
|
|
|
|
|
2021-09-14 11:23:56 +01:00
|
|
|
func (suite *FromFederatorTestSuite) TestProcessReplyMention() {
|
|
|
|
repliedAccount := suite.testAccounts["local_account_1"]
|
|
|
|
repliedStatus := suite.testStatuses["local_account_1_status_1"]
|
|
|
|
replyingAccount := suite.testAccounts["remote_account_1"]
|
2022-08-15 11:35:05 +01:00
|
|
|
|
2021-09-14 11:23:56 +01:00
|
|
|
replyingStatus := >smodel.Status{
|
|
|
|
CreatedAt: time.Now(),
|
|
|
|
UpdatedAt: time.Now(),
|
|
|
|
URI: "http://fossbros-anonymous.io/users/foss_satan/statuses/106221634728637552",
|
|
|
|
URL: "http://fossbros-anonymous.io/@foss_satan/106221634728637552",
|
|
|
|
Content: `<p><span class="h-card"><a href="http://localhost:8080/@the_mighty_zork" class="u-url mention">@<span>the_mighty_zork</span></a></span> nice there it is:</p><p><a href="http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY/activity" rel="nofollow noopener noreferrer" target="_blank"><span class="invisible">https://</span><span class="ellipsis">social.pixie.town/users/f0x/st</span><span class="invisible">atuses/106221628567855262/activity</span></a></p>`,
|
|
|
|
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,
|
2023-08-07 18:38:11 +01:00
|
|
|
Federated: util.Ptr(true),
|
|
|
|
Boostable: util.Ptr(true),
|
|
|
|
Replyable: util.Ptr(true),
|
|
|
|
Likeable: util.Ptr(false),
|
2021-09-14 11:23:56 +01:00
|
|
|
}
|
|
|
|
|
2023-02-22 15:05:26 +00:00
|
|
|
wssStream, errWithCode := suite.processor.Stream().Open(context.Background(), repliedAccount, stream.TimelineHome)
|
2021-11-22 18:03:21 +00:00
|
|
|
suite.NoError(errWithCode)
|
|
|
|
|
2021-09-14 11:23:56 +01:00
|
|
|
// 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
|
2023-05-12 10:15:54 +01:00
|
|
|
var notif gtsmodel.Notification
|
|
|
|
err = suite.db.GetWhere(context.Background(), []db.Where{
|
|
|
|
{Key: "status_id", Value: replyingStatus.ID},
|
|
|
|
}, ¬if)
|
2021-09-14 11:23:56 +01:00
|
|
|
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)
|
2022-08-15 11:35:05 +01:00
|
|
|
suite.False(*notif.Read)
|
|
|
|
|
|
|
|
// the notification should be streamed
|
|
|
|
var msg *stream.Message
|
|
|
|
select {
|
|
|
|
case msg = <-wssStream.Messages:
|
|
|
|
// fine
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
suite.FailNow("no message from wssStream")
|
|
|
|
}
|
2021-11-22 18:03:21 +00:00
|
|
|
|
|
|
|
suite.Equal(stream.EventTypeNotification, msg.Event)
|
|
|
|
suite.NotEmpty(msg.Payload)
|
|
|
|
suite.EqualValues([]string{stream.TimelineHome}, msg.Stream)
|
2023-01-02 12:10:50 +00:00
|
|
|
notifStreamed := &apimodel.Notification{}
|
2021-11-22 18:03:21 +00:00
|
|
|
err = json.Unmarshal([]byte(msg.Payload), notifStreamed)
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.Equal("mention", notifStreamed.Type)
|
|
|
|
suite.Equal(replyingAccount.ID, notifStreamed.Account.ID)
|
2021-09-14 11:23:56 +01:00
|
|
|
}
|
|
|
|
|
2021-09-27 16:42:20 +01:00
|
|
|
func (suite *FromFederatorTestSuite) TestProcessFave() {
|
|
|
|
favedAccount := suite.testAccounts["local_account_1"]
|
|
|
|
favedStatus := suite.testStatuses["local_account_1_status_1"]
|
|
|
|
favingAccount := suite.testAccounts["remote_account_1"]
|
|
|
|
|
2023-02-22 15:05:26 +00:00
|
|
|
wssStream, errWithCode := suite.processor.Stream().Open(context.Background(), favedAccount, stream.TimelineNotifications)
|
2021-09-27 16:42:20 +01:00
|
|
|
suite.NoError(errWithCode)
|
|
|
|
|
|
|
|
fave := >smodel.StatusFave{
|
|
|
|
ID: "01FGKJPXFTVQPG9YSSZ95ADS7Q",
|
|
|
|
CreatedAt: time.Now(),
|
|
|
|
UpdatedAt: time.Now(),
|
|
|
|
AccountID: favingAccount.ID,
|
|
|
|
Account: favingAccount,
|
|
|
|
TargetAccountID: favedAccount.ID,
|
|
|
|
TargetAccount: favedAccount,
|
|
|
|
StatusID: favedStatus.ID,
|
|
|
|
Status: favedStatus,
|
|
|
|
URI: favingAccount.URI + "/faves/aaaaaaaaaaaa",
|
|
|
|
}
|
|
|
|
|
|
|
|
err := suite.db.Put(context.Background(), fave)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
err = suite.processor.ProcessFromFederator(context.Background(), messages.FromFederator{
|
|
|
|
APObjectType: ap.ActivityLike,
|
|
|
|
APActivityType: ap.ActivityCreate,
|
|
|
|
GTSModel: fave,
|
|
|
|
ReceivingAccount: favedAccount,
|
|
|
|
})
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
// side effects should be triggered
|
|
|
|
// 1. a notification should exist for the fave
|
|
|
|
where := []db.Where{
|
|
|
|
{
|
|
|
|
Key: "status_id",
|
|
|
|
Value: favedStatus.ID,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "origin_account_id",
|
|
|
|
Value: favingAccount.ID,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
notif := >smodel.Notification{}
|
|
|
|
err = suite.db.GetWhere(context.Background(), where, notif)
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.Equal(gtsmodel.NotificationFave, notif.NotificationType)
|
|
|
|
suite.Equal(fave.TargetAccountID, notif.TargetAccountID)
|
|
|
|
suite.Equal(fave.AccountID, notif.OriginAccountID)
|
|
|
|
suite.Equal(fave.StatusID, notif.StatusID)
|
2022-08-15 11:35:05 +01:00
|
|
|
suite.False(*notif.Read)
|
2021-09-27 16:42:20 +01:00
|
|
|
|
|
|
|
// 2. a notification should be streamed
|
2022-08-15 11:35:05 +01:00
|
|
|
var msg *stream.Message
|
|
|
|
select {
|
|
|
|
case msg = <-wssStream.Messages:
|
|
|
|
// fine
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
suite.FailNow("no message from wssStream")
|
|
|
|
}
|
2021-11-22 18:03:21 +00:00
|
|
|
suite.Equal(stream.EventTypeNotification, msg.Event)
|
2021-09-27 16:42:20 +01:00
|
|
|
suite.NotEmpty(msg.Payload)
|
2021-11-22 18:03:21 +00:00
|
|
|
suite.EqualValues([]string{stream.TimelineNotifications}, msg.Stream)
|
2021-09-27 16:42:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// TestProcessFaveWithDifferentReceivingAccount ensures that when an account receives a fave that's for
|
|
|
|
// another account in their AP inbox, a notification isn't streamed to the receiving account.
|
|
|
|
//
|
|
|
|
// This tests for an issue we were seeing where Misskey sends out faves to inboxes of people that don't own
|
|
|
|
// the fave, but just follow the actor who received the fave.
|
|
|
|
func (suite *FromFederatorTestSuite) TestProcessFaveWithDifferentReceivingAccount() {
|
|
|
|
receivingAccount := suite.testAccounts["local_account_2"]
|
|
|
|
favedAccount := suite.testAccounts["local_account_1"]
|
|
|
|
favedStatus := suite.testStatuses["local_account_1_status_1"]
|
|
|
|
favingAccount := suite.testAccounts["remote_account_1"]
|
|
|
|
|
2023-02-22 15:05:26 +00:00
|
|
|
wssStream, errWithCode := suite.processor.Stream().Open(context.Background(), receivingAccount, stream.TimelineHome)
|
2021-09-27 16:42:20 +01:00
|
|
|
suite.NoError(errWithCode)
|
|
|
|
|
|
|
|
fave := >smodel.StatusFave{
|
|
|
|
ID: "01FGKJPXFTVQPG9YSSZ95ADS7Q",
|
|
|
|
CreatedAt: time.Now(),
|
|
|
|
UpdatedAt: time.Now(),
|
|
|
|
AccountID: favingAccount.ID,
|
|
|
|
Account: favingAccount,
|
|
|
|
TargetAccountID: favedAccount.ID,
|
|
|
|
TargetAccount: favedAccount,
|
|
|
|
StatusID: favedStatus.ID,
|
|
|
|
Status: favedStatus,
|
|
|
|
URI: favingAccount.URI + "/faves/aaaaaaaaaaaa",
|
|
|
|
}
|
|
|
|
|
|
|
|
err := suite.db.Put(context.Background(), fave)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
err = suite.processor.ProcessFromFederator(context.Background(), messages.FromFederator{
|
|
|
|
APObjectType: ap.ActivityLike,
|
|
|
|
APActivityType: ap.ActivityCreate,
|
|
|
|
GTSModel: fave,
|
|
|
|
ReceivingAccount: receivingAccount,
|
|
|
|
})
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
// side effects should be triggered
|
|
|
|
// 1. a notification should exist for the fave
|
|
|
|
where := []db.Where{
|
|
|
|
{
|
|
|
|
Key: "status_id",
|
|
|
|
Value: favedStatus.ID,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "origin_account_id",
|
|
|
|
Value: favingAccount.ID,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
notif := >smodel.Notification{}
|
|
|
|
err = suite.db.GetWhere(context.Background(), where, notif)
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.Equal(gtsmodel.NotificationFave, notif.NotificationType)
|
|
|
|
suite.Equal(fave.TargetAccountID, notif.TargetAccountID)
|
|
|
|
suite.Equal(fave.AccountID, notif.OriginAccountID)
|
|
|
|
suite.Equal(fave.StatusID, notif.StatusID)
|
2022-08-15 11:35:05 +01:00
|
|
|
suite.False(*notif.Read)
|
2021-09-27 16:42:20 +01:00
|
|
|
|
|
|
|
// 2. no notification should be streamed to the account that received the fave message, because they weren't the target
|
2021-11-22 18:03:21 +00:00
|
|
|
suite.Empty(wssStream.Messages)
|
2021-09-27 16:42:20 +01:00
|
|
|
}
|
|
|
|
|
2021-09-30 09:56:02 +01:00
|
|
|
func (suite *FromFederatorTestSuite) TestProcessAccountDelete() {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
deletedAccount := suite.testAccounts["remote_account_1"]
|
|
|
|
receivingAccount := suite.testAccounts["local_account_1"]
|
|
|
|
|
|
|
|
// before doing the delete....
|
|
|
|
// make local_account_1 and remote_account_1 into mufos
|
|
|
|
zorkFollowSatan := >smodel.Follow{
|
|
|
|
ID: "01FGRY72ASHBSET64353DPHK9T",
|
|
|
|
CreatedAt: time.Now().Add(-1 * time.Hour),
|
|
|
|
UpdatedAt: time.Now().Add(-1 * time.Hour),
|
|
|
|
AccountID: deletedAccount.ID,
|
|
|
|
TargetAccountID: receivingAccount.ID,
|
2023-08-07 18:38:11 +01:00
|
|
|
ShowReblogs: util.Ptr(true),
|
2021-09-30 09:56:02 +01:00
|
|
|
URI: fmt.Sprintf("%s/follows/01FGRY72ASHBSET64353DPHK9T", deletedAccount.URI),
|
2023-08-07 18:38:11 +01:00
|
|
|
Notify: util.Ptr(false),
|
2021-09-30 09:56:02 +01:00
|
|
|
}
|
|
|
|
err := suite.db.Put(ctx, zorkFollowSatan)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
satanFollowZork := >smodel.Follow{
|
|
|
|
ID: "01FGRYAVAWWPP926J175QGM0WV",
|
|
|
|
CreatedAt: time.Now().Add(-1 * time.Hour),
|
|
|
|
UpdatedAt: time.Now().Add(-1 * time.Hour),
|
|
|
|
AccountID: receivingAccount.ID,
|
|
|
|
TargetAccountID: deletedAccount.ID,
|
2023-08-07 18:38:11 +01:00
|
|
|
ShowReblogs: util.Ptr(true),
|
2021-09-30 09:56:02 +01:00
|
|
|
URI: fmt.Sprintf("%s/follows/01FGRYAVAWWPP926J175QGM0WV", receivingAccount.URI),
|
2023-08-07 18:38:11 +01:00
|
|
|
Notify: util.Ptr(false),
|
2021-09-30 09:56:02 +01:00
|
|
|
}
|
|
|
|
err = suite.db.Put(ctx, satanFollowZork)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
// now they are mufos!
|
|
|
|
err = suite.processor.ProcessFromFederator(ctx, messages.FromFederator{
|
|
|
|
APObjectType: ap.ObjectProfile,
|
|
|
|
APActivityType: ap.ActivityDelete,
|
|
|
|
GTSModel: deletedAccount,
|
|
|
|
ReceivingAccount: receivingAccount,
|
|
|
|
})
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
// local account 2 blocked foss_satan, that block should be gone now
|
|
|
|
testBlock := suite.testBlocks["local_account_2_block_remote_account_1"]
|
|
|
|
dbBlock := >smodel.Block{}
|
|
|
|
err = suite.db.GetByID(ctx, testBlock.ID, dbBlock)
|
|
|
|
suite.ErrorIs(err, db.ErrNoEntries)
|
|
|
|
|
|
|
|
// the mufos should be gone now too
|
[performance] refactoring + add fave / follow / request / visibility caching (#1607)
* refactor visibility checking, add caching for visibility
* invalidate visibility cache items on account / status deletes
* fix requester ID passed to visibility cache nil ptr
* de-interface caches, fix home / public timeline caching + visibility
* finish adding code comments for visibility filter
* fix angry goconst linter warnings
* actually finish adding filter visibility code comments for timeline functions
* move home timeline status author check to after visibility
* remove now-unused code
* add more code comments
* add TODO code comment, update printed cache start names
* update printed cache names on stop
* start adding separate follow(request) delete db functions, add specific visibility cache tests
* add relationship type caching
* fix getting local account follows / followed-bys, other small codebase improvements
* simplify invalidation using cache hooks, add more GetAccountBy___() functions
* fix boosting to return 404 if not boostable but no error (to not leak status ID)
* remove dead code
* improved placement of cache invalidation
* update license headers
* add example follow, follow-request config entries
* add example visibility cache configuration to config file
* use specific PutFollowRequest() instead of just Put()
* add tests for all GetAccountBy()
* add GetBlockBy() tests
* update block to check primitive fields
* update and finish adding Get{Account,Block,Follow,FollowRequest}By() tests
* fix copy-pasted code
* update envparsing test
* whitespace
* fix bun struct tag
* add license header to gtscontext
* fix old license header
* improved error creation to not use fmt.Errorf() when not needed
* fix various rebase conflicts, fix account test
* remove commented-out code, fix-up mention caching
* fix mention select bun statement
* ensure mention target account populated, pass in context to customrenderer logging
* remove more uncommented code, fix typeutil test
* add statusfave database model caching
* add status fave cache configuration
* add status fave cache example config
* woops, catch missed error. nice catch linter!
* add back testrig panic on nil db
* update example configuration to match defaults, slight tweak to cache configuration defaults
* update envparsing test with new defaults
* fetch followingget to use the follow target account
* use accounnt.IsLocal() instead of empty domain check
* use constants for the cache visibility type check
* use bun.In() for notification type restriction in db query
* include replies when fetching PublicTimeline() (to account for single-author threads in Visibility{}.StatusPublicTimelineable())
* use bun query building for nested select statements to ensure working with postgres
* update public timeline future status checks to match visibility filter
* same as previous, for home timeline
* update public timeline tests to dynamically check for appropriate statuses
* migrate accounts to allow unique constraint on public_key
* provide minimal account with publicKey
---------
Signed-off-by: kim <grufwub@gmail.com>
Co-authored-by: tsmethurst <tobi.smethurst@protonmail.com>
2023-03-28 14:03:14 +01:00
|
|
|
satanFollowsZork, err := suite.db.IsFollowing(ctx, deletedAccount.ID, receivingAccount.ID)
|
2021-09-30 09:56:02 +01:00
|
|
|
suite.NoError(err)
|
|
|
|
suite.False(satanFollowsZork)
|
[performance] refactoring + add fave / follow / request / visibility caching (#1607)
* refactor visibility checking, add caching for visibility
* invalidate visibility cache items on account / status deletes
* fix requester ID passed to visibility cache nil ptr
* de-interface caches, fix home / public timeline caching + visibility
* finish adding code comments for visibility filter
* fix angry goconst linter warnings
* actually finish adding filter visibility code comments for timeline functions
* move home timeline status author check to after visibility
* remove now-unused code
* add more code comments
* add TODO code comment, update printed cache start names
* update printed cache names on stop
* start adding separate follow(request) delete db functions, add specific visibility cache tests
* add relationship type caching
* fix getting local account follows / followed-bys, other small codebase improvements
* simplify invalidation using cache hooks, add more GetAccountBy___() functions
* fix boosting to return 404 if not boostable but no error (to not leak status ID)
* remove dead code
* improved placement of cache invalidation
* update license headers
* add example follow, follow-request config entries
* add example visibility cache configuration to config file
* use specific PutFollowRequest() instead of just Put()
* add tests for all GetAccountBy()
* add GetBlockBy() tests
* update block to check primitive fields
* update and finish adding Get{Account,Block,Follow,FollowRequest}By() tests
* fix copy-pasted code
* update envparsing test
* whitespace
* fix bun struct tag
* add license header to gtscontext
* fix old license header
* improved error creation to not use fmt.Errorf() when not needed
* fix various rebase conflicts, fix account test
* remove commented-out code, fix-up mention caching
* fix mention select bun statement
* ensure mention target account populated, pass in context to customrenderer logging
* remove more uncommented code, fix typeutil test
* add statusfave database model caching
* add status fave cache configuration
* add status fave cache example config
* woops, catch missed error. nice catch linter!
* add back testrig panic on nil db
* update example configuration to match defaults, slight tweak to cache configuration defaults
* update envparsing test with new defaults
* fetch followingget to use the follow target account
* use accounnt.IsLocal() instead of empty domain check
* use constants for the cache visibility type check
* use bun.In() for notification type restriction in db query
* include replies when fetching PublicTimeline() (to account for single-author threads in Visibility{}.StatusPublicTimelineable())
* use bun query building for nested select statements to ensure working with postgres
* update public timeline future status checks to match visibility filter
* same as previous, for home timeline
* update public timeline tests to dynamically check for appropriate statuses
* migrate accounts to allow unique constraint on public_key
* provide minimal account with publicKey
---------
Signed-off-by: kim <grufwub@gmail.com>
Co-authored-by: tsmethurst <tobi.smethurst@protonmail.com>
2023-03-28 14:03:14 +01:00
|
|
|
zorkFollowsSatan, err := suite.db.IsFollowing(ctx, receivingAccount.ID, deletedAccount.ID)
|
2021-09-30 09:56:02 +01:00
|
|
|
suite.NoError(err)
|
|
|
|
suite.False(zorkFollowsSatan)
|
|
|
|
|
|
|
|
// no statuses from foss satan should be left in the database
|
2022-09-21 18:55:52 +01:00
|
|
|
if !testrig.WaitFor(func() bool {
|
2023-02-25 12:16:30 +00:00
|
|
|
s, err := suite.db.GetAccountStatuses(ctx, deletedAccount.ID, 0, false, false, "", "", false, false)
|
2022-10-03 09:46:11 +01:00
|
|
|
return s == nil && err == db.ErrNoEntries
|
2022-09-21 18:55:52 +01:00
|
|
|
}) {
|
|
|
|
suite.FailNow("timeout waiting for statuses to be deleted")
|
|
|
|
}
|
2021-09-30 09:56:02 +01:00
|
|
|
|
|
|
|
dbAccount, err := suite.db.GetAccountByID(ctx, deletedAccount.ID)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
suite.Empty(dbAccount.Note)
|
|
|
|
suite.Empty(dbAccount.DisplayName)
|
|
|
|
suite.Empty(dbAccount.AvatarMediaAttachmentID)
|
|
|
|
suite.Empty(dbAccount.AvatarRemoteURL)
|
|
|
|
suite.Empty(dbAccount.HeaderMediaAttachmentID)
|
|
|
|
suite.Empty(dbAccount.HeaderRemoteURL)
|
|
|
|
suite.Empty(dbAccount.Reason)
|
|
|
|
suite.Empty(dbAccount.Fields)
|
2022-08-15 11:35:05 +01:00
|
|
|
suite.True(*dbAccount.HideCollections)
|
|
|
|
suite.False(*dbAccount.Discoverable)
|
2021-09-30 09:56:02 +01:00
|
|
|
suite.WithinDuration(time.Now(), dbAccount.SuspendedAt, 30*time.Second)
|
|
|
|
suite.Equal(dbAccount.ID, dbAccount.SuspensionOrigin)
|
|
|
|
}
|
|
|
|
|
2021-10-01 18:08:50 +01:00
|
|
|
func (suite *FromFederatorTestSuite) TestProcessFollowRequestLocked() {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
originAccount := suite.testAccounts["remote_account_1"]
|
|
|
|
|
|
|
|
// target is a locked account
|
|
|
|
targetAccount := suite.testAccounts["local_account_2"]
|
|
|
|
|
2023-02-22 15:05:26 +00:00
|
|
|
wssStream, errWithCode := suite.processor.Stream().Open(context.Background(), targetAccount, stream.TimelineHome)
|
2021-10-01 18:08:50 +01:00
|
|
|
suite.NoError(errWithCode)
|
|
|
|
|
|
|
|
// put the follow request in the database as though it had passed through the federating db already
|
|
|
|
satanFollowRequestTurtle := >smodel.FollowRequest{
|
|
|
|
ID: "01FGRYAVAWWPP926J175QGM0WV",
|
|
|
|
CreatedAt: time.Now(),
|
|
|
|
UpdatedAt: time.Now(),
|
|
|
|
AccountID: originAccount.ID,
|
|
|
|
Account: originAccount,
|
|
|
|
TargetAccountID: targetAccount.ID,
|
|
|
|
TargetAccount: targetAccount,
|
2023-08-07 18:38:11 +01:00
|
|
|
ShowReblogs: util.Ptr(true),
|
2021-10-01 18:08:50 +01:00
|
|
|
URI: fmt.Sprintf("%s/follows/01FGRYAVAWWPP926J175QGM0WV", originAccount.URI),
|
2023-08-07 18:38:11 +01:00
|
|
|
Notify: util.Ptr(false),
|
2021-10-01 18:08:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
err := suite.db.Put(ctx, satanFollowRequestTurtle)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
err = suite.processor.ProcessFromFederator(ctx, messages.FromFederator{
|
|
|
|
APObjectType: ap.ActivityFollow,
|
|
|
|
APActivityType: ap.ActivityCreate,
|
|
|
|
GTSModel: satanFollowRequestTurtle,
|
|
|
|
ReceivingAccount: targetAccount,
|
|
|
|
})
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
// a notification should be streamed
|
2022-08-15 11:35:05 +01:00
|
|
|
var msg *stream.Message
|
|
|
|
select {
|
|
|
|
case msg = <-wssStream.Messages:
|
|
|
|
// fine
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
suite.FailNow("no message from wssStream")
|
|
|
|
}
|
2021-11-22 18:03:21 +00:00
|
|
|
suite.Equal(stream.EventTypeNotification, msg.Event)
|
2021-10-01 18:08:50 +01:00
|
|
|
suite.NotEmpty(msg.Payload)
|
2021-11-22 18:03:21 +00:00
|
|
|
suite.EqualValues([]string{stream.TimelineHome}, msg.Stream)
|
2023-01-02 12:10:50 +00:00
|
|
|
notif := &apimodel.Notification{}
|
2021-10-01 18:08:50 +01:00
|
|
|
err = json.Unmarshal([]byte(msg.Payload), notif)
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.Equal("follow_request", notif.Type)
|
|
|
|
suite.Equal(originAccount.ID, notif.Account.ID)
|
|
|
|
|
|
|
|
// no messages should have been sent out, since we didn't need to federate an accept
|
2022-06-11 10:01:34 +01:00
|
|
|
suite.Empty(suite.httpClient.SentMessages)
|
2021-10-01 18:08:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *FromFederatorTestSuite) TestProcessFollowRequestUnlocked() {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
originAccount := suite.testAccounts["remote_account_1"]
|
|
|
|
|
|
|
|
// target is an unlocked account
|
|
|
|
targetAccount := suite.testAccounts["local_account_1"]
|
|
|
|
|
2023-02-22 15:05:26 +00:00
|
|
|
wssStream, errWithCode := suite.processor.Stream().Open(context.Background(), targetAccount, stream.TimelineHome)
|
2021-10-01 18:08:50 +01:00
|
|
|
suite.NoError(errWithCode)
|
|
|
|
|
|
|
|
// put the follow request in the database as though it had passed through the federating db already
|
|
|
|
satanFollowRequestTurtle := >smodel.FollowRequest{
|
|
|
|
ID: "01FGRYAVAWWPP926J175QGM0WV",
|
|
|
|
CreatedAt: time.Now(),
|
|
|
|
UpdatedAt: time.Now(),
|
|
|
|
AccountID: originAccount.ID,
|
|
|
|
Account: originAccount,
|
|
|
|
TargetAccountID: targetAccount.ID,
|
|
|
|
TargetAccount: targetAccount,
|
2023-08-07 18:38:11 +01:00
|
|
|
ShowReblogs: util.Ptr(true),
|
2021-10-01 18:08:50 +01:00
|
|
|
URI: fmt.Sprintf("%s/follows/01FGRYAVAWWPP926J175QGM0WV", originAccount.URI),
|
2023-08-07 18:38:11 +01:00
|
|
|
Notify: util.Ptr(false),
|
2021-10-01 18:08:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
err := suite.db.Put(ctx, satanFollowRequestTurtle)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
err = suite.processor.ProcessFromFederator(ctx, messages.FromFederator{
|
|
|
|
APObjectType: ap.ActivityFollow,
|
|
|
|
APActivityType: ap.ActivityCreate,
|
|
|
|
GTSModel: satanFollowRequestTurtle,
|
|
|
|
ReceivingAccount: targetAccount,
|
|
|
|
})
|
|
|
|
suite.NoError(err)
|
|
|
|
|
2022-08-31 16:31:21 +01:00
|
|
|
// an accept message should be sent to satan's inbox
|
|
|
|
var sent [][]byte
|
|
|
|
if !testrig.WaitFor(func() bool {
|
2022-09-23 20:27:35 +01:00
|
|
|
sentI, ok := suite.httpClient.SentMessages.Load(*originAccount.SharedInboxURI)
|
2022-08-31 16:31:21 +01:00
|
|
|
if ok {
|
|
|
|
sent, ok = sentI.([][]byte)
|
|
|
|
if !ok {
|
|
|
|
panic("SentMessages entry was not []byte")
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}) {
|
|
|
|
suite.FailNow("timed out waiting for message")
|
2022-08-15 11:35:05 +01:00
|
|
|
}
|
2021-10-01 18:08:50 +01:00
|
|
|
|
|
|
|
accept := &struct {
|
|
|
|
Actor string `json:"actor"`
|
|
|
|
ID string `json:"id"`
|
|
|
|
Object struct {
|
|
|
|
Actor string `json:"actor"`
|
|
|
|
ID string `json:"id"`
|
|
|
|
Object string `json:"object"`
|
|
|
|
To string `json:"to"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
}
|
|
|
|
To string `json:"to"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
}{}
|
2022-08-31 16:31:21 +01:00
|
|
|
err = json.Unmarshal(sent[0], accept)
|
2021-10-01 18:08:50 +01:00
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
suite.Equal(targetAccount.URI, accept.Actor)
|
|
|
|
suite.Equal(originAccount.URI, accept.Object.Actor)
|
|
|
|
suite.Equal(satanFollowRequestTurtle.URI, accept.Object.ID)
|
|
|
|
suite.Equal(targetAccount.URI, accept.Object.Object)
|
|
|
|
suite.Equal(targetAccount.URI, accept.Object.To)
|
|
|
|
suite.Equal("Follow", accept.Object.Type)
|
|
|
|
suite.Equal(originAccount.URI, accept.To)
|
|
|
|
suite.Equal("Accept", accept.Type)
|
2022-08-31 16:31:21 +01:00
|
|
|
|
|
|
|
// a notification should be streamed
|
|
|
|
var msg *stream.Message
|
|
|
|
select {
|
|
|
|
case msg = <-wssStream.Messages:
|
|
|
|
// fine
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
suite.FailNow("no message from wssStream")
|
|
|
|
}
|
|
|
|
suite.Equal(stream.EventTypeNotification, msg.Event)
|
|
|
|
suite.NotEmpty(msg.Payload)
|
|
|
|
suite.EqualValues([]string{stream.TimelineHome}, msg.Stream)
|
2023-01-02 12:10:50 +00:00
|
|
|
notif := &apimodel.Notification{}
|
2022-08-31 16:31:21 +01:00
|
|
|
err = json.Unmarshal([]byte(msg.Payload), notif)
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.Equal("follow", notif.Type)
|
|
|
|
suite.Equal(originAccount.ID, notif.Account.ID)
|
2021-10-01 18:08:50 +01:00
|
|
|
}
|
|
|
|
|
2021-10-10 11:39:25 +01:00
|
|
|
// TestCreateStatusFromIRI checks if a forwarded status can be dereferenced by the processor.
|
|
|
|
func (suite *FromFederatorTestSuite) TestCreateStatusFromIRI() {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
receivingAccount := suite.testAccounts["local_account_1"]
|
|
|
|
statusCreator := suite.testAccounts["remote_account_2"]
|
|
|
|
|
|
|
|
err := suite.processor.ProcessFromFederator(ctx, messages.FromFederator{
|
|
|
|
APObjectType: ap.ObjectNote,
|
|
|
|
APActivityType: ap.ActivityCreate,
|
|
|
|
GTSModel: nil, // gtsmodel is nil because this is a forwarded status -- we want to dereference it using the iri
|
|
|
|
ReceivingAccount: receivingAccount,
|
2022-11-30 16:44:02 +00:00
|
|
|
APIri: testrig.URLMustParse("http://example.org/users/Some_User/statuses/afaba698-5740-4e32-a702-af61aa543bc1"),
|
2021-10-10 11:39:25 +01:00
|
|
|
})
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
// status should now be in the database, attributed to remote_account_2
|
2022-11-30 16:44:02 +00:00
|
|
|
s, err := suite.db.GetStatusByURI(context.Background(), "http://example.org/users/Some_User/statuses/afaba698-5740-4e32-a702-af61aa543bc1")
|
2021-10-10 11:39:25 +01:00
|
|
|
suite.NoError(err)
|
|
|
|
suite.Equal(statusCreator.URI, s.AccountURI)
|
|
|
|
}
|
|
|
|
|
2021-09-04 12:29:56 +01:00
|
|
|
func TestFromFederatorTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, &FromFederatorTestSuite{})
|
|
|
|
}
|