Skip to content

Commit 91e9eca

Browse files
authored
fix: return error if session id does not exist (#1538)
## What kind of change does this PR introduce? * return error if session id doesn't exist in the db ## What is the current behavior? Please link any relevant issues here. ## What is the new behavior? Feel free to include screenshots if it includes visual changes. ## Additional context Add any other context or screenshots.
1 parent 348a1da commit 91e9eca

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

internal/api/auth.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@ func (a *API) maybeLoadUserOrSession(ctx context.Context) (context.Context, erro
123123
return ctx, forbiddenError(ErrorCodeBadJWT, "invalid claim: session_id claim must be a UUID").WithInternalError(err)
124124
}
125125
session, err = models.FindSessionByID(db, sessionId, false)
126-
if err != nil && !models.IsNotFoundError(err) {
127-
return ctx, forbiddenError(ErrorCodeSessionNotFound, "Session from session_id claim in JWT does not exist")
126+
if err != nil {
127+
if models.IsNotFoundError(err) {
128+
return ctx, forbiddenError(ErrorCodeSessionNotFound, "Session from session_id claim in JWT does not exist")
129+
}
130+
return ctx, err
128131
}
129132
ctx = withSession(ctx, session)
130133
}

internal/api/auth_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,19 @@ func (ts *AuthTestSuite) TestMaybeLoadUserOrSession() {
158158
ExpectedUser: u,
159159
ExpectedSession: s,
160160
},
161+
{
162+
Desc: "Session ID doesn't exist",
163+
UserJwtClaims: &AccessTokenClaims{
164+
StandardClaims: jwt.StandardClaims{
165+
Subject: u.ID.String(),
166+
},
167+
Role: "authenticated",
168+
SessionId: "73bf9ee0-9e8c-453b-b484-09cb93e2f341",
169+
},
170+
ExpectedError: forbiddenError(ErrorCodeSessionNotFound, "Session from session_id claim in JWT does not exist"),
171+
ExpectedUser: u,
172+
ExpectedSession: nil,
173+
},
161174
}
162175

163176
for _, c := range cases {

0 commit comments

Comments
 (0)