Skip to content

Commit 4722f3b

Browse files
authored
Prevent a non-None empty username from being passed down and used to create a connection (#336)
1 parent 78048e1 commit 4722f3b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

awsiot/mqtt_connection_builder.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ def _builder(
199199
if _get(kwargs, 'enable_metrics_collection', True):
200200
username += _get_metrics_str(username)
201201

202+
if username == "":
203+
username = None
204+
202205
client_bootstrap = _get(kwargs, 'client_bootstrap')
203206
if client_bootstrap is None:
204207
client_bootstrap = awscrt.io.ClientBootstrap.get_or_create_static_default()
@@ -427,6 +430,7 @@ def websockets_with_custom_handshake(
427430
websocket_proxy_options=websocket_proxy_options,
428431
**kwargs)
429432

433+
430434
def _add_to_username_parameter(input_string, parameter_value, parameter_pretext):
431435
"""
432436
Helper function to add parameters to the username in the direct_with_custom_authorizer function
@@ -443,6 +447,7 @@ def _add_to_username_parameter(input_string, parameter_value, parameter_pretext)
443447
else:
444448
return return_string + parameter_pretext + parameter_value
445449

450+
446451
def direct_with_custom_authorizer(
447452
auth_username=None,
448453
auth_authorizer_name=None,
@@ -482,10 +487,10 @@ def direct_with_custom_authorizer(
482487
else:
483488
username_string += auth_username
484489

485-
if not auth_authorizer_name is None:
490+
if auth_authorizer_name is not None:
486491
username_string = _add_to_username_parameter(
487492
username_string, auth_authorizer_name, "x-amz-customauthorizer-name=")
488-
if not auth_authorizer_signature is None:
493+
if auth_authorizer_signature is not None:
489494
username_string = _add_to_username_parameter(
490495
username_string, auth_authorizer_signature, "x-amz-customauthorizer-signature=")
491496

0 commit comments

Comments
 (0)