@@ -89,7 +89,7 @@ func TestClaims(t *testing.T) {
89
89
sc * jwt.Claims
90
90
pc * privateClaims
91
91
92
- featureJTI , featurePodNodeInfo , featureNodeBinding bool
92
+ featureNodeBinding bool
93
93
}{
94
94
{
95
95
// pod and secret
@@ -115,6 +115,7 @@ func TestClaims(t *testing.T) {
115
115
IssuedAt : jwt .NewNumericDate (time .Unix (1514764800 , 0 )),
116
116
NotBefore : jwt .NewNumericDate (time .Unix (1514764800 , 0 )),
117
117
Expiry : jwt .NewNumericDate (time .Unix (1514764800 + 100 , 0 )),
118
+ ID : "fixed" ,
118
119
},
119
120
pc : & privateClaims {
120
121
Kubernetes : kubernetes {
@@ -138,6 +139,7 @@ func TestClaims(t *testing.T) {
138
139
IssuedAt : jwt .NewNumericDate (time .Unix (1514764800 , 0 )),
139
140
NotBefore : jwt .NewNumericDate (time .Unix (1514764800 , 0 )),
140
141
Expiry : jwt .NewNumericDate (time .Unix (1514764800 + 100 , 0 )),
142
+ ID : "fixed" ,
141
143
},
142
144
pc : & privateClaims {
143
145
Kubernetes : kubernetes {
@@ -160,6 +162,7 @@ func TestClaims(t *testing.T) {
160
162
IssuedAt : jwt .NewNumericDate (time .Unix (1514764800 , 0 )),
161
163
NotBefore : jwt .NewNumericDate (time .Unix (1514764800 , 0 )),
162
164
Expiry : jwt .NewNumericDate (time .Unix (1514764800 + 100 , 0 )),
165
+ ID : "fixed" ,
163
166
},
164
167
pc : & privateClaims {
165
168
Kubernetes : kubernetes {
@@ -182,6 +185,7 @@ func TestClaims(t *testing.T) {
182
185
IssuedAt : jwt .NewNumericDate (time .Unix (1514764800 , 0 )),
183
186
NotBefore : jwt .NewNumericDate (time .Unix (1514764800 , 0 )),
184
187
Expiry : jwt .NewNumericDate (time .Unix (1514764800 + 60 * 60 * 24 , 0 )),
188
+ ID : "fixed" ,
185
189
},
186
190
pc : & privateClaims {
187
191
Kubernetes : kubernetes {
@@ -202,30 +206,6 @@ func TestClaims(t *testing.T) {
202
206
aud : nil ,
203
207
err : "token bound to Node object requested, but \" ServiceAccountTokenNodeBinding\" feature gate is disabled" ,
204
208
},
205
- {
206
- // node & pod with feature gate disabled
207
- sa : sa ,
208
- node : node ,
209
- pod : pod ,
210
- // really fast
211
- exp : 0 ,
212
- // nil audience
213
- aud : nil ,
214
-
215
- sc : & jwt.Claims {
216
- Subject : "system:serviceaccount:myns:mysvcacct" ,
217
- IssuedAt : jwt .NewNumericDate (time .Unix (1514764800 , 0 )),
218
- NotBefore : jwt .NewNumericDate (time .Unix (1514764800 , 0 )),
219
- Expiry : jwt .NewNumericDate (time .Unix (1514764800 , 0 )),
220
- },
221
- pc : & privateClaims {
222
- Kubernetes : kubernetes {
223
- Namespace : "myns" ,
224
- Pod : & ref {Name : "mypod" , UID : "mypod-uid" },
225
- Svcacct : ref {Name : "mysvcacct" , UID : "mysvcacct-uid" },
226
- },
227
- },
228
- },
229
209
{
230
210
// node alone
231
211
sa : sa ,
@@ -242,6 +222,7 @@ func TestClaims(t *testing.T) {
242
222
IssuedAt : jwt .NewNumericDate (time .Unix (1514764800 , 0 )),
243
223
NotBefore : jwt .NewNumericDate (time .Unix (1514764800 , 0 )),
244
224
Expiry : jwt .NewNumericDate (time .Unix (1514764800 , 0 )),
225
+ ID : "fixed" ,
245
226
},
246
227
pc : & privateClaims {
247
228
Kubernetes : kubernetes {
@@ -256,8 +237,6 @@ func TestClaims(t *testing.T) {
256
237
sa : sa ,
257
238
pod : pod ,
258
239
node : node ,
259
- // enable embedding pod node info feature
260
- featurePodNodeInfo : true ,
261
240
// really fast
262
241
exp : 0 ,
263
242
// nil audience
@@ -268,6 +247,7 @@ func TestClaims(t *testing.T) {
268
247
IssuedAt : jwt .NewNumericDate (time .Unix (1514764800 , 0 )),
269
248
NotBefore : jwt .NewNumericDate (time .Unix (1514764800 , 0 )),
270
249
Expiry : jwt .NewNumericDate (time .Unix (1514764800 , 0 )),
250
+ ID : "fixed" ,
271
251
},
272
252
pc : & privateClaims {
273
253
Kubernetes : kubernetes {
@@ -294,8 +274,6 @@ func TestClaims(t *testing.T) {
294
274
{
295
275
// ensure JTI is set
296
276
sa : sa ,
297
- // enable setting JTI feature
298
- featureJTI : true ,
299
277
// really fast
300
278
exp : 0 ,
301
279
// nil audience
@@ -342,9 +320,7 @@ func TestClaims(t *testing.T) {
342
320
}
343
321
344
322
// set feature flags for the duration of the test case
345
- featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .ServiceAccountTokenJTI , c .featureJTI )
346
323
featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .ServiceAccountTokenNodeBinding , c .featureNodeBinding )
347
- featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .ServiceAccountTokenPodNodeInfo , c .featurePodNodeInfo )
348
324
349
325
sc , pc , err := Claims (c .sa , c .pod , c .sec , c .node , c .exp , c .warnafter , c .aud )
350
326
if err != nil && err .Error () != c .err {
@@ -376,8 +352,6 @@ type claimTestCase struct {
376
352
expiry jwt.NumericDate
377
353
notBefore jwt.NumericDate
378
354
expectErr string
379
-
380
- featureNodeBindingValidation bool
381
355
}
382
356
383
357
func TestValidatePrivateClaims (t * testing.T ) {
@@ -458,11 +432,10 @@ func TestValidatePrivateClaims(t *testing.T) {
458
432
expectErr : "service account token has been invalidated" ,
459
433
},
460
434
{
461
- name : "missing node" ,
462
- getter : fakeGetter {serviceAccount , nil , nil , nil },
463
- private : & privateClaims {Kubernetes : kubernetes {Svcacct : ref {Name : "saname" , UID : "sauid" }, Node : & ref {Name : "nodename" , UID : "nodeuid" }, Namespace : "ns" }},
464
- expectErr : "service account token has been invalidated" ,
465
- featureNodeBindingValidation : true ,
435
+ name : "missing node" ,
436
+ getter : fakeGetter {serviceAccount , nil , nil , nil },
437
+ private : & privateClaims {Kubernetes : kubernetes {Svcacct : ref {Name : "saname" , UID : "sauid" }, Node : & ref {Name : "nodename" , UID : "nodeuid" }, Namespace : "ns" }},
438
+ expectErr : "service account token has been invalidated" ,
466
439
},
467
440
{
468
441
name : "different uid serviceaccount" ,
@@ -522,11 +495,10 @@ func TestValidatePrivateClaims(t *testing.T) {
522
495
expectErr : deletedErr ,
523
496
},
524
497
claimTestCase {
525
- name : deletionTestCase .name + " node" ,
526
- getter : fakeGetter {serviceAccount , nil , nil , deletedNode },
527
- private : & privateClaims {Kubernetes : kubernetes {Svcacct : ref {Name : "saname" , UID : "sauid" }, Node : & ref {Name : "nodename" , UID : "nodeuid" }, Namespace : "ns" }},
528
- expectErr : deletedErr ,
529
- featureNodeBindingValidation : true ,
498
+ name : deletionTestCase .name + " node" ,
499
+ getter : fakeGetter {serviceAccount , nil , nil , deletedNode },
500
+ private : & privateClaims {Kubernetes : kubernetes {Svcacct : ref {Name : "saname" , UID : "sauid" }, Node : & ref {Name : "nodename" , UID : "nodeuid" }, Namespace : "ns" }},
501
+ expectErr : deletedErr ,
530
502
},
531
503
)
532
504
}
@@ -539,8 +511,6 @@ func TestValidatePrivateClaims(t *testing.T) {
539
511
expiry = tc .expiry
540
512
}
541
513
542
- featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .ServiceAccountTokenNodeBindingValidation , tc .featureNodeBindingValidation )
543
-
544
514
_ , err := v .Validate (context .Background (), "" , & jwt.Claims {Expiry : & expiry , NotBefore : & tc .notBefore }, tc .private )
545
515
if len (tc .expectErr ) > 0 {
546
516
if errStr := errString (err ); tc .expectErr != errStr {
0 commit comments