2023-03-12 16:00:57 +01: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-24 17:56:48 +02:00
|
|
|
|
2023-01-02 13:10:50 +01:00
|
|
|
package users_test
|
2021-09-24 17:56:48 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
2023-05-28 21:05:15 +02:00
|
|
|
"errors"
|
|
|
|
"io"
|
2021-09-24 17:56:48 +02:00
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/stretchr/testify/suite"
|
2021-11-13 17:29:43 +01:00
|
|
|
"github.com/superseriousbusiness/activity/pub"
|
|
|
|
"github.com/superseriousbusiness/activity/streams"
|
2023-02-03 21:03:05 +01:00
|
|
|
"github.com/superseriousbusiness/activity/streams/vocab"
|
2023-05-09 12:16:10 +02:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
2023-01-02 13:10:50 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/api/activitypub/users"
|
2021-09-24 17:56:48 +02:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
2023-05-28 21:05:15 +02:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
2021-09-24 17:56:48 +02:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/id"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/testrig"
|
|
|
|
)
|
|
|
|
|
|
|
|
type InboxPostTestSuite struct {
|
|
|
|
UserStandardTestSuite
|
|
|
|
}
|
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
func (suite *InboxPostTestSuite) inboxPost(
|
|
|
|
activity pub.Activity,
|
|
|
|
requestingAccount *gtsmodel.Account,
|
|
|
|
targetAccount *gtsmodel.Account,
|
|
|
|
expectedHTTPStatus int,
|
|
|
|
expectedBody string,
|
|
|
|
middlewares ...func(*gin.Context),
|
|
|
|
) {
|
|
|
|
var (
|
|
|
|
recorder = httptest.NewRecorder()
|
|
|
|
ctx, _ = testrig.CreateGinTestContext(recorder, nil)
|
|
|
|
)
|
|
|
|
|
|
|
|
// Prepare the requst body bytes.
|
|
|
|
bodyI, err := ap.Serialize(activity)
|
|
|
|
if err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
b, err := json.MarshalIndent(bodyI, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
suite.T().Logf("prepared POST body:\n%s", string(b))
|
|
|
|
|
|
|
|
// Prepare signature headers for this Activity.
|
|
|
|
signature, digestHeader, dateHeader := testrig.GetSignatureForActivity(
|
|
|
|
activity,
|
|
|
|
requestingAccount.PublicKeyURI,
|
|
|
|
requestingAccount.PrivateKey,
|
|
|
|
testrig.URLMustParse(targetAccount.InboxURI),
|
|
|
|
)
|
|
|
|
|
|
|
|
// Put the request together.
|
|
|
|
ctx.AddParam(users.UsernameKey, targetAccount.Username)
|
|
|
|
ctx.Request = httptest.NewRequest(http.MethodPost, targetAccount.InboxURI, bytes.NewReader(b))
|
|
|
|
ctx.Request.Header.Set("Signature", signature)
|
|
|
|
ctx.Request.Header.Set("Date", dateHeader)
|
|
|
|
ctx.Request.Header.Set("Digest", digestHeader)
|
|
|
|
ctx.Request.Header.Set("Content-Type", "application/activity+json")
|
|
|
|
|
|
|
|
// Pass the context through provided middlewares.
|
|
|
|
for _, middleware := range middlewares {
|
|
|
|
middleware(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Trigger the function being tested.
|
|
|
|
suite.userModule.InboxPOSTHandler(ctx)
|
2021-09-24 17:56:48 +02:00
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
// Read the result.
|
|
|
|
result := recorder.Result()
|
|
|
|
defer result.Body.Close()
|
|
|
|
|
|
|
|
b, err = io.ReadAll(result.Body)
|
|
|
|
if err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
|
2023-08-02 17:21:46 +02:00
|
|
|
errs := gtserror.NewMultiError(2)
|
2023-05-28 21:05:15 +02:00
|
|
|
|
|
|
|
// Check expected code + body.
|
|
|
|
if resultCode := recorder.Code; expectedHTTPStatus != resultCode {
|
2023-08-02 17:21:46 +02:00
|
|
|
errs.Appendf("expected %d got %d", expectedHTTPStatus, resultCode)
|
2023-05-28 21:05:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we got an expected body, return early.
|
|
|
|
if expectedBody != "" && string(b) != expectedBody {
|
2023-08-02 17:21:46 +02:00
|
|
|
errs.Appendf("expected %s got %s", expectedBody, string(b))
|
2023-05-28 21:05:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := errs.Combine(); err != nil {
|
|
|
|
suite.FailNow("", "%v (body %s)", err, string(b))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *InboxPostTestSuite) newBlock(blockID string, blockingAccount *gtsmodel.Account, blockedAccount *gtsmodel.Account) vocab.ActivityStreamsBlock {
|
2021-09-24 17:56:48 +02:00
|
|
|
block := streams.NewActivityStreamsBlock()
|
|
|
|
|
|
|
|
// set the actor property to the block-ing account's URI
|
|
|
|
actorProp := streams.NewActivityStreamsActorProperty()
|
|
|
|
actorIRI := testrig.URLMustParse(blockingAccount.URI)
|
|
|
|
actorProp.AppendIRI(actorIRI)
|
|
|
|
block.SetActivityStreamsActor(actorProp)
|
|
|
|
|
|
|
|
// set the ID property to the blocks's URI
|
|
|
|
idProp := streams.NewJSONLDIdProperty()
|
2023-05-28 21:05:15 +02:00
|
|
|
idProp.Set(testrig.URLMustParse(blockID))
|
2021-09-24 17:56:48 +02:00
|
|
|
block.SetJSONLDId(idProp)
|
|
|
|
|
|
|
|
// set the object property to the target account's URI
|
|
|
|
objectProp := streams.NewActivityStreamsObjectProperty()
|
|
|
|
targetIRI := testrig.URLMustParse(blockedAccount.URI)
|
|
|
|
objectProp.AppendIRI(targetIRI)
|
|
|
|
block.SetActivityStreamsObject(objectProp)
|
|
|
|
|
|
|
|
// set the TO property to the target account's IRI
|
|
|
|
toProp := streams.NewActivityStreamsToProperty()
|
|
|
|
toIRI := testrig.URLMustParse(blockedAccount.URI)
|
|
|
|
toProp.AppendIRI(toIRI)
|
|
|
|
block.SetActivityStreamsTo(toProp)
|
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
return block
|
2021-09-24 17:56:48 +02:00
|
|
|
}
|
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
func (suite *InboxPostTestSuite) newUndo(
|
|
|
|
originalActivity pub.Activity,
|
|
|
|
objectF func() vocab.ActivityStreamsObjectProperty,
|
|
|
|
to string,
|
|
|
|
undoIRI string,
|
|
|
|
) vocab.ActivityStreamsUndo {
|
2021-09-24 17:56:48 +02:00
|
|
|
undo := streams.NewActivityStreamsUndo()
|
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
// Set the appropriate actor.
|
|
|
|
undo.SetActivityStreamsActor(originalActivity.GetActivityStreamsActor())
|
|
|
|
|
|
|
|
// Set the original activity uri as the 'object' property.
|
|
|
|
undo.SetActivityStreamsObject(objectF())
|
2021-09-24 17:56:48 +02:00
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
// Set the To of the undo as the target of the activity.
|
2021-09-24 17:56:48 +02:00
|
|
|
undoTo := streams.NewActivityStreamsToProperty()
|
2023-05-28 21:05:15 +02:00
|
|
|
undoTo.AppendIRI(testrig.URLMustParse(to))
|
2021-09-24 17:56:48 +02:00
|
|
|
undo.SetActivityStreamsTo(undoTo)
|
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
// Set the ID property to the undo's URI.
|
2021-09-24 17:56:48 +02:00
|
|
|
undoID := streams.NewJSONLDIdProperty()
|
2023-05-28 21:05:15 +02:00
|
|
|
undoID.SetIRI(testrig.URLMustParse(undoIRI))
|
2021-09-24 17:56:48 +02:00
|
|
|
undo.SetJSONLDId(undoID)
|
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
return undo
|
2021-09-24 17:56:48 +02:00
|
|
|
}
|
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
func (suite *InboxPostTestSuite) newUpdatePerson(person vocab.ActivityStreamsPerson, cc string, updateIRI string) vocab.ActivityStreamsUpdate {
|
2021-09-28 15:21:59 +02:00
|
|
|
// create an update
|
|
|
|
update := streams.NewActivityStreamsUpdate()
|
|
|
|
|
|
|
|
// set the appropriate actor on it
|
|
|
|
updateActor := streams.NewActivityStreamsActorProperty()
|
2023-05-28 21:05:15 +02:00
|
|
|
updateActor.AppendIRI(person.GetJSONLDId().Get())
|
2021-09-28 15:21:59 +02:00
|
|
|
update.SetActivityStreamsActor(updateActor)
|
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
// Set the person as the 'object' property.
|
2021-09-28 15:21:59 +02:00
|
|
|
updateObject := streams.NewActivityStreamsObjectProperty()
|
2023-05-28 21:05:15 +02:00
|
|
|
updateObject.AppendActivityStreamsPerson(person)
|
2021-09-28 15:21:59 +02:00
|
|
|
update.SetActivityStreamsObject(updateObject)
|
|
|
|
|
|
|
|
// Set the To of the update as public
|
|
|
|
updateTo := streams.NewActivityStreamsToProperty()
|
2021-10-06 18:18:02 +02:00
|
|
|
updateTo.AppendIRI(testrig.URLMustParse(pub.PublicActivityPubIRI))
|
2021-09-28 15:21:59 +02:00
|
|
|
update.SetActivityStreamsTo(updateTo)
|
|
|
|
|
|
|
|
// set the cc of the update to the receivingAccount
|
|
|
|
updateCC := streams.NewActivityStreamsCcProperty()
|
2023-05-28 21:05:15 +02:00
|
|
|
updateCC.AppendIRI(testrig.URLMustParse(cc))
|
2021-09-28 15:21:59 +02:00
|
|
|
update.SetActivityStreamsCc(updateCC)
|
|
|
|
|
|
|
|
// set some random-ass ID for the activity
|
2023-05-28 21:05:15 +02:00
|
|
|
updateID := streams.NewJSONLDIdProperty()
|
|
|
|
updateID.SetIRI(testrig.URLMustParse(updateIRI))
|
|
|
|
update.SetJSONLDId(updateID)
|
2021-09-28 15:21:59 +02:00
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
return update
|
|
|
|
}
|
2021-09-28 15:21:59 +02:00
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
func (suite *InboxPostTestSuite) newDelete(actorIRI string, objectIRI string, deleteIRI string) vocab.ActivityStreamsDelete {
|
|
|
|
// create a delete
|
|
|
|
delete := streams.NewActivityStreamsDelete()
|
2021-09-28 15:21:59 +02:00
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
// set the appropriate actor on it
|
|
|
|
deleteActor := streams.NewActivityStreamsActorProperty()
|
|
|
|
deleteActor.AppendIRI(testrig.URLMustParse(actorIRI))
|
|
|
|
delete.SetActivityStreamsActor(deleteActor)
|
2023-03-01 19:26:53 +01:00
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
// Set 'object' property.
|
|
|
|
deleteObject := streams.NewActivityStreamsObjectProperty()
|
|
|
|
deleteObject.AppendIRI(testrig.URLMustParse(objectIRI))
|
|
|
|
delete.SetActivityStreamsObject(deleteObject)
|
2021-09-28 15:21:59 +02:00
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
// Set the To of the delete as public
|
|
|
|
deleteTo := streams.NewActivityStreamsToProperty()
|
|
|
|
deleteTo.AppendIRI(testrig.URLMustParse(pub.PublicActivityPubIRI))
|
|
|
|
delete.SetActivityStreamsTo(deleteTo)
|
|
|
|
|
|
|
|
// set some random-ass ID for the activity
|
|
|
|
deleteID := streams.NewJSONLDIdProperty()
|
|
|
|
deleteID.SetIRI(testrig.URLMustParse(deleteIRI))
|
|
|
|
delete.SetJSONLDId(deleteID)
|
|
|
|
|
|
|
|
return delete
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestPostBlock verifies that a remote account can block one of
|
|
|
|
// our instance users.
|
|
|
|
func (suite *InboxPostTestSuite) TestPostBlock() {
|
|
|
|
var (
|
|
|
|
requestingAccount = suite.testAccounts["remote_account_1"]
|
|
|
|
targetAccount = suite.testAccounts["local_account_1"]
|
|
|
|
activityID = requestingAccount.URI + "/some-new-activity/01FG9C441MCTW3R2W117V2PQK3"
|
|
|
|
)
|
|
|
|
|
|
|
|
block := suite.newBlock(activityID, requestingAccount, targetAccount)
|
|
|
|
|
|
|
|
// Block.
|
|
|
|
suite.inboxPost(
|
|
|
|
block,
|
|
|
|
requestingAccount,
|
|
|
|
targetAccount,
|
|
|
|
http.StatusAccepted,
|
|
|
|
`{"status":"Accepted"}`,
|
|
|
|
suite.signatureCheck,
|
|
|
|
)
|
|
|
|
|
|
|
|
// Ensure block created in the database.
|
|
|
|
var (
|
|
|
|
dbBlock *gtsmodel.Block
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
if !testrig.WaitFor(func() bool {
|
|
|
|
dbBlock, err = suite.db.GetBlock(context.Background(), requestingAccount.ID, targetAccount.ID)
|
|
|
|
return err == nil && dbBlock != nil
|
|
|
|
}) {
|
|
|
|
suite.FailNow("timed out waiting for block to be created")
|
|
|
|
}
|
|
|
|
}
|
2021-09-28 15:21:59 +02:00
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
// TestPostUnblock verifies that a remote account who blocks
|
|
|
|
// one of our instance users should be able to undo that block.
|
|
|
|
func (suite *InboxPostTestSuite) TestPostUnblock() {
|
|
|
|
var (
|
|
|
|
ctx = context.Background()
|
|
|
|
requestingAccount = suite.testAccounts["remote_account_1"]
|
|
|
|
targetAccount = suite.testAccounts["local_account_1"]
|
|
|
|
blockID = "http://fossbros-anonymous.io/blocks/01H1462TPRTVG2RTQCTSQ7N6Q0"
|
|
|
|
undoID = "http://fossbros-anonymous.io/some-activity/01H1463RDQNG5H98F29BXYHW6B"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Put a block in the database so we have something to undo.
|
|
|
|
block := >smodel.Block{
|
|
|
|
ID: id.NewULID(),
|
|
|
|
URI: blockID,
|
|
|
|
AccountID: requestingAccount.ID,
|
|
|
|
TargetAccountID: targetAccount.ID,
|
|
|
|
}
|
|
|
|
if err := suite.db.PutBlock(ctx, block); err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
2021-09-28 15:21:59 +02:00
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
// Create the undo from the AS model block.
|
|
|
|
asBlock, err := suite.tc.BlockToAS(ctx, block)
|
|
|
|
if err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
2021-09-28 15:21:59 +02:00
|
|
|
}
|
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
undo := suite.newUndo(asBlock, func() vocab.ActivityStreamsObjectProperty {
|
|
|
|
// Append the whole block as Object.
|
|
|
|
op := streams.NewActivityStreamsObjectProperty()
|
|
|
|
op.AppendActivityStreamsBlock(asBlock)
|
|
|
|
return op
|
|
|
|
}, targetAccount.URI, undoID)
|
|
|
|
|
|
|
|
// Undo.
|
|
|
|
suite.inboxPost(
|
|
|
|
undo,
|
|
|
|
requestingAccount,
|
|
|
|
targetAccount,
|
|
|
|
http.StatusAccepted,
|
|
|
|
`{"status":"Accepted"}`,
|
|
|
|
suite.signatureCheck,
|
|
|
|
)
|
|
|
|
|
|
|
|
// Ensure block removed from the database.
|
|
|
|
if !testrig.WaitFor(func() bool {
|
|
|
|
_, err := suite.db.GetBlockByID(ctx, block.ID)
|
|
|
|
return errors.Is(err, db.ErrNoEntries)
|
|
|
|
}) {
|
|
|
|
suite.FailNow("timed out waiting for block to be removed")
|
|
|
|
}
|
|
|
|
}
|
2021-09-28 15:21:59 +02:00
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
func (suite *InboxPostTestSuite) TestPostUpdate() {
|
|
|
|
var (
|
|
|
|
requestingAccount = new(gtsmodel.Account)
|
|
|
|
targetAccount = suite.testAccounts["local_account_1"]
|
|
|
|
activityID = "http://fossbros-anonymous.io/72cc96a3-f742-4daf-b9f5-3407667260c5"
|
|
|
|
updatedDisplayName = "updated display name!"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Copy the requesting account, since we'll be changing it.
|
|
|
|
*requestingAccount = *suite.testAccounts["remote_account_1"]
|
|
|
|
|
|
|
|
// Update the account's display name.
|
|
|
|
requestingAccount.DisplayName = updatedDisplayName
|
|
|
|
|
|
|
|
// Add an emoji to the account; because we're serializing this
|
|
|
|
// remote account from our own instance, we need to cheat a bit
|
|
|
|
// to get the emoji to work properly, just for this test.
|
|
|
|
testEmoji := >smodel.Emoji{}
|
|
|
|
*testEmoji = *testrig.NewTestEmojis()["yell"]
|
|
|
|
testEmoji.ImageURL = testEmoji.ImageRemoteURL // <- here's the cheat
|
|
|
|
requestingAccount.Emojis = []*gtsmodel.Emoji{testEmoji}
|
|
|
|
|
|
|
|
// Create an update from the account.
|
|
|
|
asAccount, err := suite.tc.AccountToAS(context.Background(), requestingAccount)
|
|
|
|
if err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
update := suite.newUpdatePerson(asAccount, targetAccount.URI, activityID)
|
|
|
|
|
|
|
|
// Update.
|
|
|
|
suite.inboxPost(
|
|
|
|
update,
|
|
|
|
requestingAccount,
|
|
|
|
targetAccount,
|
|
|
|
http.StatusAccepted,
|
|
|
|
`{"status":"Accepted"}`,
|
|
|
|
suite.signatureCheck,
|
|
|
|
)
|
2021-09-28 15:21:59 +02:00
|
|
|
|
|
|
|
// account should be changed in the database now
|
2022-09-26 11:56:01 +02:00
|
|
|
var dbUpdatedAccount *gtsmodel.Account
|
|
|
|
|
|
|
|
if !testrig.WaitFor(func() bool {
|
|
|
|
// displayName should be updated
|
2023-05-28 21:05:15 +02:00
|
|
|
dbUpdatedAccount, _ = suite.db.GetAccountByID(context.Background(), requestingAccount.ID)
|
|
|
|
return dbUpdatedAccount.DisplayName == updatedDisplayName
|
2022-09-26 11:56:01 +02:00
|
|
|
}) {
|
|
|
|
suite.FailNow("timed out waiting for account update")
|
|
|
|
}
|
|
|
|
|
|
|
|
// emojis should be updated
|
|
|
|
suite.Contains(dbUpdatedAccount.EmojiIDs, testEmoji.ID)
|
2021-09-28 15:21:59 +02:00
|
|
|
|
2023-02-03 21:03:05 +01:00
|
|
|
// account should be freshly fetched
|
|
|
|
suite.WithinDuration(time.Now(), dbUpdatedAccount.FetchedAt, 10*time.Second)
|
2021-09-28 15:21:59 +02:00
|
|
|
|
|
|
|
// everything else should be the same as it was before
|
2023-05-28 21:05:15 +02:00
|
|
|
suite.EqualValues(requestingAccount.Username, dbUpdatedAccount.Username)
|
|
|
|
suite.EqualValues(requestingAccount.Domain, dbUpdatedAccount.Domain)
|
|
|
|
suite.EqualValues(requestingAccount.AvatarMediaAttachmentID, dbUpdatedAccount.AvatarMediaAttachmentID)
|
|
|
|
suite.EqualValues(requestingAccount.AvatarMediaAttachment, dbUpdatedAccount.AvatarMediaAttachment)
|
|
|
|
suite.EqualValues(requestingAccount.AvatarRemoteURL, dbUpdatedAccount.AvatarRemoteURL)
|
|
|
|
suite.EqualValues(requestingAccount.HeaderMediaAttachmentID, dbUpdatedAccount.HeaderMediaAttachmentID)
|
|
|
|
suite.EqualValues(requestingAccount.HeaderMediaAttachment, dbUpdatedAccount.HeaderMediaAttachment)
|
|
|
|
suite.EqualValues(requestingAccount.HeaderRemoteURL, dbUpdatedAccount.HeaderRemoteURL)
|
|
|
|
suite.EqualValues(requestingAccount.Note, dbUpdatedAccount.Note)
|
|
|
|
suite.EqualValues(requestingAccount.Memorial, dbUpdatedAccount.Memorial)
|
|
|
|
suite.EqualValues(requestingAccount.AlsoKnownAs, dbUpdatedAccount.AlsoKnownAs)
|
|
|
|
suite.EqualValues(requestingAccount.MovedToAccountID, dbUpdatedAccount.MovedToAccountID)
|
|
|
|
suite.EqualValues(requestingAccount.Bot, dbUpdatedAccount.Bot)
|
|
|
|
suite.EqualValues(requestingAccount.Reason, dbUpdatedAccount.Reason)
|
|
|
|
suite.EqualValues(requestingAccount.Locked, dbUpdatedAccount.Locked)
|
|
|
|
suite.EqualValues(requestingAccount.Discoverable, dbUpdatedAccount.Discoverable)
|
|
|
|
suite.EqualValues(requestingAccount.Privacy, dbUpdatedAccount.Privacy)
|
|
|
|
suite.EqualValues(requestingAccount.Sensitive, dbUpdatedAccount.Sensitive)
|
|
|
|
suite.EqualValues(requestingAccount.Language, dbUpdatedAccount.Language)
|
|
|
|
suite.EqualValues(requestingAccount.URI, dbUpdatedAccount.URI)
|
|
|
|
suite.EqualValues(requestingAccount.URL, dbUpdatedAccount.URL)
|
|
|
|
suite.EqualValues(requestingAccount.InboxURI, dbUpdatedAccount.InboxURI)
|
|
|
|
suite.EqualValues(requestingAccount.OutboxURI, dbUpdatedAccount.OutboxURI)
|
|
|
|
suite.EqualValues(requestingAccount.FollowingURI, dbUpdatedAccount.FollowingURI)
|
|
|
|
suite.EqualValues(requestingAccount.FollowersURI, dbUpdatedAccount.FollowersURI)
|
|
|
|
suite.EqualValues(requestingAccount.FeaturedCollectionURI, dbUpdatedAccount.FeaturedCollectionURI)
|
|
|
|
suite.EqualValues(requestingAccount.ActorType, dbUpdatedAccount.ActorType)
|
|
|
|
suite.EqualValues(requestingAccount.PublicKey, dbUpdatedAccount.PublicKey)
|
|
|
|
suite.EqualValues(requestingAccount.PublicKeyURI, dbUpdatedAccount.PublicKeyURI)
|
|
|
|
suite.EqualValues(requestingAccount.SensitizedAt, dbUpdatedAccount.SensitizedAt)
|
|
|
|
suite.EqualValues(requestingAccount.SilencedAt, dbUpdatedAccount.SilencedAt)
|
|
|
|
suite.EqualValues(requestingAccount.SuspendedAt, dbUpdatedAccount.SuspendedAt)
|
|
|
|
suite.EqualValues(requestingAccount.HideCollections, dbUpdatedAccount.HideCollections)
|
|
|
|
suite.EqualValues(requestingAccount.SuspensionOrigin, dbUpdatedAccount.SuspensionOrigin)
|
2021-09-28 15:21:59 +02:00
|
|
|
}
|
|
|
|
|
2021-09-30 10:56:02 +02:00
|
|
|
func (suite *InboxPostTestSuite) TestPostDelete() {
|
2023-05-28 21:05:15 +02:00
|
|
|
var (
|
|
|
|
ctx = context.Background()
|
|
|
|
requestingAccount = suite.testAccounts["remote_account_1"]
|
|
|
|
targetAccount = suite.testAccounts["local_account_1"]
|
|
|
|
activityID = requestingAccount.URI + "/some-new-activity/01FG9C441MCTW3R2W117V2PQK3"
|
|
|
|
)
|
|
|
|
|
|
|
|
delete := suite.newDelete(requestingAccount.URI, requestingAccount.URI, activityID)
|
|
|
|
|
|
|
|
// Delete.
|
|
|
|
suite.inboxPost(
|
|
|
|
delete,
|
|
|
|
requestingAccount,
|
|
|
|
targetAccount,
|
|
|
|
http.StatusAccepted,
|
|
|
|
`{"status":"Accepted"}`,
|
|
|
|
suite.signatureCheck,
|
|
|
|
)
|
2021-09-30 10:56:02 +02:00
|
|
|
|
2022-08-31 17:31:21 +02:00
|
|
|
if !testrig.WaitFor(func() bool {
|
|
|
|
// local account 2 blocked foss_satan, that block should be gone now
|
|
|
|
testBlock := suite.testBlocks["local_account_2_block_remote_account_1"]
|
2023-05-28 21:05:15 +02:00
|
|
|
_, err := suite.db.GetBlockByID(ctx, testBlock.ID)
|
2022-08-31 17:31:21 +02:00
|
|
|
return suite.ErrorIs(err, db.ErrNoEntries)
|
|
|
|
}) {
|
|
|
|
suite.FailNow("timed out waiting for block to be removed")
|
|
|
|
}
|
2021-09-30 10:56:02 +02:00
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
if !testrig.WaitFor(func() bool {
|
|
|
|
// no statuses from foss satan should be left in the database
|
|
|
|
dbStatuses, err := suite.db.GetAccountStatuses(ctx, requestingAccount.ID, 0, false, false, "", "", false, false)
|
|
|
|
return len(dbStatuses) == 0 && errors.Is(err, db.ErrNoEntries)
|
|
|
|
}) {
|
|
|
|
suite.FailNow("timed out waiting for statuses to be removed")
|
|
|
|
}
|
2021-09-30 10:56:02 +02:00
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
// Account should be stubbified.
|
|
|
|
dbAccount, err := suite.db.GetAccountByID(ctx, requestingAccount.ID)
|
2021-09-30 10:56:02 +02:00
|
|
|
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 12:35:05 +02:00
|
|
|
suite.True(*dbAccount.HideCollections)
|
|
|
|
suite.False(*dbAccount.Discoverable)
|
2021-09-30 10:56:02 +02:00
|
|
|
suite.WithinDuration(time.Now(), dbAccount.SuspendedAt, 30*time.Second)
|
|
|
|
suite.Equal(dbAccount.ID, dbAccount.SuspensionOrigin)
|
|
|
|
}
|
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
func (suite *InboxPostTestSuite) TestPostEmptyCreate() {
|
|
|
|
var (
|
|
|
|
requestingAccount = suite.testAccounts["remote_account_1"]
|
|
|
|
targetAccount = suite.testAccounts["local_account_1"]
|
|
|
|
)
|
|
|
|
|
|
|
|
// Post a create with no object.
|
|
|
|
create := streams.NewActivityStreamsCreate()
|
|
|
|
|
|
|
|
suite.inboxPost(
|
|
|
|
create,
|
|
|
|
requestingAccount,
|
|
|
|
targetAccount,
|
|
|
|
http.StatusBadRequest,
|
2023-10-03 15:59:30 +02:00
|
|
|
`{"error":"Bad Request: missing ActivityStreams id property"}`,
|
2023-05-28 21:05:15 +02:00
|
|
|
suite.signatureCheck,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *InboxPostTestSuite) TestPostFromBlockedAccount() {
|
|
|
|
var (
|
|
|
|
requestingAccount = suite.testAccounts["remote_account_1"]
|
|
|
|
targetAccount = suite.testAccounts["local_account_2"]
|
|
|
|
activityID = requestingAccount.URI + "/some-new-activity/01FG9C441MCTW3R2W117V2PQK3"
|
|
|
|
)
|
|
|
|
|
|
|
|
person, err := suite.tc.AccountToAS(context.Background(), requestingAccount)
|
|
|
|
if err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Post an update from foss satan to turtle, who blocks him.
|
|
|
|
update := suite.newUpdatePerson(person, targetAccount.URI, activityID)
|
|
|
|
|
|
|
|
suite.inboxPost(
|
|
|
|
update,
|
|
|
|
requestingAccount,
|
|
|
|
targetAccount,
|
|
|
|
http.StatusForbidden,
|
2023-10-03 15:59:30 +02:00
|
|
|
`{"error":"Forbidden: blocked"}`,
|
2023-05-28 21:05:15 +02:00
|
|
|
suite.signatureCheck,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-06-13 16:47:56 +02:00
|
|
|
func (suite *InboxPostTestSuite) TestPostFromBlockedAccountToOtherAccount() {
|
|
|
|
var (
|
|
|
|
requestingAccount = suite.testAccounts["remote_account_1"]
|
|
|
|
targetAccount = suite.testAccounts["local_account_1"]
|
|
|
|
activity = suite.testActivities["reply_to_turtle_for_turtle"]
|
|
|
|
statusURI = "http://fossbros-anonymous.io/users/foss_satan/statuses/2f1195a6-5cb0-4475-adf5-92ab9a0147fe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Post an reply to turtle to ZORK from remote account.
|
|
|
|
// Turtle blocks the remote account but is only tangentially
|
|
|
|
// related to this POST request. The response will indicate
|
|
|
|
// accepted but the post won't actually be processed.
|
|
|
|
suite.inboxPost(
|
|
|
|
activity.Activity,
|
|
|
|
requestingAccount,
|
|
|
|
targetAccount,
|
|
|
|
http.StatusAccepted,
|
|
|
|
`{"status":"Accepted"}`,
|
|
|
|
suite.signatureCheck,
|
|
|
|
)
|
|
|
|
|
|
|
|
_, err := suite.state.DB.GetStatusByURI(context.Background(), statusURI)
|
|
|
|
suite.ErrorIs(err, db.ErrNoEntries)
|
|
|
|
}
|
|
|
|
|
2023-05-28 21:05:15 +02:00
|
|
|
func (suite *InboxPostTestSuite) TestPostUnauthorized() {
|
|
|
|
var (
|
|
|
|
requestingAccount = suite.testAccounts["remote_account_1"]
|
|
|
|
targetAccount = suite.testAccounts["local_account_1"]
|
|
|
|
)
|
|
|
|
|
|
|
|
// Post an empty create.
|
|
|
|
create := streams.NewActivityStreamsCreate()
|
|
|
|
|
|
|
|
suite.inboxPost(
|
|
|
|
create,
|
|
|
|
requestingAccount,
|
|
|
|
targetAccount,
|
|
|
|
http.StatusUnauthorized,
|
2023-10-03 15:59:30 +02:00
|
|
|
`{"error":"Unauthorized: not authenticated"}`,
|
2023-05-28 21:05:15 +02:00
|
|
|
// Omit signature check middleware.
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-09-24 17:56:48 +02:00
|
|
|
func TestInboxPostTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, &InboxPostTestSuite{})
|
|
|
|
}
|