diff --git a/test/broker/01-bad-packets.py b/test/broker/01-bad-packets.py new file mode 100755 index 000000000..e56282e77 --- /dev/null +++ b/test/broker/01-bad-packets.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 + +# tests bad packets + +from mosq_test_helper import * + +rc = 0 +keepalive = 10 +port = mosq_test.get_port() + +def do_test(clientid, send, expected): + global rc + connect_packet = mosq_test.gen_connect(clientid, proto_ver=5, keepalive=keepalive) + connack_packet = mosq_test.gen_connack(rc=0, proto_ver=5) + + broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port) + + try: + sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port) + sock.send(send) + + except mosq_test.TestError: + pass + + finally: + broker.terminate() + broker.wait() + (stdo, stde) = broker.communicate() + stde_string = stde.decode('utf-8') + if expected not in stde_string: + print(clientid, 'test failed! Expected', expected) + print(stde_string) + rc += 1; + +pingreq_packet = mosq_test.gen_pingreq() +do_test('pingreq', pingreq_packet, 'Sending PINGRESP to pingreq') +do_test('reserved-command', b"\x0a\xc0t", 'Client reserved-command disconnected due to protocol error.') +do_test('reserved-flags', b"\xc1\x00", 'Client reserved-flags disconnected due to malformed packet.') +do_test('illegal-remaining', b"\xc0\x02\0x33\0x33", 'Client illegal-remaining disconnected due to malformed packet.') + + +exit(rc) diff --git a/test/broker/Makefile b/test/broker/Makefile index 5b0ed94e2..bc6707c65 100644 --- a/test/broker/Makefile +++ b/test/broker/Makefile @@ -24,6 +24,7 @@ msg_sequence_test: 01 : ./01-bad-initial-packets.py + ./01-bad-packets.py ./01-connect-575314.py ./01-connect-allow-anonymous.py ./01-connect-disconnect-v5.py diff --git a/test/broker/test.py b/test/broker/test.py index 28b54601b..559c88286 100755 --- a/test/broker/test.py +++ b/test/broker/test.py @@ -5,7 +5,8 @@ tests = [ #(ports required, 'path'), - (1, './01-bad-initial-packets.py'), + (1, './01-bad-initial-packets.py'), + (1, './01-bad-packets.py'), (1, './01-connect-575314.py'), (1, './01-connect-allow-anonymous.py'), (1, './01-connect-disconnect-v5.py'), @@ -70,7 +71,7 @@ (1, './04-retain-check-source-persist.py'), (1, './04-retain-check-source.py'), - (1, './04-retain-clear-multiple.py'), + (1, './04-retain-clear-multiple.py'), (1, './04-retain-qos0-clear.py'), (1, './04-retain-qos0-fresh.py'), (1, './04-retain-qos0-repeated.py'),