summaryrefslogtreecommitdiff
path: root/passlib/tests/test_apache.py
diff options
context:
space:
mode:
Diffstat (limited to 'passlib/tests/test_apache.py')
-rw-r--r--passlib/tests/test_apache.py79
1 files changed, 14 insertions, 65 deletions
diff --git a/passlib/tests/test_apache.py b/passlib/tests/test_apache.py
index 198b425..fcdbbc6 100644
--- a/passlib/tests/test_apache.py
+++ b/passlib/tests/test_apache.py
@@ -2,19 +2,16 @@
#=============================================================================
# imports
#=============================================================================
-from __future__ import with_statement
# core
from logging import getLogger
+import unittest
import os
import subprocess
# site
# pkg
from passlib import apache, registry
from passlib.exc import MissingBackendError
-from passlib.utils.compat import irange
-from passlib.tests.backports import unittest
from passlib.tests.utils import TestCase, get_file, set_file, ensure_mtime_changed
-from passlib.utils.compat import u
from passlib.utils import to_bytes
from passlib.utils.handlers import to_unicode_for_identify
# module
@@ -122,8 +119,8 @@ class HtpasswdFileTest(TestCase):
b'user6:$5$rounds=110000$cCRp/xUUGVgwR4aP$'
b'p0.QKFS5qLNRqw1/47lXYiAcgIjJK.WjCO8nrEKuUK.\n')
- def test_00_constructor_autoload(self):
- """test constructor autoload"""
+ def test_00_constructor_new(self):
+ """constructor -- 'new' keyword"""
# check with existing file
path = self.mktemp()
set_file(path, self.sample_01)
@@ -143,13 +140,6 @@ class HtpasswdFileTest(TestCase):
self.assertEqual(ht.path, path)
self.assertFalse(ht.mtime)
- # check autoload=False (deprecated alias for new=True)
- with self.assertWarningList("``autoload=False`` is deprecated"):
- ht = apache.HtpasswdFile(path, autoload=False)
- self.assertEqual(ht.to_string(), b"")
- self.assertEqual(ht.path, path)
- self.assertFalse(ht.mtime)
-
# check missing file
os.remove(path)
self.assertRaises(IOError, apache.HtpasswdFile, path)
@@ -196,21 +186,9 @@ class HtpasswdFileTest(TestCase):
self.assertFalse(ht.set_password("user5", "pass5"))
self.assertEqual(ht.to_string(), self.sample_03)
- # test legacy default kwd
- with self.assertWarningList("``default`` is deprecated"):
- ht = apache.HtpasswdFile.from_string(self.sample_01, default="plaintext")
- self.assertTrue(ht.set_password("user2", "pass2x"))
- self.assertFalse(ht.set_password("user5", "pass5"))
- self.assertEqual(ht.to_string(), self.sample_03)
-
# invalid user
self.assertRaises(ValueError, ht.set_password, "user:", "pass")
- # test that legacy update() still works
- with self.assertWarningList("update\(\) is deprecated"):
- ht.update("user2", "test")
- self.assertTrue(ht.check_password("user2", "test"))
-
def test_02_set_password_autosave(self):
path = self.mktemp()
sample = b'user1:pass1\n'
@@ -263,7 +241,7 @@ class HtpasswdFileTest(TestCase):
# users 1..6 of sample_01 run through all the main hash formats,
# to make sure they're recognized.
- for i in irange(1, 7):
+ for i in range(1, 7):
i = str(i)
try:
self.assertTrue(ht.check_password("user"+i, "pass"+i))
@@ -276,11 +254,6 @@ class HtpasswdFileTest(TestCase):
self.assertRaises(ValueError, ht.check_password, "user:", "pass")
- # test that legacy verify() still works
- with self.assertWarningList(["verify\(\) is deprecated"]*2):
- self.assertTrue(ht.verify("user1", "pass1"))
- self.assertFalse(ht.verify("user1", "pass2"))
-
def test_05_load(self):
"""test load()"""
# setup empty file
@@ -348,17 +321,16 @@ class HtpasswdFileTest(TestCase):
# check sample utf-8
ht = apache.HtpasswdFile.from_string(self.sample_04_utf8, encoding="utf-8",
return_unicode=True)
- self.assertEqual(ht.users(), [ u("user\u00e6") ])
+ self.assertEqual(ht.users(), [ u"user\u00e6" ])
- # test deprecated encoding=None
- with self.assertWarningList("``encoding=None`` is deprecated"):
- ht = apache.HtpasswdFile.from_string(self.sample_04_utf8, encoding=None)
- self.assertEqual(ht.users(), [ b'user\xc3\xa6' ])
+ # encoding=None should throw error
+ self.assertRaises(TypeError, apache.HtpasswdFile.from_string,
+ self.sample_04_utf8, encoding=None)
# check sample latin-1
ht = apache.HtpasswdFile.from_string(self.sample_04_latin1,
encoding="latin-1", return_unicode=True)
- self.assertEqual(ht.users(), [ u("user\u00e6") ])
+ self.assertEqual(ht.users(), [ u"user\u00e6" ])
def test_08_get_hash(self):
"""test get_hash()"""
@@ -367,9 +339,6 @@ class HtpasswdFileTest(TestCase):
self.assertEqual(ht.get_hash("user4"), b"pass4")
self.assertEqual(ht.get_hash("user5"), None)
- with self.assertWarningList("find\(\) is deprecated"):
- self.assertEqual(ht.find("user4"), b"pass4")
-
def test_09_to_string(self):
"""test to_string"""
@@ -602,11 +571,6 @@ class HtdigestFileTest(TestCase):
self.assertRaises(ValueError, ht.set_password, "user", "realm:", "pass")
self.assertRaises(ValueError, ht.set_password, "user", "r"*256, "pass")
- # test that legacy update() still works
- with self.assertWarningList("update\(\) is deprecated"):
- ht.update("user2", "realm2", "test")
- self.assertTrue(ht.check_password("user2", "test"))
-
# TODO: test set_password autosave
def test_03_users(self):
@@ -625,7 +589,7 @@ class HtdigestFileTest(TestCase):
self.assertRaises(TypeError, ht.check_password, 1, 'realm', 'pass5')
self.assertRaises(TypeError, ht.check_password, 'user', 1, 'pass5')
self.assertIs(ht.check_password("user5", "realm","pass5"), None)
- for i in irange(1,5):
+ for i in range(1, 5):
i = str(i)
self.assertTrue(ht.check_password("user"+i, "realm", "pass"+i))
self.assertIs(ht.check_password("user"+i, "realm", "pass5"), False)
@@ -636,11 +600,6 @@ class HtdigestFileTest(TestCase):
self.assertTrue(ht.check_password("user1", "pass1"))
self.assertIs(ht.check_password("user5", "pass5"), None)
- # test that legacy verify() still works
- with self.assertWarningList(["verify\(\) is deprecated"]*2):
- self.assertTrue(ht.verify("user1", "realm", "pass1"))
- self.assertFalse(ht.verify("user1", "realm", "pass2"))
-
# invalid user
self.assertRaises(ValueError, ht.check_password, "user:", "realm", "pass")
@@ -678,13 +637,6 @@ class HtdigestFileTest(TestCase):
hc.load(path)
self.assertEqual(hc.to_string(), self.sample_01)
- # change file, test deprecated force=False kwd
- ensure_mtime_changed(path)
- set_file(path, "")
- with self.assertWarningList(r"load\(force=False\) is deprecated"):
- ha.load(force=False)
- self.assertEqual(ha.to_string(), b"")
-
def test_06_save(self):
"""test save()"""
# load from file
@@ -725,9 +677,6 @@ class HtdigestFileTest(TestCase):
self.assertEqual(ht.get_hash("user4", "realm"), "ab7b5d5f28ccc7666315f508c7358519")
self.assertEqual(ht.get_hash("user5", "realm"), None)
- with self.assertWarningList("find\(\) is deprecated"):
- self.assertEqual(ht.find("user4", "realm"), "ab7b5d5f28ccc7666315f508c7358519")
-
def test_09_encodings(self):
"""test encoding parameter"""
# test bad encodings cause failure in constructor
@@ -735,13 +684,13 @@ class HtdigestFileTest(TestCase):
# check sample utf-8
ht = apache.HtdigestFile.from_string(self.sample_04_utf8, encoding="utf-8", return_unicode=True)
- self.assertEqual(ht.realms(), [ u("realm\u00e6") ])
- self.assertEqual(ht.users(u("realm\u00e6")), [ u("user\u00e6") ])
+ self.assertEqual(ht.realms(), [ u"realm\u00e6" ])
+ self.assertEqual(ht.users(u"realm\u00e6"), [ u"user\u00e6" ])
# check sample latin-1
ht = apache.HtdigestFile.from_string(self.sample_04_latin1, encoding="latin-1", return_unicode=True)
- self.assertEqual(ht.realms(), [ u("realm\u00e6") ])
- self.assertEqual(ht.users(u("realm\u00e6")), [ u("user\u00e6") ])
+ self.assertEqual(ht.realms(), [ u"realm\u00e6" ])
+ self.assertEqual(ht.users(u"realm\u00e6"), [ u"user\u00e6" ])
def test_10_to_string(self):
"""test to_string()"""