aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mailman_pgp/config/tests/test_config.py5
-rw-r--r--src/mailman_pgp/model/list.py2
-rw-r--r--src/mailman_pgp/pgp/__init__.py12
-rw-r--r--src/mailman_pgp/pgp/keygen.py14
-rw-r--r--src/mailman_pgp/rest/tests/test_lists.py5
-rw-r--r--src/mailman_pgp/rules/tests/test_signature.py10
-rw-r--r--src/mailman_pgp/testing/__init__.py0
-rw-r--r--src/mailman_pgp/testing/layers.py64
-rw-r--r--src/mailman_pgp/tests/test_plugin.py4
9 files changed, 97 insertions, 19 deletions
diff --git a/src/mailman_pgp/config/tests/test_config.py b/src/mailman_pgp/config/tests/test_config.py
index c274d8e..0c2bfe7 100644
--- a/src/mailman_pgp/config/tests/test_config.py
+++ b/src/mailman_pgp/config/tests/test_config.py
@@ -17,15 +17,14 @@
from unittest import TestCase
-from mailman.testing.layers import ConfigLayer
-
from mailman_pgp.config import config
from mailman_pgp.database import Database
from mailman_pgp.pgp import PGP
+from mailman_pgp.testing.layers import PGPConfigLayer
class TestConfig(TestCase):
- layer = ConfigLayer
+ layer = PGPConfigLayer
def test_name(self):
self.assertEqual(config.name, 'pgp')
diff --git a/src/mailman_pgp/model/list.py b/src/mailman_pgp/model/list.py
index 7e80705..66f9af3 100644
--- a/src/mailman_pgp/model/list.py
+++ b/src/mailman_pgp/model/list.py
@@ -117,6 +117,8 @@ class PGPMailingList(Base):
if self._key_generator is None or \
not self._key_generator.is_alive():
self._generate(self.mlist)
+ else:
+ self._key_generator.join(0.2)
return self._key
@property
diff --git a/src/mailman_pgp/pgp/__init__.py b/src/mailman_pgp/pgp/__init__.py
index 80ed146..d273f5e 100644
--- a/src/mailman_pgp/pgp/__init__.py
+++ b/src/mailman_pgp/pgp/__init__.py
@@ -57,12 +57,14 @@ class PGP:
"""
# Get all the [keypairs] config variables.
self.keypair_config = dict(
- (k, config.get('keypairs', k)) for k in KEYPAIR_CONFIG_VARIABLES)
+ (k, config.get('keypairs', k)) for k in
+ KEYPAIR_CONFIG_VARIABLES)
# Get and expand all [keydirs] config paths against Mailman's paths.
self.keydir_config = dict(
- (k, expand(config.get('keydirs', k), None, mailman_config.paths))
- for k in KEYDIR_CONFIG_PATHS)
+ (k,
+ expand(config.get('keydirs', k), None, mailman_config.paths))
+ for k in KEYDIR_CONFIG_PATHS)
def _validate_config(self):
"""
@@ -75,14 +77,14 @@ class PGP:
raise ValueError('Invalid key_type. {}'.format(key_type))
self.keypair_config['key_type'] = KEYPAIR_TYPE_MAP[key_type]
self.keypair_config['key_length'] = int(
- self.keypair_config['key_length'])
+ self.keypair_config['key_length'])
subkey_type = self.keypair_config['subkey_type'].upper()
if subkey_type not in KEYPAIR_SUBKEY_TYPE_VALID:
raise ValueError('Invalid subkey_type. {}'.format(subkey_type))
self.keypair_config['subkey_type'] = KEYPAIR_TYPE_MAP[subkey_type]
self.keypair_config['subkey_length'] = int(
- self.keypair_config['subkey_length'])
+ self.keypair_config['subkey_length'])
# Make sure the keydir paths are directories and exist.
for keydir in self.keydir_config.values():
diff --git a/src/mailman_pgp/pgp/keygen.py b/src/mailman_pgp/pgp/keygen.py
index 06ca22b..c816b08 100644
--- a/src/mailman_pgp/pgp/keygen.py
+++ b/src/mailman_pgp/pgp/keygen.py
@@ -81,8 +81,7 @@ class ListKeyGenerator(mp.Process):
compression=[CompressionAlgorithm.ZLIB,
CompressionAlgorithm.BZ2,
CompressionAlgorithm.ZIP,
- CompressionAlgorithm.Uncompressed],
- primary=True)
+ CompressionAlgorithm.Uncompressed])
# Generate the posting + request uids.
main_uid = PGPUID.new(display_name, email=posting_address)
request_uid = PGPUID.new(display_name,
@@ -96,7 +95,7 @@ class ListKeyGenerator(mp.Process):
primary=False
)
# Put it all together.
- key.add_uid(main_uid, **key_params)
+ key.add_uid(main_uid, primary=True, **key_params)
key.add_uid(request_uid, **key_params)
key.add_subkey(subkey, **subkey_params)
return key
@@ -108,5 +107,10 @@ class ListKeyGenerator(mp.Process):
:param key:
:param key_path:
"""
- with open(key_path, 'w') as key_file:
- key_file.write(str(key))
+ try:
+ with open(key_path, 'w') as key_file:
+ key_file.write(str(key))
+ except FileNotFoundError:
+ # Just eat it up.
+ pass
+
diff --git a/src/mailman_pgp/rest/tests/test_lists.py b/src/mailman_pgp/rest/tests/test_lists.py
index 4a80bde..a7b1c2a 100644
--- a/src/mailman_pgp/rest/tests/test_lists.py
+++ b/src/mailman_pgp/rest/tests/test_lists.py
@@ -21,12 +21,13 @@ from urllib.error import HTTPError
from mailman.app.lifecycle import create_list
from mailman.database.transaction import transaction as mailman_transaction
from mailman.testing.helpers import call_api
-from mailman.testing.layers import RESTLayer
from pgpy import PGPKey
+from mailman_pgp.testing.layers import PGPRESTLayer
+
class TestLists(TestCase):
- layer = RESTLayer
+ layer = PGPRESTLayer
def setUp(self):
with mailman_transaction():
diff --git a/src/mailman_pgp/rules/tests/test_signature.py b/src/mailman_pgp/rules/tests/test_signature.py
index 1e509e7..86141a9 100644
--- a/src/mailman_pgp/rules/tests/test_signature.py
+++ b/src/mailman_pgp/rules/tests/test_signature.py
@@ -18,14 +18,20 @@ from unittest import TestCase
from mailman.app.lifecycle import create_list
from mailman.config import config
+from mailman.database.transaction import transaction as mailman_transaction
from mailman.testing.helpers import specialized_message_from_string as mfs
-from mailman.testing.layers import ConfigLayer
from mailman_pgp.rules.signature import Signature
+from mailman_pgp.testing.layers import PGPConfigLayer
class TestSignature(TestCase):
- layer = ConfigLayer
+ layer = PGPConfigLayer
+
+ def setUp(self):
+ with mailman_transaction():
+ self.mlist = create_list('nobody@example.com',
+ style_name='pgp-default')
def test_has_rule(self):
self.assertIn(Signature.name, config.rules.keys())
diff --git a/src/mailman_pgp/testing/__init__.py b/src/mailman_pgp/testing/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/mailman_pgp/testing/__init__.py
diff --git a/src/mailman_pgp/testing/layers.py b/src/mailman_pgp/testing/layers.py
new file mode 100644
index 0000000..d0d30d0
--- /dev/null
+++ b/src/mailman_pgp/testing/layers.py
@@ -0,0 +1,64 @@
+# 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/>.
+import os
+from os.path import isfile
+
+from mailman.testing.layers import ConfigLayer, RESTLayer, SMTPLayer
+
+from mailman_pgp.config import config
+from mailman_pgp.database import transaction
+from mailman_pgp.model.base import Base
+
+
+def reset_pgp_world():
+ for keydir in (config.pgp.keydir_config.values()):
+ for path in os.listdir(keydir):
+ if isfile(path):
+ os.remove(path)
+ with transaction():
+ Base.metadata.drop_all(config.db.engine)
+ Base.metadata.create_all(config.db.engine)
+
+
+class PGPConfigLayer(ConfigLayer):
+ @classmethod
+ def tearDown(cls):
+ reset_pgp_world()
+
+ @classmethod
+ def testTearDown(cls):
+ reset_pgp_world()
+
+
+class PGPSMTPLayer(SMTPLayer):
+ @classmethod
+ def tearDown(cls):
+ reset_pgp_world()
+
+ @classmethod
+ def testTearDown(cls):
+ reset_pgp_world()
+
+
+class PGPRESTLayer(RESTLayer):
+ @classmethod
+ def tearDown(cls):
+ reset_pgp_world()
+
+ @classmethod
+ def testTearDown(cls):
+ reset_pgp_world()
diff --git a/src/mailman_pgp/tests/test_plugin.py b/src/mailman_pgp/tests/test_plugin.py
index bcdf751..c216226 100644
--- a/src/mailman_pgp/tests/test_plugin.py
+++ b/src/mailman_pgp/tests/test_plugin.py
@@ -18,13 +18,13 @@
from unittest import TestCase
from mailman.config import config as mailman_config
-from mailman.testing.layers import ConfigLayer
from mailman_pgp.plugin import PGPMailman
+from mailman_pgp.testing.layers import PGPConfigLayer
class TestPlugin(TestCase):
- layer = ConfigLayer
+ layer = PGPConfigLayer
def test_instance_loaded(self):
self.assertIn('pgp', mailman_config.plugins.keys())