1 |
5fdd01a6
|
Stanislav Král
|
import pytest
|
2 |
|
|
|
3 |
181e1196
|
Jan Pašek
|
from src.model.subject import Subject
|
4 |
|
|
from src.services.cryptography import CryptographyException
|
5 |
5fdd01a6
|
Stanislav Král
|
|
6 |
|
|
|
7 |
|
|
def test_verify_valid_ca(service):
|
8 |
|
|
# verify validation of valid certificates
|
9 |
|
|
private_key = service.create_private_key()
|
10 |
02f63b07
|
Stanislav Král
|
root_cert = service.create_sscrt(Subject(common_name="foo"), private_key)
|
11 |
5fdd01a6
|
Stanislav Král
|
child_cert = service.create_crt(Subject(common_name="Expired Foo"), private_key, root_cert, private_key, days=1)
|
12 |
|
|
|
13 |
dd03da19
|
Stanislav Král
|
assert service.verify_cert(root_cert)
|
14 |
|
|
assert service.verify_cert(child_cert)
|
15 |
5fdd01a6
|
Stanislav Král
|
|
16 |
|
|
|
17 |
|
|
def test_verify_invalid_ca(service):
|
18 |
|
|
# test whether expired certificate will fail to get verified
|
19 |
|
|
private_key = service.create_private_key()
|
20 |
02f63b07
|
Stanislav Král
|
root_cert = service.create_sscrt(Subject(common_name="foo"), private_key)
|
21 |
5fdd01a6
|
Stanislav Král
|
|
22 |
|
|
expired_cert = service.create_crt(Subject(common_name="Expired Foo"), private_key, root_cert, private_key, days=0)
|
23 |
|
|
|
24 |
dd03da19
|
Stanislav Král
|
assert not service.verify_cert(expired_cert)
|
25 |
5fdd01a6
|
Stanislav Král
|
|
26 |
|
|
|
27 |
|
|
def test_verify_invalid_cert_format(service):
|
28 |
|
|
# verify that certificate in invalid format raises <CryptographyException>
|
29 |
|
|
|
30 |
|
|
with pytest.raises(CryptographyException):
|
31 |
dd03da19
|
Stanislav Král
|
service.verify_cert("invalid cert")
|