test: harden version endpoint boundaries

This commit is contained in:
2026-09-20 18:50:27 +08:00
parent 6d4b010460
commit 6d194122af
2 changed files with 34 additions and 1 deletions

View File

@@ -26,7 +26,7 @@ func TestVersionIsPublicAndBounded(t *testing.T) {
server := New("127.0.0.1:0", nil)
rr := httptest.NewRecorder()
server.Handler.ServeHTTP(rr, httptest.NewRequest(http.MethodGet, "/version", nil))
if rr.Code != http.StatusOK || !strings.Contains(rr.Body.String(), `"http_protocol_version":"1"`) || strings.Contains(rr.Body.String(), "ORBIT_MYSQL_DSN") {
if rr.Code != http.StatusOK || rr.Header().Get("Cache-Control") != "no-store" || rr.Header().Get("X-Content-Type-Options") != "nosniff" || rr.Header().Get("Content-Type") != "application/json" || !strings.Contains(rr.Body.String(), `"http_protocol_version":"1"`) || strings.Contains(rr.Body.String(), "ORBIT_MYSQL_DSN") {
t.Fatalf("unexpected version response: %d %s", rr.Code, rr.Body.String())
}
}