2015-05-12 01:23:18 +00:00
|
|
|
import unittest
|
|
|
|
|
2017-03-20 21:53:15 +00:00
|
|
|
import ldap
|
|
|
|
|
2015-05-12 01:23:18 +00:00
|
|
|
from app import app
|
|
|
|
from initdb import setup_database_for_testing, finished_database_for_testing
|
|
|
|
from data.users import LDAPUsers
|
2016-09-08 22:43:50 +00:00
|
|
|
from data import model
|
2015-05-12 01:23:18 +00:00
|
|
|
from mockldap import MockLdap
|
2016-10-27 19:32:01 +00:00
|
|
|
from mock import patch
|
2016-12-05 22:19:38 +00:00
|
|
|
from contextlib import contextmanager
|
|
|
|
|
|
|
|
def _create_ldap(requires_email=True):
|
|
|
|
base_dn = ['dc=quay', 'dc=io']
|
|
|
|
admin_dn = 'uid=testy,ou=employees,dc=quay,dc=io'
|
|
|
|
admin_passwd = 'password'
|
|
|
|
user_rdn = ['ou=employees']
|
|
|
|
uid_attr = 'uid'
|
|
|
|
email_attr = 'mail'
|
|
|
|
secondary_user_rdns = ['ou=otheremployees']
|
|
|
|
|
|
|
|
ldap = LDAPUsers('ldap://localhost', base_dn, admin_dn, admin_passwd, user_rdn,
|
|
|
|
uid_attr, email_attr, secondary_user_rdns=secondary_user_rdns,
|
2017-03-20 21:53:15 +00:00
|
|
|
requires_email=requires_email)
|
2016-12-05 22:19:38 +00:00
|
|
|
return ldap
|
|
|
|
|
|
|
|
@contextmanager
|
|
|
|
def mock_ldap(requires_email=True):
|
2016-12-21 20:00:55 +00:00
|
|
|
mock_data = {
|
2016-12-05 22:19:38 +00:00
|
|
|
'dc=quay,dc=io': {'dc': ['quay', 'io']},
|
|
|
|
'ou=employees,dc=quay,dc=io': {
|
|
|
|
'dc': ['quay', 'io'],
|
|
|
|
'ou': 'employees'
|
|
|
|
},
|
|
|
|
'ou=otheremployees,dc=quay,dc=io': {
|
|
|
|
'dc': ['quay', 'io'],
|
|
|
|
'ou': 'otheremployees'
|
|
|
|
},
|
2017-02-16 20:16:47 +00:00
|
|
|
'cn=AwesomeFolk,dc=quay,dc=io': {
|
|
|
|
'dc': ['quay', 'io'],
|
|
|
|
'cn': 'AwesomeFolk'
|
|
|
|
},
|
2016-12-05 22:19:38 +00:00
|
|
|
'uid=testy,ou=employees,dc=quay,dc=io': {
|
|
|
|
'dc': ['quay', 'io'],
|
|
|
|
'ou': 'employees',
|
2017-02-16 20:16:47 +00:00
|
|
|
'uid': ['testy'],
|
|
|
|
'userPassword': ['password'],
|
|
|
|
'mail': ['bar@baz.com'],
|
|
|
|
'memberOf': ['cn=AwesomeFolk,dc=quay,dc=io'],
|
2016-12-05 22:19:38 +00:00
|
|
|
},
|
|
|
|
'uid=someuser,ou=employees,dc=quay,dc=io': {
|
|
|
|
'dc': ['quay', 'io'],
|
|
|
|
'ou': 'employees',
|
|
|
|
'uid': ['someuser'],
|
|
|
|
'userPassword': ['somepass'],
|
2017-02-16 20:16:47 +00:00
|
|
|
'mail': ['foo@bar.com'],
|
|
|
|
'memberOf': ['cn=AwesomeFolk,dc=quay,dc=io'],
|
2016-12-05 22:19:38 +00:00
|
|
|
},
|
|
|
|
'uid=nomail,ou=employees,dc=quay,dc=io': {
|
|
|
|
'dc': ['quay', 'io'],
|
|
|
|
'ou': 'employees',
|
|
|
|
'uid': ['nomail'],
|
|
|
|
'userPassword': ['somepass']
|
|
|
|
},
|
|
|
|
'uid=cool.user,ou=employees,dc=quay,dc=io': {
|
|
|
|
'dc': ['quay', 'io'],
|
|
|
|
'ou': 'employees',
|
|
|
|
'uid': ['cool.user', 'referred'],
|
|
|
|
'userPassword': ['somepass'],
|
|
|
|
'mail': ['foo@bar.com']
|
|
|
|
},
|
|
|
|
'uid=referred,ou=employees,dc=quay,dc=io': {
|
|
|
|
'uid': ['referred'],
|
|
|
|
'_referral': 'ldap:///uid=cool.user,ou=employees,dc=quay,dc=io'
|
|
|
|
},
|
|
|
|
'uid=invalidreferred,ou=employees,dc=quay,dc=io': {
|
|
|
|
'uid': ['invalidreferred'],
|
|
|
|
'_referral': 'ldap:///uid=someinvaliduser,ou=employees,dc=quay,dc=io'
|
|
|
|
},
|
|
|
|
'uid=multientry,ou=subgroup1,ou=employees,dc=quay,dc=io': {
|
|
|
|
'uid': ['multientry'],
|
|
|
|
'mail': ['foo@bar.com'],
|
|
|
|
'userPassword': ['somepass'],
|
|
|
|
},
|
|
|
|
'uid=multientry,ou=subgroup2,ou=employees,dc=quay,dc=io': {
|
|
|
|
'uid': ['multientry'],
|
|
|
|
'another': ['key']
|
|
|
|
},
|
2016-12-21 20:00:55 +00:00
|
|
|
'uid=secondaryuser,ou=otheremployees,dc=quay,dc=io': {
|
2016-12-05 22:19:38 +00:00
|
|
|
'dc': ['quay', 'io'],
|
|
|
|
'ou': 'otheremployees',
|
|
|
|
'uid': ['secondaryuser'],
|
|
|
|
'userPassword': ['somepass'],
|
|
|
|
'mail': ['foosecondary@bar.com']
|
|
|
|
},
|
2016-12-21 20:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if not requires_email:
|
|
|
|
for path in mock_data:
|
|
|
|
mock_data[path].pop('mail', None)
|
|
|
|
|
|
|
|
mockldap = MockLdap(mock_data)
|
2016-12-05 22:19:38 +00:00
|
|
|
|
|
|
|
def initializer(uri, trace_level=0):
|
|
|
|
obj = mockldap[uri]
|
|
|
|
|
|
|
|
# Seed to "support" wildcard queries, which MockLDAP does not support natively.
|
2016-12-21 20:00:55 +00:00
|
|
|
cool_block = {
|
|
|
|
'dc': ['quay', 'io'],
|
|
|
|
'ou': 'employees',
|
|
|
|
'uid': ['cool.user', 'referred'],
|
|
|
|
'userPassword': ['somepass'],
|
|
|
|
'mail': ['foo@bar.com']
|
|
|
|
}
|
|
|
|
|
|
|
|
if not requires_email:
|
|
|
|
cool_block.pop('mail', None)
|
|
|
|
|
2016-12-05 22:19:38 +00:00
|
|
|
obj.search_s.seed('ou=employees,dc=quay,dc=io', 2, '(|(uid=cool*)(mail=cool*))')([
|
2016-12-21 20:00:55 +00:00
|
|
|
('uid=cool.user,ou=employees,dc=quay,dc=io', cool_block)
|
2016-12-05 22:19:38 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
obj.search_s.seed('ou=otheremployees,dc=quay,dc=io', 2, '(|(uid=cool*)(mail=cool*))')([])
|
|
|
|
|
|
|
|
obj.search_s.seed('ou=employees,dc=quay,dc=io', 2, '(|(uid=unknown*)(mail=unknown*))')([])
|
|
|
|
obj.search_s.seed('ou=otheremployees,dc=quay,dc=io', 2,
|
|
|
|
'(|(uid=unknown*)(mail=unknown*))')([])
|
2017-03-20 21:53:15 +00:00
|
|
|
|
|
|
|
obj._results = {}
|
|
|
|
|
|
|
|
def result3(messageid):
|
|
|
|
if messageid is None:
|
|
|
|
return None, [], None, None
|
|
|
|
|
|
|
|
return obj._results[messageid]
|
|
|
|
|
|
|
|
def search_ext(user_search_dn, scope, search_flt, serverctrls=None, attrlist=None):
|
|
|
|
if scope != ldap.SCOPE_SUBTREE:
|
|
|
|
return None
|
|
|
|
|
|
|
|
if not serverctrls:
|
|
|
|
return None
|
|
|
|
|
|
|
|
page_control = serverctrls[0]
|
|
|
|
if page_control.controlType != ldap.controls.SimplePagedResultsControl.controlType:
|
|
|
|
return None
|
|
|
|
|
|
|
|
msgid = obj.search(user_search_dn, scope, search_flt, attrlist=attrlist)
|
|
|
|
_, rdata = obj.result(msgid)
|
|
|
|
|
|
|
|
msgid = 'messageid'
|
|
|
|
cookie = int(page_control.cookie) if page_control.cookie else 0
|
|
|
|
|
|
|
|
results = rdata[cookie:cookie+page_control.size]
|
|
|
|
cookie = cookie + page_control.size
|
|
|
|
if cookie > len(results):
|
|
|
|
page_control.cookie = None
|
|
|
|
else:
|
|
|
|
page_control.cookie = cookie
|
|
|
|
|
|
|
|
obj._results['messageid'] = (None, results, None, [page_control])
|
|
|
|
return msgid
|
|
|
|
|
|
|
|
obj.search_ext = search_ext
|
|
|
|
obj.result3 = result3
|
|
|
|
|
2016-12-05 22:19:38 +00:00
|
|
|
return obj
|
|
|
|
|
|
|
|
mockldap.start()
|
|
|
|
with patch('ldap.initialize', new=initializer):
|
|
|
|
yield _create_ldap(requires_email=requires_email)
|
|
|
|
mockldap.stop()
|
|
|
|
|
2015-05-12 01:23:18 +00:00
|
|
|
|
|
|
|
class TestLDAP(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
setup_database_for_testing(self)
|
|
|
|
self.app = app.test_client()
|
|
|
|
self.ctx = app.test_request_context()
|
|
|
|
self.ctx.__enter__()
|
|
|
|
|
2016-09-08 16:24:47 +00:00
|
|
|
def tearDown(self):
|
|
|
|
finished_database_for_testing(self)
|
|
|
|
self.ctx.__exit__(True, None, None)
|
|
|
|
|
2015-06-12 19:39:55 +00:00
|
|
|
def test_invalid_admin_password(self):
|
|
|
|
base_dn = ['dc=quay', 'dc=io']
|
|
|
|
admin_dn = 'uid=testy,ou=employees,dc=quay,dc=io'
|
|
|
|
admin_passwd = 'INVALIDPASSWORD'
|
|
|
|
user_rdn = ['ou=employees']
|
|
|
|
uid_attr = 'uid'
|
|
|
|
email_attr = 'mail'
|
|
|
|
|
2016-12-05 22:19:38 +00:00
|
|
|
with mock_ldap():
|
|
|
|
ldap = LDAPUsers('ldap://localhost', base_dn, admin_dn, admin_passwd, user_rdn,
|
|
|
|
uid_attr, email_attr)
|
2015-06-12 19:39:55 +00:00
|
|
|
|
2016-12-05 22:19:38 +00:00
|
|
|
# Try to login.
|
|
|
|
(response, err_msg) = ldap.verify_and_link_user('someuser', 'somepass')
|
|
|
|
self.assertIsNone(response)
|
|
|
|
self.assertEquals('LDAP Admin dn or password is invalid', err_msg)
|
2015-06-12 19:39:55 +00:00
|
|
|
|
2015-05-26 19:46:35 +00:00
|
|
|
def test_login(self):
|
2016-12-05 22:19:38 +00:00
|
|
|
with mock_ldap() as ldap:
|
|
|
|
# Verify we can login.
|
|
|
|
(response, _) = ldap.verify_and_link_user('someuser', 'somepass')
|
|
|
|
self.assertEquals(response.username, 'someuser')
|
|
|
|
self.assertTrue(model.user.has_user_prompt(response, 'confirm_username'))
|
2015-05-12 01:23:18 +00:00
|
|
|
|
2016-12-05 22:19:38 +00:00
|
|
|
# Verify we can confirm the user.
|
|
|
|
(response, _) = ldap.confirm_existing_user('someuser', 'somepass')
|
|
|
|
self.assertEquals(response.username, 'someuser')
|
2015-05-20 20:37:09 +00:00
|
|
|
|
2016-07-07 18:26:14 +00:00
|
|
|
def test_login_secondary(self):
|
2016-12-05 22:19:38 +00:00
|
|
|
with mock_ldap() as ldap:
|
|
|
|
# Verify we can login.
|
|
|
|
(response, _) = ldap.verify_and_link_user('secondaryuser', 'somepass')
|
|
|
|
self.assertEquals(response.username, 'secondaryuser')
|
2016-07-07 18:26:14 +00:00
|
|
|
|
2016-12-05 22:19:38 +00:00
|
|
|
# Verify we can confirm the user.
|
|
|
|
(response, _) = ldap.confirm_existing_user('secondaryuser', 'somepass')
|
|
|
|
self.assertEquals(response.username, 'secondaryuser')
|
2016-07-07 18:26:14 +00:00
|
|
|
|
2015-08-18 16:15:40 +00:00
|
|
|
def test_invalid_password(self):
|
2016-12-05 22:19:38 +00:00
|
|
|
with mock_ldap() as ldap:
|
|
|
|
# Verify we cannot login with an invalid password.
|
|
|
|
(response, err_msg) = ldap.verify_and_link_user('someuser', 'invalidpass')
|
|
|
|
self.assertIsNone(response)
|
|
|
|
self.assertEquals(err_msg, 'Invalid password')
|
2015-08-18 16:15:40 +00:00
|
|
|
|
2016-12-05 22:19:38 +00:00
|
|
|
# Verify we cannot confirm the user.
|
|
|
|
(response, err_msg) = ldap.confirm_existing_user('someuser', 'invalidpass')
|
|
|
|
self.assertIsNone(response)
|
|
|
|
self.assertEquals(err_msg, 'Invalid user')
|
2015-08-18 16:15:40 +00:00
|
|
|
|
2015-05-12 01:23:18 +00:00
|
|
|
def test_missing_mail(self):
|
2016-12-05 22:19:38 +00:00
|
|
|
with mock_ldap() as ldap:
|
|
|
|
(response, err_msg) = ldap.get_user('nomail')
|
|
|
|
self.assertIsNone(response)
|
|
|
|
self.assertEquals('Missing mail field "mail" in user record', err_msg)
|
2015-05-12 01:23:18 +00:00
|
|
|
|
2016-09-08 16:24:47 +00:00
|
|
|
def test_missing_mail_allowed(self):
|
2016-12-05 22:19:38 +00:00
|
|
|
with mock_ldap(requires_email=False) as ldap:
|
|
|
|
(response, _) = ldap.get_user('nomail')
|
|
|
|
self.assertEquals(response.username, 'nomail')
|
2016-09-08 16:24:47 +00:00
|
|
|
|
2015-05-20 20:37:09 +00:00
|
|
|
def test_confirm_different_username(self):
|
2016-12-05 22:19:38 +00:00
|
|
|
with mock_ldap() as ldap:
|
|
|
|
# Verify that the user is logged in and their username was adjusted.
|
|
|
|
(response, _) = ldap.verify_and_link_user('cool.user', 'somepass')
|
|
|
|
self.assertEquals(response.username, 'cool_user')
|
2015-05-20 20:37:09 +00:00
|
|
|
|
2016-12-05 22:19:38 +00:00
|
|
|
# Verify we can confirm the user's quay username.
|
|
|
|
(response, _) = ldap.confirm_existing_user('cool_user', 'somepass')
|
|
|
|
self.assertEquals(response.username, 'cool_user')
|
2015-05-20 20:37:09 +00:00
|
|
|
|
2016-12-05 22:19:38 +00:00
|
|
|
# Verify that we *cannot* confirm the LDAP username.
|
|
|
|
(response, _) = ldap.confirm_existing_user('cool.user', 'somepass')
|
|
|
|
self.assertIsNone(response)
|
2015-05-26 19:46:35 +00:00
|
|
|
|
|
|
|
def test_referral(self):
|
2016-12-05 22:19:38 +00:00
|
|
|
with mock_ldap() as ldap:
|
|
|
|
(response, _) = ldap.verify_and_link_user('referred', 'somepass')
|
|
|
|
self.assertEquals(response.username, 'cool_user')
|
2015-05-26 19:46:35 +00:00
|
|
|
|
2016-12-05 22:19:38 +00:00
|
|
|
# Verify we can confirm the user's quay username.
|
|
|
|
(response, _) = ldap.confirm_existing_user('cool_user', 'somepass')
|
|
|
|
self.assertEquals(response.username, 'cool_user')
|
2015-05-26 19:46:35 +00:00
|
|
|
|
|
|
|
def test_invalid_referral(self):
|
2016-12-05 22:19:38 +00:00
|
|
|
with mock_ldap() as ldap:
|
|
|
|
(response, _) = ldap.verify_and_link_user('invalidreferred', 'somepass')
|
|
|
|
self.assertIsNone(response)
|
2015-05-20 20:37:09 +00:00
|
|
|
|
2015-05-26 19:46:35 +00:00
|
|
|
def test_multientry(self):
|
2016-12-05 22:19:38 +00:00
|
|
|
with mock_ldap() as ldap:
|
|
|
|
(response, _) = ldap.verify_and_link_user('multientry', 'somepass')
|
|
|
|
self.assertEquals(response.username, 'multientry')
|
2015-05-12 01:23:18 +00:00
|
|
|
|
2016-07-22 18:40:53 +00:00
|
|
|
def test_login_empty_userdn(self):
|
2016-12-05 22:19:38 +00:00
|
|
|
with mock_ldap():
|
|
|
|
base_dn = ['ou=employees', 'dc=quay', 'dc=io']
|
|
|
|
admin_dn = 'uid=testy,ou=employees,dc=quay,dc=io'
|
|
|
|
admin_passwd = 'password'
|
|
|
|
user_rdn = []
|
|
|
|
uid_attr = 'uid'
|
|
|
|
email_attr = 'mail'
|
|
|
|
secondary_user_rdns = ['ou=otheremployees']
|
|
|
|
|
|
|
|
ldap = LDAPUsers('ldap://localhost', base_dn, admin_dn, admin_passwd, user_rdn,
|
|
|
|
uid_attr, email_attr, secondary_user_rdns=secondary_user_rdns)
|
|
|
|
|
|
|
|
# Verify we can login.
|
|
|
|
(response, _) = ldap.verify_and_link_user('someuser', 'somepass')
|
|
|
|
self.assertEquals(response.username, 'someuser')
|
|
|
|
|
|
|
|
# Verify we can confirm the user.
|
|
|
|
(response, _) = ldap.confirm_existing_user('someuser', 'somepass')
|
|
|
|
self.assertEquals(response.username, 'someuser')
|
2016-07-22 18:40:53 +00:00
|
|
|
|
2016-12-05 22:19:38 +00:00
|
|
|
def test_link_user(self):
|
|
|
|
with mock_ldap() as ldap:
|
|
|
|
# Link someuser.
|
|
|
|
user, error_message = ldap.link_user('someuser')
|
|
|
|
self.assertIsNone(error_message)
|
|
|
|
self.assertIsNotNone(user)
|
|
|
|
self.assertEquals('someuser', user.username)
|
2016-07-22 18:40:53 +00:00
|
|
|
|
2016-12-05 22:19:38 +00:00
|
|
|
# Link again. Should return the same user record.
|
|
|
|
user_again, _ = ldap.link_user('someuser')
|
|
|
|
self.assertEquals(user_again.id, user.id)
|
2016-07-22 18:40:53 +00:00
|
|
|
|
2016-12-05 22:19:38 +00:00
|
|
|
# Confirm someuser.
|
|
|
|
result, _ = ldap.confirm_existing_user('someuser', 'somepass')
|
|
|
|
self.assertIsNotNone(result)
|
|
|
|
self.assertEquals('someuser', result.username)
|
|
|
|
self.assertTrue(model.user.has_user_prompt(user, 'confirm_username'))
|
2016-10-27 19:32:01 +00:00
|
|
|
|
|
|
|
def test_query(self):
|
2016-12-05 22:19:38 +00:00
|
|
|
with mock_ldap() as ldap:
|
2016-10-27 19:32:01 +00:00
|
|
|
# Lookup cool.
|
2016-12-05 22:19:38 +00:00
|
|
|
(response, federated_id, error_message) = ldap.query_users('cool')
|
2016-10-27 19:32:01 +00:00
|
|
|
self.assertIsNone(error_message)
|
|
|
|
self.assertEquals(1, len(response))
|
2016-12-05 22:19:38 +00:00
|
|
|
self.assertEquals('ldap', federated_id)
|
2016-10-27 19:32:01 +00:00
|
|
|
|
|
|
|
user_info = response[0]
|
|
|
|
self.assertEquals("cool.user", user_info.username)
|
|
|
|
self.assertEquals("foo@bar.com", user_info.email)
|
|
|
|
|
|
|
|
# Lookup unknown.
|
2016-12-05 22:19:38 +00:00
|
|
|
(response, federated_id, error_message) = ldap.query_users('unknown')
|
2016-10-27 19:32:01 +00:00
|
|
|
self.assertIsNone(error_message)
|
|
|
|
self.assertEquals(0, len(response))
|
2016-12-05 22:19:38 +00:00
|
|
|
self.assertEquals('ldap', federated_id)
|
2016-10-27 19:32:01 +00:00
|
|
|
|
2016-12-19 16:53:06 +00:00
|
|
|
def test_timeout(self):
|
|
|
|
base_dn = ['dc=quay', 'dc=io']
|
|
|
|
admin_dn = 'uid=testy,ou=employees,dc=quay,dc=io'
|
|
|
|
admin_passwd = 'password'
|
|
|
|
user_rdn = ['ou=employees']
|
|
|
|
uid_attr = 'uid'
|
|
|
|
email_attr = 'mail'
|
|
|
|
secondary_user_rdns = ['ou=otheremployees']
|
|
|
|
|
|
|
|
with self.assertRaisesRegexp(Exception, "Can't contact LDAP server"):
|
|
|
|
ldap = LDAPUsers('ldap://localhost', base_dn, admin_dn, admin_passwd, user_rdn,
|
|
|
|
uid_attr, email_attr, secondary_user_rdns=secondary_user_rdns,
|
|
|
|
requires_email=False, timeout=5)
|
|
|
|
ldap.query_users('cool')
|
2016-10-27 19:32:01 +00:00
|
|
|
|
2017-02-16 20:16:47 +00:00
|
|
|
def test_iterate_group_members(self):
|
|
|
|
with mock_ldap() as ldap:
|
|
|
|
(it, err) = ldap.iterate_group_members({'group_dn': 'cn=AwesomeFolk'},
|
|
|
|
disable_pagination=True)
|
|
|
|
self.assertIsNone(err)
|
|
|
|
|
|
|
|
results = list(it)
|
|
|
|
self.assertEquals(2, len(results))
|
|
|
|
|
|
|
|
first = results[0][0]
|
|
|
|
second = results[1][0]
|
2017-02-17 23:19:35 +00:00
|
|
|
|
2017-03-20 21:53:15 +00:00
|
|
|
if first.id == 'testy':
|
|
|
|
testy, someuser = first, second
|
|
|
|
else:
|
|
|
|
testy, someuser = second, first
|
|
|
|
|
|
|
|
self.assertEquals('testy', testy.id)
|
|
|
|
self.assertEquals('testy', testy.username)
|
|
|
|
self.assertEquals('bar@baz.com', testy.email)
|
|
|
|
|
|
|
|
self.assertEquals('someuser', someuser.id)
|
|
|
|
self.assertEquals('someuser', someuser.username)
|
|
|
|
self.assertEquals('foo@bar.com', someuser.email)
|
|
|
|
|
|
|
|
def test_iterate_group_members_with_pagination(self):
|
|
|
|
with mock_ldap() as ldap:
|
|
|
|
(it, err) = ldap.iterate_group_members({'group_dn': 'cn=AwesomeFolk'}, page_size=1)
|
|
|
|
self.assertIsNone(err)
|
|
|
|
|
|
|
|
results = list(it)
|
|
|
|
self.assertEquals(2, len(results))
|
|
|
|
|
|
|
|
first = results[0][0]
|
|
|
|
second = results[1][0]
|
|
|
|
|
2017-02-17 23:19:35 +00:00
|
|
|
if first.id == 'testy':
|
|
|
|
testy, someuser = first, second
|
|
|
|
else:
|
|
|
|
testy, someuser = second, first
|
|
|
|
|
|
|
|
self.assertEquals('testy', testy.id)
|
|
|
|
self.assertEquals('testy', testy.username)
|
|
|
|
self.assertEquals('bar@baz.com', testy.email)
|
|
|
|
|
|
|
|
self.assertEquals('someuser', someuser.id)
|
|
|
|
self.assertEquals('someuser', someuser.username)
|
|
|
|
self.assertEquals('foo@bar.com', someuser.email)
|
2017-02-16 20:16:47 +00:00
|
|
|
|
2017-02-17 22:10:26 +00:00
|
|
|
def test_check_group_lookup_args(self):
|
|
|
|
with mock_ldap() as ldap:
|
|
|
|
(result, err) = ldap.check_group_lookup_args({'group_dn': 'cn=invalid'},
|
|
|
|
disable_pagination=True)
|
|
|
|
self.assertFalse(result)
|
|
|
|
self.assertIsNotNone(err)
|
|
|
|
|
|
|
|
(result, err) = ldap.check_group_lookup_args({'group_dn': 'cn=AwesomeFolk'},
|
|
|
|
disable_pagination=True)
|
|
|
|
self.assertTrue(result)
|
|
|
|
self.assertIsNone(err)
|
|
|
|
|
|
|
|
def test_metadata(self):
|
|
|
|
with mock_ldap() as ldap:
|
|
|
|
assert 'base_dn' in ldap.service_metadata()
|
|
|
|
|
2015-05-12 01:23:18 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
|