Skip to content

Commit

Permalink
Merge pull request #42 from GabrielInTheWorld/fixes-auth-pip-lib
Browse files Browse the repository at this point in the history
Corrects hashing in pip-lib
  • Loading branch information
GabrielInTheWorld committed Nov 2, 2020
2 parents bb90ce7 + 589af60 commit 39a4148
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion auth/libraries/pip-auth/authlib/hashing_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ def __getSalt(self, hash_reference: Optional[str] = None) -> str:
return (
hash_reference[0:64]
if hash_reference is not None and len(hash_reference) == HASHED_LENGTH
else secrets.token_hex(64)
else secrets.token_hex(32)
)
6 changes: 5 additions & 1 deletion auth/libraries/pip-auth/authlib/test/test_hashing.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
from ..auth_handler import AuthHandler
from .base import BaseTestEnvironment
from ..constants import AUTH_TEST_URL
from ..constants import AUTH_TEST_URL, HASHED_LENGTH


class TestHashing(BaseTestEnvironment):
def test_hash(self):
to_hash = "helloworld"
to_compare = b"316af7b2ddc20ead599c38541fbe87e9a9e4e960d4017d6e59de188b41b2758fww7VCxnNrYsz6Z38Fv+Wf6o4Ait5IkAE21CyknNS05lHSIzwF5AAObWhjzkeqV+oQ/Xc1y7FPsPg+n8cZnZy6w=="
self.assertEqual(HASHED_LENGTH, len(self.auth_handler.hash(to_hash)))
self.assertEqual(to_compare, self.auth_handler.hash(to_hash, to_compare))

def test_is_equals(self):
to_hash = "helloworld"
to_compare = b"316af7b2ddc20ead599c38541fbe87e9a9e4e960d4017d6e59de188b41b2758fww7VCxnNrYsz6Z38Fv+Wf6o4Ait5IkAE21CyknNS05lHSIzwF5AAObWhjzkeqV+oQ/Xc1y7FPsPg+n8cZnZy6w=="
self.assertEqual(True, self.auth_handler.is_equals(to_hash, to_compare))
self.assertEqual(
True, self.auth_handler.is_equals("x", self.auth_handler.hash("x"))
)

0 comments on commit 39a4148

Please sign in to comment.