|
|
@@ -22,15 +22,19 @@ func TestCtlV3RoleAddClientTLS(t *testing.T) { testCtl(t, roleAddTest, withCfg(c
|
|
|
func TestCtlV3RoleAddPeerTLS(t *testing.T) { testCtl(t, roleAddTest, withCfg(configPeerTLS)) }
|
|
|
func TestCtlV3RoleAddTimeout(t *testing.T) { testCtl(t, roleAddTest, withDialTimeout(0)) }
|
|
|
|
|
|
+func TestCtlV3RoleGrant(t *testing.T) { testCtl(t, roleGrantTest) }
|
|
|
+
|
|
|
func roleAddTest(cx ctlCtx) {
|
|
|
cmdSet := []struct {
|
|
|
args []string
|
|
|
expectedStr string
|
|
|
}{
|
|
|
+ // Add a role.
|
|
|
{
|
|
|
args: []string{"add", "root"},
|
|
|
expectedStr: "Role root created",
|
|
|
},
|
|
|
+ // Try adding the same role.
|
|
|
{
|
|
|
args: []string{"add", "root"},
|
|
|
expectedStr: "role name already exists",
|
|
|
@@ -46,6 +50,45 @@ func roleAddTest(cx ctlCtx) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func roleGrantTest(cx ctlCtx) {
|
|
|
+ cmdSet := []struct {
|
|
|
+ args []string
|
|
|
+ expectedStr string
|
|
|
+ }{
|
|
|
+ // Add a role.
|
|
|
+ {
|
|
|
+ args: []string{"add", "root"},
|
|
|
+ expectedStr: "Role root created",
|
|
|
+ },
|
|
|
+ // Grant read permission to the role.
|
|
|
+ {
|
|
|
+ args: []string{"grant", "root", "read", "foo"},
|
|
|
+ expectedStr: "Role root updated",
|
|
|
+ },
|
|
|
+ // Grant write permission to the role.
|
|
|
+ {
|
|
|
+ args: []string{"grant", "root", "write", "foo"},
|
|
|
+ expectedStr: "Role root updated",
|
|
|
+ },
|
|
|
+ // Grant rw permission to the role.
|
|
|
+ {
|
|
|
+ args: []string{"grant", "root", "readwrite", "foo"},
|
|
|
+ expectedStr: "Role root updated",
|
|
|
+ },
|
|
|
+ // Try granting invalid permission to the role.
|
|
|
+ {
|
|
|
+ args: []string{"grant", "root", "123", "foo"},
|
|
|
+ expectedStr: "invalid permission type",
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ for i, cmd := range cmdSet {
|
|
|
+ if err := ctlV3Role(cx, cmd.args, cmd.expectedStr); err != nil {
|
|
|
+ cx.t.Fatalf("roleGrantTest #%d: ctlV3Role error (%v)", i, err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func ctlV3Role(cx ctlCtx, args []string, expStr string) error {
|
|
|
cmdArgs := append(cx.PrefixArgs(), "role")
|
|
|
cmdArgs = append(cmdArgs, args...)
|