A brutal shutdown of an SSL server should raise an OSError in the client when attempting handshake.
(self)
| 3557 | s.read(1000) |
| 3558 | |
| 3559 | def test_rude_shutdown(self): |
| 3560 | """A brutal shutdown of an SSL server should raise an OSError |
| 3561 | in the client when attempting handshake. |
| 3562 | """ |
| 3563 | listener_ready = threading.Event() |
| 3564 | listener_gone = threading.Event() |
| 3565 | |
| 3566 | s = socket.socket() |
| 3567 | port = socket_helper.bind_port(s, HOST) |
| 3568 | |
| 3569 | # `listener` runs in a thread. It sits in an accept() until |
| 3570 | # the main thread connects. Then it rudely closes the socket, |
| 3571 | # and sets Event `listener_gone` to let the main thread know |
| 3572 | # the socket is gone. |
| 3573 | def listener(): |
| 3574 | s.listen() |
| 3575 | listener_ready.set() |
| 3576 | newsock, addr = s.accept() |
| 3577 | newsock.close() |
| 3578 | s.close() |
| 3579 | listener_gone.set() |
| 3580 | |
| 3581 | def connector(): |
| 3582 | listener_ready.wait() |
| 3583 | with socket.socket() as c: |
| 3584 | c.connect((HOST, port)) |
| 3585 | listener_gone.wait() |
| 3586 | try: |
| 3587 | ssl_sock = test_wrap_socket(c) |
| 3588 | except OSError: |
| 3589 | pass |
| 3590 | else: |
| 3591 | self.fail('connecting to closed SSL socket should have failed') |
| 3592 | |
| 3593 | t = threading.Thread(target=listener) |
| 3594 | t.start() |
| 3595 | try: |
| 3596 | connector() |
| 3597 | finally: |
| 3598 | t.join() |
| 3599 | |
| 3600 | def test_ssl_cert_verify_error(self): |
| 3601 | if support.verbose: |