Skip to content

Commit f8c7a32

Browse files
a-narsudinovhashhar
authored andcommitted
Fix cert and key kwargs parsing from URL in sqlachemy
Previous version of code contained an always true condition that may lead to unintended behaviour.
1 parent a875667 commit f8c7a32

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

tests/unit/sqlalchemy/test_dialect.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,23 @@ def test_trino_connection_certificate_auth():
298298
assert cparams['auth']._key == key
299299

300300

301+
def test_trino_connection_certificate_auth_cert_and_key_required():
302+
dialect = TrinoDialect()
303+
cert = '/path/to/cert.pem'
304+
key = '/path/to/key.pem'
305+
url = make_url(f'trino://host/?cert={cert}')
306+
_, cparams = dialect.create_connect_args(url)
307+
308+
assert 'http_scheme' not in cparams
309+
assert 'auth' not in cparams
310+
311+
url = make_url(f'trino://host/?key={key}')
312+
_, cparams = dialect.create_connect_args(url)
313+
314+
assert 'http_scheme' not in cparams
315+
assert 'auth' not in cparams
316+
317+
301318
def test_trino_connection_oauth2_auth():
302319
dialect = TrinoDialect()
303320
url = make_url('trino://host/?externalAuthentication=true')

trino/sqlalchemy/dialect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def create_connect_args(self, url: URL) -> Tuple[Sequence[Any], Mapping[str, Any
131131
kwargs["http_scheme"] = "https"
132132
kwargs["auth"] = JWTAuthentication(unquote_plus(url.query["access_token"]))
133133

134-
if "cert" and "key" in url.query:
134+
if "cert" in url.query and "key" in url.query:
135135
kwargs["http_scheme"] = "https"
136136
kwargs["auth"] = CertificateAuthentication(unquote_plus(url.query['cert']), unquote_plus(url.query['key']))
137137

0 commit comments

Comments
 (0)