diff --git a/pkg/smb/nodeserver_test.go b/pkg/smb/nodeserver_test.go index 1a58cb911cf..d8ca16ff9b6 100644 --- a/pkg/smb/nodeserver_test.go +++ b/pkg/smb/nodeserver_test.go @@ -969,3 +969,92 @@ func TestNodePublishVolumeIdempotentMount(t *testing.T) { err = os.RemoveAll(targetTest) assert.NoError(t, err) } + +func TestEnableGroupRWX(t *testing.T) { + tests := []struct { + value string + expectedValue string + }{ + { + value: "qwerty", + expectedValue: "qwerty", + }, + { + value: "0111", + expectedValue: "0171", + }, + } + + for _, test := range tests { + mode := enableGroupRWX(test.value) + assert.Equal(t, test.expectedValue, mode) + } +} + +func TestRaiseGroupRWXInMountFlags(t *testing.T) { + tests := []struct { + mountFlags []string + flag string + expectedResult bool + mountFlagsUpdated bool + expectedMountFlags []string + }{ + { + mountFlags: []string{""}, + flag: "flag", + expectedResult: false, + }, + { + mountFlags: []string{"irrelevant"}, + flag: "flag", + expectedResult: false, + }, + { + mountFlags: []string{"key=val"}, + flag: "flag", + expectedResult: false, + }, + { + mountFlags: []string{"flag=key=val"}, + flag: "flag", + expectedResult: false, + }, + { + // This is important: if we return false here, the caller will append another flag=... + mountFlags: []string{"flag=invalid"}, + flag: "flag", + expectedResult: true, + }, + { + // Main case: raising group bits in the value + mountFlags: []string{"flag=0111"}, + flag: "flag", + expectedResult: true, + mountFlagsUpdated: true, + expectedMountFlags: []string{"flag=0171"}, + }, + } + + for _, test := range tests { + savedMountFlags := make([]string, len(test.mountFlags)) + copy(savedMountFlags, test.mountFlags) + + result := raiseGroupRWXInMountFlags(test.mountFlags, test.flag) + if result != test.expectedResult { + t.Errorf("raiseGroupRWXInMountFlags(%v, %s) returned %t (expected: %t)", + test.mountFlags, test.flag, result, test.expectedResult) + } + + if test.mountFlagsUpdated { + if !reflect.DeepEqual(test.expectedMountFlags, test.mountFlags) { + t.Errorf("raiseGroupRWXInMountFlags(%v, %s) did not update mountFlags (expected: %v)", + savedMountFlags, test.flag, test.expectedMountFlags) + } + } else { + if !reflect.DeepEqual(savedMountFlags, test.mountFlags) { + t.Errorf("raiseGroupRWXInMountFlags(%v, %s) updated mountFlags: %v", + savedMountFlags, test.flag, test.mountFlags) + } + } + } +}