Fix #16211: Fix special charechter encoding in trino username (#16258)

* Fix #16211: Fix special charechter encoding in trino username

* fix test and add comments
This commit is contained in:
Mayur Singal 2024-05-15 14:48:22 +05:30 committed by GitHub
parent 945cd35148
commit a677910982
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 2 deletions

View File

@ -49,7 +49,10 @@ def get_connection_url(connection: TrinoConnection) -> str:
"""
url = f"{connection.scheme.value}://"
if connection.username:
url += f"{quote_plus(connection.username)}"
# we need to encode twice because trino dialect internally
# url decodes the username and if there is an special char in username
# it will fail to authenticate
url += f"{quote_plus(quote_plus(connection.username))}"
if (
isinstance(connection.authType, basicAuth.BasicAuth)
and connection.authType.password

View File

@ -407,7 +407,7 @@ class SourceConnectionTest(TestCase):
assert expected_url == get_connection_url(trino_conn_obj)
# Passing @ in username and password
expected_url = "trino://username%40444:pass%40111@localhost:443/catalog"
expected_url = "trino://username%2540444:pass%40111@localhost:443/catalog"
trino_conn_obj = TrinoConnection(
scheme=TrinoScheme.trino,
hostPort="localhost:443",