2016-10-15 09:04:35 +02:00
|
|
|
from datetime import datetime
|
2018-06-20 17:42:34 +02:00
|
|
|
|
|
|
|
import pytest
|
2016-10-15 09:04:35 +02:00
|
|
|
from marshmallow.exceptions import ValidationError
|
2016-10-09 02:04:54 +02:00
|
|
|
|
2018-06-20 17:42:34 +02:00
|
|
|
from lemur.common.utils import parse_private_key
|
|
|
|
from lemur.common.validators import verify_private_key_match
|
|
|
|
from lemur.tests.vectors import INTERMEDIATE_CERT, SAN_CERT, SAN_CERT_KEY
|
|
|
|
|
2016-10-09 02:04:54 +02:00
|
|
|
|
2016-10-15 09:04:35 +02:00
|
|
|
def test_private_key(session):
|
2018-06-20 17:42:34 +02:00
|
|
|
parse_private_key(SAN_CERT_KEY)
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
2019-05-16 16:57:02 +02:00
|
|
|
parse_private_key("invalid_private_key")
|
2018-06-20 17:42:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_validate_private_key(session):
|
|
|
|
key = parse_private_key(SAN_CERT_KEY)
|
2016-10-09 02:04:54 +02:00
|
|
|
|
2018-06-20 17:42:34 +02:00
|
|
|
verify_private_key_match(key, SAN_CERT)
|
2016-10-09 02:04:54 +02:00
|
|
|
|
2016-10-15 09:04:35 +02:00
|
|
|
with pytest.raises(ValidationError):
|
2018-06-20 17:42:34 +02:00
|
|
|
# Wrong key for certificate
|
|
|
|
verify_private_key_match(key, INTERMEDIATE_CERT)
|
2016-10-09 02:04:54 +02:00
|
|
|
|
|
|
|
|
2016-10-31 19:00:15 +01:00
|
|
|
def test_sub_alt_type(session):
|
|
|
|
from lemur.common.validators import sub_alt_type
|
|
|
|
|
|
|
|
with pytest.raises(ValidationError):
|
2019-05-16 16:57:02 +02:00
|
|
|
sub_alt_type("CNAME")
|
2016-10-31 19:00:15 +01:00
|
|
|
|
|
|
|
|
2016-10-15 09:04:35 +02:00
|
|
|
def test_dates(session):
|
|
|
|
from lemur.common.validators import dates
|
|
|
|
|
|
|
|
dates(dict(validity_start=datetime(2016, 1, 1), validity_end=datetime(2016, 1, 5)))
|
|
|
|
|
|
|
|
with pytest.raises(ValidationError):
|
|
|
|
dates(dict(validity_start=datetime(2016, 1, 1)))
|
|
|
|
|
|
|
|
with pytest.raises(ValidationError):
|
|
|
|
dates(dict(validity_end=datetime(2016, 1, 1)))
|
|
|
|
|
|
|
|
with pytest.raises(ValidationError):
|
2019-05-16 16:57:02 +02:00
|
|
|
dates(
|
|
|
|
dict(validity_start=datetime(2016, 1, 5), validity_end=datetime(2016, 1, 1))
|
|
|
|
)
|
2016-10-15 09:04:35 +02:00
|
|
|
|
|
|
|
with pytest.raises(ValidationError):
|
2019-05-16 16:57:02 +02:00
|
|
|
dates(
|
|
|
|
dict(
|
|
|
|
validity_start=datetime(2016, 1, 1), validity_end=datetime(2016, 1, 10)
|
|
|
|
)
|
|
|
|
)
|