Skip to content

Commit 4b0fb27

Browse files
authored
Merge pull request #1196 from andyzhangx/fix-mount-permission-issue
fix: mountPermission settting issue due to case insensitive parameter
2 parents 03a3da1 + 44ac3d6 commit 4b0fb27

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

pkg/blob/blob.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,20 @@ func setKeyValueInMap(m map[string]string, key, value string) {
994994
m[key] = value
995995
}
996996

997+
// getValueInMap get value from map by key
998+
// key in the map is case insensitive
999+
func getValueInMap(m map[string]string, key string) string {
1000+
if m == nil {
1001+
return ""
1002+
}
1003+
for k, v := range m {
1004+
if strings.EqualFold(k, key) {
1005+
return v
1006+
}
1007+
}
1008+
return ""
1009+
}
1010+
9971011
// replaceWithMap replace key with value for str
9981012
func replaceWithMap(str string, m map[string]string) string {
9991013
for k, v := range m {

pkg/blob/blob_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,6 +1578,52 @@ func TestSetKeyValueInMap(t *testing.T) {
15781578
}
15791579
}
15801580

1581+
func TestGetValueInMap(t *testing.T) {
1582+
tests := []struct {
1583+
desc string
1584+
m map[string]string
1585+
key string
1586+
expected string
1587+
}{
1588+
{
1589+
desc: "nil map",
1590+
key: "key",
1591+
expected: "",
1592+
},
1593+
{
1594+
desc: "empty map",
1595+
m: map[string]string{},
1596+
key: "key",
1597+
expected: "",
1598+
},
1599+
{
1600+
desc: "non-empty map",
1601+
m: map[string]string{"k": "v"},
1602+
key: "key",
1603+
expected: "",
1604+
},
1605+
{
1606+
desc: "same key already exists",
1607+
m: map[string]string{"subDir": "value2"},
1608+
key: "subDir",
1609+
expected: "value2",
1610+
},
1611+
{
1612+
desc: "case insensitive key already exists",
1613+
m: map[string]string{"subDir": "value2"},
1614+
key: "subdir",
1615+
expected: "value2",
1616+
},
1617+
}
1618+
1619+
for _, test := range tests {
1620+
result := getValueInMap(test.m, test.key)
1621+
if result != test.expected {
1622+
t.Errorf("test[%s]: unexpected output: %v, expected result: %v", test.desc, result, test.expected)
1623+
}
1624+
}
1625+
}
1626+
15811627
func TestReplaceWithMap(t *testing.T) {
15821628
tests := []struct {
15831629
desc string

pkg/blob/nodeserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
9898
return &csi.NodePublishVolumeResponse{}, err
9999
}
100100

101-
if perm := context[mountPermissionsField]; perm != "" {
101+
if perm := getValueInMap(context, mountPermissionsField); perm != "" {
102102
var err error
103103
if mountPermissions, err = strconv.ParseUint(perm, 8, 32); err != nil {
104104
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid mountPermissions %s", perm))

0 commit comments

Comments
 (0)