-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #249 from averevki/test-tlspolicy-attrs
Add tests for TLSPolicy certificate parameters
- Loading branch information
Showing
5 changed files
with
107 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"""Test parameters of TLS certificate generated by the TLSPolicy""" | ||
from datetime import timedelta | ||
|
||
import pytest | ||
from cryptography import x509 | ||
|
||
pytestmark = [pytest.mark.mgc] | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def dns_policy(): | ||
"""Don't need DNSPolicy because only testing certificate generated by TLSPolicy""" | ||
return None | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def tls_policy(tls_policy): | ||
"""Update TLSPolicy with custom certificate parameters""" | ||
tls_policy["commonName"] = "testCommonName" | ||
tls_policy["duration"] = "240h" | ||
tls_policy["usages"] = ["digital signature", "cert sign", "crl sign"] | ||
tls_policy["privateKey"] = { | ||
"algorithm": "ECDSA", | ||
"size": 384, | ||
} | ||
|
||
return tls_policy | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def tls_cert(upstream_gateway, gateway): # pylint: disable=unused-argument | ||
"""Return certificate generated by TLSPolicy""" | ||
return upstream_gateway.get_tls_cert() | ||
|
||
|
||
def test_tls_cert_common_name(tls_cert): | ||
"""Test certificate Common Name""" | ||
assert tls_cert.common_names[0].value == "testCommonName" | ||
|
||
|
||
def test_tls_cert_duration(tls_cert): | ||
"""Test certificate duration""" | ||
assert tls_cert.duration == timedelta(hours=240) | ||
|
||
|
||
def test_tls_cert_usages(tls_cert): | ||
"""Test certificate usages""" | ||
assert tls_cert.usages.digital_signature | ||
assert tls_cert.usages.key_cert_sign | ||
assert tls_cert.usages.crl_sign | ||
|
||
assert not tls_cert.usages.key_encipherment | ||
assert not tls_cert.usages.key_agreement | ||
|
||
|
||
def test_tls_cert_algorithm(tls_cert): | ||
"""Test certificate algorithm""" | ||
assert tls_cert.algorithm == x509.SignatureAlgorithmOID.ECDSA_WITH_SHA384 |