Skip to content

Commit 1b981b4

Browse files
hashharclaude
andcommitted
Raise error when sending credentials over HTTP
Aligns with the Java client behavior where TLS/SSL is required for authentication. The error message matches the Java client phrasing: "TLS/SSL is required for authentication." Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 25693ec commit 1b981b4

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

tests/unit/test_dbapi.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from httpretty import httprettified
1919
from requests import Session
2020

21+
import trino.exceptions
2122
from tests.unit.oauth_test_utils import _get_token_requests
2223
from tests.unit.oauth_test_utils import _post_statement_requests
2324
from tests.unit.oauth_test_utils import GetTokenCallback
@@ -27,6 +28,7 @@
2728
from tests.unit.oauth_test_utils import SERVER_ADDRESS
2829
from tests.unit.oauth_test_utils import TOKEN_RESOURCE
2930
from trino import constants
31+
from trino.auth import BasicAuthentication
3032
from trino.auth import OAuth2Authentication
3133
from trino.dbapi import connect
3234
from trino.dbapi import Connection
@@ -362,3 +364,12 @@ def test_default_encoding_zstd():
362364
def test_default_encoding_all():
363365
connection = Connection("host", 8080, user="test")
364366
assert connection._client_session.encoding == ["json+zstd", "json+lz4", "json"]
367+
368+
369+
def test_error_when_auth_over_http():
370+
with pytest.raises(trino.exceptions.TrinoAuthError, match="TLS/SSL is required for authentication"):
371+
Connection("mytrinoserver.domain", auth=BasicAuthentication("u", "p"))
372+
373+
374+
def test_no_error_when_auth_over_https():
375+
Connection("mytrinoserver.domain", http_scheme=constants.HTTPS, auth=BasicAuthentication("u", "p"))

trino/dbapi.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@ def __init__(
215215
else:
216216
self.http_scheme = constants.HTTP
217217

218+
if auth is not None and self.http_scheme == constants.HTTP:
219+
raise trino.exceptions.TrinoAuthError(
220+
"TLS/SSL is required for authentication. "
221+
"To use HTTPS, specify 'https://' in the host URL (which takes precedence "
222+
"over http_scheme), or, if the host URL has no scheme, pass http_scheme='https'."
223+
)
224+
218225
# Infer connection port: `hostname` takes precedence over explicit `port` argument
219226
# If none is given, use default based on HTTP protocol
220227
default_port = constants.DEFAULT_TLS_PORT if self.http_scheme == constants.HTTPS else constants.DEFAULT_PORT

0 commit comments

Comments
 (0)