From 15ede4c1ea4e5a9f69b3f0ed72d94ce764ffed1d Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Wed, 3 Apr 2024 13:57:07 +0100 Subject: [bugfix] improved authenticate post inbox error handling (#2803) * improved PostInboxScheme() error handling / logging in case of failed auth * dumbass kim. returning err instead of errWithCode... * add checks for the slightly changed error handling in tests, add notes in codebase about the odd way of working --- internal/federation/federatingactor.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'internal/federation/federatingactor.go') diff --git a/internal/federation/federatingactor.go b/internal/federation/federatingactor.go index bf54962db..18cee1666 100644 --- a/internal/federation/federatingactor.go +++ b/internal/federation/federatingactor.go @@ -80,8 +80,23 @@ func (f *federatingActor) PostInboxScheme(ctx context.Context, w http.ResponseWr } // Authenticate request by checking http signature. + // + // NOTE: the behaviour here is a little strange as we have + // the competing code styles of the go-fed interface expecting + // that any 'err' is fatal, but 'authenticated' bool is intended to + // be the main passer of whether failed auth occurred, but we in + // the gts codebase use errors to pass-back non-200 status codes, + // so we specifically have to check for already wrapped with code. + // ctx, authenticated, err := f.sideEffectActor.AuthenticatePostInbox(ctx, w, r) - if err != nil { + if errors.As(err, new(gtserror.WithCode)) { + // If it was already wrapped with an + // HTTP code then don't bother rewrapping + // it, just return it as-is for caller to + // handle. AuthenticatePostInbox already + // calls WriteHeader() in some situations. + return false, err + } else if err != nil { err := gtserror.Newf("error authenticating post inbox: %w", err) return false, gtserror.NewErrorInternalError(err) } -- cgit v1.2.3