aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'okupy/tests/unit')
-rw-r--r--okupy/tests/unit/test_auth.py9
-rw-r--r--okupy/tests/unit/test_index.py7
-rw-r--r--okupy/tests/unit/test_ldapuser.py13
-rw-r--r--okupy/tests/unit/test_lists.py7
-rw-r--r--okupy/tests/unit/test_login.py13
-rw-r--r--okupy/tests/unit/test_secondary_password.py39
-rw-r--r--okupy/tests/unit/test_signup.py17
7 files changed, 70 insertions, 35 deletions
diff --git a/okupy/tests/unit/test_auth.py b/okupy/tests/unit/test_auth.py
index d514999..586987b 100644
--- a/okupy/tests/unit/test_auth.py
+++ b/okupy/tests/unit/test_auth.py
@@ -19,12 +19,17 @@ class AuthSSLUnitTests(TestCase):
def setUpClass(cls):
cls.mockldap = MockLdap(vars.DIRECTORY)
+ @classmethod
+ def tearDownClass(cls):
+ del cls.mockldap
+
def setUp(self):
self.mockldap.start()
- self.ldapobject = self.mockldap[settings.AUTH_LDAP_SERVER_URI]
+ self.ldapobj = self.mockldap[settings.AUTH_LDAP_SERVER_URI]
def tearDown(self):
self.mockldap.stop()
+ del self.ldapobj
def test_valid_certificate_authenticates_alice(self):
request = set_request(uri='/login')
@@ -74,7 +79,7 @@ class AuthSSHUnitTests(TestCase):
def setUp(self):
self.mockldap.start()
- self.ldapobject = self.mockldap[settings.AUTH_LDAP_SERVER_URI]
+ self.ldapobj = self.mockldap[settings.AUTH_LDAP_SERVER_URI]
def tearDown(self):
self.mockldap.stop()
diff --git a/okupy/tests/unit/test_index.py b/okupy/tests/unit/test_index.py
index b35d99a..9f71230 100644
--- a/okupy/tests/unit/test_index.py
+++ b/okupy/tests/unit/test_index.py
@@ -16,12 +16,17 @@ class IndexUnitTests(TestCase):
def setUpClass(cls):
cls.mockldap = MockLdap(vars.DIRECTORY)
+ @classmethod
+ def tearDownClass(cls):
+ del cls.mockldap
+
def setUp(self):
self.mockldap.start()
- self.ldapobject = self.mockldap[settings.AUTH_LDAP_SERVER_URI]
+ self.ldapobj = self.mockldap[settings.AUTH_LDAP_SERVER_URI]
def tearDown(self):
self.mockldap.stop()
+ del self.ldapobj
def test_index_url_resolves_to_index_view(self):
found = resolve('/')
diff --git a/okupy/tests/unit/test_ldapuser.py b/okupy/tests/unit/test_ldapuser.py
index 7dd2b5f..4ca821f 100644
--- a/okupy/tests/unit/test_ldapuser.py
+++ b/okupy/tests/unit/test_ldapuser.py
@@ -23,12 +23,17 @@ class LDAPUserUnitTests(TestCase):
def setUpClass(cls):
cls.mockldap = MockLdap(vars.DIRECTORY)
+ @classmethod
+ def tearDownClass(cls):
+ del cls.mockldap
+
def setUp(self):
self.mockldap.start()
- self.ldapobject = self.mockldap[settings.AUTH_LDAP_SERVER_URI]
+ self.ldapobj = self.mockldap[settings.AUTH_LDAP_SERVER_URI]
def tearDown(self):
self.mockldap.stop()
+ del self.ldapobj
def test_return_unicode_username(self):
alice = LDAPUser.objects.get(username='alice')
@@ -39,7 +44,7 @@ class LDAPUserUnitTests(TestCase):
secondary_password = Random.get_random_bytes(48)
secondary_password_crypt = ldap_md5_crypt.encrypt(b64encode(
secondary_password))
- self.ldapobject.directory[ldap_users('alice')[0]][
+ self.ldapobj.directory[ldap_users('alice')[0]][
'userPassword'].append(secondary_password_crypt)
request = set_request('/', user=vars.USER_ALICE)
request.session['secondary_password'] = cipher.encrypt(
@@ -51,7 +56,7 @@ class LDAPUserUnitTests(TestCase):
secondary_password = Random.get_random_bytes(48)
secondary_password_crypt = ldap_md5_crypt.encrypt(b64encode(
secondary_password))
- self.ldapobject.directory[ldap_users('alice')[0]][
+ self.ldapobj.directory[ldap_users('alice')[0]][
'userPassword'].append(secondary_password_crypt)
request = set_request('/', user=vars.USER_ALICE)
request.session['secondary_password'] = cipher.encrypt(
@@ -102,7 +107,7 @@ class LDAPUserUnitTests(TestCase):
secondary_password = Random.get_random_bytes(48)
secondary_password_crypt = ldap_md5_crypt.encrypt(b64encode(
secondary_password))
- self.ldapobject.directory[ldap_users('alice')[0]][
+ self.ldapobj.directory[ldap_users('alice')[0]][
'userPassword'].append(secondary_password_crypt)
request = set_request('/', user=vars.USER_ALICE)
request.session['secondary_password'] = cipher.encrypt(
diff --git a/okupy/tests/unit/test_lists.py b/okupy/tests/unit/test_lists.py
index d34e27c..8cdcb6f 100644
--- a/okupy/tests/unit/test_lists.py
+++ b/okupy/tests/unit/test_lists.py
@@ -15,12 +15,17 @@ class ListsUnitTests(OkupyTestCase):
def setUpClass(cls):
cls.mockldap = MockLdap(vars.DIRECTORY)
+ @classmethod
+ def tearDownClass(cls):
+ del cls.mockldap
+
def setUp(self):
self.mockldap.start()
- self.ldapobject = self.mockldap[settings.AUTH_LDAP_SERVER_URI]
+ self.ldapobj = self.mockldap[settings.AUTH_LDAP_SERVER_URI]
def tearDown(self):
self.mockldap.stop()
+ del self.ldapobj
def test_devlist_url_resolves_to_lists_view(self):
found = resolve('/devlist/')
diff --git a/okupy/tests/unit/test_login.py b/okupy/tests/unit/test_login.py
index b602d65..f781741 100644
--- a/okupy/tests/unit/test_login.py
+++ b/okupy/tests/unit/test_login.py
@@ -25,12 +25,17 @@ class LoginUnitTests(OkupyTestCase):
def setUpClass(cls):
cls.mockldap = MockLdap(vars.DIRECTORY)
+ @classmethod
+ def tearDownClass(cls):
+ del cls.mockldap
+
def setUp(self):
self.mockldap.start()
- self.ldapobject = self.mockldap[settings.AUTH_LDAP_SERVER_URI]
+ self.ldapobj = self.mockldap[settings.AUTH_LDAP_SERVER_URI]
def tearDown(self):
self.mockldap.stop()
+ del self.ldapobj
def test_incorrect_user_raises_login_failed(self):
request = set_request(uri='/login', post=vars.LOGIN_WRONG,
@@ -86,14 +91,14 @@ class LoginUnitTests(OkupyTestCase):
login(request)
self.assertEqual(len(ldap_users(
'alice',
- directory=self.ldapobject.directory)[1]['userPassword']), 2)
+ directory=self.ldapobj.directory)[1]['userPassword']), 2)
self.assertEqual(len(request.session['secondary_password']), 48)
def test_secondary_password_is_removed_in_logout(self):
secondary_password = Random.get_random_bytes(48)
secondary_password_crypt = ldap_md5_crypt.encrypt(b64encode(
secondary_password))
- self.ldapobject.directory[ldap_users('alice')[0]][
+ self.ldapobj.directory[ldap_users('alice')[0]][
'userPassword'].append(secondary_password_crypt)
request = set_request(uri='/login', post=vars.LOGIN_ALICE,
user=vars.USER_ALICE)
@@ -102,7 +107,7 @@ class LoginUnitTests(OkupyTestCase):
logout(request)
self.assertEqual(len(ldap_users(
'alice',
- directory=self.ldapobject.directory)[1]['userPassword']), 1)
+ directory=self.ldapobj.directory)[1]['userPassword']), 1)
class LoginUnitTestsNoLDAP(OkupyTestCase):
diff --git a/okupy/tests/unit/test_secondary_password.py b/okupy/tests/unit/test_secondary_password.py
index ff0a794..62c9890 100644
--- a/okupy/tests/unit/test_secondary_password.py
+++ b/okupy/tests/unit/test_secondary_password.py
@@ -20,12 +20,17 @@ class SecondaryPassword(TestCase):
def setUpClass(cls):
cls.mockldap = MockLdap(vars.DIRECTORY)
+ @classmethod
+ def tearDownClass(cls):
+ del cls.mockldap
+
def setUp(self):
self.mockldap.start()
- self.ldapobject = self.mockldap[settings.AUTH_LDAP_SERVER_URI]
+ self.ldapobj = self.mockldap[settings.AUTH_LDAP_SERVER_URI]
def tearDown(self):
self.mockldap.stop()
+ del self.ldapobj
def test_secondary_password_gets_added_in_session(self):
request = set_request(uri='/', user=vars.USER_ALICE)
@@ -38,39 +43,39 @@ class SecondaryPassword(TestCase):
set_secondary_password(request, 'ldaptest')
self.assertEqual(len(ldap_users(
'alice',
- directory=self.ldapobject.directory)[1]['userPassword']), 2)
+ directory=self.ldapobj.directory)[1]['userPassword']), 2)
def test_remove_leftovers_before_adding_secondary_password(self):
leftover = ldap_md5_crypt.encrypt('leftover_password')
- self.ldapobject.directory[ldap_users('alice')[0]][
+ self.ldapobj.directory[ldap_users('alice')[0]][
'userPassword'].append(leftover)
request = set_request(uri='/', user=vars.USER_ALICE)
set_secondary_password(request, 'ldaptest')
self.assertNotIn(leftover, ldap_users(
- 'alice', directory=self.ldapobject.directory)[1]['userPassword'])
+ 'alice', directory=self.ldapobj.directory)[1]['userPassword'])
def test_dont_remove_primary_password_while_cleaning_leftovers(self):
leftover = ldap_md5_crypt.encrypt('leftover_password')
- self.ldapobject.directory[ldap_users('alice')[0]][
+ self.ldapobj.directory[ldap_users('alice')[0]][
'userPassword'].append(leftover)
request = set_request(uri='/', user=vars.USER_ALICE)
set_secondary_password(request, 'ldaptest')
self.assertTrue(ldap_md5_crypt.verify(
'ldaptest', ldap_users(
'alice',
- directory=self.ldapobject.directory)[1]['userPassword'][0]))
+ directory=self.ldapobj.directory)[1]['userPassword'][0]))
def test_dont_remove_unknown_hashes_while_cleaning_leftovers(self):
leftover = ldap_md5_crypt.encrypt('leftover_password')
- self.ldapobject.directory[ldap_users('alice')[0]][
+ self.ldapobj.directory[ldap_users('alice')[0]][
'userPassword'].append(leftover)
leftover2 = 'plain_leftover2'
- self.ldapobject.directory[ldap_users('alice')[0]][
+ self.ldapobj.directory[ldap_users('alice')[0]][
'userPassword'].append(leftover2)
request = set_request(uri='/', user=vars.USER_ALICE)
set_secondary_password(request, 'ldaptest')
self.assertIn(leftover2, ldap_users(
- 'alice', directory=self.ldapobject.directory)[1]['userPassword'])
+ 'alice', directory=self.ldapobj.directory)[1]['userPassword'])
def test_session_and_ldap_secondary_passwords_match(self):
request = set_request(uri='/', user=vars.USER_ALICE)
@@ -79,26 +84,26 @@ class SecondaryPassword(TestCase):
request.session['secondary_password'], 48)),
ldap_users(
'alice',
- directory=self.ldapobject.directory)[1]['userPassword'][1]))
+ directory=self.ldapobj.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[ldap_users('alice')[0]][
+ self.ldapobj.directory[ldap_users('alice')[0]][
'userPassword'].append(secondary_password_crypt)
request = set_request(uri='/', user=vars.USER_ALICE)
request.session['secondary_password'] = cipher.encrypt(
secondary_password)
remove_secondary_password(request)
self.assertNotIn(secondary_password_crypt, ldap_users(
- 'alice', directory=self.ldapobject.directory)[1]['userPassword'])
+ 'alice', directory=self.ldapobj.directory)[1]['userPassword'])
def test_dont_remove_primary_password_when_removing_secondary_passwd(self):
secondary_password = Random.get_random_bytes(48)
secondary_password_crypt = ldap_md5_crypt.encrypt(b64encode(
secondary_password))
- self.ldapobject.directory[ldap_users('alice')[0]][
+ self.ldapobj.directory[ldap_users('alice')[0]][
'userPassword'].append(secondary_password_crypt)
request = set_request(uri='/', user=vars.USER_ALICE)
request.session['secondary_password'] = cipher.encrypt(
@@ -106,19 +111,19 @@ class SecondaryPassword(TestCase):
remove_secondary_password(request)
self.assertTrue(ldap_md5_crypt.verify('ldaptest', ldap_users(
'alice',
- directory=self.ldapobject.directory)[1]['userPassword'][0]))
+ directory=self.ldapobj.directory)[1]['userPassword'][0]))
def test_dont_remove_unknown_hashes_when_removing_secondary_password(self):
secondary_password = Random.get_random_bytes(48)
secondary_password_crypt = ldap_md5_crypt.encrypt(b64encode(
secondary_password))
- self.ldapobject.directory[ldap_users('alice')[0]][
+ self.ldapobj.directory[ldap_users('alice')[0]][
'userPassword'].append('unknown_hash')
- self.ldapobject.directory[ldap_users('alice')[0]][
+ self.ldapobj.directory[ldap_users('alice')[0]][
'userPassword'].append(secondary_password_crypt)
request = set_request(uri='/', user=vars.USER_ALICE)
request.session['secondary_password'] = cipher.encrypt(
secondary_password)
remove_secondary_password(request)
self.assertIn('unknown_hash', ldap_users(
- 'alice', directory=self.ldapobject.directory)[1]['userPassword'])
+ 'alice', directory=self.ldapobj.directory)[1]['userPassword'])
diff --git a/okupy/tests/unit/test_signup.py b/okupy/tests/unit/test_signup.py
index 8009546..dc43c74 100644
--- a/okupy/tests/unit/test_signup.py
+++ b/okupy/tests/unit/test_signup.py
@@ -21,12 +21,17 @@ class SignupUnitTests(OkupyTestCase):
def setUpClass(cls):
cls.mockldap = MockLdap(vars.DIRECTORY)
+ @classmethod
+ def tearDownClass(cls):
+ del cls.mockldap
+
def setUp(self):
self.mockldap.start()
- self.ldapobject = self.mockldap[settings.AUTH_LDAP_SERVER_URI]
+ self.ldapobj = self.mockldap[settings.AUTH_LDAP_SERVER_URI]
def tearDown(self):
self.mockldap.stop()
+ del self.ldapobj
def test_username_already_exists_in_ldap(self):
_form = vars.SIGNUP_TESTUSER.copy()
@@ -79,9 +84,9 @@ class SignupUnitTests(OkupyTestCase):
request = set_request(activate_url, messages=True)
activate(request, vars.QUEUEDUSER.encrypted_id)
self.assertTrue(ldap_users(vars.QUEUEDUSER.username,
- directory=self.ldapobject.directory))
+ directory=self.ldapobj.directory))
ldap_account = ldap_users(vars.QUEUEDUSER.username,
- directory=self.ldapobject.directory)[1]
+ directory=self.ldapobj.directory)[1]
self.assertEqual(ldap_account['objectClass'],
settings.AUTH_LDAP_USER_OBJECTCLASS)
self.assertEqual(ldap_account['sn'][0], vars.QUEUEDUSER.last_name)
@@ -181,14 +186,14 @@ class SignupUnitTests(OkupyTestCase):
def test_add_first_user_in_empty_ldap_directory(self):
vars.QUEUEDUSER.save()
activate_url = '/activate/%s/' % vars.QUEUEDUSER.encrypted_id
- self.ldapobject.directory = ldap_users(clean=True)
+ self.ldapobj.directory = ldap_users(clean=True)
request = set_request(activate_url, messages=True)
activate(request, vars.QUEUEDUSER.encrypted_id)
self.assertTrue(ldap_users(vars.QUEUEDUSER.username,
- directory=self.ldapobject.directory))
+ directory=self.ldapobj.directory))
self.assertEqual(ldap_users(
vars.QUEUEDUSER.username,
- directory=self.ldapobject.directory)[1]['uidNumber'][0], '1')
+ directory=self.ldapobj.directory)[1]['uidNumber'][0], '1')
class SignupunitTestsNoLDAP(OkupyTestCase):