This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.
@pytest.fixture(scope="module")defca_cert()->Certificate:"""Create a self-signed CA certificate for testing."""returnCertificate.create_ca(common_name="Test CA",organization_name="Test Organization",validity_days=365)
@pytest.fixturedefcert_with_extra_whitespace(client_cert:Certificate)->str:"""Returns a certificate PEM with extra whitespace."""returnf" {client_cert.cert_pem}\n\n "
@pytest.fixturedefcert_with_windows_line_endings(client_cert:Certificate)->str:"""Returns a certificate PEM with Windows line endings."""returnclient_cert.cert_pem.replace("\n","\r\n")
@pytest.fixture(scope="module")defexternal_ca_pem()->str:"""Provides an externally generated CA certificate PEM."""return"""-----BEGIN CERTIFICATE-----MIIB4TCCAYegAwIBAgIJAPZ9vcVfR8AdMAoGCCqGSM49BAMCMFExCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTEUMBIGA1UEBwwLU2FuIEZyYW5jaXNjbzEOMAwGA1UECgwFTXlPcmcxEzARBgNVBAMMCkV4dGVybmFsIENBMB4XDTI0MDgwMjEwNTgwMVoXDTM0MDczMDEwNTgwMVowUTELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMREwDwYDVQQHDAhTYW5EaWVnbzEOMAwGA1UECgwFTXlPcmcxEzARBgNVBAMMCkV4dGVybmFsIENBMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEgyF5Y8upm+M3ZzO8P4n7q2sS+L4cmhl5XGg3vIOwFf7lG8XZCgJ6Xy4t1t8oD3zY0m9X8H8Z4YhY7K6b7c8Y7Xv6Y9fVQ8M7Jg9nJ0x5c1N40zQwZzKjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBTGX00Gq7b09y/0C9eK0XgJp0mY7DAKBggqhkjOPQQDAgNJADBGAiEAx1xH/b83/u5t7r29a/THZnFjQ7pvT2N0L4hG4BgGgXACIQD02W2+MHB78ZWM+JOgikYj99qD6nLp0nkMyGmkSC7RYg==-----END CERTIFICATE-----"""
@pytest.fixturedefmalformed_cert_pem()->str:"""Returns a PEM certificate with incorrect headers."""return"-----BEGIN CERT-----\nMALFORMED DATA\n-----END CERT-----"
@pytest.fixturedeftemporary_cert_file(tmp_path:any,client_cert:Certificate)->str:"""Creates a temporary file containing the client certificate."""cert_file=tmp_path/"client_cert.pem"cert_file.write_text(client_cert.cert_pem)# Handle Windows drive letters in file URIscert_path=Path(cert_file)ifcert_path.drive:# Windows path with drive letterreturnf"file:///{pathname2url(str(cert_file))}"returnf"file://{cert_file}"
@pytest.fixturedeftemporary_key_file(tmp_path:any,client_cert:Certificate)->str:"""Creates a temporary file containing the client private key."""key_file=tmp_path/"client_key.pem"key_file.write_text(client_cert.key_pem)# Handle Windows drive letters in file URIskey_path=Path(key_file)ifkey_path.drive:# Windows path with drive letterreturnf"file:///{pathname2url(str(key_file))}"returnf"file://{key_file}"
@pytest.fixturedefvalid_cert_pem(client_cert:Certificate)->str:"""Get a valid certificate PEM from the client cert fixture."""returnclient_cert.cert_pem
@pytest.fixture(scope="module")defvalid_key_pem(client_cert:Certificate)->str:"""Get a valid key PEM from the client cert fixture."""returnclient_cert.key_pem