|
| 1 | +# Test whether a client produces a correct connect and subsequent disconnect when using SSL. |
| 2 | +# Client must provide a certificate. |
| 3 | +# |
| 4 | +# The client should connect with keepalive=60, clean session set, |
| 5 | +# and client id 08-ssl-connect-alpn |
| 6 | +# It should use the CA certificate ssl/all-ca.crt for verifying the server. |
| 7 | +# The test will send a CONNACK message to the client with rc=0. Upon receiving |
| 8 | +# the CONNACK and verifying that rc=0, the client should send a DISCONNECT |
| 9 | +# message. If rc!=0, the client should exit with an error. |
| 10 | +# |
| 11 | +# Additionally, the secure socket must have been negotiated with the "paho-test-protocol" |
| 12 | + |
| 13 | + |
| 14 | +from tests import paho_test |
| 15 | +from tests.paho_test import ssl |
| 16 | + |
| 17 | + |
| 18 | +def test_08_ssl_connect_alpn(alpn_ssl_server_socket, start_client): |
| 19 | + connect_packet = paho_test.gen_connect("08-ssl-connect-alpn", keepalive=60) |
| 20 | + connack_packet = paho_test.gen_connack(rc=0) |
| 21 | + disconnect_packet = paho_test.gen_disconnect() |
| 22 | + |
| 23 | + start_client("08-ssl-connect-alpn.py") |
| 24 | + |
| 25 | + (conn, address) = alpn_ssl_server_socket.accept() |
| 26 | + conn.settimeout(10) |
| 27 | + |
| 28 | + paho_test.expect_packet(conn, "connect", connect_packet) |
| 29 | + conn.send(connack_packet) |
| 30 | + |
| 31 | + paho_test.expect_packet(conn, "disconnect", disconnect_packet) |
| 32 | + |
| 33 | + if ssl.HAS_ALPN: |
| 34 | + negotiated_protocol = conn.selected_alpn_protocol() |
| 35 | + if negotiated_protocol != "paho-test-protocol": |
| 36 | + raise Exception(f"Unexpected protocol '{negotiated_protocol}'") |
| 37 | + |
| 38 | + conn.close() |
0 commit comments