@@ -292,7 +292,7 @@ func TestHealthCheck(t *testing.T) {
292292 })
293293 })
294294 // Health exposed even when require Authorization
295- testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , ValidateToken : true }}, func (ctx * httpContext ) {
295+ testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , ValidateToken : true , ClusterProviderStrategy : config . ClusterProviderKubeConfig }}, func (ctx * httpContext ) {
296296 resp , err := http .Get (fmt .Sprintf ("http://%s/healthz" , ctx .HttpAddress ))
297297 if err != nil {
298298 t .Fatalf ("Failed to get health check endpoint with OAuth: %v" , err )
@@ -313,7 +313,7 @@ func TestWellKnownReverseProxy(t *testing.T) {
313313 ".well-known/openid-configuration" ,
314314 }
315315 // With No Authorization URL configured
316- testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , ValidateToken : true }}, func (ctx * httpContext ) {
316+ testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , ValidateToken : true , ClusterProviderStrategy : config . ClusterProviderKubeConfig }}, func (ctx * httpContext ) {
317317 for _ , path := range cases {
318318 resp , err := http .Get (fmt .Sprintf ("http://%s/%s" , ctx .HttpAddress , path ))
319319 t .Cleanup (func () { _ = resp .Body .Close () })
@@ -333,7 +333,12 @@ func TestWellKnownReverseProxy(t *testing.T) {
333333 _ , _ = w .Write ([]byte (`NOT A JSON PAYLOAD` ))
334334 }))
335335 t .Cleanup (invalidPayloadServer .Close )
336- invalidPayloadConfig := & config.StaticConfig {AuthorizationURL : invalidPayloadServer .URL , RequireOAuth : true , ValidateToken : true }
336+ invalidPayloadConfig := & config.StaticConfig {
337+ AuthorizationURL : invalidPayloadServer .URL ,
338+ RequireOAuth : true ,
339+ ValidateToken : true ,
340+ ClusterProviderStrategy : config .ClusterProviderKubeConfig ,
341+ }
337342 testCaseWithContext (t , & httpContext {StaticConfig : invalidPayloadConfig }, func (ctx * httpContext ) {
338343 for _ , path := range cases {
339344 resp , err := http .Get (fmt .Sprintf ("http://%s/%s" , ctx .HttpAddress , path ))
@@ -358,7 +363,12 @@ func TestWellKnownReverseProxy(t *testing.T) {
358363 _ , _ = w .Write ([]byte (`{"issuer": "https://example.com","scopes_supported":["mcp-server"]}` ))
359364 }))
360365 t .Cleanup (testServer .Close )
361- staticConfig := & config.StaticConfig {AuthorizationURL : testServer .URL , RequireOAuth : true , ValidateToken : true }
366+ staticConfig := & config.StaticConfig {
367+ AuthorizationURL : testServer .URL ,
368+ RequireOAuth : true ,
369+ ValidateToken : true ,
370+ ClusterProviderStrategy : config .ClusterProviderKubeConfig ,
371+ }
362372 testCaseWithContext (t , & httpContext {StaticConfig : staticConfig }, func (ctx * httpContext ) {
363373 for _ , path := range cases {
364374 resp , err := http .Get (fmt .Sprintf ("http://%s/%s" , ctx .HttpAddress , path ))
@@ -401,7 +411,12 @@ func TestWellKnownOverrides(t *testing.T) {
401411 }` ))
402412 }))
403413 t .Cleanup (testServer .Close )
404- baseConfig := config.StaticConfig {AuthorizationURL : testServer .URL , RequireOAuth : true , ValidateToken : true }
414+ baseConfig := config.StaticConfig {
415+ AuthorizationURL : testServer .URL ,
416+ RequireOAuth : true ,
417+ ValidateToken : true ,
418+ ClusterProviderStrategy : config .ClusterProviderKubeConfig ,
419+ }
405420 // With Dynamic Client Registration disabled
406421 disableDynamicRegistrationConfig := baseConfig
407422 disableDynamicRegistrationConfig .DisableDynamicClientRegistration = true
@@ -488,7 +503,7 @@ func TestMiddlewareLogging(t *testing.T) {
488503
489504func TestAuthorizationUnauthorized (t * testing.T ) {
490505 // Missing Authorization header
491- testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , ValidateToken : true }}, func (ctx * httpContext ) {
506+ testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , ValidateToken : true , ClusterProviderStrategy : config . ClusterProviderKubeConfig }}, func (ctx * httpContext ) {
492507 resp , err := http .Get (fmt .Sprintf ("http://%s/mcp" , ctx .HttpAddress ))
493508 if err != nil {
494509 t .Fatalf ("Failed to get protected endpoint: %v" , err )
@@ -513,7 +528,7 @@ func TestAuthorizationUnauthorized(t *testing.T) {
513528 })
514529 })
515530 // Authorization header without Bearer prefix
516- testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , ValidateToken : true }}, func (ctx * httpContext ) {
531+ testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , ValidateToken : true , ClusterProviderStrategy : config . ClusterProviderKubeConfig }}, func (ctx * httpContext ) {
517532 req , err := http .NewRequest ("GET" , fmt .Sprintf ("http://%s/mcp" , ctx .HttpAddress ), nil )
518533 if err != nil {
519534 t .Fatalf ("Failed to create request: %v" , err )
@@ -538,7 +553,7 @@ func TestAuthorizationUnauthorized(t *testing.T) {
538553 })
539554 })
540555 // Invalid Authorization header
541- testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , ValidateToken : true }}, func (ctx * httpContext ) {
556+ testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , ValidateToken : true , ClusterProviderStrategy : config . ClusterProviderKubeConfig }}, func (ctx * httpContext ) {
542557 req , err := http .NewRequest ("GET" , fmt .Sprintf ("http://%s/mcp" , ctx .HttpAddress ), nil )
543558 if err != nil {
544559 t .Fatalf ("Failed to create request: %v" , err )
@@ -569,7 +584,7 @@ func TestAuthorizationUnauthorized(t *testing.T) {
569584 })
570585 })
571586 // Expired Authorization Bearer token
572- testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , ValidateToken : true }}, func (ctx * httpContext ) {
587+ testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , ValidateToken : true , ClusterProviderStrategy : config . ClusterProviderKubeConfig }}, func (ctx * httpContext ) {
573588 req , err := http .NewRequest ("GET" , fmt .Sprintf ("http://%s/mcp" , ctx .HttpAddress ), nil )
574589 if err != nil {
575590 t .Fatalf ("Failed to create request: %v" , err )
@@ -600,7 +615,7 @@ func TestAuthorizationUnauthorized(t *testing.T) {
600615 })
601616 })
602617 // Invalid audience claim Bearer token
603- testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , OAuthAudience : "expected-audience" , ValidateToken : true }}, func (ctx * httpContext ) {
618+ testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , OAuthAudience : "expected-audience" , ValidateToken : true , ClusterProviderStrategy : config . ClusterProviderKubeConfig }}, func (ctx * httpContext ) {
604619 req , err := http .NewRequest ("GET" , fmt .Sprintf ("http://%s/mcp" , ctx .HttpAddress ), nil )
605620 if err != nil {
606621 t .Fatalf ("Failed to create request: %v" , err )
@@ -633,7 +648,7 @@ func TestAuthorizationUnauthorized(t *testing.T) {
633648 // Failed OIDC validation
634649 oidcTestServer := NewOidcTestServer (t )
635650 t .Cleanup (oidcTestServer .Close )
636- testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , OAuthAudience : "mcp-server" , ValidateToken : true }, OidcProvider : oidcTestServer .Provider }, func (ctx * httpContext ) {
651+ testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , OAuthAudience : "mcp-server" , ValidateToken : true , ClusterProviderStrategy : config . ClusterProviderKubeConfig }, OidcProvider : oidcTestServer .Provider }, func (ctx * httpContext ) {
637652 req , err := http .NewRequest ("GET" , fmt .Sprintf ("http://%s/mcp" , ctx .HttpAddress ), nil )
638653 if err != nil {
639654 t .Fatalf ("Failed to create request: %v" , err )
@@ -670,7 +685,7 @@ func TestAuthorizationUnauthorized(t *testing.T) {
670685 "aud": "mcp-server"
671686 }`
672687 validOidcToken := oidctest .SignIDToken (oidcTestServer .PrivateKey , "test-oidc-key-id" , oidc .RS256 , rawClaims )
673- testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , OAuthAudience : "mcp-server" , ValidateToken : true }, OidcProvider : oidcTestServer .Provider }, func (ctx * httpContext ) {
688+ testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , OAuthAudience : "mcp-server" , ValidateToken : true , ClusterProviderStrategy : config . ClusterProviderKubeConfig }, OidcProvider : oidcTestServer .Provider }, func (ctx * httpContext ) {
674689 req , err := http .NewRequest ("GET" , fmt .Sprintf ("http://%s/mcp" , ctx .HttpAddress ), nil )
675690 if err != nil {
676691 t .Fatalf ("Failed to create request: %v" , err )
@@ -703,7 +718,7 @@ func TestAuthorizationUnauthorized(t *testing.T) {
703718}
704719
705720func TestAuthorizationRequireOAuthFalse (t * testing.T ) {
706- testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : false }}, func (ctx * httpContext ) {
721+ testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : false , ClusterProviderStrategy : config . ClusterProviderKubeConfig }}, func (ctx * httpContext ) {
707722 resp , err := http .Get (fmt .Sprintf ("http://%s/mcp" , ctx .HttpAddress ))
708723 if err != nil {
709724 t .Fatalf ("Failed to get protected endpoint: %v" , err )
@@ -728,7 +743,7 @@ func TestAuthorizationRawToken(t *testing.T) {
728743 {"mcp-server" , true }, // Audience set, validation enabled
729744 }
730745 for _ , c := range cases {
731- testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , OAuthAudience : c .audience , ValidateToken : c .validateToken }}, func (ctx * httpContext ) {
746+ testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , OAuthAudience : c .audience , ValidateToken : c .validateToken , ClusterProviderStrategy : config . ClusterProviderKubeConfig }}, func (ctx * httpContext ) {
732747 tokenReviewed := false
733748 ctx .mockServer .Handle (http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
734749 if req .URL .EscapedPath () == "/apis/authentication.k8s.io/v1/tokenreviews" {
@@ -777,7 +792,7 @@ func TestAuthorizationOidcToken(t *testing.T) {
777792 validOidcToken := oidctest .SignIDToken (oidcTestServer .PrivateKey , "test-oidc-key-id" , oidc .RS256 , rawClaims )
778793 cases := []bool {false , true }
779794 for _ , validateToken := range cases {
780- testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , OAuthAudience : "mcp-server" , ValidateToken : validateToken }, OidcProvider : oidcTestServer .Provider }, func (ctx * httpContext ) {
795+ testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , OAuthAudience : "mcp-server" , ValidateToken : validateToken , ClusterProviderStrategy : config . ClusterProviderKubeConfig }, OidcProvider : oidcTestServer .Provider }, func (ctx * httpContext ) {
781796 tokenReviewed := false
782797 ctx .mockServer .Handle (http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
783798 if req .URL .EscapedPath () == "/apis/authentication.k8s.io/v1/tokenreviews" {
@@ -833,13 +848,14 @@ func TestAuthorizationOidcTokenExchange(t *testing.T) {
833848 cases := []bool {false , true }
834849 for _ , validateToken := range cases {
835850 staticConfig := & config.StaticConfig {
836- RequireOAuth : true ,
837- OAuthAudience : "mcp-server" ,
838- ValidateToken : validateToken ,
839- StsClientId : "test-sts-client-id" ,
840- StsClientSecret : "test-sts-client-secret" ,
841- StsAudience : "backend-audience" ,
842- StsScopes : []string {"backend-scope" },
851+ RequireOAuth : true ,
852+ OAuthAudience : "mcp-server" ,
853+ ValidateToken : validateToken ,
854+ StsClientId : "test-sts-client-id" ,
855+ StsClientSecret : "test-sts-client-secret" ,
856+ StsAudience : "backend-audience" ,
857+ StsScopes : []string {"backend-scope" },
858+ ClusterProviderStrategy : config .ClusterProviderKubeConfig ,
843859 }
844860 testCaseWithContext (t , & httpContext {StaticConfig : staticConfig , OidcProvider : oidcTestServer .Provider }, func (ctx * httpContext ) {
845861 tokenReviewed := false
0 commit comments