MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_getpeercert

Method test_getpeercert

Lib/test/test_ssl.py:2909–2943  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2907 USE_SAME_TEST_CONTEXT = False
2908
2909 def test_getpeercert(self):
2910 if support.verbose:
2911 sys.stdout.write("\n")
2912
2913 client_context, server_context, hostname = testing_context()
2914 server = ThreadedEchoServer(context=server_context, chatty=False)
2915 with server:
2916 with client_context.wrap_socket(socket.socket(),
2917 do_handshake_on_connect=False,
2918 server_hostname=hostname) as s:
2919 s.connect((HOST, server.port))
2920 # getpeercert() raise ValueError while the handshake isn't
2921 # done.
2922 with self.assertRaises(ValueError):
2923 s.getpeercert()
2924 s.do_handshake()
2925 cert = s.getpeercert()
2926 self.assertTrue(cert, "Can't get peer certificate.")
2927 cipher = s.cipher()
2928 if support.verbose:
2929 sys.stdout.write(pprint.pformat(cert) + '\n')
2930 sys.stdout.write("Connection cipher is " + str(cipher) + '.\n')
2931 if 'subject' not in cert:
2932 self.fail("No subject field in certificate: %s." %
2933 pprint.pformat(cert))
2934 if ((('organizationName', 'Python Software Foundation'),)
2935 not in cert['subject']):
2936 self.fail(
2937 "Missing or invalid 'organizationName' field in certificate subject; "
2938 "should be 'Python Software Foundation'.")
2939 self.assertIn('notBefore', cert)
2940 self.assertIn('notAfter', cert)
2941 before = ssl.cert_time_to_seconds(cert['notBefore'])
2942 after = ssl.cert_time_to_seconds(cert['notAfter'])
2943 self.assertLess(before, after)
2944
2945 def test_crl_check(self):
2946 if support.verbose:

Callers

nothing calls this directly

Calls 15

testing_contextFunction · 0.85
ThreadedEchoServerClass · 0.85
strFunction · 0.85
wrap_socketMethod · 0.80
socketMethod · 0.80
assertTrueMethod · 0.80
pformatMethod · 0.80
assertInMethod · 0.80
writeMethod · 0.45
connectMethod · 0.45
assertRaisesMethod · 0.45
getpeercertMethod · 0.45

Tested by

no test coverage detected