Test for unsupported extended auth.

This commit is contained in:
Roger A. Light 2019-04-02 10:22:02 +01:00
parent 0d7523c309
commit e5f58a8ff3
4 changed files with 47 additions and 4 deletions

View File

@ -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)

View File

@ -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

View File

@ -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'),

View File

@ -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: