55
66from __future__ import annotations
77
8+ import logging
89import os
10+ import unittest .mock
11+
12+ import pytest
13+
14+ import snowflake .connector
15+ from snowflake .connector .errors import OperationalError
916
1017
1118def test_set_proxies ():
@@ -31,3 +38,60 @@ def test_set_proxies():
3138 # NOTE environment variable is set if the proxy parameter is specified.
3239 del os .environ ["HTTP_PROXY" ]
3340 del os .environ ["HTTPS_PROXY" ]
41+
42+
43+ @pytest .mark .skipolddriver
44+ def test_socks_5_proxy_missing_proxy_header_attribute (caplog ):
45+ from snowflake .connector .vendored .urllib3 .poolmanager import ProxyManager
46+
47+ os .environ ["HTTPS_PROXY" ] = "socks5://localhost:8080"
48+
49+ class MockSOCKSProxyManager :
50+ def __init__ (self ):
51+ pass
52+
53+ def connection_from_url (self , url ):
54+ pass
55+
56+ def mock_proxy_manager_for_url_no_header (* args , ** kwargs ):
57+ return MockSOCKSProxyManager ()
58+
59+ def mock_proxy_manager_for_url_wiht_header (* args , ** kwargs ):
60+ return ProxyManager ("testurl" )
61+
62+ # connection
63+ caplog .set_level (logging .DEBUG , "snowflake.connector" )
64+
65+ # bad path
66+ with unittest .mock .patch (
67+ "snowflake.connector.network.ProxySupportAdapter.proxy_manager_for" ,
68+ mock_proxy_manager_for_url_no_header ,
69+ ):
70+ with pytest .raises (OperationalError ):
71+ snowflake .connector .connect (
72+ account = "testaccount" ,
73+ user = "testuser" ,
74+ password = "testpassword" ,
75+ database = "TESTDB" ,
76+ warehouse = "TESTWH" ,
77+ )
78+ assert "Unable to set 'Host' to proxy manager of type" in caplog .text
79+
80+ caplog .clear ()
81+
82+ # happy path
83+ with unittest .mock .patch (
84+ "snowflake.connector.network.ProxySupportAdapter.proxy_manager_for" ,
85+ mock_proxy_manager_for_url_wiht_header ,
86+ ):
87+ with pytest .raises (OperationalError ):
88+ snowflake .connector .connect (
89+ account = "testaccount" ,
90+ user = "testuser" ,
91+ password = "testpassword" ,
92+ database = "TESTDB" ,
93+ warehouse = "TESTWH" ,
94+ )
95+ assert "Unable to set 'Host' to proxy manager of type" not in caplog .text
96+
97+ del os .environ ["HTTPS_PROXY" ]
0 commit comments