Skip to content

Commit

Permalink
SNOW-956671: We should change the user-agent of the diagnostic report… (
Browse files Browse the repository at this point in the history
#1789)

* SNOW-956671: We should change the user-agent of the diagnostic report so we can track it's usage

* SNOW-956671: We should change the user-agent of the diagnostic report so we can track it's usage

* Added a test and try/except block
  • Loading branch information
sfc-gh-cconner authored Mar 8, 2024
1 parent 95b08c0 commit 55628a7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
- Added the `socket_timeout` argument to `snowflake.connector.connect` specifying socket read and connect timeout.
- Fixed `login_timeout` and `network_timeout` behaviour. Retries of login and network requests are now properly halted after these timeouts expire.
- Fixed bug for issue https://github.com/urllib3/urllib3/issues/1878 in vendored `urllib`.
- Add User-Agent header for diagnostic report for tracking.

- v3.3.1(October 16,2023)

Expand Down
11 changes: 11 additions & 0 deletions src/snowflake/connector/connection_diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,17 @@ def __test_socket_get_cert(
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
sock = context.wrap_socket(conn, server_hostname=host)
certificate = ssl.DER_cert_to_PEM_cert(sock.getpeercert(True))
http_request = f"""GET / {host}:{port} HTTP/1.1\r\n
Host: {host}\r\n
User-Agent: snowflake-connector-python-diagnostic
\r\n\r\n"""
try:
sock.send(str.encode(http_request))
except Exception as e:
self.__append_message(
host_type,
f"{host}:{port}: URL Check: Failed: Unknown Exception: {e}",
)
conn.close()
return certificate
else:
Expand Down
14 changes: 14 additions & 0 deletions test/unit/test_connection_diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ def test_https_host_report(caplog):
)


def test_test_socket_get_cert(caplog):
connection_diag = ConnectionDiagnostic(
account="test", host="test.snowflakecomputing.com"
)
test_socket_get_cert = connection_diag._ConnectionDiagnostic__test_socket_get_cert
result = test_socket_get_cert(
host="client-telemetry.snowflakecomputing.com",
port=443,
host_type="OUT_OF_BAND_TELEMETRY",
)

assert "BEGIN CERTIFICATE" in result


def test_decode_dict():
test_dict = {b"CN": b"client-telemetry.snowflakecomputing.com"}
result = _decode_dict(test_dict)
Expand Down

0 comments on commit 55628a7

Please sign in to comment.