aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp
diff options
context:
space:
mode:
authorJ08nY2017-07-31 02:34:00 +0200
committerJ08nY2017-07-31 02:34:00 +0200
commita07fe54b768359360bbcd84ea04dfe204637849d (patch)
tree7bd8256b8173dac249dbc07c493e6f4bcddb72f4 /src/mailman_pgp
parent6d87f5b0c8c7e7a3f71e0c5d5392201b4e4769ff (diff)
downloadmailman-pgp-a07fe54b768359360bbcd84ea04dfe204637849d.tar.gz
mailman-pgp-a07fe54b768359360bbcd84ea04dfe204637849d.tar.zst
mailman-pgp-a07fe54b768359360bbcd84ea04dfe204637849d.zip
Diffstat (limited to 'src/mailman_pgp')
-rw-r--r--src/mailman_pgp/config/tests/test_validator.py13
-rw-r--r--src/mailman_pgp/config/validator.py4
-rw-r--r--src/mailman_pgp/model/list.py8
-rw-r--r--src/mailman_pgp/model/tests/__init__.py0
-rw-r--r--src/mailman_pgp/model/tests/test_list.py41
-rw-r--r--src/mailman_pgp/rules/tests/test_signature.py18
-rw-r--r--src/mailman_pgp/styles/tests/test_base.py17
7 files changed, 94 insertions, 7 deletions
diff --git a/src/mailman_pgp/config/tests/test_validator.py b/src/mailman_pgp/config/tests/test_validator.py
index 15b0b62..d24dfc7 100644
--- a/src/mailman_pgp/config/tests/test_validator.py
+++ b/src/mailman_pgp/config/tests/test_validator.py
@@ -102,3 +102,16 @@ class TestValidator(TestCase):
""")
validator.validate(valid)
self.assertRaises(ValueError, validator.validate, invalid)
+
+ def test_none(self):
+ schema = """\
+ [test]
+ test_option:
+ """
+ validator = ConfigValidator(schema)
+ cfg = Config()
+ cfg.read_string("""\
+ [test]
+ test_option: something
+ """)
+ self.assertRaises(ValueError, validator.validate, cfg)
diff --git a/src/mailman_pgp/config/validator.py b/src/mailman_pgp/config/validator.py
index debbf0a..1010663 100644
--- a/src/mailman_pgp/config/validator.py
+++ b/src/mailman_pgp/config/validator.py
@@ -51,14 +51,12 @@ class ConfigValidator:
try:
call = find_name(schema)
except:
- try:
+ if len(schema) != 0:
def call(value):
match = re.search(schema, value)
if match is None:
raise ValueError
return match
- except:
- pass
if call is None:
raise ValueError
diff --git a/src/mailman_pgp/model/list.py b/src/mailman_pgp/model/list.py
index a0101a7..8448368 100644
--- a/src/mailman_pgp/model/list.py
+++ b/src/mailman_pgp/model/list.py
@@ -23,7 +23,7 @@ from os.path import exists, isfile, join
from flufl.lock import Lock
from mailman.database.types import Enum, SAUnicode
from mailman.interfaces.action import Action
-from mailman.interfaces.listmanager import IListManager, ListDeletedEvent
+from mailman.interfaces.listmanager import (IListManager, ListDeletingEvent)
from pgpy import PGPKey
from public import public
from sqlalchemy import Boolean, Column, Integer
@@ -153,9 +153,9 @@ class PGPMailingList(Base):
return PGPMailingList.query().filter_by(list_id=mlist.list_id).first()
-@classhandler.handler(ListDeletedEvent)
-def on_delete(mlist):
- pgp_list = PGPMailingList.for_list(mlist)
+@classhandler.handler(ListDeletingEvent)
+def on_delete(event):
+ pgp_list = PGPMailingList.for_list(event.mailing_list)
if pgp_list:
with transaction() as session:
# TODO shred the list key
diff --git a/src/mailman_pgp/model/tests/__init__.py b/src/mailman_pgp/model/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/mailman_pgp/model/tests/__init__.py
diff --git a/src/mailman_pgp/model/tests/test_list.py b/src/mailman_pgp/model/tests/test_list.py
new file mode 100644
index 0000000..58f52f2
--- /dev/null
+++ b/src/mailman_pgp/model/tests/test_list.py
@@ -0,0 +1,41 @@
+# 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 unittest import TestCase
+
+from mailman.app.lifecycle import create_list
+from mailman.interfaces.listmanager import IListManager
+from zope.component import getUtility
+
+from mailman_pgp.database import mm_transaction
+from mailman_pgp.model.list import PGPMailingList
+from mailman_pgp.testing.layers import PGPConfigLayer
+
+
+class TestPGPMailingList(TestCase):
+ layer = PGPConfigLayer
+
+ def setUp(self):
+ with mm_transaction():
+ self.mlist = create_list('test@example.com',
+ style_name='pgp-default')
+
+ def test_delete(self):
+ getUtility(IListManager).delete(self.mlist)
+ pgp_list = PGPMailingList.for_list(self.mlist)
+ self.assertIsNone(pgp_list)
diff --git a/src/mailman_pgp/rules/tests/test_signature.py b/src/mailman_pgp/rules/tests/test_signature.py
index c6bcb16..2dce173 100644
--- a/src/mailman_pgp/rules/tests/test_signature.py
+++ b/src/mailman_pgp/rules/tests/test_signature.py
@@ -19,6 +19,7 @@
from unittest import TestCase
from mailman.app.lifecycle import create_list
+from mailman.email.message import Message
from mailman.interfaces.action import Action
from mailman.interfaces.chain import AcceptEvent
from mailman.interfaces.member import MemberRole
@@ -245,3 +246,20 @@ class TestPostingEvent(TestCase):
sig_hash = PGPSigHash.query().filter_by(hash=hash).one()
self.assertIsNotNone(sig_hash)
self.assertEqual(sig_hash.fingerprint, self.sender_key.fingerprint)
+
+ def test_no_pgp_list(self):
+ with mm_transaction():
+ mlist = create_list('ordinary@example.com')
+ notify(AcceptEvent(mlist, Message(), dict(),
+ mm_config.chains[PGPChain.name]))
+
+ def test_no_pgp_address(self):
+ msg = mfs("""\
+From: anne@example.com
+To: test@example.com
+Subject: something
+
+Some text.
+""")
+ notify(AcceptEvent(self.mlist, msg, dict(),
+ mm_config.chains[PGPChain.name]))
diff --git a/src/mailman_pgp/styles/tests/test_base.py b/src/mailman_pgp/styles/tests/test_base.py
index d343fe4..6726d3a 100644
--- a/src/mailman_pgp/styles/tests/test_base.py
+++ b/src/mailman_pgp/styles/tests/test_base.py
@@ -18,6 +18,7 @@ from unittest import TestCase
from mailman.app.lifecycle import create_list
+from mailman_pgp.config import config
from mailman_pgp.model.list import PGPMailingList
from mailman_pgp.styles.base import PGPStyle
from mailman_pgp.testing.layers import PGPConfigLayer
@@ -42,3 +43,19 @@ class TestBaseStyle(TestCase):
# Test another apply doesn't fail
base_style.apply(mlist)
+
+ def test_autogenerate(self):
+ self.addCleanup(config.set, 'keypairs', 'autogenerate', 'no')
+ config.set('keypairs', 'autogenerate', 'yes')
+
+ # Create with default style.
+ mlist = create_list('test@example.com')
+ # Manually apply base PGPStyle.
+ base_style = PGPStyle()
+ base_style.apply(mlist)
+
+ pgp_list = PGPMailingList.for_list(mlist)
+
+ # Test that we have our PGPMailingList
+ self.assertIsNotNone(pgp_list)
+ self.assertIsNotNone(pgp_list.key)