From 33afa20db94b3ec5c44964593c397747ac1daf6d Mon Sep 17 00:00:00 2001 From: Ghiles Meddour Date: Sat, 11 Sep 2021 20:42:37 +0200 Subject: [PATCH] password fixes --- src/pyfaktory/client.py | 12 +++++++----- tests/test_client.py | 5 ++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/pyfaktory/client.py b/src/pyfaktory/client.py index a0abb5c..fe4ee50 100644 --- a/src/pyfaktory/client.py +++ b/src/pyfaktory/client.py @@ -78,7 +78,7 @@ def __init__(self, parsed_url = urlparse(faktory_url) self.host = parsed_url.hostname self.port = parsed_url.port or C.DEFAULT_PORT - self.password = str(parsed_url.password) + self.password = parsed_url.password self.sock: socket.socket self.timeout = timeout @@ -147,15 +147,17 @@ def connect(self) -> bool: password_hash_iterations = msg_args['i'] password_hash_salt = msg_args['s'] self.logger.info('Hashing password...') - password_hash = str.encode( - self.password) + str.encode(password_hash_salt) + password_hash = str.encode(str( + self.password)) + str.encode(password_hash_salt) for _ in range(password_hash_iterations): password_hash = hashlib.sha256(password_hash).digest() - password_hash_str = password_hash.hex() else: self.logger.info('Password is not required') - _ = self._hello(pwdhash=password_hash_str) + if password_hash: + _ = self._hello(pwdhash=password_hash.hex()) + else: + _ = self._hello() return True diff --git a/tests/test_client.py b/tests/test_client.py index a092217..7b6d959 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -61,13 +61,16 @@ def test_set_password(self): def test_consumer_specific_fields(self): consumer_specific_fields = { - 'labels', 'worker_id', 'beat_period', 'rss_kb', 'heartbeat_thread' + 'labels', 'worker_id', 'beat_period', 'rss_kb' } client_both = Client(role='both') client_consumer = Client(role='consumer') client_producer = Client(role='producer') + print(client_both.__dict__.keys()) + print() + print(consumer_specific_fields) assert consumer_specific_fields.issubset(client_both.__dict__) assert consumer_specific_fields.issubset(client_consumer.__dict__) assert not consumer_specific_fields.issubset(client_producer.__dict__)