@@ -22,6 +22,7 @@ import (
2222
2323 "github.com/container-storage-interface/spec/lib/go/csi"
2424 "github.com/golang/protobuf/proto"
25+ csi03 "github.com/kubernetes-csi/csi-lib-utils/protosanitizer/test/csi03"
2526 "github.com/kubernetes-csi/csi-lib-utils/protosanitizer/test/csitest"
2627 "github.com/stretchr/testify/assert"
2728)
@@ -30,6 +31,42 @@ func TestStripSecrets(t *testing.T) {
3031 secretName := "secret-abc"
3132 secretValue := "123"
3233
34+ // CSI 0.3.0.
35+ createVolumeCSI03 := & csi03.CreateVolumeRequest {
36+ AccessibilityRequirements : & csi03.TopologyRequirement {
37+ Requisite : []* csi03.Topology {
38+ & csi03.Topology {
39+ Segments : map [string ]string {
40+ "foo" : "bar" ,
41+ "x" : "y" ,
42+ },
43+ },
44+ & csi03.Topology {
45+ Segments : map [string ]string {
46+ "a" : "b" ,
47+ },
48+ },
49+ },
50+ },
51+ Name : "foo" ,
52+ VolumeCapabilities : []* csi03.VolumeCapability {
53+ & csi03.VolumeCapability {
54+ AccessType : & csi03.VolumeCapability_Mount {
55+ Mount : & csi03.VolumeCapability_MountVolume {
56+ FsType : "ext4" ,
57+ },
58+ },
59+ },
60+ },
61+ CapacityRange : & csi03.CapacityRange {
62+ RequiredBytes : 1024 ,
63+ },
64+ ControllerCreateSecrets : map [string ]string {
65+ secretName : secretValue ,
66+ "secret-xyz" : "987" ,
67+ },
68+ }
69+
3370 // Current spec.
3471 createVolume := & csi.CreateVolumeRequest {
3572 AccessibilityRequirements : & csi.TopologyRequirement {
@@ -142,6 +179,7 @@ func TestStripSecrets(t *testing.T) {
142179 AccessibilityRequirements : & csi.TopologyRequirement {},
143180 }, `{"accessibility_requirements":{},"capacity_range":{"limit_bytes":1024,"required_bytes":1024},"name":"test-volume","parameters":{"param1":"param1","param2":"param2"},"secrets":"***stripped***","volume_capabilities":[{"AccessType":{"Mount":{"fs_type":"ext4","mount_flags":["flag1","flag2","flag3"]}},"access_mode":{"mode":5}}],"volume_content_source":{"Type":null}}` },
144181 {createVolume , `{"accessibility_requirements":{"requisite":[{"segments":{"foo":"bar","x":"y"}},{"segments":{"a":"b"}}]},"capacity_range":{"required_bytes":1024},"name":"foo","secrets":"***stripped***","volume_capabilities":[{"AccessType":{"Mount":{"fs_type":"ext4"}}}]}` },
182+ {createVolumeCSI03 , `{"accessibility_requirements":{"requisite":[{"segments":{"foo":"bar","x":"y"}},{"segments":{"a":"b"}}]},"capacity_range":{"required_bytes":1024},"controller_create_secrets":"***stripped***","name":"foo","volume_capabilities":[{"AccessType":{"Mount":{"fs_type":"ext4"}}}]}` },
145183 {& csitest.CreateVolumeRequest {}, `{}` },
146184 {createVolumeFuture ,
147185 // Secrets are *not* removed from all fields yet. This will have to be fixed one way or another
@@ -165,7 +203,12 @@ func TestStripSecrets(t *testing.T) {
165203
166204 for _ , c := range cases {
167205 before := fmt .Sprint (c .original )
168- stripped := StripSecrets (c .original )
206+ var stripped fmt.Stringer
207+ if _ , ok := c .original .(* csi03.CreateVolumeRequest ); ok {
208+ stripped = StripSecretsCSI03 (c .original )
209+ } else {
210+ stripped = StripSecrets (c .original )
211+ }
169212 if assert .Equal (t , c .stripped , fmt .Sprintf ("%s" , stripped ), "unexpected result for fmt s of %s" , c .original ) {
170213 assert .Equal (t , c .stripped , fmt .Sprintf ("%v" , stripped ), "unexpected result for fmt v of %s" , c .original )
171214 }
0 commit comments