@@ -619,10 +619,12 @@ func TestAuthorizationRawToken(t *testing.T) {
619
619
}
620
620
for _ , c := range cases {
621
621
testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , OAuthAudience : c .audience , ValidateToken : c .validateToken }}, func (ctx * httpContext ) {
622
+ tokenReviewed := false
622
623
ctx .mockServer .Handle (http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
623
624
if req .URL .EscapedPath () == "/apis/authentication.k8s.io/v1/tokenreviews" {
624
625
w .Header ().Set ("Content-Type" , "application/json" )
625
626
_ , _ = w .Write ([]byte (tokenReviewSuccessful ))
627
+ tokenReviewed = true
626
628
return
627
629
}
628
630
}))
@@ -641,6 +643,14 @@ func TestAuthorizationRawToken(t *testing.T) {
641
643
t .Errorf ("Expected HTTP 200 OK, got %d" , resp .StatusCode )
642
644
}
643
645
})
646
+ t .Run (fmt .Sprintf ("Protected resource with audience = '%s' and validate-token = '%t', with VALID Authorization header performs token validation accordingly" , c .audience , c .validateToken ), func (t * testing.T ) {
647
+ if tokenReviewed == true && ! c .validateToken {
648
+ t .Errorf ("Expected token review to be skipped when validate-token is false, but it was performed" )
649
+ }
650
+ if tokenReviewed == false && c .validateToken {
651
+ t .Errorf ("Expected token review to be performed when validate-token is true, but it was skipped" )
652
+ }
653
+ })
644
654
})
645
655
}
646
656
@@ -658,10 +668,12 @@ func TestAuthorizationOidcToken(t *testing.T) {
658
668
cases := []bool {false , true }
659
669
for _ , validateToken := range cases {
660
670
testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {RequireOAuth : true , OAuthAudience : "mcp-server" , ValidateToken : validateToken }, OidcProvider : oidcProvider }, func (ctx * httpContext ) {
671
+ tokenReviewed := false
661
672
ctx .mockServer .Handle (http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
662
673
if req .URL .EscapedPath () == "/apis/authentication.k8s.io/v1/tokenreviews" {
663
674
w .Header ().Set ("Content-Type" , "application/json" )
664
675
_ , _ = w .Write ([]byte (tokenReviewSuccessful ))
676
+ tokenReviewed = true
665
677
return
666
678
}
667
679
}))
@@ -680,6 +692,14 @@ func TestAuthorizationOidcToken(t *testing.T) {
680
692
t .Errorf ("Expected HTTP 200 OK, got %d" , resp .StatusCode )
681
693
}
682
694
})
695
+ t .Run (fmt .Sprintf ("Protected resource with validate-token='%t' with VALID OIDC Authorization header performs token validation accordingly" , validateToken ), func (t * testing.T ) {
696
+ if tokenReviewed == true && ! validateToken {
697
+ t .Errorf ("Expected token review to be skipped when validate-token is false, but it was performed" )
698
+ }
699
+ if tokenReviewed == false && validateToken {
700
+ t .Errorf ("Expected token review to be performed when validate-token is true, but it was skipped" )
701
+ }
702
+ })
683
703
})
684
704
685
705
}
0 commit comments