def manifest_load_store(self, src_file): """ Loads a manifest object from a given sample in the data directory, then re-writes it and verifies that the result matches the original. """ src_file = get_data_fn(src_file) # the expected result is identical to what we feed into the # manifest parser with open(src_file) as f: expected_result = f.read() # create a manifest and parse the chosen test data mf = Manifest() mf.parse_file(src_file) result = mf.get_data() self.assertEquals( result, expected_result, "Manifest load/store does not match with file %s. Received:\n%s" % (src_file, result)) return mf
def test_verify_mf_checksums_no_whole_digest(self): sf_file = "test_manifest/sf-no-whole-digest.sf" mf_file = "test_manifest/sf-no-whole-digest.mf" sf = SignatureManifest() sf.parse_file(get_data_fn(sf_file)) mf = Manifest() mf.parse_file(get_data_fn(mf_file)) self.assertFalse( sf.verify_manifest_main_checksum(mf), "Verification of main signature in file %s against manifest %s" " succeeded, but the SF file has no Digest-Manifest section" % (sf_file, mf_file)) self.assertTrue( sf.verify_manifest_main_attributes_checksum(mf), "Verification of Main-Attibutes in file %s against manifest %s" "failed" % (sf_file, mf_file)) errors = sf.verify_manifest_entry_checksums(mf) self.assertEqual( 0, len(errors), "The following entries in signature file %s against manifest %s" " failed: %s" % (sf_file, mf_file, ",".join(errors)))
def test_add_jar_entries(self): mf = Manifest() mf.parse_file(get_data_fn("test_manifest/no-entries.mf")) mf.add_jar_entries(get_data_fn("test_manifest/junk-entries.jar"), "SHA-512") self.assertIsNotNone(mf.sub_sections.get("README.md", None), "Expected entry not added to the manifest")
def test_verify_mf_checksums_no_whole_digest(self): sf_file = "sf-no-whole-digest.sf" mf_file = "sf-no-whole-digest.mf" sf = SignatureManifest() sf.parse_file(get_data_fn(sf_file)) mf = Manifest() mf.parse_file(get_data_fn(mf_file)) error_message = sf.verify_manifest_checksums(mf) self.assertIsNone(error_message, "Verification of signature file %s against manifest %s failed: %s" % (sf_file, mf_file, error_message))
def test_verify_mf_checksums_no_whole_digest(self): sf_file = "sf-no-whole-digest.sf" mf_file = "sf-no-whole-digest.mf" sf = SignatureManifest() sf.parse_file(get_data_fn(sf_file)) mf = Manifest() mf.parse_file(get_data_fn(mf_file)) error_message = sf.verify_manifest_checksums(mf) self.assertIsNone( error_message, "Verification of signature file %s against manifest %s failed: %s" % (sf_file, mf_file, error_message))
def test_multi_digests(self): jar_file = "multi-digests.jar" mf_ok_file = "one-valid-digest-of-several.mf" mf = Manifest() mf.parse_file(get_data_fn(mf_ok_file)) error_message = mf.verify_jar_checksums(get_data_fn(jar_file)) self.assertIsNone(error_message, "Digest verification of %s against JAR %s failed: %s" \ % (mf_ok_file, jar_file, error_message)) sf_ok_file = "one-valid-digest-of-several.sf" sf = SignatureManifest() sf.parse_file(get_data_fn(sf_ok_file)) error_message = sf.verify_manifest_checksums(mf) self.assertIsNone(error_message, "Signature file digest verification of %s against manifest %s failed: %s" \ % (sf_ok_file, mf_ok_file, error_message))
def test_multi_digests(self): jar_file = "multi-digests.jar" mf_ok_file = "one-valid-digest-of-several.mf" mf = Manifest() mf.parse_file(get_data_fn(mf_ok_file)) errors = mf.verify_jar_checksums(get_data_fn(jar_file)) self.assertEqual( 0, len(errors), "The following entries in jar file %s do not match" " in manifest %s: %s" % (jar_file, mf_ok_file, ",".join(errors))) sf_ok_file = "one-valid-digest-of-several.sf" sf = SignatureManifest() sf.parse_file(get_data_fn(sf_ok_file)) errors = sf.verify_manifest(mf) self.assertEqual( 0, len(errors), "The following entries in signature file %s against manifest %s" " failed: %s" % (sf_ok_file, mf_ok_file, ",".join(errors)))
def test_multi_digests(self): jar_file = "test_manifest/multi-digests.jar" mf_ok_file = "test_manifest/one-valid-digest-of-several.mf" mf = Manifest() mf.parse_file(get_data_fn(mf_ok_file)) errors = mf.verify_jar_checksums(get_data_fn(jar_file)) self.assertEqual( 0, len(errors), "The following entries in jar file %s do not match" " in manifest %s: %s" % (jar_file, mf_ok_file, ",".join(errors))) sf_ok_file = "test_manifest/one-valid-digest-of-several.sf" sf = SignatureManifest() sf.parse_file(get_data_fn(sf_ok_file)) errors = sf.verify_manifest(mf) self.assertEqual( 0, len(errors), "The following entries in signature file %s against manifest %s" " failed: %s" % (sf_ok_file, mf_ok_file, ",".join(errors)))
def test_verify_mf_checksums_no_whole_digest(self): sf_file = "sf-no-whole-digest.sf" mf_file = "sf-no-whole-digest.mf" sf = SignatureManifest() sf.parse_file(get_data_fn(sf_file)) mf = Manifest() mf.parse_file(get_data_fn(mf_file)) self.assertFalse( sf.verify_manifest_main_checksum(mf), "Verification of main signature in file %s against manifest %s" " succeeded, but the SF file has no Digest-Manifest section" % (sf_file, mf_file)) self.assertTrue( sf.verify_manifest_main_attributes_checksum(mf), "Verification of Main-Attibutes in file %s against manifest %s" "failed" % (sf_file, mf_file)) errors = sf.verify_manifest_entry_checksums(mf) self.assertEqual( 0, len(errors), "The following entries in signature file %s against manifest %s" " failed: %s" % (sf_file, mf_file, ",".join(errors)))