(t *testing.T)
| 109 | } |
| 110 | |
| 111 | func TestMCPAuthMiddlewareValidToken(t *testing.T) { |
| 112 | secret := "test-secret-key" |
| 113 | profile := &config.Profile{Mode: common.ReleaseModeDev} |
| 114 | |
| 115 | e := echo.New() |
| 116 | req := httptest.NewRequest(http.MethodPost, "/mcp", strings.NewReader(`{}`)) |
| 117 | req.Header.Set("Content-Type", "application/json") |
| 118 | req.Header.Set("Authorization", "Bearer "+generateValidToken(t, secret)) |
| 119 | rec := httptest.NewRecorder() |
| 120 | c := e.NewContext(req, rec) |
| 121 | |
| 122 | // Create server with auth - note: we pass nil store since we're testing middleware only |
| 123 | // A full integration test would require a real store |
| 124 | s, err := NewServer(nil, profile, secret) |
| 125 | require.NoError(t, err) |
| 126 | handler := s.authMiddleware(func(c *echo.Context) error { |
| 127 | // Verify access token is set in request context |
| 128 | ctx := c.Request().Context() |
| 129 | token := getAccessToken(ctx) |
| 130 | require.NotEmpty(t, token) |
| 131 | return c.String(http.StatusOK, "success") |
| 132 | }) |
| 133 | |
| 134 | err = handler(c) |
| 135 | require.NoError(t, err) |
| 136 | require.Equal(t, http.StatusOK, rec.Code) |
| 137 | } |
| 138 | |
| 139 | // TestMCPProxiedPublicHostNotRejected is the BYT-9693 regression. Behind a |
| 140 | // same-host reverse proxy (proxy_pass http://127.0.0.1:8080), the connection |
nothing calls this directly
no test coverage detected