Skip to content

Commit fd13a36

Browse files
committed
fix mqtt3 basic auth test/mqtt5 still fail for testing
1 parent 3899777 commit fd13a36

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

awscrt/mqtt.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ class Connection(NativeResource):
330330
331331
proxy_options (Optional[awscrt.http.HttpProxyOptions]):
332332
Optional proxy options for all connections.
333+
334+
enable_metrics (bool): If true, append AWS IoT metrics to the username. (Default to true)
333335
"""
334336

335337
def __init__(self,
@@ -355,7 +357,8 @@ def __init__(self,
355357
proxy_options=None,
356358
on_connection_success=None,
357359
on_connection_failure=None,
358-
on_connection_closed=None
360+
on_connection_closed=None,
361+
enable_metrics=True
359362
):
360363

361364
assert isinstance(client, Client) or isinstance(client, Mqtt5Client)
@@ -404,8 +407,12 @@ def __init__(self,
404407
self.ping_timeout_ms = ping_timeout_ms
405408
self.protocol_operation_timeout_ms = protocol_operation_timeout_ms
406409
self.will = will
407-
username = username if username else ""
408-
self.username = username + _get_awsiot_metrics_str(username if username else "")
410+
411+
if enable_metrics:
412+
username = username if username else ""
413+
username += _get_awsiot_metrics_str(username)
414+
415+
self.username = username
409416
self.password = password
410417
self.socket_options = socket_options if socket_options else SocketOptions()
411418
self.proxy_options = proxy_options if proxy_options else websocket_proxy_options

awscrt/mqtt5.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,10 +1758,11 @@ class Client(NativeResource):
17581758
17591759
Args:
17601760
client_options (ClientOptions): The ClientOptions dataclass to used to configure the new Client.
1761+
enable_metrics (bool): Whether to append AWS IoT metrics to the username field during CONNECT. Default: True
17611762
17621763
"""
17631764

1764-
def __init__(self, client_options: ClientOptions):
1765+
def __init__(self, client_options: ClientOptions, enable_metrics: bool = True):
17651766

17661767
super().__init__()
17671768

@@ -1787,8 +1788,10 @@ def __init__(self, client_options: ClientOptions):
17871788
is_will_none = False
17881789
will = connect_options.will
17891790

1790-
username = connect_options.username if connect_options.username else ""
1791-
username += _get_awsiot_metrics_str(username)
1791+
username = connect_options.username
1792+
if enable_metrics:
1793+
username = username if username else ""
1794+
username += _get_awsiot_metrics_str(username)
17921795
connect_options.username = username
17931796
websocket_is_none = client_options.websocket_handshake_transform is None
17941797
self.tls_ctx = client_options.tls_ctx

test/test_mqtt.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,8 @@ def _test_mqtt311_direct_connect_basic_auth(self):
629629
host_name=input_host_name,
630630
port=input_port,
631631
username=input_username,
632-
password=input_password)
632+
password=input_password,
633+
enable_metrics=False)
633634
connection.connect().result(TIMEOUT)
634635
connection.disconnect().result(TIMEOUT)
635636

0 commit comments

Comments
 (0)