Fix http tests (#5195)

This commit is contained in:
Brian Kassouf
2018-08-27 15:13:41 -07:00
committed by GitHub
parent 213314a76a
commit e5aaf80764
2 changed files with 19 additions and 0 deletions

View File

@@ -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"`

View File

@@ -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)