fix: harden health probe responses
This commit is contained in:
@@ -19,6 +19,14 @@ func TestHealthSeparatesLivenessAndReadiness(t *testing.T) {
|
||||
if rr.Code != want || strings.Contains(rr.Body.String(), "internal-database-details") {
|
||||
t.Fatalf("%s: %d %s", path, rr.Code, rr.Body.String())
|
||||
}
|
||||
if strings.HasPrefix(path, "/health/") {
|
||||
if rr.Header().Get("Cache-Control") != "no-store" || rr.Header().Get("X-Content-Type-Options") != "nosniff" {
|
||||
t.Fatalf("%s: missing anti-cache/security headers: %#v", path, rr.Header())
|
||||
}
|
||||
if path == "/health/ready" && rr.Header().Get("Retry-After") != "1" {
|
||||
t.Fatalf("readiness failure missing retry hint: %#v", rr.Header())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +48,9 @@ func TestReadinessEntersDrainBeforeShutdown(t *testing.T) {
|
||||
if draining.Code != http.StatusServiceUnavailable || checks != 1 || strings.Contains(draining.Body.String(), "server is draining") {
|
||||
t.Fatalf("during drain: status=%d checks=%d body=%s", draining.Code, checks, draining.Body.String())
|
||||
}
|
||||
if draining.Header().Get("Retry-After") != "1" || draining.Header().Get("Cache-Control") != "no-store" {
|
||||
t.Fatalf("draining readiness headers: %#v", draining.Header())
|
||||
}
|
||||
}
|
||||
|
||||
func TestVersionIsPublicAndBounded(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user