MCPcopy Create free account
hub / github.com/urllib3/urllib3 / setup_class

Method setup_class

test/with_dummyserver/test_https.py:99–130  ·  view source on GitHub ↗
(cls)

Source from the content-addressed store, hash-verified

97
98 @classmethod
99 def setup_class(cls) -> None:
100 super().setup_class()
101
102 cls.certs_dir = tempfile.mkdtemp()
103 # Start from existing root CA as we don't want to change the server certificate yet
104 with open(DEFAULT_CA, "rb") as crt, open(DEFAULT_CA_KEY, "rb") as key:
105 root_ca = trustme.CA.from_pem(crt.read(), key.read())
106
107 # Generate another CA to test verification failure
108 bad_ca = trustme.CA()
109 cls.bad_ca_path = os.path.join(cls.certs_dir, "ca_bad.pem")
110 bad_ca.cert_pem.write_to_path(cls.bad_ca_path)
111
112 # client cert chain
113 intermediate_ca = root_ca.create_child_ca()
114 cert = intermediate_ca.issue_cert("example.com")
115 encrypted_key = encrypt_key_pem(cert.private_key_pem, b"letmein")
116
117 cert.private_key_pem.write_to_path(
118 os.path.join(cls.certs_dir, CLIENT_INTERMEDIATE_KEY)
119 )
120 encrypted_key.write_to_path(
121 os.path.join(cls.certs_dir, PASSWORD_CLIENT_KEYFILE)
122 )
123 # Write the client cert and the intermediate CA
124 client_cert = os.path.join(cls.certs_dir, CLIENT_INTERMEDIATE_PEM)
125 cert.cert_chain_pems[0].write_to_path(client_cert)
126 cert.cert_chain_pems[1].write_to_path(client_cert, append=True)
127 # Write only the client cert
128 cert.cert_chain_pems[0].write_to_path(
129 os.path.join(cls.certs_dir, CLIENT_NO_INTERMEDIATE_PEM)
130 )
131
132 @classmethod
133 def teardown_class(cls) -> None:

Callers 1

poolFunction · 0.45

Calls 2

encrypt_key_pemFunction · 0.90
readMethod · 0.45

Tested by

no test coverage detected