Skip to content

Commit

Permalink
password fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ghilesmeddour committed Sep 11, 2021
1 parent 4f0add2 commit 33afa20
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/pyfaktory/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down

0 comments on commit 33afa20

Please sign in to comment.