@@ -21,6 +21,7 @@ import (
21
21
"os"
22
22
"path/filepath"
23
23
"testing"
24
+ "time"
24
25
25
26
secretsstorev1 "sigs.k8s.io/secrets-store-csi-driver/apis/v1"
26
27
"sigs.k8s.io/secrets-store-csi-driver/pkg/secrets-store/mocks"
@@ -267,6 +268,7 @@ func TestNodePublishVolume(t *testing.T) {
267
268
name string
268
269
nodePublishVolReq * csi.NodePublishVolumeRequest
269
270
initObjects []client.Object
271
+ rotationConfig * RotationConfig
270
272
}{
271
273
{
272
274
name : "volume mount" ,
@@ -294,9 +296,14 @@ func TestNodePublishVolume(t *testing.T) {
294
296
},
295
297
},
296
298
},
299
+ rotationConfig : & RotationConfig {
300
+ enabled : false ,
301
+ nextRotationTime : time .Now (),
302
+ interval : time .Minute ,
303
+ },
297
304
},
298
305
{
299
- name : "volume mount with refresh token" ,
306
+ name : "volume mount with refresh token " ,
300
307
nodePublishVolReq : & csi.NodePublishVolumeRequest {
301
308
VolumeCapability : & csi.VolumeCapability {},
302
309
VolumeId : "testvolid1" ,
@@ -324,6 +331,43 @@ func TestNodePublishVolume(t *testing.T) {
324
331
},
325
332
},
326
333
},
334
+ rotationConfig : & RotationConfig {
335
+ enabled : true ,
336
+ nextRotationTime : time .Now ().Add (- 3 * time .Minute ), // so that rotation period is passed and secret will be mounted.
337
+ interval : time .Minute ,
338
+ },
339
+ },
340
+ {
341
+ name : "volume mount with rotation but skipped" ,
342
+ nodePublishVolReq : & csi.NodePublishVolumeRequest {
343
+ VolumeCapability : & csi.VolumeCapability {},
344
+ VolumeId : "testvolid1" ,
345
+ TargetPath : targetPath (t ),
346
+ VolumeContext : map [string ]string {
347
+ "secretProviderClass" : "provider1" ,
348
+ CSIPodName : "pod1" ,
349
+ CSIPodNamespace : "default" ,
350
+ CSIPodUID : "poduid1" ,
351
+ },
352
+ Readonly : true ,
353
+ },
354
+ initObjects : []client.Object {
355
+ & secretsstorev1.SecretProviderClass {
356
+ ObjectMeta : metav1.ObjectMeta {
357
+ Name : "provider1" ,
358
+ Namespace : "default" ,
359
+ },
360
+ Spec : secretsstorev1.SecretProviderClassSpec {
361
+ Provider : "provider1" ,
362
+ Parameters : map [string ]string {"parameter1" : "value1" },
363
+ },
364
+ },
365
+ },
366
+ rotationConfig : & RotationConfig {
367
+ enabled : true ,
368
+ nextRotationTime : time .Now ().Add (2 * time .Minute ),
369
+ interval : time .Minute ,
370
+ },
327
371
},
328
372
}
329
373
@@ -338,7 +382,7 @@ func TestNodePublishVolume(t *testing.T) {
338
382
t .Run (test .name , func (t * testing.T ) {
339
383
r := mocks .NewFakeReporter ()
340
384
341
- ns , err := testNodeServer (t , fake .NewClientBuilder ().WithScheme (s ).WithObjects (test .initObjects ... ).Build (), r , & RotationConfig {} )
385
+ ns , err := testNodeServer (t , fake .NewClientBuilder ().WithScheme (s ).WithObjects (test .initObjects ... ).Build (), r , test . rotationConfig )
342
386
if err != nil {
343
387
t .Fatalf ("expected error to be nil, got: %+v" , err )
344
388
}
@@ -365,8 +409,13 @@ func TestNodePublishVolume(t *testing.T) {
365
409
if err != nil {
366
410
t .Fatalf ("expected err to be nil, got: %v" , err )
367
411
}
368
- if len (mnts ) == 0 {
369
- t .Errorf ("expected mounts...: %v" , mnts )
412
+ expectedMounts := 1
413
+ if ns .rotationConfig .enabled && ns .rotationConfig .nextRotationTime .After (time .Now ()) {
414
+ // If rotation time is not reached, there should not be any mounts.
415
+ expectedMounts = 0
416
+ }
417
+ if len (mnts ) != expectedMounts {
418
+ t .Errorf ("[Number of mounts] want : %d, got mount: %d" , expectedMounts , len (mnts ))
370
419
}
371
420
}
372
421
})
0 commit comments