2016-10-15 00:04:35 -07:00
|
|
|
from datetime import datetime
|
2018-06-20 18:42:34 +03:00
|
|
|
|
|
|
|
import pytest
|
2016-10-15 00:04:35 -07:00
|
|
|
from marshmallow.exceptions import ValidationError
|
2016-10-08 19:04:54 -05:00
|
|
|
|
2018-06-20 18:42:34 +03: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-08 19:04:54 -05:00
|
|
|
|
2016-10-15 00:04:35 -07:00
|
|
|
def test_private_key(session):
|
2018-06-20 18:42:34 +03:00
|
|
|
parse_private_key(SAN_CERT_KEY)
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
2019-05-16 07:57:02 -07:00
|
|
|
parse_private_key("invalid_private_key")
|
2018-06-20 18:42:34 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_validate_private_key(session):
|
|
|
|
key = parse_private_key(SAN_CERT_KEY)
|
2016-10-08 19:04:54 -05:00
|
|
|
|
2018-06-20 18:42:34 +03:00
|
|
|
verify_private_key_match(key, SAN_CERT)
|
2016-10-08 19:04:54 -05:00
|
|
|
|
2016-10-15 00:04:35 -07:00
|
|
|
with pytest.raises(ValidationError):
|
2018-06-20 18:42:34 +03:00
|
|
|
# Wrong key for certificate
|
|
|
|
verify_private_key_match(key, INTERMEDIATE_CERT)
|
2016-10-08 19:04:54 -05:00
|
|
|
|
|
|
|
|
2016-10-31 11:00:15 -07:00
|
|
|
def test_sub_alt_type(session):
|
|
|
|
from lemur.common.validators import sub_alt_type
|
|
|
|
|
|
|
|
with pytest.raises(ValidationError):
|
2019-05-16 07:57:02 -07:00
|
|
|
sub_alt_type("CNAME")
|
2016-10-31 11:00:15 -07:00
|
|
|
|
|
|
|
|
2016-10-15 00:04:35 -07: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 07:57:02 -07:00
|
|
|
dates(
|
|
|
|
dict(validity_start=datetime(2016, 1, 5), validity_end=datetime(2016, 1, 1))
|
|
|
|
)
|
2016-10-15 00:04:35 -07:00
|
|
|
|
|
|
|
with pytest.raises(ValidationError):
|
2019-05-16 07:57:02 -07:00
|
|
|
dates(
|
|
|
|
dict(
|
|
|
|
validity_start=datetime(2016, 1, 1), validity_end=datetime(2016, 1, 10)
|
|
|
|
)
|
|
|
|
)
|