mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #5078 from ajityagaty/role_cmd_tests
e2e: Test case for the etcdctlv3 role command.
This commit is contained in:
commit
da1132662a
54
e2e/ctl_v3_role_test.go
Normal file
54
e2e/ctl_v3_role_test.go
Normal file
@ -0,0 +1,54 @@
|
||||
// Copyright 2016 CoreOS, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package e2e
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCtlV3RoleAdd(t *testing.T) { testCtl(t, roleAddTest) }
|
||||
func TestCtlV3RoleAddNoTLS(t *testing.T) { testCtl(t, roleAddTest, withCfg(configNoTLS)) }
|
||||
func TestCtlV3RoleAddClientTLS(t *testing.T) { testCtl(t, roleAddTest, withCfg(configClientTLS)) }
|
||||
func TestCtlV3RoleAddPeerTLS(t *testing.T) { testCtl(t, roleAddTest, withCfg(configPeerTLS)) }
|
||||
func TestCtlV3RoleAddTimeout(t *testing.T) { testCtl(t, roleAddTest, withDialTimeout(0)) }
|
||||
|
||||
func roleAddTest(cx ctlCtx) {
|
||||
cmdSet := []struct {
|
||||
args []string
|
||||
expectedStr string
|
||||
}{
|
||||
{
|
||||
args: []string{"add", "root"},
|
||||
expectedStr: "Role root created",
|
||||
},
|
||||
{
|
||||
args: []string{"add", "root"},
|
||||
expectedStr: "role name already exists",
|
||||
},
|
||||
}
|
||||
|
||||
for i, cmd := range cmdSet {
|
||||
if err := ctlV3Role(cx, cmd.args, cmd.expectedStr); err != nil {
|
||||
if cx.dialTimeout > 0 && !isGRPCTimedout(err) {
|
||||
cx.t.Fatalf("roleAddTest #%d: ctlV3Role error (%v)", i, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ctlV3Role(cx ctlCtx, args []string, expStr string) error {
|
||||
cmdArgs := append(cx.PrefixArgs(), "role")
|
||||
cmdArgs = append(cmdArgs, args...)
|
||||
|
||||
return spawnWithExpect(cmdArgs, expStr)
|
||||
}
|
@ -24,6 +24,7 @@ func TestCtlV3UserAddTimeout(t *testing.T) { testCtl(t, userAddTest, withDialT
|
||||
|
||||
func TestCtlV3UserDelete(t *testing.T) { testCtl(t, userDelTest) }
|
||||
func TestCtlV3UserPasswd(t *testing.T) { testCtl(t, userPasswdTest) }
|
||||
func TestCtlV3UserGrant(t *testing.T) { testCtl(t, userGrantTest) }
|
||||
|
||||
type userCmdDesc struct {
|
||||
args []string
|
||||
@ -106,6 +107,43 @@ func userPasswdTest(cx ctlCtx) {
|
||||
}
|
||||
}
|
||||
|
||||
func userGrantTest(cx ctlCtx) {
|
||||
// Add a role.
|
||||
if err := ctlV3Role(cx, []string{"add", "root"}, "Role root created"); err != nil {
|
||||
cx.t.Fatalf("userGrantTest: ctlV3Role error (%v)", err)
|
||||
}
|
||||
|
||||
cmdSet := []userCmdDesc{
|
||||
// Add a user name.
|
||||
{
|
||||
args: []string{"add", "username", "--interactive=false"},
|
||||
expectedStr: "User username created",
|
||||
stdIn: []string{"password"},
|
||||
},
|
||||
// Grant the previously added user a role.
|
||||
{
|
||||
args: []string{"grant", "username", "root"},
|
||||
expectedStr: "Role root is granted to user username",
|
||||
},
|
||||
// Supply a wrong user name.
|
||||
{
|
||||
args: []string{"grant", "username1", "root"},
|
||||
expectedStr: "user name not found",
|
||||
},
|
||||
// Supply a wrong role name.
|
||||
{
|
||||
args: []string{"grant", "username", "root1"},
|
||||
expectedStr: "role name not found",
|
||||
},
|
||||
}
|
||||
|
||||
for i, cmd := range cmdSet {
|
||||
if err := ctlV3User(cx, cmd.args, cmd.expectedStr, cmd.stdIn); err != nil {
|
||||
cx.t.Fatalf("userPasswdTest #%d: ctlV3User error (%v)", i, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ctlV3User(cx ctlCtx, args []string, expStr string, stdIn []string) error {
|
||||
cmdArgs := append(cx.PrefixArgs(), "user")
|
||||
cmdArgs = append(cmdArgs, args...)
|
||||
|
Loading…
x
Reference in New Issue
Block a user