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