| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
# |
| 4 |
|
| 5 |
from mosq_test_helper import * |
| 6 |
|
| 7 |
def do_test(proto_ver): |
| 8 |
rc = 1 |
| 9 |
|
| 10 |
port = mosq_test.get_port() |
| 11 |
|
| 12 |
env = { |
| 13 |
'XDG_CONFIG_HOME':'/tmp/missing' |
| 14 |
} |
| 15 |
env = mosq_test.env_add_ld_library_path(env) |
| 16 |
if proto_ver == 5: |
| 17 |
V = 'mqttv5' |
| 18 |
elif proto_ver == 4: |
| 19 |
V = 'mqttv311' |
| 20 |
else: |
| 21 |
V = 'mqttv31' |
| 22 |
|
| 23 |
cmd = [f'{mosq_test.get_build_root()}/client/mosquitto_pub', |
| 24 |
'-p', str(port), |
| 25 |
'-q', '1', |
| 26 |
'-t', '03/pub/qos1/test/properties', |
| 27 |
'-m', 'message', |
| 28 |
'-V', V, |
| 29 |
'-D', 'publish', 'content-type', 'application/json', |
| 30 |
'-D', 'publish', 'correlation-data', 'some-data', |
| 31 |
'-D', 'publish', 'message-expiry-interval', '59', |
| 32 |
'-D', 'publish', 'payload-format-indicator', '1', |
| 33 |
'-D', 'publish', 'response-topic', '/dev/null', |
| 34 |
'-D', 'publish', 'topic-alias', '4', |
| 35 |
'-D', 'publish', 'user-property', 'publish', 'up' |
| 36 |
] |
| 37 |
|
| 38 |
mid = 1 |
| 39 |
props = mqtt5_props.gen_string_prop(mqtt5_props.CONTENT_TYPE, "application/json") |
| 40 |
props += mqtt5_props.gen_string_prop(mqtt5_props.CORRELATION_DATA, "some-data") |
| 41 |
props += mqtt5_props.gen_byte_prop(mqtt5_props.PAYLOAD_FORMAT_INDICATOR, 1) |
| 42 |
props += mqtt5_props.gen_string_prop(mqtt5_props.RESPONSE_TOPIC, "/dev/null") |
| 43 |
props += mqtt5_props.gen_string_pair_prop(mqtt5_props.USER_PROPERTY, "publish", "up") |
| 44 |
props += mqtt5_props.gen_uint32_prop(mqtt5_props.MESSAGE_EXPIRY_INTERVAL, 59) |
| 45 |
publish_packet = mosq_test.gen_publish("03/pub/qos1/test/properties", qos=1, mid=mid, payload="message", proto_ver=proto_ver, properties=props) |
| 46 |
puback_packet = mosq_test.gen_puback(mid, proto_ver=proto_ver, reason_code=mqtt5_rc.NO_MATCHING_SUBSCRIBERS) |
| 47 |
|
| 48 |
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port) |
| 49 |
|
| 50 |
try: |
| 51 |
sock = mosq_test.sub_helper(port=port, topic="#", qos=1, proto_ver=5) |
| 52 |
|
| 53 |
pub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) |
| 54 |
pub_terminate_rc = 0 |
| 55 |
if mosq_test.wait_for_subprocess(pub): |
| 56 |
print("pub not terminated") |
| 57 |
pub_terminate_rc = 1 |
| 58 |
(stdo, stde) = pub.communicate() |
| 59 |
|
| 60 |
mosq_test.expect_packet(sock, "publish", publish_packet) |
| 61 |
rc = pub_terminate_rc |
| 62 |
sock.close() |
| 63 |
except mosq_test.TestError: |
| 64 |
pass |
| 65 |
except Exception as e: |
| 66 |
print(e) |
| 67 |
finally: |
| 68 |
broker.terminate() |
| 69 |
if mosq_test.wait_for_subprocess(broker): |
| 70 |
print("broker not terminated") |
| 71 |
if rc == 0: rc=1 |
| 72 |
(stdo, stde) = broker.communicate() |
| 73 |
if rc: |
| 74 |
print(stde.decode('utf-8')) |
| 75 |
print("proto_ver=%d" % (proto_ver)) |
| 76 |
exit(rc) |
| 77 |
|
| 78 |
|
| 79 |
do_test(proto_ver=5) |