TestChallengeWriter_SetsHeaderOnlyOn401 pins the WWW-Authenticate behavior: present on a 401, absent on a 2xx (e.g. public getInfo).
(t *testing.T)
| 49 | // TestChallengeWriter_SetsHeaderOnlyOn401 pins the WWW-Authenticate behavior: |
| 50 | // present on a 401, absent on a 2xx (e.g. public getInfo). |
| 51 | func 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 | } |
nothing calls this directly
no test coverage detected