MCPcopy Index your code
hub / github.com/GoogleCloudPlatform/cloud-sql-python-connector / create_ssl_context

Function create_ssl_context

tests/unit/mocks.py:195–214  ·  view source on GitHub ↗

Helper method to build an ssl.SSLContext for tests

(instance: FakeCSQLInstance)

Source from the content-addressed store, hash-verified

193
194
195async def create_ssl_context(instance: FakeCSQLInstance) -> ssl.SSLContext:
196 """Helper method to build an ssl.SSLContext for tests"""
197 client_private, client_bytes = await generate_keys()
198 client_key: rsa.RSAPublicKey = serialization.load_pem_public_key(
199 client_bytes.encode("UTF-8"),
200 ) # type: ignore
201 ephemeral_cert = client_key_signed_cert(
202 instance.server_ca, instance.server_key, client_key
203 )
204 # create SSL/TLS context
205 context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
206 context.check_hostname = False
207 # load ssl.SSLContext with certs
208 async with TemporaryDirectory() as tmpdir:
209 ca_filename, cert_filename, key_filename = await write_to_file(
210 tmpdir, instance.server_cert_pem, ephemeral_cert, client_private
211 )
212 context.load_cert_chain(cert_filename, keyfile=key_filename)
213 context.load_verify_locations(cafile=ca_filename)
214 return context
215
216
217class FakeCSQLInstance:

Callers 1

contextFunction · 0.90

Calls 3

generate_keysFunction · 0.90
write_to_fileFunction · 0.90
client_key_signed_certFunction · 0.85

Tested by 1

contextFunction · 0.72