From 77813949e7dbadc77c51be9ee77bbbee1d7fe39d Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 30 Apr 2019 09:59:28 +0100 Subject: [PATCH] Test for Will property usage. --- test/broker/07-will-properties.py | 93 +++++++++++++++++++++++++++++++ test/broker/Makefile | 1 + test/broker/test.py | 1 + 3 files changed, 95 insertions(+) create mode 100755 test/broker/07-will-properties.py diff --git a/test/broker/07-will-properties.py b/test/broker/07-will-properties.py new file mode 100755 index 00000000..b9e78d01 --- /dev/null +++ b/test/broker/07-will-properties.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python3 + +# Test for bug #1244. This occurs if a V5 will message is used where the first +# Will property is one of: content-type, payload-format-indicator, +# response-topic. These are the properties that are attached to the will for +# later use, as opposed to e.g. will-delay-interval which is a value which is +# read immediately and not passed + +from mosq_test_helper import * + +def do_test(will_props, recvd_props): + rc = 1 + keepalive = 60 + + mid = 1 + connect1_packet = mosq_test.gen_connect("will-helper", keepalive=keepalive, proto_ver=5) + connack1_packet = mosq_test.gen_connack(rc=0, proto_ver=5) + + subscribe1_packet = mosq_test.gen_subscribe(mid, "will/test", 0, proto_ver=5) + suback1_packet = mosq_test.gen_suback(mid, 0, proto_ver=5) + + connect2_packet = mosq_test.gen_connect("will-test", keepalive=keepalive, proto_ver=5, will_topic="will/test", will_payload=b"will payload", will_properties=will_props) + connack2_packet = mosq_test.gen_connack(rc=0, proto_ver=5) + + publish_packet = mosq_test.gen_publish("will/test", qos=0, payload="will payload", proto_ver=5, properties=recvd_props) + + port = mosq_test.get_port() + broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port) + + try: + sock1 = mosq_test.do_client_connect(connect1_packet, connack1_packet, timeout=30, port=port) + mosq_test.do_send_receive(sock1, subscribe1_packet, suback1_packet, "suback") + + sock2 = mosq_test.do_client_connect(connect2_packet, connack2_packet, timeout=30, port=port) + sock2.close() + + if mosq_test.expect_packet(sock1, "publish", publish_packet): + rc = 0 + + sock1.close() + finally: + broker.terminate() + broker.wait() + (stdo, stde) = broker.communicate() + if rc: + print(stde.decode('utf-8')) + exit(rc) + + +# Single test property +will_props = mqtt5_props.gen_string_prop(mqtt5_props.PROP_RESPONSE_TOPIC, "response/topic") +#do_test(will_props, will_props) + +# Multiple test properties +will_props = mqtt5_props.gen_string_prop(mqtt5_props.PROP_RESPONSE_TOPIC, "response/topic") +will_props += mqtt5_props.gen_byte_prop(mqtt5_props.PROP_PAYLOAD_FORMAT_INDICATOR, 0) +#do_test(will_props, will_props) + +# Multiple test properties, with property that is removed +will_props = mqtt5_props.gen_string_prop(mqtt5_props.PROP_RESPONSE_TOPIC, "response/topic") +will_props += mqtt5_props.gen_uint32_prop(mqtt5_props.PROP_WILL_DELAY_INTERVAL, 0) +will_props += mqtt5_props.gen_byte_prop(mqtt5_props.PROP_PAYLOAD_FORMAT_INDICATOR, 0) + +recv_props = mqtt5_props.gen_string_prop(mqtt5_props.PROP_RESPONSE_TOPIC, "response/topic") +recv_props += mqtt5_props.gen_byte_prop(mqtt5_props.PROP_PAYLOAD_FORMAT_INDICATOR, 0) +#do_test(will_props, recv_props) + +# Multiple test properties, with property that is removed *first* +will_props = mqtt5_props.gen_uint32_prop(mqtt5_props.PROP_WILL_DELAY_INTERVAL, 0) +will_props += mqtt5_props.gen_string_prop(mqtt5_props.PROP_RESPONSE_TOPIC, "response/topic") +will_props += mqtt5_props.gen_string_prop(mqtt5_props.PROP_CORRELATION_DATA, "data") + +recv_props = mqtt5_props.gen_string_prop(mqtt5_props.PROP_RESPONSE_TOPIC, "response/topic") +recv_props += mqtt5_props.gen_string_prop(mqtt5_props.PROP_CORRELATION_DATA, "data") +#do_test(will_props, recv_props) + +# All properties, plus multiple user properties (excluding +# message-expiry-interval, for ease of testing reasons) +will_props = mqtt5_props.gen_string_pair_prop(mqtt5_props.PROP_USER_PROPERTY, "key1", "value1") +will_props += mqtt5_props.gen_string_prop(mqtt5_props.PROP_RESPONSE_TOPIC, "response/topic") +will_props += mqtt5_props.gen_string_prop(mqtt5_props.PROP_CORRELATION_DATA, "data") +will_props += mqtt5_props.gen_uint32_prop(mqtt5_props.PROP_WILL_DELAY_INTERVAL, 0) +will_props += mqtt5_props.gen_byte_prop(mqtt5_props.PROP_PAYLOAD_FORMAT_INDICATOR, 1) +will_props += mqtt5_props.gen_string_prop(mqtt5_props.PROP_CONTENT_TYPE, "application/test") +will_props += mqtt5_props.gen_string_pair_prop(mqtt5_props.PROP_USER_PROPERTY, "key2", "value2") + +recv_props = mqtt5_props.gen_string_pair_prop(mqtt5_props.PROP_USER_PROPERTY, "key1", "value1") +recv_props += mqtt5_props.gen_string_prop(mqtt5_props.PROP_RESPONSE_TOPIC, "response/topic") +recv_props += mqtt5_props.gen_string_prop(mqtt5_props.PROP_CORRELATION_DATA, "data") +recv_props += mqtt5_props.gen_byte_prop(mqtt5_props.PROP_PAYLOAD_FORMAT_INDICATOR, 1) +recv_props += mqtt5_props.gen_string_prop(mqtt5_props.PROP_CONTENT_TYPE, "application/test") +recv_props += mqtt5_props.gen_string_pair_prop(mqtt5_props.PROP_USER_PROPERTY, "key2", "value2") +do_test(will_props, recv_props) diff --git a/test/broker/Makefile b/test/broker/Makefile index eace92da..292f0f82 100644 --- a/test/broker/Makefile +++ b/test/broker/Makefile @@ -141,6 +141,7 @@ endif ./07-will-no-flag.py ./07-will-null-topic.py ./07-will-null.py + ./07-will-properties.py ./07-will-qos0.py 08 : diff --git a/test/broker/test.py b/test/broker/test.py index c43e50b5..77bad2c1 100755 --- a/test/broker/test.py +++ b/test/broker/test.py @@ -115,6 +115,7 @@ tests = [ (1, './07-will-no-flag.py'), (1, './07-will-null-topic.py'), (1, './07-will-null.py'), + (1, './07-will-properties.py'), (1, './07-will-qos0.py'), (2, './08-ssl-bridge.py'),