(t *testing.T)
| 42 | } |
| 43 | |
| 44 | func TestBearerAuthMiddleware_ValidToken(t *testing.T) { |
| 45 | cfg := &Config{Host: "127.0.0.1", Port: 8080, AuthToken: "secret"} |
| 46 | called := false |
| 47 | next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 48 | called = true |
| 49 | w.WriteHeader(http.StatusOK) |
| 50 | }) |
| 51 | |
| 52 | handler := BearerAuthMiddleware(cfg, next) |
| 53 | req := httptest.NewRequest(http.MethodPost, "/mcp", nil) |
| 54 | req.Header.Set("Authorization", "Bearer secret") |
| 55 | rr := httptest.NewRecorder() |
| 56 | handler.ServeHTTP(rr, req) |
| 57 | |
| 58 | if !called { |
| 59 | t.Error("next handler was not called with valid token") |
| 60 | } |
| 61 | if rr.Code != http.StatusOK { |
| 62 | t.Errorf("status = %d, want 200", rr.Code) |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | func TestBearerAuthMiddleware_InvalidToken(t *testing.T) { |
| 67 | cfg := &Config{Host: "127.0.0.1", Port: 8080, AuthToken: "secret"} |
nothing calls this directly
no test coverage detected