mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
Fix http tests (#5195)
This commit is contained in:
@@ -75,6 +75,7 @@ func handleSysHealthHead(core *vault.Core, w http.ResponseWriter, r *http.Reques
|
||||
func getSysHealth(core *vault.Core, r *http.Request) (int, *HealthResponse, error) {
|
||||
// Check if being a standby is allowed for the purpose of a 200 OK
|
||||
_, standbyOK := r.URL.Query()["standbyok"]
|
||||
_, perfStandbyOK := r.URL.Query()["perfstandbyok"]
|
||||
|
||||
uninitCode := http.StatusNotImplemented
|
||||
if code, found, ok := fetchStatusCode(r, "uninitcode"); !ok {
|
||||
@@ -111,11 +112,19 @@ func getSysHealth(core *vault.Core, r *http.Request) (int, *HealthResponse, erro
|
||||
drSecondaryCode = code
|
||||
}
|
||||
|
||||
perfStandbyCode := 473 // unofficial 4xx status code
|
||||
if code, found, ok := fetchStatusCode(r, "performancestandbycode"); !ok {
|
||||
return http.StatusBadRequest, nil, nil
|
||||
} else if found {
|
||||
perfStandbyCode = code
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Check system status
|
||||
sealed := core.Sealed()
|
||||
standby, _ := core.Standby()
|
||||
perfStandby := core.PerfStandby()
|
||||
var replicationState consts.ReplicationState
|
||||
if standby {
|
||||
replicationState = core.ActiveNodeReplicationState()
|
||||
@@ -137,6 +146,8 @@ func getSysHealth(core *vault.Core, r *http.Request) (int, *HealthResponse, erro
|
||||
code = sealedCode
|
||||
case replicationState.HasState(consts.ReplicationDRSecondary):
|
||||
code = drSecondaryCode
|
||||
case !perfStandbyOK && perfStandby:
|
||||
code = perfStandbyCode
|
||||
case !standbyOK && standby:
|
||||
code = standbyCode
|
||||
}
|
||||
@@ -160,6 +171,7 @@ func getSysHealth(core *vault.Core, r *http.Request) (int, *HealthResponse, erro
|
||||
Initialized: init,
|
||||
Sealed: sealed,
|
||||
Standby: standby,
|
||||
PerformanceStandby: perfStandby,
|
||||
ReplicationPerformanceMode: replicationState.GetPerformanceString(),
|
||||
ReplicationDRMode: replicationState.GetDRString(),
|
||||
ServerTimeUTC: time.Now().UTC().Unix(),
|
||||
@@ -174,6 +186,7 @@ type HealthResponse struct {
|
||||
Initialized bool `json:"initialized"`
|
||||
Sealed bool `json:"sealed"`
|
||||
Standby bool `json:"standby"`
|
||||
PerformanceStandby bool `json:"performance_standby"`
|
||||
ReplicationPerformanceMode string `json:"replication_performance_mode"`
|
||||
ReplicationDRMode string `json:"replication_dr_mode"`
|
||||
ServerTimeUTC int64 `json:"server_time_utc"`
|
||||
|
||||
@@ -29,6 +29,7 @@ func TestSysHealth_get(t *testing.T) {
|
||||
"initialized": false,
|
||||
"sealed": true,
|
||||
"standby": true,
|
||||
"performance_standby": false,
|
||||
}
|
||||
testResponseStatus(t, resp, 501)
|
||||
testResponseBody(t, resp, &actual)
|
||||
@@ -61,6 +62,7 @@ func TestSysHealth_get(t *testing.T) {
|
||||
"initialized": true,
|
||||
"sealed": true,
|
||||
"standby": true,
|
||||
"performance_standby": false,
|
||||
}
|
||||
testResponseStatus(t, resp, 503)
|
||||
testResponseBody(t, resp, &actual)
|
||||
@@ -97,6 +99,7 @@ func TestSysHealth_get(t *testing.T) {
|
||||
"initialized": true,
|
||||
"sealed": false,
|
||||
"standby": false,
|
||||
"performance_standby": false,
|
||||
}
|
||||
testResponseStatus(t, resp, 200)
|
||||
testResponseBody(t, resp, &actual)
|
||||
@@ -139,6 +142,7 @@ func TestSysHealth_customcodes(t *testing.T) {
|
||||
"initialized": false,
|
||||
"sealed": true,
|
||||
"standby": true,
|
||||
"performance_standby": false,
|
||||
}
|
||||
testResponseStatus(t, resp, 581)
|
||||
testResponseBody(t, resp, &actual)
|
||||
@@ -172,6 +176,7 @@ func TestSysHealth_customcodes(t *testing.T) {
|
||||
"initialized": true,
|
||||
"sealed": true,
|
||||
"standby": true,
|
||||
"performance_standby": false,
|
||||
}
|
||||
testResponseStatus(t, resp, 523)
|
||||
testResponseBody(t, resp, &actual)
|
||||
@@ -209,6 +214,7 @@ func TestSysHealth_customcodes(t *testing.T) {
|
||||
"initialized": true,
|
||||
"sealed": false,
|
||||
"standby": false,
|
||||
"performance_standby": false,
|
||||
}
|
||||
testResponseStatus(t, resp, 202)
|
||||
testResponseBody(t, resp, &actual)
|
||||
|
||||
Reference in New Issue
Block a user