summaryrefslogtreecommitdiff
path: root/tests/db/utils_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/db/utils_test.py')
-rw-r--r--tests/db/utils_test.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/db/utils_test.py b/tests/db/utils_test.py
index d07dd56a..8e00b1c2 100644
--- a/tests/db/utils_test.py
+++ b/tests/db/utils_test.py
@@ -11,7 +11,10 @@ import os
import os.path
import unittest
+import mock
+
from alot.db import utils
+from ..crypto_test import make_key
class TestGetParams(unittest.TestCase):
@@ -321,3 +324,49 @@ class TestDecodeHeader(unittest.TestCase):
expected = u'first\nsecond third fourth fifth'
actual = utils.decode_header(text, normalize=True)
self.assertEqual(actual, expected)
+
+
+class TestAddSignatureHeaders(unittest.TestCase):
+
+ class FakeMail(object):
+ def __init__(self):
+ self.headers = []
+
+ def add_header(self, header, value):
+ self.headers.append((header, value))
+
+ def test_length_0(self):
+ mail = self.FakeMail()
+ utils.add_signature_headers(mail, [], u'')
+ self.assertIn((utils.X_SIGNATURE_VALID_HEADER, u'False'), mail.headers)
+ self.assertIn(
+ (utils.X_SIGNATURE_MESSAGE_HEADER, u'Invalid: no signature found'),
+ mail.headers)
+
+ def test_valid(self):
+ mail = self.FakeMail()
+ key = make_key()
+
+ with mock.patch('alot.db.utils.crypto.get_key',
+ mock.Mock(return_value=key)), \
+ mock.patch('alot.db.utils.crypto.check_uid_validity',
+ mock.Mock(return_value=True)):
+ utils.add_signature_headers(mail, [mock.Mock(fpr=None)], u'')
+
+ self.assertIn((utils.X_SIGNATURE_VALID_HEADER, u'True'), mail.headers)
+ self.assertIn(
+ (utils.X_SIGNATURE_MESSAGE_HEADER, u'Valid: mocked'), mail.headers)
+
+ def test_untrusted(self):
+ mail = self.FakeMail()
+ key = make_key()
+
+ with mock.patch('alot.db.utils.crypto.get_key',
+ mock.Mock(return_value=key)), \
+ mock.patch('alot.db.utils.crypto.check_uid_validity',
+ mock.Mock(return_value=False)):
+ utils.add_signature_headers(mail, [mock.Mock(fpr=None)], u'')
+
+ self.assertIn((utils.X_SIGNATURE_VALID_HEADER, u'True'), mail.headers)
+ self.assertIn(
+ (utils.X_SIGNATURE_MESSAGE_HEADER, u'Untrusted: mocked'), mail.headers)