A brutal shutdown of an SSL server should raise an OSError in the client when attempting handshake.
(self)
| 3274 | s.read(1000) |
| 3275 | |
| 3276 | def test_rude_shutdown(self): |
| 3277 | """A brutal shutdown of an SSL server should raise an OSError |
| 3278 | in the client when attempting handshake. |
| 3279 | """ |
| 3280 | listener_ready = threading.Event() |
| 3281 | listener_gone = threading.Event() |
| 3282 | |
| 3283 | s = socket.socket() |
| 3284 | port = socket_helper.bind_port(s, HOST) |
| 3285 | |
| 3286 | # `listener` runs in a thread. It sits in an accept() until |
| 3287 | # the main thread connects. Then it rudely closes the socket, |
| 3288 | # and sets Event `listener_gone` to let the main thread know |
| 3289 | # the socket is gone. |
| 3290 | def listener(): |
| 3291 | s.listen() |
| 3292 | listener_ready.set() |
| 3293 | newsock, addr = s.accept() |
| 3294 | newsock.close() |
| 3295 | s.close() |
| 3296 | listener_gone.set() |
| 3297 | |
| 3298 | def connector(): |
| 3299 | listener_ready.wait() |
| 3300 | with socket.socket() as c: |
| 3301 | c.connect((HOST, port)) |
| 3302 | listener_gone.wait() |
| 3303 | try: |
| 3304 | ssl_sock = test_wrap_socket(c) |
| 3305 | except OSError: |
| 3306 | pass |
| 3307 | else: |
| 3308 | self.fail('connecting to closed SSL socket should have failed') |
| 3309 | |
| 3310 | t = threading.Thread(target=listener) |
| 3311 | t.start() |
| 3312 | try: |
| 3313 | connector() |
| 3314 | finally: |
| 3315 | t.join() |
| 3316 | |
| 3317 | def test_ssl_cert_verify_error(self): |
| 3318 | if support.verbose: |