|
13 | 13 | from ietf.utils.mail import outbox, empty_outbox |
14 | 14 | from ietf.person.models import Person, Email |
15 | 15 | from ietf.group.models import Group, Role, RoleName |
| 16 | +from ietf.ietfauth.htpasswd import update_htpasswd_file |
16 | 17 |
|
17 | 18 | class IetfAuthTests(TestCase): |
18 | 19 | def setUp(self): |
| 20 | + self.saved_use_python_htdigest = getattr(settings, "USE_PYTHON_HTDIGEST", None) |
| 21 | + settings.USE_PYTHON_HTDIGEST = True |
| 22 | + |
19 | 23 | self.saved_htpasswd_file = settings.HTPASSWD_FILE |
20 | 24 | self.htpasswd_dir = os.path.abspath("tmp-htpasswd-dir") |
21 | 25 | os.mkdir(self.htpasswd_dir) |
22 | 26 | settings.HTPASSWD_FILE = os.path.join(self.htpasswd_dir, "htpasswd") |
23 | 27 | open(settings.HTPASSWD_FILE, 'a').close() # create empty file |
| 28 | + |
24 | 29 | self.saved_htdigest_realm = getattr(settings, "HTDIGEST_REALM", None) |
25 | 30 | settings.HTDIGEST_REALM = "test-realm" |
26 | 31 |
|
27 | 32 | def tearDown(self): |
28 | 33 | shutil.rmtree(self.htpasswd_dir) |
| 34 | + settings.USE_PYTHON_HTDIGEST = self.saved_use_python_htdigest |
29 | 35 | settings.HTPASSWD_FILE = self.saved_htpasswd_file |
30 | 36 | settings.HTDIGEST_REALM = self.saved_htdigest_realm |
31 | 37 |
|
@@ -71,8 +77,11 @@ def extract_confirm_url(self, confirm_email): |
71 | 77 | def username_in_htpasswd_file(self, username): |
72 | 78 | with open(settings.HTPASSWD_FILE) as f: |
73 | 79 | for l in f: |
74 | | - if l.startswith(username + ":" + settings.HTDIGEST_REALM): |
| 80 | + if l.startswith(username + ":"): |
75 | 81 | return True |
| 82 | + with open(settings.HTPASSWD_FILE) as f: |
| 83 | + print f.read() |
| 84 | + |
76 | 85 | return False |
77 | 86 |
|
78 | 87 | def test_create_account(self): |
@@ -260,3 +269,18 @@ def test_reset_password(self): |
260 | 269 | q = PyQuery(r.content) |
261 | 270 | self.assertEqual(len(q("form .has-error")), 0) |
262 | 271 | self.assertTrue(self.username_in_htpasswd_file(user.username)) |
| 272 | + |
| 273 | + def test_htpasswd_file_with_python(self): |
| 274 | + # make sure we test both Python and call-out to binary |
| 275 | + settings.USE_PYTHON_HTDIGEST = True |
| 276 | + |
| 277 | + update_htpasswd_file("foo", "passwd") |
| 278 | + self.assertTrue(self.username_in_htpasswd_file("foo")) |
| 279 | + |
| 280 | + def test_htpasswd_file_with_htpasswd_binary(self): |
| 281 | + # make sure we test both Python and call-out to binary |
| 282 | + settings.USE_PYTHON_HTDIGEST = False |
| 283 | + |
| 284 | + update_htpasswd_file("foo", "passwd") |
| 285 | + self.assertTrue(self.username_in_htpasswd_file("foo")) |
| 286 | + |
0 commit comments