summaryrefslogtreecommitdiff
path: root/tests/db
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2017-07-24 16:01:22 -0700
committerDylan Baker <dylan@pnwbakers.com>2017-07-24 16:36:12 -0700
commit380be7dd329332bbb193fddb7ba2207907106ea1 (patch)
tree06ec09b3b7c1b7927046a86c8d3fcb1087e69cd7 /tests/db
parent32f2de6877a8ff92cef9a8cef6a1f54be2e4935e (diff)
tests: Add some basic tests for alot.db.utils.add_signature_header
These are pretty basic, but they do cover most of the conditions, even if they rely heavily on mocking.
Diffstat (limited to 'tests/db')
-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)