@@ -79,6 +79,76 @@ func TestOIDCAuthenticationSucceeded(t *testing.T) {
79
79
// TODO(jpkroehling): assert that the authentication routine set the subject/membership to the resource
80
80
}
81
81
82
+ func TestOIDCAuthenticationSucceededIgnoreAudienceMismatch (t * testing.T ) {
83
+ // prepare
84
+ oidcServer , err := newOIDCServer ()
85
+ require .NoError (t , err )
86
+ oidcServer .Start ()
87
+ defer oidcServer .Close ()
88
+
89
+ config := & Config {
90
+ IssuerURL : oidcServer .URL ,
91
+ Audience : "unit-test" ,
92
+ IgnoreAudience : true ,
93
+ }
94
+ p := newTestExtension (t , config )
95
+
96
+ err = p .Start (context .Background (), componenttest .NewNopHost ())
97
+ require .NoError (t , err )
98
+
99
+ payload , _ := json .Marshal (map [string ]any {
100
+ "iss" : oidcServer .URL ,
101
+ "aud" : "not-unit-test" ,
102
+ "exp" : time .Now ().Add (time .Minute ).Unix (),
103
+ })
104
+ token , err := oidcServer .token (payload )
105
+ require .NoError (t , err )
106
+
107
+ srvAuth , ok := p .(extensionauth.Server )
108
+ require .True (t , ok )
109
+
110
+ // test
111
+ ctx , err := srvAuth .Authenticate (context .Background (), map [string ][]string {"authorization" : {fmt .Sprintf ("Bearer %s" , token )}})
112
+
113
+ // verify
114
+ assert .NoError (t , err )
115
+ assert .NotNil (t , ctx )
116
+ }
117
+
118
+ func TestOIDCAuthenticationFailAudienceMismatch (t * testing.T ) {
119
+ // prepare
120
+ oidcServer , err := newOIDCServer ()
121
+ require .NoError (t , err )
122
+ oidcServer .Start ()
123
+ defer oidcServer .Close ()
124
+
125
+ config := & Config {
126
+ IssuerURL : oidcServer .URL ,
127
+ Audience : "unit-test" ,
128
+ }
129
+ p := newTestExtension (t , config )
130
+
131
+ err = p .Start (context .Background (), componenttest .NewNopHost ())
132
+ require .NoError (t , err )
133
+
134
+ payload , _ := json .Marshal (map [string ]any {
135
+ "iss" : oidcServer .URL ,
136
+ "aud" : "not-unit-test" ,
137
+ "exp" : time .Now ().Add (time .Minute ).Unix (),
138
+ })
139
+ token , err := oidcServer .token (payload )
140
+ require .NoError (t , err )
141
+
142
+ srvAuth , ok := p .(extensionauth.Server )
143
+ require .True (t , ok )
144
+
145
+ // test
146
+ _ , err = srvAuth .Authenticate (context .Background (), map [string ][]string {"authorization" : {fmt .Sprintf ("Bearer %s" , token )}})
147
+
148
+ // verify
149
+ assert .Error (t , err )
150
+ }
151
+
82
152
func TestOIDCProviderForConfigWithTLS (t * testing.T ) {
83
153
// prepare the CA cert for the TLS handler
84
154
cert := x509.Certificate {
@@ -441,6 +511,20 @@ func TestMissingClient(t *testing.T) {
441
511
assert .Equal (t , errNoAudienceProvided , err )
442
512
}
443
513
514
+ func TestIgnoreMissingClient (t * testing.T ) {
515
+ // prepare
516
+ config := & Config {
517
+ IssuerURL : "http://example.com/" ,
518
+ IgnoreAudience : true ,
519
+ }
520
+
521
+ // test
522
+ err := config .Validate ()
523
+
524
+ // verify
525
+ assert .NoError (t , err )
526
+ }
527
+
444
528
func TestMissingIssuerURL (t * testing.T ) {
445
529
// prepare
446
530
config := & Config {
0 commit comments