MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestBearerAuthMiddleware_MissingHeader

Function TestBearerAuthMiddleware_MissingHeader

pkg/mcp/middleware_test.go:86–100  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

84}
85
86func TestBearerAuthMiddleware_MissingHeader(t *testing.T) {
87 cfg := &Config{Host: "127.0.0.1", Port: 8080, AuthToken: "secret"}
88 next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
89 t.Error("next handler should not be called with missing header")
90 })
91
92 handler := BearerAuthMiddleware(cfg, next)
93 req := httptest.NewRequest(http.MethodPost, "/mcp", nil)
94 rr := httptest.NewRecorder()
95 handler.ServeHTTP(rr, req)
96
97 if rr.Code != http.StatusUnauthorized {
98 t.Errorf("status = %d, want 401", rr.Code)
99 }
100}
101
102func TestBearerAuthMiddleware_MalformedHeader(t *testing.T) {
103 cfg := &Config{Host: "127.0.0.1", Port: 8080, AuthToken: "secret"}

Callers

nothing calls this directly

Calls 3

BearerAuthMiddlewareFunction · 0.85
ErrorfMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected