Skip to content

Commit 55628a7

Browse files
SNOW-956671: We should change the user-agent of the diagnostic report… (#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
1 parent 95b08c0 commit 55628a7

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

DESCRIPTION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
7575
- Added the `socket_timeout` argument to `snowflake.connector.connect` specifying socket read and connect timeout.
7676
- Fixed `login_timeout` and `network_timeout` behaviour. Retries of login and network requests are now properly halted after these timeouts expire.
7777
- Fixed bug for issue https://github.com/urllib3/urllib3/issues/1878 in vendored `urllib`.
78+
- Add User-Agent header for diagnostic report for tracking.
7879

7980
- v3.3.1(October 16,2023)
8081

src/snowflake/connector/connection_diagnostic.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,17 @@ def __test_socket_get_cert(
214214
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
215215
sock = context.wrap_socket(conn, server_hostname=host)
216216
certificate = ssl.DER_cert_to_PEM_cert(sock.getpeercert(True))
217+
http_request = f"""GET / {host}:{port} HTTP/1.1\r\n
218+
Host: {host}\r\n
219+
User-Agent: snowflake-connector-python-diagnostic
220+
\r\n\r\n"""
221+
try:
222+
sock.send(str.encode(http_request))
223+
except Exception as e:
224+
self.__append_message(
225+
host_type,
226+
f"{host}:{port}: URL Check: Failed: Unknown Exception: {e}",
227+
)
217228
conn.close()
218229
return certificate
219230
else:

test/unit/test_connection_diagnostic.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ def test_https_host_report(caplog):
3737
)
3838

3939

40+
def test_test_socket_get_cert(caplog):
41+
connection_diag = ConnectionDiagnostic(
42+
account="test", host="test.snowflakecomputing.com"
43+
)
44+
test_socket_get_cert = connection_diag._ConnectionDiagnostic__test_socket_get_cert
45+
result = test_socket_get_cert(
46+
host="client-telemetry.snowflakecomputing.com",
47+
port=443,
48+
host_type="OUT_OF_BAND_TELEMETRY",
49+
)
50+
51+
assert "BEGIN CERTIFICATE" in result
52+
53+
4054
def test_decode_dict():
4155
test_dict = {b"CN": b"client-telemetry.snowflakecomputing.com"}
4256
result = _decode_dict(test_dict)

0 commit comments

Comments
 (0)