diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2020-05-27 08:34:12 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2020-05-28 04:11:13 +0300 |
commit | 08d8a8c4b27ec66485dbc4cbcb0d9088ba52720b (patch) | |
tree | dc52df4613b425113e2f377f4204c5498d88ab56 /internal | |
parent | febba427ebf268ac498f0eda09d5f9818ff2bf10 (diff) |
Revert goconst changes in auth_test.go
Diffstat (limited to 'internal')
-rw-r--r-- | internal/auth/auth_test.go | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go index 87cc988d..4a5d63fa 100644 --- a/internal/auth/auth_test.go +++ b/internal/auth/auth_test.go @@ -16,11 +16,6 @@ import ( "gitlab.com/gitlab-org/gitlab-pages/internal/source" ) -const ( - testAccessToken = "abc" - apiPagesAccess = "/api/v4/projects/1000/pages_access" -) - func createAuth(t *testing.T) *Auth { return New("pages.gitlab-example.com", "something-very-secret", @@ -103,7 +98,7 @@ func testTryAuthenticateWithCodeAndState(t *testing.T, https bool) { require.Equal(t, "POST", r.Method) w.WriteHeader(http.StatusOK) fmt.Fprint(w, "{\"access_token\":\"abc\"}") - case apiPagesAccess: + case "/api/v4/projects/1000/pages_access": require.Equal(t, "Bearer abc", r.Header.Get("Authorization")) w.WriteHeader(http.StatusOK) default: @@ -155,7 +150,7 @@ func TestTryAuthenticateWithCodeAndStateOverHTTPS(t *testing.T) { func TestCheckAuthenticationWhenAccess(t *testing.T) { apiServer := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { - case apiPagesAccess: + case "/api/v4/projects/1000/pages_access": require.Equal(t, "Bearer abc", r.Header.Get("Authorization")) w.WriteHeader(http.StatusOK) default: @@ -183,7 +178,7 @@ func TestCheckAuthenticationWhenAccess(t *testing.T) { r := &http.Request{URL: reqURL} session, _ := store.Get(r, "gitlab-pages") - session.Values["access_token"] = testAccessToken + session.Values["access_token"] = "abc" session.Save(r, result) require.Equal(t, false, auth.CheckAuthentication(result, r, 1000)) @@ -193,7 +188,7 @@ func TestCheckAuthenticationWhenAccess(t *testing.T) { func TestCheckAuthenticationWhenNoAccess(t *testing.T) { apiServer := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { - case apiPagesAccess: + case "/api/v4/projects/1000/pages_access": require.Equal(t, "Bearer abc", r.Header.Get("Authorization")) w.WriteHeader(http.StatusUnauthorized) default: @@ -221,7 +216,7 @@ func TestCheckAuthenticationWhenNoAccess(t *testing.T) { r := &http.Request{URL: reqURL} session, _ := store.Get(r, "gitlab-pages") - session.Values["access_token"] = testAccessToken + session.Values["access_token"] = "abc" session.Save(r, result) require.Equal(t, true, auth.CheckAuthentication(result, r, 1000)) @@ -231,7 +226,7 @@ func TestCheckAuthenticationWhenNoAccess(t *testing.T) { func TestCheckAuthenticationWhenInvalidToken(t *testing.T) { apiServer := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { - case apiPagesAccess: + case "/api/v4/projects/1000/pages_access": require.Equal(t, "Bearer abc", r.Header.Get("Authorization")) w.WriteHeader(http.StatusUnauthorized) fmt.Fprint(w, "{\"error\":\"invalid_token\"}") @@ -259,7 +254,7 @@ func TestCheckAuthenticationWhenInvalidToken(t *testing.T) { r := &http.Request{URL: reqURL} session, _ := store.Get(r, "gitlab-pages") - session.Values["access_token"] = testAccessToken + session.Values["access_token"] = "abc" session.Save(r, result) require.Equal(t, true, auth.CheckAuthentication(result, r, 1000)) @@ -297,7 +292,7 @@ func TestCheckAuthenticationWithoutProject(t *testing.T) { r := &http.Request{URL: reqURL} session, _ := store.Get(r, "gitlab-pages") - session.Values["access_token"] = testAccessToken + session.Values["access_token"] = "abc" session.Save(r, result) require.Equal(t, false, auth.CheckAuthenticationWithoutProject(result, r)) @@ -334,7 +329,7 @@ func TestCheckAuthenticationWithoutProjectWhenInvalidToken(t *testing.T) { require.NoError(t, err) r := &http.Request{URL: reqURL} session, _ := store.Get(r, "gitlab-pages") - session.Values["access_token"] = testAccessToken + session.Values["access_token"] = "abc" session.Save(r, result) require.Equal(t, true, auth.CheckAuthenticationWithoutProject(result, r)) @@ -363,11 +358,11 @@ func TestGetTokenIfExistsWhenTokenExists(t *testing.T) { r := &http.Request{URL: reqURL} session, _ := store.Get(r, "gitlab-pages") - session.Values["access_token"] = testAccessToken + session.Values["access_token"] = "abc" session.Save(r, result) token, err := auth.GetTokenIfExists(result, r) - require.Equal(t, testAccessToken, token) + require.Equal(t, "abc", token) } func TestGetTokenIfExistsWhenTokenDoesNotExist(t *testing.T) { |