mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	auth: Log when a user tries to login with deactivated account.
Helps to see if users are often trying to login with deactived accounts. A use case: Trackdown whether any deactivated bot users are still trying to access the API. This implementation adds a new key `inactive_user_id` to `return_data` in the function `is_user_active` which check if a `user_profile` is active. This reduces the effort of getting `user_id` just before logging. Modified tests for line coverage.
This commit is contained in:
		@@ -887,11 +887,14 @@ class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase):
 | 
			
		||||
        # We expect to go through the "choose email" screen here,
 | 
			
		||||
        # because there won't be an existing user account we can
 | 
			
		||||
        # auto-select for the user.
 | 
			
		||||
        result = self.social_auth_test(account_data_dict,
 | 
			
		||||
                                       expect_choose_email_screen=True,
 | 
			
		||||
                                       subdomain='zulip')
 | 
			
		||||
        self.assertEqual(result.status_code, 302)
 | 
			
		||||
        self.assertEqual(result.url, "/login/?is_deactivated=true")
 | 
			
		||||
        with mock.patch('zproject.backends.logging.info') as m:
 | 
			
		||||
            result = self.social_auth_test(account_data_dict,
 | 
			
		||||
                                           expect_choose_email_screen=True,
 | 
			
		||||
                                           subdomain='zulip')
 | 
			
		||||
            self.assertEqual(result.status_code, 302)
 | 
			
		||||
            self.assertEqual(result.url, "/login/?is_deactivated=true")
 | 
			
		||||
            m.assert_called_with("Failed login attempt for deactivated account: %s@%s",
 | 
			
		||||
                                 user_profile.id, 'zulip')
 | 
			
		||||
        # TODO: verify whether we provide a clear error message
 | 
			
		||||
 | 
			
		||||
    def test_social_auth_invalid_realm(self) -> None:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user