mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-10-31 22:18:52 +00:00
add checks for the slightly changed error handling in tests, add notes in codebase about the odd way of working
This commit is contained in:
parent
7cd2434481
commit
2e6b0e2c0b
3 changed files with 19 additions and 2 deletions
|
@ -590,7 +590,7 @@ func (suite *InboxPostTestSuite) TestPostUnauthorized() {
|
|||
requestingAccount,
|
||||
targetAccount,
|
||||
http.StatusUnauthorized,
|
||||
`{"error":"Unauthorized: not authenticated"}`,
|
||||
`{"error":"Unauthorized: http request wasn't signed or http signature was invalid: (verifier)"}`,
|
||||
// Omit signature check middleware.
|
||||
)
|
||||
}
|
||||
|
|
|
@ -80,6 +80,14 @@ 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 errors.As(err, new(gtserror.WithCode)) {
|
||||
// If it was already wrapped with an
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
@ -30,6 +31,7 @@ import (
|
|||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtscontext"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||
"github.com/superseriousbusiness/httpsig"
|
||||
|
@ -99,7 +101,14 @@ func (suite *FederatingProtocolTestSuite) authenticatePostInbox(
|
|||
|
||||
recorder := httptest.NewRecorder()
|
||||
newContext, authed, err := suite.federator.AuthenticatePostInbox(ctx, recorder, request)
|
||||
if err != nil {
|
||||
if withCode := new(gtserror.WithCode); (errors.As(err, withCode) &&
|
||||
(*withCode).Code() >= 500) || (err != nil && (*withCode) == nil) {
|
||||
// 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 a no-go, but authed 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 an internal error code.
|
||||
suite.FailNow(err.Error())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue