@@ -658,6 +658,30 @@ def test_single_session(self):
658658 # client1 will be logged out
659659 assert response .status_code == 302
660660
661+ @patch .dict ("django.conf.settings.FEATURES" , {'PREVENT_CONCURRENT_LOGINS' : True })
662+ def test_single_session_exempt_user (self ):
663+ """
664+ A user whose username is in SINGLE_LOGIN_EXEMPT_USERNAMES is not subject
665+ to single-login enforcement: a concurrent login does not record the
666+ single-session slot and therefore does not evict the first session.
667+ """
668+ creds = {'email' : self .user_email , 'password' : self .password }
669+ client1 = Client ()
670+ client2 = Client ()
671+
672+ with override_settings (SINGLE_LOGIN_EXEMPT_USERNAMES = [self .user .username ]):
673+ response = client1 .post (self .url , creds )
674+ self ._assert_response (response , success = True )
675+
676+ # A second login must NOT evict the exempt user's first session.
677+ response = client2 .post (self .url , creds )
678+ self ._assert_response (response , success = True )
679+
680+ self .user = User .objects .get (pk = self .user .pk )
681+ # No single-session slot is recorded for exempt users, so neither
682+ # session is ever deleted.
683+ assert 'session_id' not in self .user .profile .get_meta ()
684+
661685 @patch .dict ("django.conf.settings.FEATURES" , {'PREVENT_CONCURRENT_LOGINS' : True })
662686 def test_single_session_with_no_user_profile (self ):
663687 """
0 commit comments