aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Chatzimichos <tampakrap@gentoo.org>2013-08-19 11:58:15 +0200
committerTheo Chatzimichos <tampakrap@gentoo.org>2013-08-19 23:16:58 +0200
commit34b33bee91cdedbf8028c0597e8e222c586d9b4f (patch)
tree95c3e13225ce5f587162cf7b3059cf3c9d7a8016 /okupy/tests/unit/test_secondary_password.py
parentCombine get_ldap_user and get_all_ldap_users to ldap_users (diff)
downloadidentity.gentoo.org-34b33bee91cdedbf8028c0597e8e222c586d9b4f.tar.gz
identity.gentoo.org-34b33bee91cdedbf8028c0597e8e222c586d9b4f.tar.bz2
identity.gentoo.org-34b33bee91cdedbf8028c0597e8e222c586d9b4f.zip
Apply the previous helper changes to the test suite
Move some login tests to the non-ldap class
Diffstat (limited to 'okupy/tests/unit/test_secondary_password.py')
-rw-r--r--okupy/tests/unit/test_secondary_password.py55
1 files changed, 27 insertions, 28 deletions
diff --git a/okupy/tests/unit/test_secondary_password.py b/okupy/tests/unit/test_secondary_password.py
index 4f9e4c6..3811c5e 100644
--- a/okupy/tests/unit/test_secondary_password.py
+++ b/okupy/tests/unit/test_secondary_password.py
@@ -11,7 +11,7 @@ from passlib.hash import ldap_md5_crypt
from ...common.crypto import cipher
from ...common.ldap_helpers import set_secondary_password, remove_secondary_password
-from ...common.test_helpers import set_request, set_search_seed, get_ldap_user
+from ...common.test_helpers import set_request, set_search_seed, ldap_users
class SecondaryPassword(TestCase):
@@ -27,87 +27,86 @@ class SecondaryPassword(TestCase):
self.mockldap.stop()
def test_secondary_password_gets_added_in_session(self):
- self.ldapobject.search_s.seed(settings.AUTH_LDAP_USER_BASE_DN, 2, set_search_seed('alice'))([get_ldap_user('alice')])
+ self.ldapobject.search_s.seed(settings.AUTH_LDAP_USER_BASE_DN, 2, set_search_seed('alice'))([ldap_users('alice')])
alice = User.objects.create(username='alice', password='ldaptest')
request = set_request(uri='/', user=alice)
set_secondary_password(request, 'ldaptest')
self.assertEqual(len(request.session['secondary_password']), 48)
def test_secondary_password_gets_added_in_ldap(self):
- self.ldapobject.search_s.seed(settings.AUTH_LDAP_USER_BASE_DN, 2, set_search_seed('alice'))([get_ldap_user('alice')])
+ self.ldapobject.search_s.seed(settings.AUTH_LDAP_USER_BASE_DN, 2, set_search_seed('alice'))([ldap_users('alice')])
alice = User.objects.create(username='alice', password='ldaptest')
request = set_request(uri='/', user=alice)
- self.assertEqual(len(get_ldap_user('alice')[1]['userPassword']), 1)
+ self.assertEqual(len(ldap_users('alice')[1]['userPassword']), 1)
set_secondary_password(request, 'ldaptest')
- self.assertEqual(len(get_ldap_user('alice', directory=self.ldapobject.directory)[1]['userPassword']), 2)
+ self.assertEqual(len(ldap_users('alice', directory=self.ldapobject.directory)[1]['userPassword']), 2)
def test_remove_leftovers_before_adding_secondary_password(self):
leftover = ldap_md5_crypt.encrypt('leftover_password')
- self.ldapobject.directory[get_ldap_user('alice')[0]]['userPassword'].append(leftover)
- self.ldapobject.search_s.seed(settings.AUTH_LDAP_USER_BASE_DN, 2, set_search_seed('alice'))([get_ldap_user('alice', directory=self.ldapobject.directory)])
+ self.ldapobject.directory[ldap_users('alice')[0]]['userPassword'].append(leftover)
+ self.ldapobject.search_s.seed(settings.AUTH_LDAP_USER_BASE_DN, 2, set_search_seed('alice'))([ldap_users('alice', directory=self.ldapobject.directory)])
alice = User.objects.create(username='alice', password='ldaptest')
request = set_request(uri='/', user=alice)
set_secondary_password(request, 'ldaptest')
- self.assertNotIn(leftover, get_ldap_user('alice', directory=self.ldapobject.directory)[1]['userPassword'])
+ self.assertNotIn(leftover, ldap_users('alice', directory=self.ldapobject.directory)[1]['userPassword'])
def test_dont_remove_primary_password_while_cleaning_leftovers(self):
leftover = ldap_md5_crypt.encrypt('leftover_password')
- self.ldapobject.directory[get_ldap_user('alice')[0]]['userPassword'].append(leftover)
- self.ldapobject.search_s.seed(settings.AUTH_LDAP_USER_BASE_DN, 2, set_search_seed('alice'))([get_ldap_user('alice', directory=self.ldapobject.directory)])
+ self.ldapobject.directory[ldap_users('alice')[0]]['userPassword'].append(leftover)
+ self.ldapobject.search_s.seed(settings.AUTH_LDAP_USER_BASE_DN, 2, set_search_seed('alice'))([ldap_users('alice', directory=self.ldapobject.directory)])
alice = User.objects.create(username='alice', password='ldaptest')
request = set_request(uri='/', user=alice)
set_secondary_password(request, 'ldaptest')
- self.assertTrue(ldap_md5_crypt.verify('ldaptest',get_ldap_user('alice', directory=self.ldapobject.directory)[1]['userPassword'][0]))
+ self.assertTrue(ldap_md5_crypt.verify('ldaptest',ldap_users('alice', directory=self.ldapobject.directory)[1]['userPassword'][0]))
def test_dont_remove_unknown_hashes_while_cleaning_leftovers(self):
leftover = ldap_md5_crypt.encrypt('leftover_password')
- self.ldapobject.directory[get_ldap_user('alice')[0]]['userPassword'].append(leftover)
+ self.ldapobject.directory[ldap_users('alice')[0]]['userPassword'].append(leftover)
leftover2 = 'plain_leftover2'
- self.ldapobject.directory[get_ldap_user('alice')[0]]['userPassword'].append(leftover2)
- self.ldapobject.search_s.seed(settings.AUTH_LDAP_USER_BASE_DN, 2, set_search_seed('alice'))([get_ldap_user('alice', directory=self.ldapobject.directory)])
+ self.ldapobject.directory[ldap_users('alice')[0]]['userPassword'].append(leftover2)
+ self.ldapobject.search_s.seed(settings.AUTH_LDAP_USER_BASE_DN, 2, set_search_seed('alice'))([ldap_users('alice', directory=self.ldapobject.directory)])
alice = User.objects.create(username='alice', password='ldaptest')
request = set_request(uri='/', user=alice)
set_secondary_password(request, 'ldaptest')
- self.assertIn(leftover2, get_ldap_user('alice', directory=self.ldapobject.directory)[1]['userPassword'])
+ self.assertIn(leftover2, ldap_users('alice', directory=self.ldapobject.directory)[1]['userPassword'])
def test_session_and_ldap_secondary_passwords_match(self):
- self.ldapobject.search_s.seed(settings.AUTH_LDAP_USER_BASE_DN, 2, set_search_seed('alice'))([get_ldap_user('alice')])
+ self.ldapobject.search_s.seed(settings.AUTH_LDAP_USER_BASE_DN, 2, set_search_seed('alice'))([ldap_users('alice')])
alice = User.objects.create(username='alice', password='ldaptest')
request = set_request(uri='/', user=alice)
set_secondary_password(request, 'ldaptest')
- self.assertTrue(ldap_md5_crypt.verify(b64encode(cipher.decrypt(request.session['secondary_password'], 48)), get_ldap_user('alice', directory=self.ldapobject.directory)[1]['userPassword'][1]))
+ self.assertTrue(ldap_md5_crypt.verify(b64encode(cipher.decrypt(request.session['secondary_password'], 48)), ldap_users('alice', directory=self.ldapobject.directory)[1]['userPassword'][1]))
def test_remove_secondary_password_from_ldap(self):
secondary_password = Random.get_random_bytes(48)
secondary_password_crypt = ldap_md5_crypt.encrypt(b64encode(secondary_password))
- self.ldapobject.directory[get_ldap_user('alice')[0]]['userPassword'].append(secondary_password_crypt)
- self.ldapobject.search_s.seed(settings.AUTH_LDAP_USER_BASE_DN, 2, set_search_seed('alice'))([get_ldap_user('alice', directory=self.ldapobject.directory)])
+ self.ldapobject.directory[ldap_users('alice')[0]]['userPassword'].append(secondary_password_crypt)
+ self.ldapobject.search_s.seed(settings.AUTH_LDAP_USER_BASE_DN, 2, set_search_seed('alice'))([ldap_users('alice', directory=self.ldapobject.directory)])
alice = User.objects.create(username='alice', password='ldaptest')
request = set_request(uri='/', user=alice)
request.session['secondary_password'] = cipher.encrypt(secondary_password)
remove_secondary_password(request)
- self.assertNotIn(secondary_password_crypt, get_ldap_user('alice', directory=self.ldapobject.directory)[1]['userPassword'])
+ self.assertNotIn(secondary_password_crypt, ldap_users('alice', directory=self.ldapobject.directory)[1]['userPassword'])
def test_dont_remove_primary_password_while_removing_secondary_password(self):
secondary_password = Random.get_random_bytes(48)
secondary_password_crypt = ldap_md5_crypt.encrypt(b64encode(secondary_password))
- self.ldapobject.directory[get_ldap_user('alice')[0]]['userPassword'].append(secondary_password_crypt)
- self.ldapobject.search_s.seed(settings.AUTH_LDAP_USER_BASE_DN, 2, set_search_seed('alice'))([get_ldap_user('alice', directory=self.ldapobject.directory)])
+ self.ldapobject.directory[ldap_users('alice')[0]]['userPassword'].append(secondary_password_crypt)
+ self.ldapobject.search_s.seed(settings.AUTH_LDAP_USER_BASE_DN, 2, set_search_seed('alice'))([ldap_users('alice', directory=self.ldapobject.directory)])
alice = User.objects.create(username='alice', password='ldaptest')
request = set_request(uri='/', user=alice)
request.session['secondary_password'] = cipher.encrypt(secondary_password)
remove_secondary_password(request)
- self.assertTrue(ldap_md5_crypt.verify('ldaptest',get_ldap_user('alice', directory=self.ldapobject.directory)[1]['userPassword'][0]))
+ self.assertTrue(ldap_md5_crypt.verify('ldaptest',ldap_users('alice', directory=self.ldapobject.directory)[1]['userPassword'][0]))
def test_dont_remove_unknown_hashes_while_removing_secondary_password(self):
secondary_password = Random.get_random_bytes(48)
secondary_password_crypt = ldap_md5_crypt.encrypt(b64encode(secondary_password))
- self.ldapobject.directory[get_ldap_user('alice')[0]]['userPassword'].append(secondary_password_crypt)
- unknown_hash = 'unknown_hash'
- self.ldapobject.directory[get_ldap_user('alice')[0]]['userPassword'].append(unknown_hash)
- self.ldapobject.search_s.seed(settings.AUTH_LDAP_USER_BASE_DN, 2, set_search_seed('alice'))([get_ldap_user('alice', directory=self.ldapobject.directory)])
+ self.ldapobject.directory[ldap_users('alice')[0]]['userPassword'].append('unknown_hash')
+ self.ldapobject.directory[ldap_users('alice')[0]]['userPassword'].append(secondary_password_crypt)
+ self.ldapobject.search_s.seed(settings.AUTH_LDAP_USER_BASE_DN, 2, set_search_seed('alice'))([ldap_users('alice', directory=self.ldapobject.directory)])
alice = User.objects.create(username='alice', password='ldaptest')
request = set_request(uri='/', user=alice)
request.session['secondary_password'] = cipher.encrypt(secondary_password)
remove_secondary_password(request)
- self.assertIn(unknown_hash, get_ldap_user('alice', directory=self.ldapobject.directory)[1]['userPassword'])
+ self.assertIn('unknown_hash', ldap_users('alice', directory=self.ldapobject.directory)[1]['userPassword'])