MCPcopy
hub / github.com/github/github-mcp-server / TestRegisterRoutes

Function TestRegisterRoutes

pkg/http/oauth/oauth_test.go:519–564  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

517}
518
519func TestRegisterRoutes(t *testing.T) {
520 t.Parallel()
521
522 dotcomHost, err := utils.NewAPIHost("https://api.github.com")
523 require.NoError(t, err)
524
525 handler, err := NewAuthHandler(&Config{
526 BaseURL: "https://api.example.com",
527 }, dotcomHost)
528 require.NoError(t, err)
529
530 router := chi.NewRouter()
531 handler.RegisterRoutes(router)
532
533 // List of expected routes that should be registered
534 expectedRoutes := []string{
535 OAuthProtectedResourcePrefix,
536 OAuthProtectedResourcePrefix + "/",
537 OAuthProtectedResourcePrefix + "/mcp",
538 OAuthProtectedResourcePrefix + "/mcp/",
539 OAuthProtectedResourcePrefix + "/readonly",
540 OAuthProtectedResourcePrefix + "/readonly/",
541 OAuthProtectedResourcePrefix + "/mcp/readonly",
542 OAuthProtectedResourcePrefix + "/mcp/readonly/",
543 OAuthProtectedResourcePrefix + "/x/repos",
544 OAuthProtectedResourcePrefix + "/mcp/x/repos",
545 }
546
547 for _, route := range expectedRoutes {
548 t.Run("route:"+route, func(t *testing.T) {
549 // Test GET
550 req := httptest.NewRequest(http.MethodGet, route, nil)
551 req.Host = "api.example.com"
552 rec := httptest.NewRecorder()
553 router.ServeHTTP(rec, req)
554 assert.Equal(t, http.StatusOK, rec.Code, "GET %s should return 200", route)
555
556 // Test OPTIONS (CORS preflight)
557 req = httptest.NewRequest(http.MethodOptions, route, nil)
558 req.Host = "api.example.com"
559 rec = httptest.NewRecorder()
560 router.ServeHTTP(rec, req)
561 assert.Equal(t, http.StatusNoContent, rec.Code, "OPTIONS %s should return 204", route)
562 })
563 }
564}
565
566func TestSupportedScopes(t *testing.T) {
567 t.Parallel()

Callers

nothing calls this directly

Calls 4

RegisterRoutesMethod · 0.95
NewAPIHostFunction · 0.92
NewAuthHandlerFunction · 0.85
ServeHTTPMethod · 0.80

Tested by

no test coverage detected