def run_test_for_domain(self, Verifier, url): with tempfile.TemporaryDirectory() as tmpd: package_path = os.path.join(tmpd, os.path.basename(url)) pkg_integrity.attempt_to_download(url, package_path) verifier = Verifier(**{'package_path': package_path, 'url': url}) return verifier.verify() return None
def test_from_disk(self): with tempfile.TemporaryDirectory() as tmpd: out_file = os.path.join(tmpd, os.path.basename(PACKAGE_URL)) out_key = out_file + '.asc' pkg_integrity.attempt_to_download(PACKAGE_URL, out_file) pkg_integrity.attempt_to_download(PACKAGE_URL + '.asc', out_key) result = pkg_integrity.from_disk(PACKAGE_URL, out_file, out_key) self.assertTrue(result)
def test_from_url(self): with tempfile.TemporaryDirectory() as tmpd: out_file = os.path.join(tmpd, os.path.basename(PACKAGE_URL)) pkg_integrity.attempt_to_download(PACKAGE_URL, out_file) out_file1 = os.path.join(tmpd, os.path.basename(XATTR_PKT_URL)) pkg_integrity.attempt_to_download(XATTR_PKT_URL, out_file1) result = pkg_integrity.from_url(PACKAGE_URL, tmpd) self.assertTrue(result)
def test_check_matching_sign_url(self): with tempfile.TemporaryDirectory() as tmpd: shutil.copy(os.path.join(TESTKEYDIR, "023A4420C7EC6914.pkey"), tmpd) out_file = os.path.join(tmpd, os.path.basename(PACKAGE_URL)) pkg_integrity.attempt_to_download(PACKAGE_URL, out_file) result = pkg_integrity.check(PACKAGE_URL, tmpd) self.assertTrue(result)
def test_check_with_existing_sign(self): """ Download signature for local verification """ with tempfile.TemporaryDirectory() as tmpd: out_file = os.path.join(tmpd, os.path.basename(NOSIGN_PKT_URL)) pkg_integrity.attempt_to_download(NOSIGN_PKT_URL, out_file) key_file = os.path.join(tmpd, os.path.basename(NOSIGN_PKT_URL)) pkg_integrity.attempt_to_download(NOSIGN_SIGN_URL, key_file + '.asc') result = pkg_integrity.check(NOSIGN_PKT_URL, tmpd) self.assertTrue(result)
def test_from_disk(self): with tempfile.TemporaryDirectory() as tmpd: shutil.copy(os.path.join(TESTKEYDIR, "023A4420C7EC6914.pkey"), tmpd) out_file = os.path.join(tmpd, os.path.basename(PACKAGE_URL)) out_key = out_file + '.asc' pkg_integrity.attempt_to_download(PACKAGE_URL, out_file) pkg_integrity.attempt_to_download(PACKAGE_URL + '.asc', out_key) result = pkg_integrity.from_disk(PACKAGE_URL, out_file, out_key) self.assertTrue(result)
def test_check_quit(self): with tempfile.TemporaryDirectory() as tmpd: with self.assertRaises(SystemExit) as a: out_file = os.path.join(tmpd, os.path.basename(NOSIGN_PKT_URL_BAD)) pkg_integrity.attempt_to_download(NOSIGN_PKT_URL_BAD, out_file) key_file = os.path.join(tmpd, os.path.basename(NOSIGN_PKT_URL_BAD)) pkg_integrity.attempt_to_download(NOSIGN_SIGN_URL, key_file + '.asc') result = pkg_integrity.check(NOSIGN_PKT_URL_BAD, tmpd) self.assertEqual(a.exception.code, 1)
def test_attempt_to_download(self): fakeURL = "https://download.my.url.com/file.tar.gz" realURLnoFile = "http://pypi.debian.net/alembic/alembic-0.8.8.non-existent.tar.gz" realURL = "http://pypi.debian.net/alembic/alembic-0.8.8.tar.gz" tmpf = tempfile.NamedTemporaryFile() fname = tmpf.name tmpf.close() self.assertEqual(pkg_integrity.attempt_to_download(fakeURL, fname), None) self.assertEqual( pkg_integrity.attempt_to_download(realURLnoFile, fname), 404) self.assertEqual(pkg_integrity.attempt_to_download(realURL, fname), 200) os.unlink(fname)
def test_check_matching_sign_url(self): with tempfile.TemporaryDirectory() as tmpd: out_file = os.path.join(tmpd, os.path.basename(PACKAGE_URL)) pkg_integrity.attempt_to_download(PACKAGE_URL, out_file) result = pkg_integrity.check(PACKAGE_URL, tmpd) self.assertTrue(result)
def test_result_on_nosign_package(self): with tempfile.TemporaryDirectory() as tmpd: out_file = os.path.join(tmpd, os.path.basename(NO_SIGN_PKT_URL)) pkg_integrity.attempt_to_download(NO_SIGN_PKT_URL, out_file) result = pkg_integrity.check(NO_SIGN_PKT_URL, tmpd) self.assertTrue(result is None)
def test_from_url(self): with tempfile.TemporaryDirectory() as tmpd: out_file = os.path.join(tmpd, os.path.basename(GEM_PKT)) pkg_integrity.attempt_to_download(GEM_PKT, out_file) result = pkg_integrity.from_url(GEM_PKT, tmpd) self.assertTrue(result)