(self)
| 2135 | self.assertTrue(s.getpeercert()) |
| 2136 | |
| 2137 | def test_connect_with_context(self): |
| 2138 | # Same as test_connect, but with a separately created context |
| 2139 | ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) |
| 2140 | ctx.check_hostname = False |
| 2141 | ctx.verify_mode = ssl.CERT_NONE |
| 2142 | with ctx.wrap_socket(socket.socket(socket.AF_INET)) as s: |
| 2143 | s.connect(self.server_addr) |
| 2144 | self.assertEqual({}, s.getpeercert()) |
| 2145 | # Same with a server hostname |
| 2146 | with ctx.wrap_socket(socket.socket(socket.AF_INET), |
| 2147 | server_hostname="dummy") as s: |
| 2148 | s.connect(self.server_addr) |
| 2149 | ctx.verify_mode = ssl.CERT_REQUIRED |
| 2150 | # This should succeed because we specify the root cert |
| 2151 | ctx.load_verify_locations(SIGNING_CA) |
| 2152 | with ctx.wrap_socket(socket.socket(socket.AF_INET)) as s: |
| 2153 | s.connect(self.server_addr) |
| 2154 | cert = s.getpeercert() |
| 2155 | self.assertTrue(cert) |
| 2156 | |
| 2157 | def test_connect_with_context_fail(self): |
| 2158 | # This should fail because we have no verification certs. Connection |
nothing calls this directly
no test coverage detected