|
@@ -649,6 +649,9 @@ func TestHTTPLogin(t *testing.T) {
|
|
|
if resp.StatusCode != expectedFailStatus {
|
|
|
t.Errorf("Unexpected non-%d return code %d for unauthed request", expectedFailStatus, resp.StatusCode)
|
|
|
}
|
|
|
+ if hasSessionCookie(resp.Cookies()) {
|
|
|
+ t.Errorf("Unexpected session cookie for unauthed request")
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
t.Run("incorrect password is rejected", func(t *testing.T) {
|
|
@@ -657,6 +660,9 @@ func TestHTTPLogin(t *testing.T) {
|
|
|
if resp.StatusCode != expectedFailStatus {
|
|
|
t.Errorf("Unexpected non-%d return code %d for incorrect password", expectedFailStatus, resp.StatusCode)
|
|
|
}
|
|
|
+ if hasSessionCookie(resp.Cookies()) {
|
|
|
+ t.Errorf("Unexpected session cookie for incorrect password")
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
t.Run("incorrect username is rejected", func(t *testing.T) {
|
|
@@ -665,6 +671,9 @@ func TestHTTPLogin(t *testing.T) {
|
|
|
if resp.StatusCode != expectedFailStatus {
|
|
|
t.Errorf("Unexpected non-%d return code %d for incorrect username", expectedFailStatus, resp.StatusCode)
|
|
|
}
|
|
|
+ if hasSessionCookie(resp.Cookies()) {
|
|
|
+ t.Errorf("Unexpected session cookie for incorrect username")
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
t.Run("UTF-8 auth works", func(t *testing.T) {
|
|
@@ -673,6 +682,9 @@ func TestHTTPLogin(t *testing.T) {
|
|
|
if resp.StatusCode != expectedOkStatus {
|
|
|
t.Errorf("Unexpected non-%d return code %d for authed request (UTF-8)", expectedOkStatus, resp.StatusCode)
|
|
|
}
|
|
|
+ if !hasSessionCookie(resp.Cookies()) {
|
|
|
+ t.Errorf("Expected session cookie for authed request (UTF-8)")
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
t.Run("ISO-8859-1 auth works", func(t *testing.T) {
|
|
@@ -681,6 +693,9 @@ func TestHTTPLogin(t *testing.T) {
|
|
|
if resp.StatusCode != expectedOkStatus {
|
|
|
t.Errorf("Unexpected non-%d return code %d for authed request (ISO-8859-1)", expectedOkStatus, resp.StatusCode)
|
|
|
}
|
|
|
+ if !hasSessionCookie(resp.Cookies()) {
|
|
|
+ t.Errorf("Expected session cookie for authed request (ISO-8859-1)")
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
t.Run("bad X-API-Key is rejected", func(t *testing.T) {
|
|
@@ -689,6 +704,9 @@ func TestHTTPLogin(t *testing.T) {
|
|
|
if resp.StatusCode != expectedFailStatus {
|
|
|
t.Errorf("Unexpected non-%d return code %d for bad API key", expectedFailStatus, resp.StatusCode)
|
|
|
}
|
|
|
+ if hasSessionCookie(resp.Cookies()) {
|
|
|
+ t.Errorf("Unexpected session cookie for bad API key")
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
t.Run("good X-API-Key is accepted", func(t *testing.T) {
|
|
@@ -697,13 +715,19 @@ func TestHTTPLogin(t *testing.T) {
|
|
|
if resp.StatusCode != expectedOkStatus {
|
|
|
t.Errorf("Unexpected non-%d return code %d for API key", expectedOkStatus, resp.StatusCode)
|
|
|
}
|
|
|
+ if hasSessionCookie(resp.Cookies()) {
|
|
|
+ t.Errorf("Unexpected session cookie for API key")
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
t.Run("bad Bearer is rejected", func(t *testing.T) {
|
|
|
t.Parallel()
|
|
|
resp := httpGetAuthorizationBearer(url, testAPIKey+"X")
|
|
|
if resp.StatusCode != expectedFailStatus {
|
|
|
- t.Errorf("Unexpected non-%d return code %d for bad API key", expectedFailStatus, resp.StatusCode)
|
|
|
+ t.Errorf("Unexpected non-%d return code %d for bad Authorization: Bearer", expectedFailStatus, resp.StatusCode)
|
|
|
+ }
|
|
|
+ if hasSessionCookie(resp.Cookies()) {
|
|
|
+ t.Errorf("Unexpected session cookie for bad Authorization: Bearer")
|
|
|
}
|
|
|
})
|
|
|
|
|
@@ -711,15 +735,20 @@ func TestHTTPLogin(t *testing.T) {
|
|
|
t.Parallel()
|
|
|
resp := httpGetAuthorizationBearer(url, testAPIKey)
|
|
|
if resp.StatusCode != expectedOkStatus {
|
|
|
- t.Errorf("Unexpected non-%d return code %d for API key", expectedOkStatus, resp.StatusCode)
|
|
|
+ t.Errorf("Unexpected non-%d return code %d for Authorization: Bearer", expectedOkStatus, resp.StatusCode)
|
|
|
+ }
|
|
|
+ if hasSessionCookie(resp.Cookies()) {
|
|
|
+ t.Errorf("Unexpected session cookie for bad Authorization: Bearer")
|
|
|
}
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ testWith(true, http.StatusOK, http.StatusOK, "/")
|
|
|
testWith(true, http.StatusOK, http.StatusUnauthorized, "/meta.js")
|
|
|
testWith(true, http.StatusNotFound, http.StatusUnauthorized, "/any-path/that/does/nooooooot/match-any/noauth-pattern")
|
|
|
|
|
|
+ testWith(false, http.StatusOK, http.StatusOK, "/")
|
|
|
testWith(false, http.StatusOK, http.StatusForbidden, "/meta.js")
|
|
|
testWith(false, http.StatusNotFound, http.StatusForbidden, "/any-path/that/does/nooooooot/match-any/noauth-pattern")
|
|
|
}
|