MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / TestChallengeWriter_SetsHeaderOnlyOn401

Function TestChallengeWriter_SetsHeaderOnlyOn401

internal/httpapi/middleware_test.go:51–67  ·  view source on GitHub ↗

TestChallengeWriter_SetsHeaderOnlyOn401 pins the WWW-Authenticate behavior: present on a 401, absent on a 2xx (e.g. public getInfo).

(t *testing.T)

Source from the content-addressed store, hash-verified

49// TestChallengeWriter_SetsHeaderOnlyOn401 pins the WWW-Authenticate behavior:
50// present on a 401, absent on a 2xx (e.g. public getInfo).
51func TestChallengeWriter_SetsHeaderOnlyOn401(t *testing.T) {
52 build := func(*http.Request) string { return `Bearer realm="e2a"` }
53
54 rec401 := httptest.NewRecorder()
55 cw401 := &challengeWriter{ResponseWriter: rec401, r: httptest.NewRequest(http.MethodGet, "/v1/agents", nil), build: build}
56 cw401.WriteHeader(http.StatusUnauthorized)
57 if got := rec401.Header().Get("WWW-Authenticate"); got != `Bearer realm="e2a"` {
58 t.Fatalf("401 WWW-Authenticate = %q, want the challenge", got)
59 }
60
61 rec200 := httptest.NewRecorder()
62 cw200 := &challengeWriter{ResponseWriter: rec200, r: httptest.NewRequest(http.MethodGet, "/v1/info", nil), build: build}
63 cw200.WriteHeader(http.StatusOK)
64 if got := rec200.Header().Get("WWW-Authenticate"); got != "" {
65 t.Fatalf("2xx must not set WWW-Authenticate, got %q", got)
66 }
67}

Callers

nothing calls this directly

Calls 2

WriteHeaderMethod · 0.95
GetMethod · 0.65

Tested by

no test coverage detected