Skip to content

Commit b652f69

Browse files
committed
test: cover SINGLE_LOGIN_EXEMPT_USERNAMES exemption
1 parent 906fd3f commit b652f69

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

openedx/core/djangoapps/user_authn/views/tests/test_login.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,30 @@ def test_single_session(self):
661661
# client1 will be logged out
662662
assert response.status_code == 302
663663

664+
@patch.dict("django.conf.settings.FEATURES", {'PREVENT_CONCURRENT_LOGINS': True})
665+
def test_single_session_exempt_user(self):
666+
"""
667+
A user whose username is in SINGLE_LOGIN_EXEMPT_USERNAMES is not subject
668+
to single-login enforcement: a concurrent login does not record the
669+
single-session slot and therefore does not evict the first session.
670+
"""
671+
creds = {'email': self.user_email, 'password': self.password}
672+
client1 = Client()
673+
client2 = Client()
674+
675+
with override_settings(SINGLE_LOGIN_EXEMPT_USERNAMES=[self.user.username]):
676+
response = client1.post(self.url, creds)
677+
self._assert_response(response, success=True)
678+
679+
# A second login must NOT evict the exempt user's first session.
680+
response = client2.post(self.url, creds)
681+
self._assert_response(response, success=True)
682+
683+
self.user = User.objects.get(pk=self.user.pk)
684+
# No single-session slot is recorded for exempt users, so neither
685+
# session is ever deleted.
686+
assert 'session_id' not in self.user.profile.get_meta()
687+
664688
@patch.dict("django.conf.settings.FEATURES", {'PREVENT_CONCURRENT_LOGINS': True})
665689
def test_single_session_with_no_user_profile(self):
666690
"""

0 commit comments

Comments
 (0)