Example #1
0
 def test_01_delete_autosave(self):
     path = self.mktemp()
     sample = 'user1:pass1\nuser2:pass2\n'
     set_file(path, sample)
     ht = apache.HtpasswdFile(path)
     ht.delete('user1')
     self.assertEqual(get_file(path), sample)
     ht = apache.HtpasswdFile(path, autosave=True)
     ht.delete('user1')
     self.assertEqual(get_file(path), 'user2:pass2\n')
Example #2
0
 def test_02_set_password_autosave(self):
     path = self.mktemp()
     sample = 'user1:pass1\n'
     set_file(path, sample)
     ht = apache.HtpasswdFile(path)
     ht.set_password('user1', 'pass2')
     self.assertEqual(get_file(path), sample)
     ht = apache.HtpasswdFile(path,
                              default_scheme='plaintext',
                              autosave=True)
     ht.set_password('user1', 'pass2')
     self.assertEqual(get_file(path), 'user1:pass2\n')
Example #3
0
 def test_06_save(self):
     path = self.mktemp()
     set_file(path, self.sample_01)
     ht = apache.HtpasswdFile(path)
     ht.delete('user1')
     ht.delete('user2')
     ht.save()
     self.assertEqual(get_file(path), self.sample_02)
     hb = apache.HtpasswdFile(default_scheme='plaintext')
     hb.set_password('user1', 'pass1')
     self.assertRaises(RuntimeError, hb.save)
     hb.save(path)
     self.assertEqual(get_file(path), 'user1:pass1\n')
Example #4
0
 def test_00_constructor_autoload(self):
     path = self.mktemp()
     set_file(path, self.sample_01)
     ht = apache.HtpasswdFile(path)
     self.assertEqual(ht.to_string(), self.sample_01)
     self.assertEqual(ht.path, path)
     self.assertTrue(ht.mtime)
     ht.path = path + 'x'
     self.assertEqual(ht.path, path + 'x')
     self.assertFalse(ht.mtime)
     ht = apache.HtpasswdFile(path, new=True)
     self.assertEqual(ht.to_string(), '')
     self.assertEqual(ht.path, path)
     self.assertFalse(ht.mtime)
     with self.assertWarningList('``autoload=False`` is deprecated'):
         ht = apache.HtpasswdFile(path, autoload=False)
     self.assertEqual(ht.to_string(), '')
     self.assertEqual(ht.path, path)
     self.assertFalse(ht.mtime)
     os.remove(path)
     self.assertRaises(IOError, apache.HtpasswdFile, path)
Example #5
0
 def test_05_load(self):
     path = self.mktemp()
     set_file(path, '')
     backdate_file_mtime(path, 5)
     ha = apache.HtpasswdFile(path, default_scheme='plaintext')
     self.assertEqual(ha.to_string(), '')
     ha.set_password('user1', 'pass1')
     ha.load_if_changed()
     self.assertEqual(ha.to_string(), 'user1:pass1\n')
     set_file(path, self.sample_01)
     ha.load_if_changed()
     self.assertEqual(ha.to_string(), self.sample_01)
     ha.set_password('user5', 'pass5')
     ha.load()
     self.assertEqual(ha.to_string(), self.sample_01)
     hb = apache.HtpasswdFile()
     self.assertRaises(RuntimeError, hb.load)
     self.assertRaises(RuntimeError, hb.load_if_changed)
     set_file(path, self.sample_dup)
     hc = apache.HtpasswdFile()
     hc.load(path)
     self.assertTrue(hc.check_password('user1', 'pass1'))
Example #6
0
 def test_10_repr(self):
     ht = apache.HtpasswdFile('fakepath',
                              autosave=True,
                              new=True,
                              encoding='latin-1')
     repr(ht)
Example #7
0
 def test_09_to_string(self):
     ht = apache.HtpasswdFile.from_string(self.sample_01)
     self.assertEqual(ht.to_string(), self.sample_01)
     ht = apache.HtpasswdFile()
     self.assertEqual(ht.to_string(), '')
Example #8
0
 def check(scheme):
     ht = apache.HtpasswdFile(default_scheme=scheme)
     ht.set_password('user1', 'pass1')
     return ht.context.identify(ht.get_hash('user1'))