def test_find(self): """Testing whether append works correctly.""" hs1 = apt_pkg.HashString("MD5Sum", "a60599e6200b60050d7a30721e3532ed") hs2 = apt_pkg.HashString("SHA1", "ef113338e654b1ada807a939ad47b3a67633391b") hsl = apt_pkg.HashStringList() hsl.append(hs1) hsl.append(hs2) self.assertEqual(hsl.find("MD5Sum").hashtype, "MD5Sum") self.assertEqual(hsl.find("SHA1").hashtype, "SHA1") self.assertEqual(hsl.find().hashtype, "SHA1")
def test_file_size(self): hsl = apt_pkg.HashStringList() self.assertEqual(hsl.file_size, 0) hsl.file_size = 42 self.assertEqual(hsl.file_size, 42) self.assertEqual(len(hsl), 1) # Verify that I can re-assign value (this handles the long case on # Python 2). hsl.file_size = hsl.file_size with self.assertRaises(OverflowError): hsl.file_size = -1 hsl.file_size = 0
def test_acquire_hashes(self): hs = apt_pkg.HashString("d41d8cd98f00b204e9800998ecf8427e") hsl = apt_pkg.HashStringList() hsl.append(hs) apt_pkg.AcquireFile(apt_pkg.Acquire(), "http://example.com", hash=hsl, destdir=self.file_unicode, destfile=self.file_unicode) apt_pkg.AcquireFile(apt_pkg.Acquire(), "http://example.com", hash=str(hs), destdir=self.file_unicode, destfile=self.file_unicode) self.assertRaises(TypeError, apt_pkg.AcquireFile, apt_pkg.Acquire(), "http://example.com", hash=hs, destdir=self.file_unicode, destfile=self.file_unicode)
def test_verify_file(self): with open(apt_pkg.__file__) as fobj: hashes = apt_pkg.Hashes(fobj) sha1 = apt_pkg.HashString("SHA1", hashes.sha1) sha256 = apt_pkg.HashString("SHA256", hashes.sha256) hsl = apt_pkg.HashStringList() hsl.append(sha1) hsl.append(sha256) self.assertTrue(hsl.verify_file(apt_pkg.__file__)) md5sum = apt_pkg.HashString("MD5Sum", "a60599e6200b60050d7a30721e3532ed") hsl.append(md5sum) self.assertFalse(hsl.verify_file(apt_pkg.__file__)) hsl2 = hashes.hashes self.assertIsInstance(hsl2, apt_pkg.HashStringList) self.assertGreater(len(hsl2), 0) self.assertTrue(hsl2.verify_file(apt_pkg.__file__))
def test_verify_file(self): with open(apt_pkg.__file__) as fobj: hashes = apt_pkg.Hashes(fobj) with warnings.catch_warnings(record=True): warnings.simplefilter("always") sha1 = hashes.hashes.find("sha1") sha256 = hashes.hashes.find("sha256") hsl = apt_pkg.HashStringList() hsl.append(sha1) hsl.append(sha256) self.assertTrue(hsl.verify_file(apt_pkg.__file__)) md5sum = apt_pkg.HashString("MD5Sum", "a60599e6200b60050d7a30721e3532ed") hsl.append(md5sum) self.assertFalse(hsl.verify_file(apt_pkg.__file__)) hsl2 = hashes.hashes self.assertIsInstance(hsl2, apt_pkg.HashStringList) self.assertGreater(len(hsl2), 0) self.assertTrue(hsl2.verify_file(apt_pkg.__file__))