Skip to content

Commit

Permalink
bug: account for etcd leader changes error (#5003)
Browse files Browse the repository at this point in the history
if we fail to read the secret from etcd we should return an internal
server error and not an unauthorized error.
  • Loading branch information
ricardomaraschini authored Nov 20, 2024
1 parent 270a12e commit 707d5bc
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/handlers/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func RequireValidSessionQuietMiddleware(kotsStore store.Store) mux.MiddlewareFun
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
sess, err := requireValidSession(kotsStore, w, r)
if err != nil {
logger.Errorf("failed validating session: %s", err)
return
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func requireValidSession(kotsStore store.Store, w http.ResponseWriter, r *http.R
passwordUpdatedAt, err := kotsStore.GetPasswordUpdatedAt()
if err != nil {
response := types.ErrorResponse{Error: util.StrPointer("failed to validate session with current password")}
JSON(w, http.StatusUnauthorized, response)
JSON(w, http.StatusInternalServerError, response)
return nil, err
}
if passwordUpdatedAt != nil && passwordUpdatedAt.After(sess.IssuedAt) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func Test_requireValidSession_FailedToFetchPasswordUpdated_AfterSessionIssuedErr
req.Error(err)
req.Equal("failed to fetch password updatedAt", err.Error())
req.Equal(want, got)
req.Equal(401, w.Code)
req.Equal(500, w.Code)
}

func Test_requireValidSession_PasswordUpdated_AfterSessionIssuedErr(t *testing.T) {
Expand Down

0 comments on commit 707d5bc

Please sign in to comment.