From e5f58a8ff35ba789a7a23a08d373f8ebb7c27c8b Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 2 Apr 2019 10:22:02 +0100 Subject: [PATCH] Test for unsupported extended auth. --- test/broker/09-extended-auth-unsupported.py | 33 +++++++++++++++++++++ test/broker/Makefile | 1 + test/broker/test.py | 1 + test/mosq_test.py | 16 +++++++--- 4 files changed, 47 insertions(+), 4 deletions(-) create mode 100755 test/broker/09-extended-auth-unsupported.py diff --git a/test/broker/09-extended-auth-unsupported.py b/test/broker/09-extended-auth-unsupported.py new file mode 100755 index 00000000..22baf0b6 --- /dev/null +++ b/test/broker/09-extended-auth-unsupported.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +# Test whether an unsupported extended auth is rejected. + +from mosq_test_helper import * + +port = mosq_test.get_port() + +rc = 1 + +props = mqtt5_props.gen_string_prop(mqtt5_props.PROP_AUTHENTICATION_METHOD, "unsupported") +props += mqtt5_props.gen_string_prop(mqtt5_props.PROP_AUTHENTICATION_DATA, "test") +connect_packet = mosq_test.gen_connect("client-params-test", keepalive=42, proto_ver=5, properties=props) +connack_packet = mosq_test.gen_connack(rc=mqtt5_rc.MQTT_RC_BAD_AUTHENTICATION_METHOD, proto_ver=5, properties=None) + + +broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port) + +try: + sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port) + rc = 0 + + sock.close() +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 fcbdcf8f..9d77ff1f 100644 --- a/test/broker/Makefile +++ b/test/broker/Makefile @@ -162,6 +162,7 @@ endif ./09-acl-access-variants.py ./09-acl-empty-file.py ./09-auth-bad-method.py + ./09-extended-auth-unsupported.py ./09-plugin-auth-acl-sub-denied.py ./09-plugin-auth-acl-sub.py ./09-plugin-auth-context-params.py diff --git a/test/broker/test.py b/test/broker/test.py index f435654b..867f6c46 100755 --- a/test/broker/test.py +++ b/test/broker/test.py @@ -132,6 +132,7 @@ tests = [ (1, './09-acl-access-variants.py'), (1, './09-acl-empty-file.py'), (1, './09-auth-bad-method.py'), + (1, './09-extended-auth-unsupported.py'), (1, './09-plugin-auth-acl-sub-denied.py'), (1, './09-plugin-auth-acl-sub.py'), (1, './09-plugin-auth-context-params.py'), diff --git a/test/mosq_test.py b/test/mosq_test.py index fc2289c6..870c2398 100644 --- a/test/mosq_test.py +++ b/test/mosq_test.py @@ -542,21 +542,29 @@ def gen_pingreq(): def gen_pingresp(): return struct.pack('!BB', 208, 0) -def gen_disconnect(reason_code=-1, proto_ver=4, properties=None): + +def _gen_short(cmd, reason_code=-1, proto_ver=5, properties=None): if proto_ver == 5 and (reason_code != -1 or properties is not None): if reason_code == -1: reason_code = 0 if properties is None: - return struct.pack('!BBB', 224, 1, reason_code) + return struct.pack('!BBB', cmd, 1, reason_code) elif properties == "": - return struct.pack('!BBBB', 224, 2, reason_code, 0) + return struct.pack('!BBBB', cmd, 2, reason_code, 0) else: properties = mqtt5_props.prop_finalise(properties) - return struct.pack("!BBB", 224, 1+len(properties), reason_code) + properties + return struct.pack("!BBB", cmd, 1+len(properties), reason_code) + properties else: return struct.pack('!BB', 224, 0) +def gen_disconnect(reason_code=-1, proto_ver=4, properties=None): + return _gen_short(224, reason_code, proto_ver, properties) + +def gen_auth(reason_code=-1, properties=None): + return _gen_short(240, 5, properties) + + def pack_remaining_length(remaining_length): s = b"" while True: