-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLOUDP-234532: fix atlas customDbRoles update command (#2687)
- Loading branch information
Showing
2 changed files
with
21 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,10 +29,12 @@ import ( | |
) | ||
|
||
const ( | ||
createPrivilege = "UPDATE" | ||
updatePrivilege = "LIST_SESSIONS" | ||
inheritedRole = "enableSharding@admin" | ||
enableSharding = "enableSharding" | ||
createPrivilege = "UPDATE" | ||
updatePrivilege = "LIST_SESSIONS" | ||
enableShardingRole = "enableSharding" | ||
enableShardingInheritedRole = "enableSharding@admin" | ||
readRole = "read" | ||
readInheritedRole = "read@mydb" | ||
) | ||
|
||
func TestDBRoles(t *testing.T) { | ||
|
@@ -50,7 +52,7 @@ func TestDBRoles(t *testing.T) { | |
"create", | ||
roleName, | ||
"--privilege", fmt.Sprintf("%[email protected]", createPrivilege), | ||
"--inheritedRole", inheritedRole, | ||
"--inheritedRole", enableShardingInheritedRole, | ||
"-o=json", | ||
) | ||
cmd.Env = os.Environ() | ||
|
@@ -65,7 +67,7 @@ func TestDBRoles(t *testing.T) { | |
a.Len(role.GetActions(), 1) | ||
a.Equal(createPrivilege, role.GetActions()[0].Action) | ||
a.Len(role.GetInheritedRoles(), 1) | ||
a.Equal(enableSharding, role.GetInheritedRoles()[0].Role) | ||
a.Equal(enableShardingRole, role.GetInheritedRoles()[0].Role) | ||
}) | ||
|
||
t.Run("List", func(t *testing.T) { | ||
|
@@ -101,14 +103,15 @@ func TestDBRoles(t *testing.T) { | |
a.Len(role.GetActions(), 1) | ||
a.Equal(createPrivilege, role.GetActions()[0].Action) | ||
a.Len(role.GetInheritedRoles(), 1) | ||
a.Equal(enableSharding, role.GetInheritedRoles()[0].Role) | ||
a.Equal(enableShardingRole, role.GetInheritedRoles()[0].Role) | ||
}) | ||
|
||
t.Run("Update with append", func(t *testing.T) { | ||
cmd := exec.Command(cliPath, | ||
customDBRoleEntity, | ||
"update", | ||
roleName, | ||
"--inheritedRole", readInheritedRole, | ||
"--privilege", updatePrivilege, | ||
"--privilege", fmt.Sprintf("%[email protected]", createPrivilege), | ||
"--append", | ||
|
@@ -126,15 +129,17 @@ func TestDBRoles(t *testing.T) { | |
a.ElementsMatch( | ||
[]string{role.GetActions()[0].Action, role.GetActions()[1].Action}, | ||
[]string{updatePrivilege, createPrivilege}) | ||
a.Len(role.GetInheritedRoles(), 1) | ||
a.Equal(enableSharding, role.GetInheritedRoles()[0].Role) | ||
a.ElementsMatch( | ||
[]string{enableShardingRole, readRole}, | ||
[]string{role.GetInheritedRoles()[0].Role, role.GetInheritedRoles()[1].Role}) | ||
}) | ||
|
||
t.Run("Update", func(t *testing.T) { | ||
cmd := exec.Command(cliPath, | ||
customDBRoleEntity, | ||
"update", | ||
roleName, | ||
"--inheritedRole", enableShardingInheritedRole, | ||
"--privilege", updatePrivilege, | ||
"-o=json") | ||
cmd.Env = os.Environ() | ||
|
@@ -148,6 +153,8 @@ func TestDBRoles(t *testing.T) { | |
a.Equal(roleName, role.RoleName) | ||
a.Len(role.GetActions(), 1) | ||
a.Equal(updatePrivilege, role.GetActions()[0].Action) | ||
a.Len(role.GetInheritedRoles(), 1) | ||
a.Equal(enableShardingRole, role.GetInheritedRoles()[0].Role) | ||
}) | ||
|
||
t.Run("Delete", func(t *testing.T) { | ||
|