diff options
Diffstat (limited to 'internal/api/auth/auth_test.go')
| -rw-r--r-- | internal/api/auth/auth_test.go | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/internal/api/auth/auth_test.go b/internal/api/auth/auth_test.go index 4b7ea2f5f..af90de2d6 100644 --- a/internal/api/auth/auth_test.go +++ b/internal/api/auth/auth_test.go @@ -107,28 +107,40 @@ func (suite *AuthStandardTestSuite) TearDownTest() { testrig.StopWorkers(&suite.state) } -func (suite *AuthStandardTestSuite) newContext(requestMethod string, requestPath string, requestBody []byte, bodyContentType string) (*gin.Context, *httptest.ResponseRecorder) { - // create the recorder and gin test context +func (suite *AuthStandardTestSuite) newContext( + requestMethod string, + requestPath string, + requestBody []byte, + bodyContentType string, +) (*gin.Context, *httptest.ResponseRecorder) { + // Create the recorder and test context. recorder := httptest.NewRecorder() ctx, engine := testrig.CreateGinTestContext(recorder, nil) - // load templates into the engine + // Load templates into the engine. testrig.ConfigureTemplatesWithGin(engine, "../../../web/template") - // create the request + // Create the request itself. protocol := config.GetProtocol() host := config.GetHost() baseURI := fmt.Sprintf("%s://%s", protocol, host) requestURI := fmt.Sprintf("%s/%s", baseURI, requestPath) + ctx.Request = httptest.NewRequest( + requestMethod, + requestURI, + bytes.NewReader(requestBody), + ) - ctx.Request = httptest.NewRequest(requestMethod, requestURI, bytes.NewReader(requestBody)) // the endpoint we're hitting - ctx.Request.Header.Set("accept", "text/html") - + // Transmit appropriate Content-Type. if bodyContentType != "" { ctx.Request.Header.Set("Content-Type", bodyContentType) } - // trigger the session middleware on the context + // Accept whatever, so we can use + // this to test both HTML and JSON. + ctx.Request.Header.Set("accept", "*/*") + + // Trigger the session middleware on the context. store := memstore.NewStore(make([]byte, 32), make([]byte, 32)) store.Options(middleware.SessionOptions()) sessionMiddleware := sessions.Sessions("gotosocial-localhost", store) |
