@@ -22,6 +22,7 @@ import (
22
22
23
23
"github.com/container-storage-interface/spec/lib/go/csi"
24
24
"github.com/golang/protobuf/proto"
25
+ csi03 "github.com/kubernetes-csi/csi-lib-utils/protosanitizer/test/csi03"
25
26
"github.com/kubernetes-csi/csi-lib-utils/protosanitizer/test/csitest"
26
27
"github.com/stretchr/testify/assert"
27
28
)
@@ -30,6 +31,42 @@ func TestStripSecrets(t *testing.T) {
30
31
secretName := "secret-abc"
31
32
secretValue := "123"
32
33
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
+
33
70
// Current spec.
34
71
createVolume := & csi.CreateVolumeRequest {
35
72
AccessibilityRequirements : & csi.TopologyRequirement {
@@ -142,6 +179,7 @@ func TestStripSecrets(t *testing.T) {
142
179
AccessibilityRequirements : & csi.TopologyRequirement {},
143
180
}, `{"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}}` },
144
181
{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"}}}]}` },
145
183
{& csitest.CreateVolumeRequest {}, `{}` },
146
184
{createVolumeFuture ,
147
185
// 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) {
165
203
166
204
for _ , c := range cases {
167
205
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
+ }
169
212
if assert .Equal (t , c .stripped , fmt .Sprintf ("%s" , stripped ), "unexpected result for fmt s of %s" , c .original ) {
170
213
assert .Equal (t , c .stripped , fmt .Sprintf ("%v" , stripped ), "unexpected result for fmt v of %s" , c .original )
171
214
}
0 commit comments