rpcauth: Make it possible to provide a custom password
This adds the functionality to specify a custom password to `rpcauth.py`, as well as makes the code (IMO) easier to understand.
This commit is contained in:
parent
57c57df86f
commit
2a89b0c812
3 changed files with 17 additions and 11 deletions
test/util
|
@ -28,16 +28,15 @@ class TestRPCAuth(unittest.TestCase):
|
|||
self.assertGreaterEqual(len(self.rpcauth.generate_salt()), 16)
|
||||
|
||||
def test_generate_password(self):
|
||||
salt = self.rpcauth.generate_salt()
|
||||
password, password_hmac = self.rpcauth.generate_password(salt)
|
||||
|
||||
password = self.rpcauth.generate_password()
|
||||
expected_password = base64.urlsafe_b64encode(
|
||||
base64.urlsafe_b64decode(password)).decode('utf-8')
|
||||
self.assertEqual(expected_password, password)
|
||||
|
||||
def test_check_password_hmac(self):
|
||||
salt = self.rpcauth.generate_salt()
|
||||
password, password_hmac = self.rpcauth.generate_password(salt)
|
||||
password = self.rpcauth.generate_password()
|
||||
password_hmac = self.rpcauth.password_to_hmac(salt, password)
|
||||
|
||||
m = hmac.new(bytearray(salt, 'utf-8'),
|
||||
bytearray(password, 'utf-8'), 'SHA256')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue