class TestLDAPAuthenticatorPlugin(Base): """Tests for the L{LDAPAuthenticatorPlugin} IAuthenticator plugin""" def setUp(self): super(TestLDAPAuthenticatorPlugin, self).setUp() # Loading the plugin: self.plugin = LDAPAuthenticatorPlugin(self.connection, base_dn) def test_implements(self): verifyClass(IAuthenticator, LDAPAuthenticatorPlugin, tentative=True) def test_authenticate_nologin(self): result = self.plugin.authenticate(self.env, None) self.assertEqual(result, None) def test_authenticate_incomplete_credentials(self): identity1 = {'login': fakeuser['uid']} identity2 = {'password': fakeuser['password']} result1 = self.plugin.authenticate(self.env, identity1) result2 = self.plugin.authenticate(self.env, identity2) self.assertEqual(result1, None) self.assertEqual(result2, None) def test_authenticate_noresults(self): identity = {'login': '******', 'password': '******'} result = self.plugin.authenticate(self.env, identity) self.assertEqual(result, None) def test_authenticate_comparefail(self): identity = {'login': fakeuser['uid'], 'password': '******'} result = self.plugin.authenticate(self.env, identity) self.assertEqual(result, None) def test_authenticate_comparesuccess(self): identity = {'login': fakeuser['uid'], 'password': fakeuser['password']} result = self.plugin.authenticate(self.env, identity) self.assertEqual(result, fakeuser['dn']) def test_custom_authenticator(self): """L{LDAPAuthenticatorPlugin._get_dn} should be overriden with no problems""" plugin = CustomLDAPAuthenticatorPlugin(self.connection, base_dn) identity = {'login': fakeuser['uid'], 'password': fakeuser['password']} result = plugin.authenticate(self.env, identity) expected = 'uid=%s,%s' % (fakeuser['uid'], base_dn) self.assertEqual(result, expected) self.assertTrue(plugin.called)
class TestLDAPAuthenticatorPlugin(Base): """Tests for the L{LDAPAuthenticatorPlugin} IAuthenticator plugin""" def setUp(self): super(TestLDAPAuthenticatorPlugin, self).setUp() # Loading the plugin: self.plugin = LDAPAuthenticatorPlugin(self.connection, base_dn) def test_implements(self): verifyClass(IAuthenticator, LDAPAuthenticatorPlugin, tentative=True) def test_authenticate_nologin(self): result = self.plugin.authenticate(self.env, None) self.assertEqual(result, None) def test_authenticate_incomplete_credentials(self): identity1 = {'login': fakeuser['uid']} identity2 = {'password': fakeuser['password']} result1 = self.plugin.authenticate(self.env, identity1) result2 = self.plugin.authenticate(self.env, identity2) self.assertEqual(result1, None) self.assertEqual(result2, None) def test_authenticate_noresults(self): identity = { 'login': '******', 'password': '******' } result = self.plugin.authenticate(self.env, identity) self.assertEqual(result, None) def test_authenticate_comparefail(self): identity = {'login': fakeuser['uid'], 'password': '******'} result = self.plugin.authenticate(self.env, identity) self.assertEqual(result, None) def test_authenticate_comparesuccess(self): identity = {'login': fakeuser['uid'], 'password': fakeuser['password']} result = self.plugin.authenticate(self.env, identity) self.assertEqual(result, fakeuser['dn']) def test_custom_authenticator(self): """L{LDAPAuthenticatorPlugin._get_dn} should be overriden with no problems""" plugin = CustomLDAPAuthenticatorPlugin(self.connection, base_dn) identity = {'login': fakeuser['uid'], 'password': fakeuser['password']} result = plugin.authenticate(self.env, identity) expected = 'uid=%s,%s' % (fakeuser['uid'], base_dn) self.assertEqual(result, expected) self.assertTrue(plugin.called)
class TestLDAPAuthenticatorReturnLogin(Base): """ Tests the L{LDAPAuthenticatorPlugin} IAuthenticator plugin returning login. """ def setUp(self): super(TestLDAPAuthenticatorReturnLogin, self).setUp() # Loading the plugin: self.plugin = LDAPAuthenticatorPlugin( self.connection, base_dn, returned_id='login', ) def test_authenticate_noresults(self): identity = {'login': '******', 'password': '******'} result = self.plugin.authenticate(self.env, identity) self.assertEqual(result, None) def test_authenticate_comparefail(self): identity = {'login': fakeuser['uid'], 'password': '******'} result = self.plugin.authenticate(self.env, identity) self.assertEqual(result, None) def test_authenticate_comparesuccess(self): identity = {'login': fakeuser['uid'], 'password': fakeuser['password']} result = self.plugin.authenticate(self.env, identity) self.assertEqual(result, fakeuser['uid']) def test_authenticate_dn_in_userdata(self): identity = {'login': fakeuser['uid'], 'password': fakeuser['password']} expected_dn = '<dn:%s>' % b64encode(fakeuser['dn']) result = self.plugin.authenticate(self.env, identity) self.assertEqual(identity['userdata'], expected_dn)
class TestLDAPAuthenticatorReturnLogin(Base): """ Tests the L{LDAPAuthenticatorPlugin} IAuthenticator plugin returning login. """ def setUp(self): super(TestLDAPAuthenticatorReturnLogin, self).setUp() # Loading the plugin: self.plugin = LDAPAuthenticatorPlugin( self.connection, base_dn, returned_id='login', ) def test_authenticate_noresults(self): identity = { 'login': '******', 'password': '******' } result = self.plugin.authenticate(self.env, identity) self.assertEqual(result, None) def test_authenticate_comparefail(self): identity = {'login': fakeuser['uid'], 'password': '******'} result = self.plugin.authenticate(self.env, identity) self.assertEqual(result, None) def test_authenticate_comparesuccess(self): identity = {'login': fakeuser['uid'], 'password': fakeuser['password']} result = self.plugin.authenticate(self.env, identity) self.assertEqual(result, fakeuser['uid']) def test_authenticate_dn_in_userdata(self): identity = {'login': fakeuser['uid'], 'password': fakeuser['password']} expected_dn = '<dn:%s>' % b64encode(fakeuser['dn']) result = self.plugin.authenticate(self.env, identity) self.assertEqual(identity['userdata'], expected_dn)