def test_05_load(self): "test load()" if gae_env: return self.skipTest("GAE doesn't offer read/write filesystem access") #setup empty file path = mktemp() set_file(path, "") backdate_file_mtime(path, 5) ha = apache.HtdigestFile(path) self.assertEqual(ha.to_string(), b("")) #make changes, check force=False does nothing ha.update("user1", "realm", "pass1") ha.load(force=False) self.assertEqual(ha.to_string(), b('user1:realm:2a6cf53e7d8f8cf39d946dc880b14128\n')) #change file set_file(path, self.sample_01) ha.load(force=False) self.assertEqual(ha.to_string(), self.sample_01) #make changes, check force=True overwrites them ha.update("user5", "realm", "pass5") ha.load() self.assertEqual(ha.to_string(), self.sample_01) #test load w/ no path hb = apache.HtdigestFile() self.assertRaises(RuntimeError, hb.load) self.assertRaises(RuntimeError, hb.load, force=False)
def test_05_load(self): "test load()" if gae_env: return self.skipTest( "GAE doesn't offer read/write filesystem access") #setup empty file path = mktemp() set_file(path, "") backdate_file_mtime(path, 5) ha = apache.HtdigestFile(path) self.assertEqual(ha.to_string(), b("")) #make changes, check force=False does nothing ha.update("user1", "realm", "pass1") ha.load(force=False) self.assertEqual(ha.to_string(), b('user1:realm:2a6cf53e7d8f8cf39d946dc880b14128\n')) #change file set_file(path, self.sample_01) ha.load(force=False) self.assertEqual(ha.to_string(), self.sample_01) #make changes, check force=True overwrites them ha.update("user5", "realm", "pass5") ha.load() self.assertEqual(ha.to_string(), self.sample_01) #test load w/ no path hb = apache.HtdigestFile() self.assertRaises(RuntimeError, hb.load) self.assertRaises(RuntimeError, hb.load, force=False)
def test_00_constructor_autoload(self): "test constructor autoload" if gae_env: return self.skipTest("GAE doesn't offer read/write filesystem access") #check with existing file path = mktemp() set_file(path, self.sample_01) ht = apache.HtpasswdFile(path) self.assertEqual(ht.to_string(), self.sample_01) #check autoload=False ht = apache.HtpasswdFile(path, autoload=False) self.assertEqual(ht.to_string(), b("")) #check missing file os.remove(path) self.assertRaises(IOError, apache.HtpasswdFile, path)
def test_00_constructor_autoload(self): "test constructor autoload" if gae_env: return self.skipTest( "GAE doesn't offer read/write filesystem access") #check with existing file path = mktemp() set_file(path, self.sample_01) ht = apache.HtpasswdFile(path) self.assertEqual(ht.to_string(), self.sample_01) #check autoload=False ht = apache.HtpasswdFile(path, autoload=False) self.assertEqual(ht.to_string(), b("")) #check missing file os.remove(path) self.assertRaises(IOError, apache.HtpasswdFile, path)
def test_06_save(self): "test save()" if gae_env: return self.skipTest("GAE doesn't offer read/write filesystem access") #load from file path = mktemp() set_file(path, self.sample_01) ht = apache.HtdigestFile(path) #make changes, check they saved ht.delete("user1", "realm") ht.delete("user2", "realm") ht.save() self.assertEqual(get_file(path), self.sample_02) #test save w/ no path hb = apache.HtdigestFile() hb.update("user1", "realm", "pass1") self.assertRaises(RuntimeError, hb.save)
def test_06_save(self): "test save()" if gae_env: return self.skipTest( "GAE doesn't offer read/write filesystem access") #load from file path = mktemp() set_file(path, self.sample_01) ht = apache.HtdigestFile(path) #make changes, check they saved ht.delete("user1", "realm") ht.delete("user2", "realm") ht.save() self.assertEqual(get_file(path), self.sample_02) #test save w/ no path hb = apache.HtdigestFile() hb.update("user1", "realm", "pass1") self.assertRaises(RuntimeError, hb.save)
def test_01_from_path(self): "test CryptPolicy.from_path() constructor with encodings" if gae_env: return self.skipTest("GAE doesn't offer read/write filesystem access") path = mktemp() #test "\n" linesep set_file(path, self.sample_config_1s) policy = CryptPolicy.from_path(path) self.assertEqual(policy.to_dict(), self.sample_config_1pd) #test "\r\n" linesep set_file(path, self.sample_config_1s.replace("\n","\r\n")) policy = CryptPolicy.from_path(path) self.assertEqual(policy.to_dict(), self.sample_config_1pd) #test with custom encoding uc2 = to_bytes(self.sample_config_1s, "utf-16", source_encoding="utf-8") set_file(path, uc2) policy = CryptPolicy.from_path(path, encoding="utf-16") self.assertEqual(policy.to_dict(), self.sample_config_1pd)
def test_05_load(self): "test load()" if gae_env: return self.skipTest( "GAE doesn't offer read/write filesystem access") #setup empty file path = mktemp() set_file(path, "") backdate_file_mtime(path, 5) ha = apache.HtpasswdFile(path, default="plaintext") self.assertEqual(ha.to_string(), b("")) #make changes, check force=False does nothing ha.update("user1", "pass1") ha.load(force=False) self.assertEqual(ha.to_string(), b("user1:pass1\n")) #change file set_file(path, self.sample_01) ha.load(force=False) self.assertEqual(ha.to_string(), self.sample_01) #make changes, check force=True overwrites them ha.update("user5", "pass5") ha.load() self.assertEqual(ha.to_string(), self.sample_01) #test load w/ no path hb = apache.HtpasswdFile() self.assertRaises(RuntimeError, hb.load) self.assertRaises(RuntimeError, hb.load, force=False) #test load w/ dups set_file(path, self.sample_dup) hc = apache.HtpasswdFile(path) self.assertTrue(hc.verify('user1', 'pass1'))
def test_05_load(self): "test load()" if gae_env: return self.skipTest("GAE doesn't offer read/write filesystem access") #setup empty file path = mktemp() set_file(path, "") backdate_file_mtime(path, 5) ha = apache.HtpasswdFile(path, default="plaintext") self.assertEqual(ha.to_string(), b("")) #make changes, check force=False does nothing ha.update("user1", "pass1") ha.load(force=False) self.assertEqual(ha.to_string(), b("user1:pass1\n")) #change file set_file(path, self.sample_01) ha.load(force=False) self.assertEqual(ha.to_string(), self.sample_01) #make changes, check force=True overwrites them ha.update("user5", "pass5") ha.load() self.assertEqual(ha.to_string(), self.sample_01) #test load w/ no path hb = apache.HtpasswdFile() self.assertRaises(RuntimeError, hb.load) self.assertRaises(RuntimeError, hb.load, force=False) #test load w/ dups set_file(path, self.sample_dup) hc = apache.HtpasswdFile(path) self.assertTrue(hc.verify('user1','pass1'))