Skip to content

Commit 27e9afc

Browse files
committed
e2e: add a test case for protecting lease revoking with auth
1 parent 7a505a0 commit 27e9afc

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

e2e/ctl_v3_auth_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func TestCtlV3AuthRevokeWithDelete(t *testing.T) { testCtl(t, authTestRevokeWith
3939
func TestCtlV3AuthInvalidMgmt(t *testing.T) { testCtl(t, authTestInvalidMgmt) }
4040
func TestCtlV3AuthFromKeyPerm(t *testing.T) { testCtl(t, authTestFromKeyPerm) }
4141
func TestCtlV3AuthAndWatch(t *testing.T) { testCtl(t, authTestWatch) }
42+
func TestCtlV3AuthAndLease(t *testing.T) { testCtl(t, authTestLease) }
4243

4344
func authEnableTest(cx ctlCtx) {
4445
if err := authEnable(cx); err != nil {
@@ -739,3 +740,36 @@ func authTestWatch(cx ctlCtx) {
739740
}
740741

741742
}
743+
744+
func authTestLease(cx ctlCtx) {
745+
if err := authEnable(cx); err != nil {
746+
cx.t.Fatal(err)
747+
}
748+
749+
cx.user, cx.pass = "root", "root"
750+
authSetupTestUser(cx)
751+
752+
leaseID, err := ctlV3LeaseGrant(cx, 10)
753+
if err != nil {
754+
cx.t.Fatalf("authTestLease: ctlV3LeaseGrant error (%v)", err)
755+
}
756+
if err := ctlV3Put(cx, "key", "val", leaseID); err != nil {
757+
cx.t.Fatalf("authTestLease: ctlV3Put error (%v)", err)
758+
}
759+
760+
// test-user isn't granted the write permission of key, so revoking should be failed
761+
cx.user, cx.pass = "test-user", "pass"
762+
if err := ctlV3LeaseRevokeFailWithPerm(cx, leaseID); err != nil {
763+
cx.t.Fatalf("authTestLease: ctlV3LeaseRevok should be failed but succeed (%v)", err)
764+
}
765+
766+
// root can revoke
767+
cx.user, cx.pass = "root", "root"
768+
if err := ctlV3LeaseRevoke(cx, leaseID); err != nil {
769+
cx.t.Fatalf("authTestLease: ctlV3LeaseRevok error (%v)", err)
770+
}
771+
if err := ctlV3Get(cx, []string{"key"}); err != nil { // expect no output
772+
cx.t.Fatalf("authTestLease: ctlV3Get error (%v)", err)
773+
}
774+
775+
}

e2e/ctl_v3_lease_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,8 @@ func ctlV3LeaseRevoke(cx ctlCtx, leaseID string) error {
126126
cmdArgs := append(cx.PrefixArgs(), "lease", "revoke", leaseID)
127127
return spawnWithExpect(cmdArgs, fmt.Sprintf("lease %s revoked", leaseID))
128128
}
129+
130+
func ctlV3LeaseRevokeFailWithPerm(cx ctlCtx, leaseID string) error {
131+
cmdArgs := append(cx.PrefixArgs(), "lease", "revoke", leaseID)
132+
return spawnWithExpect(cmdArgs, "Error: failed to revoke lease (etcdserver: permission denied)")
133+
}

0 commit comments

Comments
 (0)