def fixture_ca( mocker: MockerFixture, tmp_path: Path, ) -> CertificateAuthority: ca = CertificateAuthority(tmp_path / "ca", "test-ca") ca.initialize() mocker.patch( "agent_receiver.certificates.ROOT_CERT", ca._root_cert_path, ) return ca
def test_initialize(ca: certs.CertificateAuthority) -> None: assert not ca.is_initialized ca.initialize() assert ca.is_initialized cert, key = ca._get_root_certificate() assert check_cn( cert, CA_NAME, ) check_certificate_against_private_key( cert, key, )
def test_write_agent_receiver_certificate( ca: certs.CertificateAuthority) -> None: ca.initialize() assert not ca.agent_receiver_certificate_exists ca.create_agent_receiver_certificate() assert ca.agent_receiver_certificate_exists assert _file_permissions_is_660(ca._agent_receiver_cert_path) cert, key = load_cert_and_private_key(ca._agent_receiver_cert_path) assert check_cn( cert, "localhost", ) check_certificate_against_private_key( cert, key, ) check_certificate_against_public_key( cert, rsa_public_key_from_cert_or_csr(ca._get_root_certificate()[0]), )
def test_create_site_certificate(ca: certs.CertificateAuthority) -> None: ca.initialize() site_id = "xyz" assert not ca.site_certificate_exists(site_id) ca.create_site_certificate(site_id) assert ca.site_certificate_exists(site_id) assert _file_permissions_is_660(ca._site_certificate_path(site_id)) cert, key = load_cert_and_private_key(ca._site_certificate_path(site_id)) assert check_cn( cert, site_id, ) check_certificate_against_private_key( cert, key, ) check_certificate_against_public_key( cert, rsa_public_key_from_cert_or_csr(ca._get_root_certificate()[0]), )
def fixture_untrusted_cert(tmp_path: Path) -> Certificate: ca2 = CertificateAuthority(tmp_path / "ca-2", "test-ca-2") ca2.initialize() cert, _priv_key = ca2._certificate_from_root("abc123") return cert