aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/model/tests/test_fs_key.py
diff options
context:
space:
mode:
authorJ08nY2017-07-31 22:02:36 +0200
committerJ08nY2017-07-31 22:02:36 +0200
commitb16fe8644ddc82584a8ff9a2f98e40c1571437f2 (patch)
tree170f1c1eeeff3c3773a369202f7dad53760e9eb9 /src/mailman_pgp/model/tests/test_fs_key.py
parent4f815c200f62cf4e4bf660649066d9bd65393ae0 (diff)
downloadmailman-pgp-b16fe8644ddc82584a8ff9a2f98e40c1571437f2.tar.gz
mailman-pgp-b16fe8644ddc82584a8ff9a2f98e40c1571437f2.tar.zst
mailman-pgp-b16fe8644ddc82584a8ff9a2f98e40c1571437f2.zip
Diffstat (limited to 'src/mailman_pgp/model/tests/test_fs_key.py')
-rw-r--r--src/mailman_pgp/model/tests/test_fs_key.py99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/mailman_pgp/model/tests/test_fs_key.py b/src/mailman_pgp/model/tests/test_fs_key.py
new file mode 100644
index 0000000..8828e4b
--- /dev/null
+++ b/src/mailman_pgp/model/tests/test_fs_key.py
@@ -0,0 +1,99 @@
+# Copyright (C) 2017 Jan Jancar
+#
+# This file is a part of the Mailman PGP plugin.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>.
+
+""""""
+from os.path import join, exists
+from tempfile import TemporaryDirectory
+from unittest import TestCase
+
+from mailman_pgp.model.fs_key import FSKey
+from mailman_pgp.testing.layers import PGPLayer
+from mailman_pgp.testing.pgp import load_key
+
+
+class TestFSKey(TestCase):
+ layer = PGPLayer
+
+ def setUp(self):
+ self.tmpdir = TemporaryDirectory()
+
+ def tearDown(self):
+ self.tmpdir.cleanup()
+
+ def test_load(self):
+ key_name = 'something.asc'
+ key_path = join(self.tmpdir.name, key_name)
+ key_data = load_key('rsa_1024.priv.asc')
+ with open(key_path, 'w') as key_file:
+ key_file.write(str(key_data))
+
+ key = FSKey(self.tmpdir.name, key_name, False)
+ self.assertEqual(key.key_path, key_path)
+
+ key.load()
+ self.assertEqual(key.key.fingerprint, key_data.fingerprint)
+
+ def test_reload_none(self):
+ key_name = 'something.asc'
+ key = FSKey(self.tmpdir.name, key_name, False)
+ key_data = load_key('rsa_1024.priv.asc')
+ with open(key.key_path, 'w') as key_file:
+ key_file.write(str(key_data))
+
+ self.assertIsNone(key.key)
+ key.reload()
+ self.assertIsNotNone(key.key)
+ self.assertEqual(key.key.fingerprint, key_data.fingerprint)
+
+ def test_reload_not_none(self):
+ key_name = 'something.asc'
+ key_path = join(self.tmpdir.name, key_name)
+ key_data = load_key('rsa_1024.priv.asc')
+ new_key_data = load_key('ecc_p256.priv.asc')
+ with open(key_path, 'w') as key_file:
+ key_file.write(str(key_data))
+
+ key = FSKey(self.tmpdir.name, key_name, True)
+
+ with open(key_path, 'w') as key_file:
+ key_file.write(str(new_key_data))
+
+ key.reload()
+ self.assertIsNotNone(key.key)
+ self.assertEqual(key.key.fingerprint, new_key_data.fingerprint)
+
+ def test_save(self):
+ key_name = 'something.asc'
+ key = FSKey(self.tmpdir.name, key_name)
+ key_data = load_key('rsa_1024.priv.asc')
+
+ key.key = key_data
+ key.save()
+ self.assertTrue(exists(key.key_path))
+
+ def test_delete(self):
+ key_name = 'something.asc'
+ key_path = join(self.tmpdir.name, key_name)
+ key_data = load_key('rsa_1024.priv.asc')
+ with open(key_path, 'w') as key_file:
+ key_file.write(str(key_data))
+
+ key = FSKey(self.tmpdir.name, key_name, True)
+
+ key.delete()
+ self.assertFalse(exists(key.key_path))
+ self.assertIsNotNone(key.key)