Skip to content

Prevent a non-None empty username from being passed down and used to … #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions awsiot/mqtt_connection_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ def _builder(
if _get(kwargs, 'enable_metrics_collection', True):
username += _get_metrics_str(username)

if username == "":
username = None

client_bootstrap = _get(kwargs, 'client_bootstrap')
if client_bootstrap is None:
client_bootstrap = awscrt.io.ClientBootstrap.get_or_create_static_default()
Expand Down Expand Up @@ -427,6 +430,7 @@ def websockets_with_custom_handshake(
websocket_proxy_options=websocket_proxy_options,
**kwargs)


def _add_to_username_parameter(input_string, parameter_value, parameter_pretext):
"""
Helper function to add parameters to the username in the direct_with_custom_authorizer function
Expand All @@ -443,6 +447,7 @@ def _add_to_username_parameter(input_string, parameter_value, parameter_pretext)
else:
return return_string + parameter_pretext + parameter_value


def direct_with_custom_authorizer(
auth_username=None,
auth_authorizer_name=None,
Expand Down Expand Up @@ -482,10 +487,10 @@ def direct_with_custom_authorizer(
else:
username_string += auth_username

if not auth_authorizer_name is None:
if auth_authorizer_name is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR but: We probably want to change this to != None instead of is not None because we got a GitHub issue where someone was having Python warnings in their logs using Python 3.8+ due to the use of is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any use of '!= None' is being auto-formatted to 'is not None' for me. We should probably tackle this as a separate issue and fix it everywhere if we fix it anywhere =]

username_string = _add_to_username_parameter(
username_string, auth_authorizer_name, "x-amz-customauthorizer-name=")
if not auth_authorizer_signature is None:
if auth_authorizer_signature is not None:
username_string = _add_to_username_parameter(
username_string, auth_authorizer_signature, "x-amz-customauthorizer-signature=")

Expand Down