Add support for verification of detached signatures.

This commit is contained in:
Roberto Rosario
2016-03-24 00:27:49 -04:00
parent a5f3d46373
commit d41dac5587
4 changed files with 71 additions and 26 deletions

View File

@@ -4,12 +4,13 @@ import tempfile
from django.test import TestCase
from ..exceptions import DecryptionError, KeyDoesNotExist
from ..exceptions import DecryptionError, KeyDoesNotExist, VerificationError
from ..models import Key
from .literals import (
TEST_KEY_DATA, TEST_KEY_FINGERPRINT, TEST_SEARCH_FINGERPRINT,
TEST_SEARCH_UID, TEST_SIGNED_FILE, TEST_SIGNED_FILE_CONTENT
TEST_DETACHED_SIGNATURE, TEST_FILE, TEST_KEY_DATA, TEST_KEY_FINGERPRINT,
TEST_SEARCH_FINGERPRINT, TEST_SEARCH_UID, TEST_SIGNED_FILE,
TEST_SIGNED_FILE_CONTENT
)
@@ -82,3 +83,19 @@ class KeyTestCase(TestCase):
Key.objects.decrypt_file(file_object=cleartext_file)
cleartext_file.close()
def test_detached_verification_no_key(self):
with open(TEST_DETACHED_SIGNATURE) as signature_file:
with open(TEST_FILE) as test_file:
with self.assertRaises(VerificationError):
Key.objects.verify_file(file_object=test_file, signature_file=signature_file)
def test_detached_verification_with_key(self):
Key.objects.create(key_data=TEST_KEY_DATA)
with open(TEST_DETACHED_SIGNATURE) as signature_file:
with open(TEST_FILE) as test_file:
result = Key.objects.verify_file(file_object=test_file, signature_file=signature_file)
self.assertTrue(result)
self.assertEqual(result.fingerprint, TEST_KEY_FINGERPRINT)