fix: /fetch, /refresh, /update and /change-password accept the session cookies the jwt guard reads
The four routes (and the other signed-in routes through authenticate) read the bearer header, then the token and auth_token cookies, through classes.SessionToken and one cookie-aware guard. A bearer header still wins and no credentials stays 401 with the old bodies. A cookie-carried /refresh answers the rotated token in the body and writes no cookie.
This commit is contained in:
@@ -24,8 +24,9 @@ const (
|
||||
|
||||
// TestLogoutEndsTheSession: POST /logout ends the session however the token
|
||||
// travels (the bearer header, or only the token or auth_token cookie the
|
||||
// jwt guard also reads), so the next request with the same token or cookie
|
||||
// is 401 on the jwt.auth routes, at /fetch and at /refresh. It clears the
|
||||
// jwt guard also reads), so the next request with the same token, through
|
||||
// the header or either cookie, is 401 on the jwt.auth routes, at /fetch and
|
||||
// at /refresh. It clears the
|
||||
// session cookies with the attributes the token cookie is written with, and
|
||||
// the revocation lasts for the token's refresh window: a logged-out token is
|
||||
// not refreshable after its access lifetime, and an expired but still
|
||||
@@ -224,8 +225,9 @@ func (e *adminEnv) guarded(t *testing.T, token, cookie string) int {
|
||||
return e.send(t, http.MethodGet, userTokensPath, "", nil, "application/json", map[string]string{"Cookie": cookie + "=" + token}).Code
|
||||
}
|
||||
|
||||
// assertSessionEnded: token no longer authenticates, through any carrier,
|
||||
// and cannot be refreshed.
|
||||
// assertSessionEnded: token no longer authenticates, through any carrier
|
||||
// (the bearer header, or only the token or auth_token cookie), at jwt.auth
|
||||
// and /fetch, and cannot be refreshed through any of them.
|
||||
func (e *adminEnv) assertSessionEnded(t *testing.T, token string) {
|
||||
t.Helper()
|
||||
for _, carrier := range []string{"", "token", "auth_token"} {
|
||||
@@ -239,6 +241,15 @@ func (e *adminEnv) assertSessionEnded(t *testing.T, token string) {
|
||||
if rec := e.refresh(t, token); rec.Code != http.StatusUnauthorized || rec.Body.String() != blacklistedBody {
|
||||
t.Fatalf("refresh after logout = %d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
for _, name := range []string{"token", "auth_token"} {
|
||||
cookie := map[string]string{"Cookie": name + "=" + token}
|
||||
if rec := e.send(t, http.MethodGet, "/_user/api/v1/fetch", "", nil, "application/json", cookie); rec.Code != http.StatusUnauthorized {
|
||||
t.Fatalf("fetch after logout (cookie %q) = %d", name, rec.Code)
|
||||
}
|
||||
if rec := e.send(t, http.MethodPost, userRefreshPath, "", nil, "application/json", cookie); rec.Code != http.StatusUnauthorized || rec.Body.String() != blacklistedBody {
|
||||
t.Fatalf("refresh after logout (cookie %q) = %d %s", name, rec.Code, rec.Body.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (e *adminEnv) cookieConfig(t *testing.T) bouncer.CookieConfig {
|
||||
|
||||
Reference in New Issue
Block a user