Skip to content

Commit

Permalink
TST Add test to generate and load a private key
Browse files Browse the repository at this point in the history
  • Loading branch information
rth authored and oroulet committed Oct 16, 2024
1 parent 4711121 commit b5a6b60
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion asyncua/common/xmlimporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def _set_attr(self, atttype, fargs, attname: str, val):
self._set_attr(sub_atttype, subargs, attname2, v2)
if "Encoding" in subargs:
del subargs["Encoding"]
fargs[attname] = atttype(**subargs)
fargs[attname] = atttype(**subargs) # type: ignore[operator]
else:
raise RuntimeError(f"Could not handle type {atttype} of type {type(atttype)}")

Expand Down
12 changes: 11 additions & 1 deletion tests/test_gen_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from cryptography.x509.oid import ExtendedKeyUsageOID, NameOID
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey
from cryptography.x509.extensions import _key_identifier_from_public_key as key_identifier_from_public_key
from asyncua.crypto.cert_gen import generate_private_key, generate_app_certificate_signing_request, generate_self_signed_app_certificate, sign_certificate_request

from asyncua.crypto.uacrypto import load_private_key
from asyncua.crypto.cert_gen import generate_private_key, generate_app_certificate_signing_request, generate_self_signed_app_certificate, sign_certificate_request, dump_private_key_as_pem


async def test_create_self_signed_app_certificate() -> None:
Expand Down Expand Up @@ -198,3 +200,11 @@ async def test_app_sign_certificate_request() -> None:

assert cert.extensions.get_extension_for_class(
x509.ExtendedKeyUsage).value == csr.extensions.get_extension_for_class(x509.ExtendedKeyUsage).value

async def test_generate_load_private_key_pem(tmp_path):
key_path = tmp_path / "cert.pem"
key = generate_private_key()
key_path.write_bytes(dump_private_key_as_pem(key))

key2 = await load_private_key(key_path)
assert dump_private_key_as_pem(key) == dump_private_key_as_pem(key2)

0 comments on commit b5a6b60

Please sign in to comment.