diff options
author | Michał Górny <mgorny@gentoo.org> | 2017-10-28 00:14:27 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2017-10-28 00:14:27 +0200 |
commit | 2f604806c29b775f542f193d5a67716f648b5e6a (patch) | |
tree | 8d97224cc5009072f0ce2a5655cd5f183952d8c6 /tests/test_openpgp.py | |
parent | 3ed385e9d9fb4cf863b7dff9c542043af85ec78d (diff) | |
download | gemato-2f604806c29b775f542f193d5a67716f648b5e6a.tar.gz |
recursiveloader: Provide more fine-grained control over signing
Diffstat (limited to 'tests/test_openpgp.py')
-rw-r--r-- | tests/test_openpgp.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/test_openpgp.py b/tests/test_openpgp.py index 8e3adf6..ab0a82b 100644 --- a/tests/test_openpgp.py +++ b/tests/test_openpgp.py @@ -680,3 +680,81 @@ class OpenPGPPrivateKeyTest(unittest.TestCase): self.assertTrue(m2.openpgp_signed) finally: shutil.rmtree(d) + + def test_recursive_manifest_loader_save_manifest_force_sign(self): + d = tempfile.mkdtemp() + try: + with io.open(os.path.join(d, 'Manifest'), 'w') as f: + f.write(SIGNED_MANIFEST) + + m = gemato.recursiveloader.ManifestRecursiveLoader( + os.path.join(d, 'Manifest'), + verify_openpgp=False, + sign_openpgp=True, + openpgp_env=self.env) + self.assertFalse(m.openpgp_signed) + + self.env.import_key(io.BytesIO(PRIVATE_KEY)) + m.save_manifest('Manifest') + + m2 = gemato.manifest.ManifestFile() + with io.open(os.path.join(d, 'Manifest'), 'r') as f: + m2.load(f, openpgp_env=self.env) + self.assertTrue(m2.openpgp_signed) + finally: + shutil.rmtree(d) + + def test_recursive_manifest_loader_save_manifest_compressed_force_sign(self): + d = tempfile.mkdtemp() + try: + with gemato.compression.open_potentially_compressed_path( + os.path.join(d, 'Manifest.gz'), 'w') as cf: + cf.write(SIGNED_MANIFEST) + + m = gemato.recursiveloader.ManifestRecursiveLoader( + os.path.join(d, 'Manifest.gz'), + verify_openpgp=False, + sign_openpgp=True, + openpgp_env=self.env) + self.assertFalse(m.openpgp_signed) + + self.env.import_key(io.BytesIO(PRIVATE_KEY)) + m.save_manifest('Manifest.gz') + + m2 = gemato.manifest.ManifestFile() + with gemato.compression.open_potentially_compressed_path( + os.path.join(d, 'Manifest.gz'), 'r') as cf: + m2.load(cf, openpgp_env=self.env) + self.assertTrue(m2.openpgp_signed) + finally: + shutil.rmtree(d) + + def test_recursive_manifest_loader_save_submanifest_force_sign(self): + """ + Test that sub-Manifests are not signed. + """ + d = tempfile.mkdtemp() + try: + with io.open(os.path.join(d, 'Manifest'), 'w') as f: + f.write(SIGNED_MANIFEST) + os.mkdir(os.path.join(d, 'eclass')) + with io.open(os.path.join(d, 'eclass/Manifest'), 'w'): + pass + + m = gemato.recursiveloader.ManifestRecursiveLoader( + os.path.join(d, 'Manifest'), + verify_openpgp=False, + sign_openpgp=True, + openpgp_env=self.env) + self.assertFalse(m.openpgp_signed) + + self.env.import_key(io.BytesIO(PRIVATE_KEY)) + m.load_manifest('eclass/Manifest') + m.save_manifest('eclass/Manifest') + + m2 = gemato.manifest.ManifestFile() + with io.open(os.path.join(d, 'eclass/Manifest'), 'r') as f: + m2.load(f, openpgp_env=self.env) + self.assertFalse(m2.openpgp_signed) + finally: + shutil.rmtree(d) |