Compare commits

...

5 commits

7 changed files with 42 additions and 46 deletions

View file

@ -74,9 +74,9 @@ func (f *federatingDB) Delete(ctx context.Context, id *url.URL) error {
return err
}
// Log at warning level, as lots of these could indicate federation
// Log at debug level, as lots of these could indicate federation
// issues between remote and this instance, or help with debugging.
log.Warnf(ctx, "received delete for unknown target: %s", uriStr)
log.Debugf(ctx, "received delete for unknown target: %s", uriStr)
return nil
}
@ -96,8 +96,9 @@ func (f *federatingDB) deleteAccount(
if account != nil {
if account.ID != requesting.ID {
const text = "signing account does not match delete target"
return false, gtserror.NewErrorForbidden(err, text)
// TODO: handled forwarded deletes,
// for now we silently drop this.
return true, nil
}
log.Debugf(ctx, "deleting account: %s", account.URI)
@ -131,8 +132,9 @@ func (f *federatingDB) deleteStatus(
if status != nil {
if status.AccountID != requesting.ID {
const text = "signing account does not match delete target owner"
return false, gtserror.NewErrorForbidden(err, text)
// TODO: handled forwarded deletes,
// for now we silently drop this.
return true, nil
}
log.Debugf(ctx, "deleting status: %s", status.URI)

View file

@ -18,6 +18,9 @@
package account_test
import (
"context"
"time"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/email"
@ -25,6 +28,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/filter/visibility"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/media"
"github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/processing/account"
@ -64,6 +68,13 @@ type AccountStandardTestSuite struct {
accountProcessor account.Processor
}
func (suite *AccountStandardTestSuite) getClientMsg(timeout time.Duration) (*messages.FromClientAPI, bool) {
ctx := context.Background()
ctx, cncl := context.WithTimeout(ctx, timeout)
defer cncl()
return suite.state.Workers.Client.Queue.PopCtx(ctx)
}
func (suite *AccountStandardTestSuite) SetupSuite() {
suite.testTokens = testrig.NewTestTokens()
suite.testClients = testrig.NewTestClients()

View file

@ -20,6 +20,7 @@ package account_test
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/ap"
@ -150,7 +151,7 @@ func (suite *FollowTestSuite) TestFollowRequestLocal() {
}
// There should be a message going to the worker.
cMsg := suite.checkClientAPIChan()
cMsg, _ := suite.getClientMsg(5 * time.Second)
suite.Equal(ap.ActivityCreate, cMsg.APActivityType)
suite.Equal(ap.ActivityFollow, cMsg.APObjectType)
suite.Equal(requestingAccount.ID, cMsg.Origin.ID)

View file

@ -71,7 +71,7 @@ func (suite *MoveTestSuite) TestMoveAccountOK() {
}
// There should be a message going to the worker.
cMsg := suite.checkClientAPIChan()
cMsg, _ := suite.getClientMsg(5 * time.Second)
move, ok := cMsg.GTSModel.(*gtsmodel.Move)
if !ok {
suite.FailNow("", "could not cast %T to *gtsmodel.Move", move)

View file

@ -26,27 +26,12 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/ap"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/messages"
)
type AccountUpdateTestSuite struct {
AccountStandardTestSuite
}
func (suite *AccountStandardTestSuite) checkClientAPIChan() *messages.FromClientAPI {
select {
case <-suite.state.Workers.Client.Queue.Wait():
case <-time.After(5 * time.Second):
}
msg, ok := suite.state.Workers.Client.Queue.Pop()
if !ok {
suite.FailNow("no queued message")
}
return msg
}
func (suite *AccountUpdateTestSuite) TestAccountUpdateSimple() {
testAccount := &gtsmodel.Account{}
*testAccount = *suite.testAccounts["local_account_1"]
@ -75,7 +60,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateSimple() {
suite.Equal(noteExpected, apiAccount.Note)
// We should have an update in the client api channel.
msg := suite.checkClientAPIChan()
msg, _ := suite.getClientMsg(5 * time.Second)
// Profile update.
suite.Equal(ap.ActivityUpdate, msg.APActivityType)
@ -125,7 +110,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateWithMention() {
suite.Equal(noteExpected, apiAccount.Note)
// We should have an update in the client api channel.
msg := suite.checkClientAPIChan()
msg, _ := suite.getClientMsg(5 * time.Second)
// Profile update.
suite.Equal(ap.ActivityUpdate, msg.APActivityType)
@ -181,7 +166,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateWithMarkdownNote() {
suite.Equal(noteExpected, apiAccount.Note)
// We should have an update in the client api channel.
msg := suite.checkClientAPIChan()
msg, _ := suite.getClientMsg(5 * time.Second)
// Profile update.
suite.Equal(ap.ActivityUpdate, msg.APActivityType)
@ -266,7 +251,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateWithFields() {
suite.EqualValues(emojisExpected, apiAccount.Emojis)
// We should have an update in the client api channel.
msg := suite.checkClientAPIChan()
msg, _ := suite.getClientMsg(5 * time.Second)
// Profile update.
suite.Equal(ap.ActivityUpdate, msg.APActivityType)
@ -323,7 +308,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateNoteNotFields() {
suite.Equal(fieldsBefore, len(apiAccount.Fields))
// We should have an update in the client api channel.
msg := suite.checkClientAPIChan()
msg, _ := suite.getClientMsg(5 * time.Second)
// Profile update.
suite.Equal(ap.ActivityUpdate, msg.APActivityType)

View file

@ -706,15 +706,14 @@ func (p *clientAPI) DeleteAccount(ctx context.Context, cMsg *messages.FromClient
p.state.Workers.Federator.Queue.Delete("Receiving.ID", account.ID)
p.state.Workers.Federator.Queue.Delete("TargetURI", account.URI)
// First perform the actual account deletion.
if err := p.account.Delete(ctx, cMsg.Target, originID); err != nil {
log.Errorf(ctx, "error deleting account: %v", err)
}
if err := p.federate.DeleteAccount(ctx, cMsg.Target); err != nil {
log.Errorf(ctx, "error federating account delete: %v", err)
}
if err := p.account.Delete(ctx, cMsg.Target, originID); err != nil {
log.Errorf(ctx, "error deleting account: %v", err)
}
return nil
}

View file

@ -42,25 +42,23 @@ import (
// Starts workers on the provided state using noop processing functions.
// Useful when you *don't* want to trigger side effects in a test.
func StartNoopWorkers(state *state.State) {
state.Workers.Client.Process = func(ctx context.Context, msg *messages.FromClientAPI) error {
log.Debugf(ctx, "Workers{}.Client{}.Noop(%s)", dump(msg))
return nil // noop
}
state.Workers.Federator.Process = func(ctx context.Context, msg *messages.FromFediAPI) error {
log.Debugf(ctx, "Workers{}.Federator{}.Noop(%s)", dump(msg))
return nil // noop
}
state.Workers.Client.Process = func(ctx context.Context, msg *messages.FromClientAPI) error { return nil }
state.Workers.Federator.Process = func(ctx context.Context, msg *messages.FromFediAPI) error { return nil }
state.Workers.Client.Init(messages.ClientMsgIndices())
state.Workers.Federator.Init(messages.FederatorMsgIndices())
state.Workers.Delivery.Init(nil)
// Specifically do NOT start the workers
// as caller may require queue contents.
// (i.e. don't want workers pulling)
// _ = state.Workers.Client.Start(1)
// _ = state.Workers.Federator.Start(1)
// _ = state.Workers.Dereference.Start(1)
// _ = state.Workers.Media.Start(1)
//
// (except for the scheduler, that's fine)
_ = state.Workers.Scheduler.Start()
_ = state.Workers.Client.Start(1)
_ = state.Workers.Federator.Start(1)
_ = state.Workers.Dereference.Start(1)
_ = state.Workers.Media.Start(1)
}
// Starts workers on the provided state using processing functions from the given