def test_at_least_one_user_exists_no_users(self): base_dn = ["dc=quay", "dc=io"] admin_dn = "uid=testy,ou=employees,dc=quay,dc=io" admin_passwd = "password" user_rdn = ["ou=nonexistent"] uid_attr = "uid" email_attr = "mail" with mock_ldap(): ldap = LDAPUsers("ldap://localhost", base_dn, admin_dn, admin_passwd, user_rdn, uid_attr, email_attr) # Try to find users in a nonexistent group. (response, err_msg) = ldap.at_least_one_user_exists() self.assertFalse(response) assert err_msg is not None
def test_at_least_one_user_exists_invalid_creds(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" with mock_ldap(): ldap = LDAPUsers("ldap://localhost", base_dn, admin_dn, admin_passwd, user_rdn, uid_attr, email_attr) # Try to query with invalid credentials. (response, err_msg) = ldap.at_least_one_user_exists() self.assertFalse(response) self.assertEqual("LDAP Admin dn or password is invalid", err_msg)
def test_at_least_one_user_exists_no_users(self): base_dn = ['dc=quay', 'dc=io'] admin_dn = 'uid=testy,ou=employees,dc=quay,dc=io' admin_passwd = 'password' user_rdn = ['ou=nonexistent'] uid_attr = 'uid' email_attr = 'mail' with mock_ldap(): ldap = LDAPUsers('ldap://localhost', base_dn, admin_dn, admin_passwd, user_rdn, uid_attr, email_attr) # Try to find users in a nonexistent group. (response, err_msg) = ldap.at_least_one_user_exists() self.assertFalse(response) assert err_msg is not None
def test_at_least_one_user_exists_invalid_creds(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' with mock_ldap(): ldap = LDAPUsers('ldap://localhost', base_dn, admin_dn, admin_passwd, user_rdn, uid_attr, email_attr) # Try to query with invalid credentials. (response, err_msg) = ldap.at_least_one_user_exists() self.assertFalse(response) self.assertEquals('LDAP Admin dn or password is invalid', err_msg)
def test_at_least_one_user_exists_filtered_away(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 mock_ldap(): ldap = LDAPUsers( "ldap://localhost", base_dn, admin_dn, admin_passwd, user_rdn, uid_attr, email_attr, ldap_user_filter="(filterField=someothervalue)", ) (response, err_msg) = ldap.at_least_one_user_exists() self.assertIsNone(err_msg) self.assertFalse(response)
def test_at_least_one_user_exists_true(self): with mock_ldap() as ldap: # Ensure we have at least a single user in the valid group (response, err_msg) = ldap.at_least_one_user_exists() self.assertIsNone(err_msg) self.assertTrue(response)