Create context client_context, server_context, hostname = testing_context()
(server_cert=SIGNED_CERTFILE, *, server_chain=True)
| 284 | _TEST_CONTEXT = None |
| 285 | |
| 286 | def testing_context(server_cert=SIGNED_CERTFILE, *, server_chain=True): |
| 287 | """Create context |
| 288 | |
| 289 | client_context, server_context, hostname = testing_context() |
| 290 | """ |
| 291 | global _TEST_CONTEXT |
| 292 | if USE_SAME_TEST_CONTEXT: |
| 293 | if _TEST_CONTEXT is not None: |
| 294 | return _TEST_CONTEXT |
| 295 | |
| 296 | if server_cert == SIGNED_CERTFILE: |
| 297 | hostname = SIGNED_CERTFILE_HOSTNAME |
| 298 | elif server_cert == SIGNED_CERTFILE2: |
| 299 | hostname = SIGNED_CERTFILE2_HOSTNAME |
| 300 | elif server_cert == NOSANFILE: |
| 301 | hostname = NOSAN_HOSTNAME |
| 302 | else: |
| 303 | raise ValueError(server_cert) |
| 304 | |
| 305 | client_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) |
| 306 | client_context.load_verify_locations(SIGNING_CA) |
| 307 | |
| 308 | server_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) |
| 309 | server_context.load_cert_chain(server_cert) |
| 310 | if server_chain: |
| 311 | server_context.load_verify_locations(SIGNING_CA) |
| 312 | |
| 313 | if USE_SAME_TEST_CONTEXT: |
| 314 | if _TEST_CONTEXT is not None: |
| 315 | _TEST_CONTEXT = client_context, server_context, hostname |
| 316 | |
| 317 | return client_context, server_context, hostname |
| 318 | |
| 319 | |
| 320 | class BasicSocketTests(unittest.TestCase): |
no test coverage detected