File tree 2 files changed +24
-3
lines changed
2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -52,9 +52,22 @@ def acl_deluser(self, username):
52
52
"Delete the ACL for the specified ``username``"
53
53
return self .execute_command ('ACL DELUSER' , username )
54
54
55
- def acl_genpass (self ):
56
- "Generate a random password value"
57
- return self .execute_command ('ACL GENPASS' )
55
+ def acl_genpass (self , bits = None ):
56
+ """Generate a random password value.
57
+ If ``bits`` is supplied then use this number of bits, rounded to
58
+ the next multiple of 4.
59
+ See: https://redis.io/commands/acl-genpass
60
+ """
61
+ pieces = []
62
+ if bits is not None :
63
+ try :
64
+ b = int (bits )
65
+ if b < 0 or b > 4096 :
66
+ raise ValueError
67
+ except ValueError :
68
+ raise DataError ('genpass optionally accepts a bits argument, '
69
+ 'between 0 and 4096.' )
70
+ return self .execute_command ('ACL GENPASS' , * pieces )
58
71
59
72
def acl_getuser (self , username ):
60
73
"""
Original file line number Diff line number Diff line change @@ -98,6 +98,14 @@ def test_acl_genpass(self, r):
98
98
password = r .acl_genpass ()
99
99
assert isinstance (password , str )
100
100
101
+ with pytest .raises (exceptions .DataError ):
102
+ r .acl_genpass ('value' )
103
+ r .acl_genpass (- 5 )
104
+ r .acl_genpass (5555 )
105
+
106
+ r .acl_genpass (555 )
107
+ assert isinstance (password , str )
108
+
101
109
@skip_if_server_version_lt (REDIS_6_VERSION )
102
110
def test_acl_getuser_setuser (self , r , request ):
103
111
username = 'redis-py-user'
You can’t perform that action at this time.
0 commit comments