Skip to content

Commit 1be7946

Browse files
authored
Fix: New created users will have unusable password (#399)
* Fix: New created users will have unusable password Closes #398 * Bump version to 1.9.2
1 parent 169fc48 commit 1be7946

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

djangosaml2/backends.py

+1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ def get_or_create_user(
290290
# Create new one if desired by settings
291291
if create_unknown_user:
292292
user = UserModel(**{user_lookup_key: user_lookup_value})
293+
user.set_unusable_password()
293294
created = True
294295
logger.debug(f"New user created: {user}", exc_info=True)
295296
else:

djangosaml2/tests/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@ def test_assertion_consumer_service(self):
462462
user_id = self.client.session[SESSION_KEY]
463463
user = User.objects.get(id=user_id)
464464
self.assertEqual(user.username, "student")
465+
# Since a new user object is created, the password
466+
# field is set to have an unusable password.
467+
self.assertEqual(user.has_usable_password(), False)
465468

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

490497
@override_settings(ACS_DEFAULT_REDIRECT_URL="testprofiles:dashboard")
491498
def test_assertion_consumer_service_default_relay_state(self):

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def read(*rnames):
2727

2828
setup(
2929
name="djangosaml2",
30-
version="1.9.1",
30+
version="1.9.2",
3131
description="pysaml2 integration for Django",
3232
long_description=read("README.md"),
3333
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)