summaryrefslogtreecommitdiff
path: root/tests/test_openpgp.py
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2017-10-28 00:01:33 +0200
committerMichał Górny <mgorny@gentoo.org>2017-10-28 00:01:33 +0200
commit3ed385e9d9fb4cf863b7dff9c542043af85ec78d (patch)
tree465087e273f1de27b79969cda2c7fcb72b41b0ff /tests/test_openpgp.py
parent0a4855d44a2cc1f19dcd6cab9f2e1d1c51c88ba5 (diff)
downloadgemato-3ed385e9d9fb4cf863b7dff9c542043af85ec78d.tar.gz
recursiveloader: Support writing signing Manifests
Diffstat (limited to 'tests/test_openpgp.py')
-rw-r--r--tests/test_openpgp.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/test_openpgp.py b/tests/test_openpgp.py
index d4a40a0..8e3adf6 100644
--- a/tests/test_openpgp.py
+++ b/tests/test_openpgp.py
@@ -173,6 +173,13 @@ XUy2tNfupdu72q9ske3dhVLhUEjtBzq5MlTf6gUjLBEsIHCGSafO2VG00lii3q4E
'''
+def strip_openpgp(text):
+ lines = text.lstrip().splitlines()
+ start = lines.index('')
+ stop = lines.index('-----BEGIN PGP SIGNATURE-----')
+ return '\n'.join(lines[start+1:stop-start+2]) + '\n'
+
+
class SignedManifestTest(unittest.TestCase):
"""
Test whether signed Manifest is read correctly.
@@ -270,6 +277,24 @@ class SignedManifestTest(unittest.TestCase):
finally:
shutil.rmtree(d)
+ def test_recursive_manifest_loader_save_manifest(self):
+ d = tempfile.mkdtemp()
+ try:
+ with io.open(os.path.join(d, 'Manifest'), 'w') as f:
+ f.write(MODIFIED_SIGNED_MANIFEST)
+
+ m = gemato.recursiveloader.ManifestRecursiveLoader(
+ os.path.join(d, 'Manifest'),
+ verify_openpgp=False)
+ self.assertFalse(m.openpgp_signed)
+ m.save_manifest('Manifest')
+
+ with io.open(os.path.join(d, 'Manifest'), 'r') as f:
+ self.assertEqual(f.read(),
+ strip_openpgp(MODIFIED_SIGNED_MANIFEST))
+ finally:
+ shutil.rmtree(d)
+
class OpenPGPCorrectKeyTest(unittest.TestCase):
"""
@@ -609,3 +634,49 @@ class OpenPGPPrivateKeyTest(unittest.TestCase):
f.seek(0)
m.load(f, openpgp_env=self.env)
self.assertFalse(m.openpgp_signed)
+
+ def test_recursive_manifest_loader_save_manifest(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=True,
+ openpgp_env=self.env)
+ self.assertTrue(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(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=True,
+ openpgp_env=self.env)
+ self.assertTrue(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)