@@ -57,6 +57,21 @@ func TestNodeStageVolume(t *testing.T) {
57
57
Mount : & csi.VolumeCapability_MountVolume {},
58
58
},
59
59
}
60
+ mountGroupVolCap := csi.VolumeCapability {
61
+ AccessType : & csi.VolumeCapability_Mount {
62
+ Mount : & csi.VolumeCapability_MountVolume {
63
+ VolumeMountGroup : "1000" ,
64
+ },
65
+ },
66
+ }
67
+ mountGroupWithModesVolCap := csi.VolumeCapability {
68
+ AccessType : & csi.VolumeCapability_Mount {
69
+ Mount : & csi.VolumeCapability_MountVolume {
70
+ VolumeMountGroup : "1000" ,
71
+ MountFlags : []string {"file_mode=0111" , "dir_mode=0111" },
72
+ },
73
+ },
74
+ }
60
75
61
76
errorMountSensSource := testutil .GetWorkDirPath ("error_mount_sens_source" , t )
62
77
smbFile := testutil .GetWorkDirPath ("smb.go" , t )
@@ -191,6 +206,30 @@ func TestNodeStageVolume(t *testing.T) {
191
206
strings .Replace (testSource , "\\ " , "\\ \\ " , - 1 ), sourceTest , testSource , sourceTest ),
192
207
expectedErr : testutil.TestError {},
193
208
},
209
+ {
210
+ desc : "[Success] Valid request with VolumeMountGroup" ,
211
+ req : csi.NodeStageVolumeRequest {VolumeId : "vol_1##" , StagingTargetPath : sourceTest ,
212
+ VolumeCapability : & mountGroupVolCap ,
213
+ VolumeContext : volContext ,
214
+ Secrets : secrets },
215
+ skipOnWindows : true ,
216
+ flakyWindowsErrorMessage : fmt .Sprintf ("rpc error: code = Internal desc = volume(vol_1##) mount \" %s\" on %#v failed with " +
217
+ "NewSmbGlobalMapping(%s, %s) failed with error: rpc error: code = Unknown desc = NewSmbGlobalMapping failed." ,
218
+ strings .Replace (testSource , "\\ " , "\\ \\ " , - 1 ), sourceTest , testSource , sourceTest ),
219
+ expectedErr : testutil.TestError {},
220
+ },
221
+ {
222
+ desc : "[Success] Valid request with VolumeMountGroup and file/dir modes" ,
223
+ req : csi.NodeStageVolumeRequest {VolumeId : "vol_1##" , StagingTargetPath : sourceTest ,
224
+ VolumeCapability : & mountGroupWithModesVolCap ,
225
+ VolumeContext : volContext ,
226
+ Secrets : secrets },
227
+ skipOnWindows : true ,
228
+ flakyWindowsErrorMessage : fmt .Sprintf ("rpc error: code = Internal desc = volume(vol_1##) mount \" %s\" on %#v failed with " +
229
+ "NewSmbGlobalMapping(%s, %s) failed with error: rpc error: code = Unknown desc = NewSmbGlobalMapping failed." ,
230
+ strings .Replace (testSource , "\\ " , "\\ \\ " , - 1 ), sourceTest , testSource , sourceTest ),
231
+ expectedErr : testutil.TestError {},
232
+ },
194
233
}
195
234
196
235
// Setup
@@ -930,3 +969,92 @@ func TestNodePublishVolumeIdempotentMount(t *testing.T) {
930
969
err = os .RemoveAll (targetTest )
931
970
assert .NoError (t , err )
932
971
}
972
+
973
+ func TestEnableGroupRWX (t * testing.T ) {
974
+ tests := []struct {
975
+ value string
976
+ expectedValue string
977
+ }{
978
+ {
979
+ value : "qwerty" ,
980
+ expectedValue : "qwerty" ,
981
+ },
982
+ {
983
+ value : "0111" ,
984
+ expectedValue : "0171" ,
985
+ },
986
+ }
987
+
988
+ for _ , test := range tests {
989
+ mode := enableGroupRWX (test .value )
990
+ assert .Equal (t , test .expectedValue , mode )
991
+ }
992
+ }
993
+
994
+ func TestRaiseGroupRWXInMountFlags (t * testing.T ) {
995
+ tests := []struct {
996
+ mountFlags []string
997
+ flag string
998
+ expectedResult bool
999
+ mountFlagsUpdated bool
1000
+ expectedMountFlags []string
1001
+ }{
1002
+ {
1003
+ mountFlags : []string {"" },
1004
+ flag : "flag" ,
1005
+ expectedResult : false ,
1006
+ },
1007
+ {
1008
+ mountFlags : []string {"irrelevant" },
1009
+ flag : "flag" ,
1010
+ expectedResult : false ,
1011
+ },
1012
+ {
1013
+ mountFlags : []string {"key=val" },
1014
+ flag : "flag" ,
1015
+ expectedResult : false ,
1016
+ },
1017
+ {
1018
+ mountFlags : []string {"flag=key=val" },
1019
+ flag : "flag" ,
1020
+ expectedResult : false ,
1021
+ },
1022
+ {
1023
+ // This is important: if we return false here, the caller will append another flag=...
1024
+ mountFlags : []string {"flag=invalid" },
1025
+ flag : "flag" ,
1026
+ expectedResult : true ,
1027
+ },
1028
+ {
1029
+ // Main case: raising group bits in the value
1030
+ mountFlags : []string {"flag=0111" },
1031
+ flag : "flag" ,
1032
+ expectedResult : true ,
1033
+ mountFlagsUpdated : true ,
1034
+ expectedMountFlags : []string {"flag=0171" },
1035
+ },
1036
+ }
1037
+
1038
+ for _ , test := range tests {
1039
+ savedMountFlags := make ([]string , len (test .mountFlags ))
1040
+ copy (savedMountFlags , test .mountFlags )
1041
+
1042
+ result := raiseGroupRWXInMountFlags (test .mountFlags , test .flag )
1043
+ if result != test .expectedResult {
1044
+ t .Errorf ("raiseGroupRWXInMountFlags(%v, %s) returned %t (expected: %t)" ,
1045
+ test .mountFlags , test .flag , result , test .expectedResult )
1046
+ }
1047
+
1048
+ if test .mountFlagsUpdated {
1049
+ if ! reflect .DeepEqual (test .expectedMountFlags , test .mountFlags ) {
1050
+ t .Errorf ("raiseGroupRWXInMountFlags(%v, %s) did not update mountFlags (expected: %v)" ,
1051
+ savedMountFlags , test .flag , test .expectedMountFlags )
1052
+ }
1053
+ } else {
1054
+ if ! reflect .DeepEqual (savedMountFlags , test .mountFlags ) {
1055
+ t .Errorf ("raiseGroupRWXInMountFlags(%v, %s) updated mountFlags: %v" ,
1056
+ savedMountFlags , test .flag , test .mountFlags )
1057
+ }
1058
+ }
1059
+ }
1060
+ }
0 commit comments