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

Fix: New created users will have unusable password #399

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 djangosaml2/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ def get_or_create_user(
# Create new one if desired by settings
if create_unknown_user:
user = UserModel(**{user_lookup_key: user_lookup_value})
user.set_unusable_password()
created = True
logger.debug(f"New user created: {user}", exc_info=True)
else:
Expand Down
7 changes: 7 additions & 0 deletions djangosaml2/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ def test_assertion_consumer_service(self):
user_id = self.client.session[SESSION_KEY]
user = User.objects.get(id=user_id)
self.assertEqual(user.username, "student")
# Since a new user object is created, the password
# field is set to have an unusable password.
self.assertEqual(user.has_usable_password(), False)
Comment on lines +465 to +467
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peppelinux I piggy backed on an existing test case to verify that new user will have an unusable password. No change would be made for user objects where password is already set.


# let's create another user and log in with that one
new_user = User.objects.create(username="teacher", password="not-used")
Expand All @@ -486,6 +489,10 @@ def test_assertion_consumer_service(self):
# as the RelayState is empty we have redirect to ACS_DEFAULT_REDIRECT_URL
self.assertRedirects(response, "/dashboard/")
self.assertEqual(str(new_user.id), client.session[SESSION_KEY])
new_user.refresh_from_db()
# Since "new_user" already had a password,
# the password field will remain unchanged.
self.assertEqual(new_user.has_usable_password(), True)

@override_settings(ACS_DEFAULT_REDIRECT_URL="testprofiles:dashboard")
def test_assertion_consumer_service_default_relay_state(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def read(*rnames):

setup(
name="djangosaml2",
version="1.9.1",
version="1.9.2",
description="pysaml2 integration for Django",
long_description=read("README.md"),
long_description_content_type="text/markdown",
Expand Down
Loading