From 367bdca25093ee76b36506d8a5e6733b0aa2e2bb Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Sun, 10 Oct 2021 12:39:25 +0200 Subject: Handle forwarded messages (#273) * correct path of foss_satan * add APIri and notes * test create forward note * rename target => receiving account * split up create into separate funcs * update extractFromCtx * tidy up from federator processing * foss satan => http not https * check if status in db * mock dereference of status from IRI * add forward message deref test * update test with activities * add remote_account_2 to test rig --- internal/federation/federatingprotocol.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'internal/federation/federatingprotocol.go') diff --git a/internal/federation/federatingprotocol.go b/internal/federation/federatingprotocol.go index c0ed97d5c..afa763d98 100644 --- a/internal/federation/federatingprotocol.go +++ b/internal/federation/federatingprotocol.go @@ -113,12 +113,12 @@ func (f *federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWr return nil, false, errors.New("username was empty") } - requestedAccount, err := f.db.GetLocalAccountByUsername(ctx, username) + receivingAccount, err := f.db.GetLocalAccountByUsername(ctx, username) if err != nil { - return nil, false, fmt.Errorf("could not fetch requested account with username %s: %s", username, err) + return nil, false, fmt.Errorf("could not fetch receiving account with username %s: %s", username, err) } - publicKeyOwnerURI, authenticated, err := f.AuthenticateFederatedRequest(ctx, requestedAccount.Username) + publicKeyOwnerURI, authenticated, err := f.AuthenticateFederatedRequest(ctx, receivingAccount.Username) if err != nil { l.Debugf("request not authenticated: %s", err) return ctx, false, err @@ -154,12 +154,12 @@ func (f *federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWr requestingAccount, _, err := f.GetRemoteAccount(ctx, username, publicKeyOwnerURI, false) if err != nil { - return nil, false, fmt.Errorf("couldn't get remote account: %s", err) + return nil, false, fmt.Errorf("couldn't get requesting account %s: %s", publicKeyOwnerURI, err) } - withRequester := context.WithValue(ctx, util.APRequestingAccount, requestingAccount) - withRequested := context.WithValue(withRequester, util.APAccount, requestedAccount) - return withRequested, true, nil + withRequesting := context.WithValue(ctx, util.APRequestingAccount, requestingAccount) + withReceiving := context.WithValue(withRequesting, util.APReceivingAccount, receivingAccount) + return withReceiving, true, nil } // Blocked should determine whether to permit a set of actors given by @@ -182,11 +182,11 @@ func (f *federator) Blocked(ctx context.Context, actorIRIs []*url.URL) (bool, er }) l.Debugf("entering BLOCKED function with IRI list: %+v", actorIRIs) - requestedAccountI := ctx.Value(util.APAccount) - requestedAccount, ok := requestedAccountI.(*gtsmodel.Account) + receivingAccountI := ctx.Value(util.APReceivingAccount) + receivingAccount, ok := receivingAccountI.(*gtsmodel.Account) if !ok { - f.log.Errorf("requested account not set on request context") - return false, errors.New("requested account not set on request context, so couldn't determine blocks") + f.log.Errorf("receiving account not set on request context") + return false, errors.New("receiving account not set on request context, so couldn't determine blocks") } blocked, err := f.db.AreURIsBlocked(ctx, actorIRIs) @@ -209,12 +209,12 @@ func (f *federator) Blocked(ctx context.Context, actorIRIs []*url.URL) (bool, er return false, fmt.Errorf("error getting account with uri %s: %s", uri.String(), err) } - blocked, err = f.db.IsBlocked(ctx, requestedAccount.ID, requestingAccount.ID, false) + blocked, err = f.db.IsBlocked(ctx, receivingAccount.ID, requestingAccount.ID, false) if err != nil { return false, fmt.Errorf("error checking account block: %s", err) } if blocked { - l.Tracef("local account %s blocks account with uri %s", requestedAccount.Username, uri) + l.Tracef("local account %s blocks account with uri %s", receivingAccount.Username, uri) return true, nil } } -- cgit v1.2.3