diff --git a/test/broker/01-connect-bad-packet.py b/test/broker/01-connect-bad-packet.py new file mode 100755 index 00000000..723e07e5 --- /dev/null +++ b/test/broker/01-connect-bad-packet.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +# Test whether a first packet of non-CONNECT is rejected. + +from mosq_test_helper import * + +rc = 1 +mid = 2 +publish_packet = mosq_test.gen_publish("pub/qos1/test", qos=1, mid=mid, payload="message") +puback_packet = mosq_test.gen_puback(mid) + + +port = mosq_test.get_port() +broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port) + +try: + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.settimeout(5) + sock.connect(("localhost", port)) + sock.send(publish_packet) + data = sock.recv(1) + sock.close() + if len(data) == 0: + rc = 0 +except socket.error: + rc = 0 +finally: + broker.terminate() + broker.wait() + (stdo, stde) = broker.communicate() + if rc: + print(stde) + +exit(rc) + diff --git a/test/broker/Makefile b/test/broker/Makefile index 102a7474..4336e50b 100644 --- a/test/broker/Makefile +++ b/test/broker/Makefile @@ -18,6 +18,7 @@ ptest : test-compile test : test-compile 01 02 03 04 05 06 07 08 09 10 11 12 01 : + ./01-connect-bad-packet.py ./01-connect-duplicate.py ./01-connect-duplicate-v5.py ./01-connect-success.py diff --git a/test/broker/ptest.py b/test/broker/ptest.py index 41f690b2..4ae7cdca 100755 --- a/test/broker/ptest.py +++ b/test/broker/ptest.py @@ -7,6 +7,7 @@ import sys max_running = 10 tests = [ #(ports required, 'path'), + (1, './01-connect-bad-packet.py'), (1, './01-connect-duplicate.py'), (1, './01-connect-duplicate-v5.py'), (1, './01-connect-success.py'),