示例#1
0
 def test_ldap_login_user_does_not_exist(self):
     backend = LdapBackend()
     with patch('ldap3.Connection') as MockLDAP:
         backend.get_ad_timestamp = MagicMock(return_value=datetime.now())
         ldap = MockLDAP.return_value
         ldap.search.return_value = [{'dn': 'test'}]
         ldap.response = [{'dn': 'test'}]
         user = backend.authenticate('*****@*****.**', 'xxxxx')
         self.assertEqual(user, None)
 def test_ldap_login_user_does_not_exist(self):
     backend = LdapBackend()
     with patch('ldap3.Connection') as MockLDAP:
         backend.get_ad_timestamp = MagicMock(return_value=datetime.now())
         ldap = MockLDAP.return_value
         ldap.search.return_value = [{'dn': 'test'}]
         ldap.response = [{'dn': 'test'}]
         user = backend.authenticate('*****@*****.**', 'xxxxx')
         self.assertEqual(user, None)
示例#3
0
 def test_ldap_login_email(self):
     backend = LdapBackend()
     with patch('ldap3.Connection') as MockLDAP:
         backend.get_ad_timestamp = MagicMock(return_value=datetime.now())
         ldap = MockLDAP.return_value
         ldap.search.return_value = [{'dn': 'test'}]
         ldap.response = [{'dn': 'test'}]
         user = backend.authenticate('*****@*****.**', 'Chop1234')
         # Check search calls
         search_call_list = ldap.search.call_args_list
         self.assertTrue(call('searchdn', '(sAMAccountName=admin)') in search_call_list)
         # Check binds
         self.assertTrue(ldap.bind.called)
         self.assertTrue(ldap.unbind.called)
         # Check is User
         self.assertTrue(isinstance(user, User))
 def test_ldap_login_email(self):
     backend = LdapBackend()
     with patch('ldap3.Connection') as MockLDAP:
         backend.get_ad_timestamp = MagicMock(return_value=datetime.now())
         ldap = MockLDAP.return_value
         ldap.search.return_value = [{'dn': 'test'}]
         ldap.response = [{'dn': 'test'}]
         user = backend.authenticate('*****@*****.**', 'Chop1234')
         # Check search calls
         search_call_list = ldap.search.call_args_list
         self.assertTrue(call('searchdn', '(sAMAccountName=admin)') in search_call_list)
         # Check binds
         self.assertTrue(ldap.bind.called)
         self.assertTrue(ldap.unbind.called)
         # Check is User
         self.assertTrue(isinstance(user, User))
示例#5
0
 def test_ldap_ad_timestamp_conversion(self):
     backend = LdapBackend()
     mock_response = [{'attributes': {'pwdLastSet': ['131157000000000000']}}]
     d = backend.get_ad_timestamp(mock_response)
     self.assertEqual(datetime(2016, 8, 15, 2), d)
 def test_ldap_ad_timestamp_conversion(self):
     backend = LdapBackend()
     mock_response = [{'attributes': {'pwdLastSet': ['131157000000000000']}}]
     d = backend.get_ad_timestamp(mock_response)
     self.assertEqual(datetime(2016, 8, 15, 2), d)