Skip to content

Commit

Permalink
pr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
miagilepner committed Nov 14, 2024
1 parent f83e217 commit f582b95
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ func forwardRequest(core *vault.Core, w http.ResponseWriter, r *http.Request) {
core.Logger().Trace("cannot forward request (possibly disabled on active node), falling back to redirection to standby")
case errors.Is(err, vault.StatusNotHAMember):
core.Logger().Trace("this node is not a member of the HA cluster", "error", err)
respondError(w, http.StatusServiceUnavailable, err)
respondError(w, http.StatusInternalServerError, err)
return
default:
core.Logger().Error("forward request error", "error", err)
Expand Down
2 changes: 1 addition & 1 deletion vault/request_forwarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func haMembershipServerCheck(ctx context.Context, c *Core, haBackend physical.Re
removed, err := haBackend.IsNodeRemoved(ctx, nodeID)
if err != nil {
c.logger.Error("failed to check if node is removed", "error", err)
return nil
return err
}
if removed {
return StatusNotHAMember
Expand Down
15 changes: 7 additions & 8 deletions vault/request_forwarding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,38 +82,37 @@ func newMockHARemovableNodeBackend(isRemoved func(context.Context, string) (bool
// when the context contains a removed node ID
func Test_haMembershipServerCheck(t *testing.T) {
nodeIDCtx := metadata.NewIncomingContext(context.Background(), metadata.MD{haNodeIDKey: {"node_id"}})
otherErr := errors.New("error checking")
testCases := []struct {
name string
nodeIDCtx context.Context
haBackend physical.RemovableNodeHABackend
wantError bool
wantError error
}{
{
name: "nil backend",
haBackend: nil,
nodeIDCtx: nodeIDCtx,
wantError: false,
}, {
name: "no node ID context",
haBackend: newMockHARemovableNodeBackend(func(ctx context.Context, s string) (bool, error) {
return false, nil
}),
nodeIDCtx: context.Background(),
wantError: false,
}, {
name: "node removed",
haBackend: newMockHARemovableNodeBackend(func(ctx context.Context, s string) (bool, error) {
return true, nil
}),
nodeIDCtx: nodeIDCtx,
wantError: true,
wantError: StatusNotHAMember,
}, {
name: "node removed err",
haBackend: newMockHARemovableNodeBackend(func(ctx context.Context, s string) (bool, error) {
return false, errors.New("error checking")
return false, otherErr
}),
nodeIDCtx: nodeIDCtx,
wantError: false,
wantError: otherErr,
},
}
for _, tc := range testCases {
Expand All @@ -122,8 +121,8 @@ func Test_haMembershipServerCheck(t *testing.T) {
logger: hclog.NewNullLogger(),
}
err := haMembershipServerCheck(tc.nodeIDCtx, c, tc.haBackend)
if tc.wantError {
require.Error(t, err)
if tc.wantError != nil {
require.EqualError(t, err, tc.wantError.Error())
} else {
require.NoError(t, err)
}
Expand Down

0 comments on commit f582b95

Please sign in to comment.