Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions 14 src/databricks/sql/auth/thrift_http_client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import logging
from typing import Dict


import thrift

import urllib.parse, six, base64

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -33,3 +36,14 @@ def flush(self):
self._headers = headers
self.setCustomHeaders(self._headers)
super().flush()

@staticmethod
def basic_proxy_auth_header(proxy):
if proxy is None or not proxy.username:
return None
ap = "%s:%s" % (
urllib.parse.unquote(proxy.username),
urllib.parse.unquote(proxy.password),
)
cr = base64.b64encode(ap.encode()).strip()
return "Basic " + six.ensure_str(cr)
15 changes: 15 additions & 0 deletions 15 tests/unit/test_thrift_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,21 @@ def test_headers_are_set(self, t_http_client_class):
ThriftBackend("foo", 123, "bar", [("header", "value")], auth_provider=AuthProvider())
t_http_client_class.return_value.setCustomHeaders.assert_called_with({"header": "value"})

def test_proxy_headers_are_set(self):

from databricks.sql.auth.thrift_http_client import THttpClient
from urllib.parse import urlparse

fake_proxy_spec = "https://someuser:somepassword@8.8.8.8:12340"
parsed_proxy = urlparse(fake_proxy_spec)

try:
result = THttpClient.basic_proxy_auth_header(parsed_proxy)
except TypeError as e:
assert False

assert isinstance(result, type(str()))

@patch("databricks.sql.auth.thrift_http_client.THttpClient")
@patch("databricks.sql.thrift_backend.create_default_context")
def test_tls_cert_args_are_propagated(self, mock_create_default_context, t_http_client_class):
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.