aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/rules
diff options
context:
space:
mode:
authorJ08nY2017-06-29 00:53:23 +0200
committerJ08nY2017-06-29 00:53:23 +0200
commit471b222e1c6c4c850c84ec8e268ec4e003f02360 (patch)
treeffda7354aebf45af7764cc0208db6939d8ca5474 /src/mailman_pgp/rules
parent912e64d36e92ab19a4c05abeb943afa34da2186b (diff)
downloadmailman-pgp-471b222e1c6c4c850c84ec8e268ec4e003f02360.tar.gz
mailman-pgp-471b222e1c6c4c850c84ec8e268ec4e003f02360.tar.zst
mailman-pgp-471b222e1c6c4c850c84ec8e268ec4e003f02360.zip
Diffstat (limited to 'src/mailman_pgp/rules')
-rw-r--r--src/mailman_pgp/rules/tests/test_encryption.py50
-rw-r--r--src/mailman_pgp/rules/tests/test_signature.py21
2 files changed, 63 insertions, 8 deletions
diff --git a/src/mailman_pgp/rules/tests/test_encryption.py b/src/mailman_pgp/rules/tests/test_encryption.py
new file mode 100644
index 0000000..276a9f3
--- /dev/null
+++ b/src/mailman_pgp/rules/tests/test_encryption.py
@@ -0,0 +1,50 @@
+# 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.testing.helpers import specialized_message_from_string as mfs
+
+from mailman_pgp.config import mm_config
+from mailman_pgp.database import mm_transaction
+from mailman_pgp.rules.encryption import Encryption
+from mailman_pgp.testing.layers import PGPConfigLayer
+
+
+class TestEncryptionRule(TestCase):
+ layer = PGPConfigLayer
+
+ def setUp(self):
+ self.rule = Encryption()
+ with mm_transaction():
+ self.mlist = create_list('test@example.com',
+ style_name='pgp-default')
+
+ def test_has_rule(self):
+ self.assertIn(Encryption.name, mm_config.rules.keys())
+
+ def test_matches(self):
+ msgdata = {'pgp_moderate': True}
+ msg = mfs("""\
+From: anne@example.com
+To: test@example.com
+
+""")
+ self.assertTrue(self.rule.check(self.mlist, msg, msgdata))
+ msgdata['pgp_moderate'] = False
+ self.assertFalse(self.rule.check(self.mlist, msg, msgdata))
+ self.assertFalse(self.rule.check(self.mlist, msg, {}))
diff --git a/src/mailman_pgp/rules/tests/test_signature.py b/src/mailman_pgp/rules/tests/test_signature.py
index a7eec5a..2f5881a 100644
--- a/src/mailman_pgp/rules/tests/test_signature.py
+++ b/src/mailman_pgp/rules/tests/test_signature.py
@@ -17,7 +17,6 @@
from unittest import TestCase
from mailman.app.lifecycle import create_list
-from mailman.config import config
from mailman.interfaces.action import Action
from mailman.interfaces.member import MemberRole
from mailman.interfaces.usermanager import IUserManager
@@ -25,6 +24,7 @@ from mailman.testing.helpers import (set_preferred,
specialized_message_from_string as mfs)
from zope.component import getUtility
+from mailman_pgp.config import mm_config
from mailman_pgp.database import mm_transaction, transaction
from mailman_pgp.model.address import PGPAddress
from mailman_pgp.model.list import PGPMailingList
@@ -33,7 +33,7 @@ from mailman_pgp.rules.signature import Signature
from mailman_pgp.testing.layers import PGPConfigLayer
-class TestSignature(TestCase):
+class TestSignatureRule(TestCase):
layer = PGPConfigLayer
def setUp(self):
@@ -41,7 +41,7 @@ class TestSignature(TestCase):
user_manager = getUtility(IUserManager)
with mm_transaction():
- self.mlist = create_list('nobody@example.com',
+ self.mlist = create_list('test@example.com',
style_name='pgp-default')
self.sender = user_manager.create_user('RSA-1024b@example.org')
set_preferred(self.sender)
@@ -64,14 +64,14 @@ class TestSignature(TestCase):
'data/mime_signed_invalid.eml')
def test_has_rule(self):
- self.assertIn(Signature.name, config.rules.keys())
+ self.assertIn(Signature.name, mm_config.rules.keys())
def test_no_pgp_list(self):
with mm_transaction():
- ordinary_list = create_list('test@example.com')
+ ordinary_list = create_list('odrinary@example.com')
msg = mfs("""\
From: anne@example.com
-To: test@example.com
+To: ordinary@example.com
""")
@@ -83,14 +83,19 @@ To: test@example.com
self.pgp_list.unsigned_msg_action = Action.defer
msg = mfs("""\
From: anne@example.com
-To: nobody@example.com
+To: test@example.com
""")
with self.assertRaises(ValueError):
self.rule.check(self.mlist, msg, {})
def test_no_key(self):
- pass
+ with transaction():
+ self.pgp_sender.key = None
+
+ msgdata = {}
+ with self.assertRaises(ValueError):
+ self.rule.check(self.mlist, self.msg_mime_signed, msgdata)
def assertAction(self, msgdata, action, reasons):
self.assertEqual(msgdata['moderation_action'], action.name)