Skip to content

Commit 707d5bc

Browse files
bug: account for etcd leader changes error (#5003)
if we fail to read the secret from etcd we should return an internal server error and not an unauthorized error.
1 parent 270a12e commit 707d5bc

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

pkg/handlers/middleware.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func RequireValidSessionQuietMiddleware(kotsStore store.Store) mux.MiddlewareFun
9999
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
100100
sess, err := requireValidSession(kotsStore, w, r)
101101
if err != nil {
102+
logger.Errorf("failed validating session: %s", err)
102103
return
103104
}
104105

pkg/handlers/session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func requireValidSession(kotsStore store.Store, w http.ResponseWriter, r *http.R
9595
passwordUpdatedAt, err := kotsStore.GetPasswordUpdatedAt()
9696
if err != nil {
9797
response := types.ErrorResponse{Error: util.StrPointer("failed to validate session with current password")}
98-
JSON(w, http.StatusUnauthorized, response)
98+
JSON(w, http.StatusInternalServerError, response)
9999
return nil, err
100100
}
101101
if passwordUpdatedAt != nil && passwordUpdatedAt.After(sess.IssuedAt) {

pkg/handlers/session_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ func Test_requireValidSession_FailedToFetchPasswordUpdated_AfterSessionIssuedErr
400400
req.Error(err)
401401
req.Equal("failed to fetch password updatedAt", err.Error())
402402
req.Equal(want, got)
403-
req.Equal(401, w.Code)
403+
req.Equal(500, w.Code)
404404
}
405405

406406
func Test_requireValidSession_PasswordUpdated_AfterSessionIssuedErr(t *testing.T) {

0 commit comments

Comments
 (0)