Address second review findings F1-F3 for 404, public URL and listen host
Independent review Approved — 0 high findings (#2)
Independent review Approved — 0 high findings (#2)
- F1: return the JSON API error shape for unknown paths (404 not_found) - F2: require a non-empty hostname in MEALQUEST_PUBLIC_URL - F3: validate the MEALQUEST_HTTP_ADDR host as an IP address or hostname Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -67,3 +67,22 @@ func TestHealthRejectsOtherMethods(t *testing.T) {
|
||||
t.Errorf("error body = %v, want %v", got.Error, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnknownPathNotFound(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
|
||||
rec := httptest.NewRecorder()
|
||||
NewRouter(logger, "dev").ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/unknown", nil))
|
||||
|
||||
if rec.Code != http.StatusNotFound {
|
||||
t.Errorf("status = %d, want 404", rec.Code)
|
||||
}
|
||||
if ct := rec.Header().Get("Content-Type"); ct != "application/json" {
|
||||
t.Errorf("Content-Type = %q, want application/json", ct)
|
||||
}
|
||||
const want = `{"error":{"code":"not_found","message":"not found","retryable":false}}`
|
||||
if got := rec.Body.String(); got != want {
|
||||
t.Errorf("body = %s, want %s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user