def test_serialize_certificate_raise_error(mocker): mock_cert = mocker.Mock() mock_cert.public_bytes.side_effect = Exception('Fake Error') with pytest.raises(X509CertificateError) as exc_info: serialize_certificate(mock_cert, serialization.Encoding.PEM) assert str( exc_info.value) == 'Could not get bytes from object: Fake Error.'
def test_serialize_certificate(mocker): mock_cert = mocker.Mock() fake_bytes = b'some_bytes' mock_cert.public_bytes.return_value = fake_bytes res = serialize_certificate(mock_cert, serialization.Encoding.PEM) assert res == fake_bytes
def test_extract_pem_bytes_from_certificate(): certs_bytes = _read_bytes('2-chain.pem') cert = parse_pem_certificates(certs_bytes)[0] cert_bytes = serialize_certificate(cert, serialization.Encoding.PEM) cert = parse_pem_certificates(cert_bytes)[0] assert isinstance(cert, Certificate) assert _extract_spiffe_id(cert) == _EXPECTED_SPIFFE_ID