Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix mypy error: auth handler "checkpw" internal function type mismatch #8569

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/8569.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix mypy not properly checking across the codebase, additionally, fix a typing assertion error in `handlers/auth.py`.
8 changes: 5 additions & 3 deletions synapse/handlers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -1122,20 +1122,22 @@ async def validate_hash(
Whether self.hash(password) == stored_hash.
"""

def _do_validate_hash():
def _do_validate_hash(checked_hash: bytes):
# Normalise the Unicode in the password
pw = unicodedata.normalize("NFKC", password)

return bcrypt.checkpw(
pw.encode("utf8") + self.hs.config.password_pepper.encode("utf8"),
stored_hash,
checked_hash,
)

if stored_hash:
if not isinstance(stored_hash, bytes):
stored_hash = stored_hash.encode("ascii")

return await defer_to_thread(self.hs.get_reactor(), _do_validate_hash)
return await defer_to_thread(
self.hs.get_reactor(), _do_validate_hash, stored_hash
)
else:
return False

Expand Down
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ commands=
coverage html

[testenv:mypy]
skip_install = True
deps =
{[base]deps}
mypy==0.782
Expand Down