diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2021-08-19 08:49:59 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2021-08-19 08:49:59 +0300 |
commit | 2bd9d969ce88e05b3b2cb1ed06e4963fe3478360 (patch) | |
tree | a470b4c7c4389fa9e14d1e07f8d315d2d3185472 /internal/auth/auth_test.go | |
parent | 111faf403e3df4c6e998a625f7ad8b22da4ff6ee (diff) | |
parent | 99bc678dfe8fc6f41a415c19ed5bfc64e162adc7 (diff) |
Merge branch 'fix/test-bodyclose' into 'master'
test: fix response body not being closed
See merge request gitlab-org/gitlab-pages!546
Diffstat (limited to 'internal/auth/auth_test.go')
-rw-r--r-- | internal/auth/auth_test.go | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go index c1fc834a..d03407a5 100644 --- a/internal/auth/auth_test.go +++ b/internal/auth/auth_test.go @@ -65,7 +65,10 @@ func setSessionValues(t *testing.T, r *http.Request, store sessions.Store, value session.Values = values session.Save(tmpRequest, result) - for _, cookie := range result.Result().Cookies() { + res := result.Result() + defer res.Body.Close() + + for _, cookie := range res.Cookies() { r.AddCookie(cookie) } } @@ -206,10 +209,14 @@ func testTryAuthenticateWithCodeAndState(t *testing.T, https bool) { result := httptest.NewRecorder() require.Equal(t, true, auth.TryAuthenticate(result, r, source.NewMockSource())) + + res := result.Result() + defer res.Body.Close() + require.Equal(t, http.StatusFound, result.Code) require.Equal(t, "https://pages.gitlab-example.com/project/", result.Header().Get("Location")) - require.Equal(t, 600, result.Result().Cookies()[0].MaxAge) - require.Equal(t, https, result.Result().Cookies()[0].Secure) + require.Equal(t, 600, res.Cookies()[0].MaxAge) + require.Equal(t, https, res.Cookies()[0].Secure) } func TestTryAuthenticateWithCodeAndStateOverHTTP(t *testing.T) { @@ -465,9 +472,12 @@ func TestCheckResponseForInvalidTokenWhenInvalidToken(t *testing.T) { r := &http.Request{URL: reqURL, Host: "pages.gitlab-example.com", RequestURI: "/test"} resp := &http.Response{StatusCode: http.StatusUnauthorized, Body: ioutil.NopCloser(bytes.NewReader([]byte("{\"error\":\"invalid_token\"}")))} + defer resp.Body.Close() require.Equal(t, true, auth.CheckResponseForInvalidToken(result, r, resp)) - require.Equal(t, http.StatusFound, result.Result().StatusCode) + res := result.Result() + defer res.Body.Close() + require.Equal(t, http.StatusFound, res.StatusCode) require.Equal(t, "http://pages.gitlab-example.com/test", result.Header().Get("Location")) } |