(self)
| 3190 | USE_SAME_TEST_CONTEXT = False |
| 3191 | |
| 3192 | def test_getpeercert(self): |
| 3193 | if support.verbose: |
| 3194 | sys.stdout.write("\n") |
| 3195 | |
| 3196 | client_context, server_context, hostname = testing_context() |
| 3197 | server = ThreadedEchoServer(context=server_context, chatty=False) |
| 3198 | with server: |
| 3199 | with client_context.wrap_socket(socket.socket(), |
| 3200 | do_handshake_on_connect=False, |
| 3201 | server_hostname=hostname) as s: |
| 3202 | s.connect((HOST, server.port)) |
| 3203 | # getpeercert() raise ValueError while the handshake isn't |
| 3204 | # done. |
| 3205 | with self.assertRaises(ValueError): |
| 3206 | s.getpeercert() |
| 3207 | s.do_handshake() |
| 3208 | cert = s.getpeercert() |
| 3209 | self.assertTrue(cert, "Can't get peer certificate.") |
| 3210 | cipher = s.cipher() |
| 3211 | if support.verbose: |
| 3212 | sys.stdout.write(pprint.pformat(cert) + '\n') |
| 3213 | sys.stdout.write("Connection cipher is " + str(cipher) + '.\n') |
| 3214 | if 'subject' not in cert: |
| 3215 | self.fail("No subject field in certificate: %s." % |
| 3216 | pprint.pformat(cert)) |
| 3217 | if ((('organizationName', 'Python Software Foundation'),) |
| 3218 | not in cert['subject']): |
| 3219 | self.fail( |
| 3220 | "Missing or invalid 'organizationName' field in certificate subject; " |
| 3221 | "should be 'Python Software Foundation'.") |
| 3222 | self.assertIn('notBefore', cert) |
| 3223 | self.assertIn('notAfter', cert) |
| 3224 | before = ssl.cert_time_to_seconds(cert['notBefore']) |
| 3225 | after = ssl.cert_time_to_seconds(cert['notAfter']) |
| 3226 | self.assertLess(before, after) |
| 3227 | |
| 3228 | def test_crl_check(self): |
| 3229 | if support.verbose: |
nothing calls this directly
no test coverage detected