Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add usedforsecurity flag #2907

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion authentication/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def load_drf_strategy(request=None):

def get_md5_hash(value):
"""Returns the md5 hash object for the given value"""
return hashlib.md5(value.lower().encode("utf-8"))
return hashlib.md5(value.lower().encode("utf-8"), usedforsecurity=False)


def is_user_email_blocked(email):
Expand Down
4 changes: 3 additions & 1 deletion users/management/tests/block_users_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def test_block_user_blocking_with_email(self):

user = UserFactory.create(email=test_email, is_active=True)
email = user.email
hashed_email = hashlib.md5(email.lower().encode("utf-8")).hexdigest()
hashed_email = hashlib.md5(
email.lower().encode("utf-8"), usedforsecurity=False
).hexdigest()
assert BlockList.objects.all().count() == 0

COMMAND.handle("block_users", users=[test_email], block_users=True)
Expand Down
8 changes: 6 additions & 2 deletions users/management/tests/retire_users_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ def test_retire_user_blocking_with_email():
user = UserFactory.create(email=test_email, is_active=True)
UserSocialAuthFactory.create(user=user, provider="edX")
email = user.email
hashed_email = hashlib.md5(email.lower().encode("utf-8")).hexdigest()
hashed_email = hashlib.md5(
email.lower().encode("utf-8"), usedforsecurity=False
).hexdigest()
assert user.is_active is True
assert "retired_email" not in user.email
assert UserSocialAuth.objects.filter(user=user).count() == 1
Expand Down Expand Up @@ -132,7 +134,9 @@ def test_user_blocking_if_not_requested():
user = UserFactory.create(email=test_email, is_active=True)
UserSocialAuthFactory.create(user=user, provider="edX")
email = user.email
hashed_email = hashlib.md5(email.lower().encode("utf-8")).hexdigest()
hashed_email = hashlib.md5(
email.lower().encode("utf-8"), usedforsecurity=False
).hexdigest()
assert user.is_active is True
assert "retired_email" not in user.email
assert UserSocialAuth.objects.filter(user=user).count() == 1
Expand Down
4 changes: 3 additions & 1 deletion users/management/tests/unblock_users_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def test_user_unblocking_with_email(self):
user = UserFactory.create(email=test_email, is_active=True)
UserSocialAuthFactory.create(user=user, provider="edX")
email = user.email
hashed_email = hashlib.md5(email.lower().encode("utf-8")).hexdigest()
hashed_email = hashlib.md5(
email.lower().encode("utf-8"), usedforsecurity=False
).hexdigest()
assert user.is_active is True
assert "retired_email" not in user.email
assert UserSocialAuth.objects.filter(user=user).count() == 1
Expand Down
Loading