diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-08-17 18:57:33 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-08-19 08:24:40 +0300 |
commit | 0036c260968d083e56e7336259e5464facb1dc73 (patch) | |
tree | 6a772cf3a6ba1bacf2478bd6573c97948c66d811 /internal/auth | |
parent | 111faf403e3df4c6e998a625f7ad8b22da4ff6ee (diff) |
test: fix response body not being closed
nolint is added when the body is nil or if
the body can't be closed
Diffstat (limited to 'internal/auth')
-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")) } |