@@ -39,6 +39,7 @@ func TestCtlV3AuthRevokeWithDelete(t *testing.T) { testCtl(t, authTestRevokeWith
39
39
func TestCtlV3AuthInvalidMgmt (t * testing.T ) { testCtl (t , authTestInvalidMgmt ) }
40
40
func TestCtlV3AuthFromKeyPerm (t * testing.T ) { testCtl (t , authTestFromKeyPerm ) }
41
41
func TestCtlV3AuthAndWatch (t * testing.T ) { testCtl (t , authTestWatch ) }
42
+ func TestCtlV3AuthAndLease (t * testing.T ) { testCtl (t , authTestLease ) }
42
43
43
44
func authEnableTest (cx ctlCtx ) {
44
45
if err := authEnable (cx ); err != nil {
@@ -739,3 +740,36 @@ func authTestWatch(cx ctlCtx) {
739
740
}
740
741
741
742
}
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
+ }
0 commit comments