Add support for verification of detached signatures.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user