@@ -69,8 +69,13 @@ def test_get_remote_connection_headers_defaults():
69
69
70
70
def test_get_remote_connection_headers_adds_auth_header_if_pass ():
71
71
url = "http://user:pass@remote"
72
- headers = RemoteConnection .get_remote_connection_headers (parse .urlparse (url ))
72
+ with pytest .warns (None ) as record :
73
+ headers = RemoteConnection .get_remote_connection_headers (parse .urlparse (url ))
73
74
assert headers .get ("Authorization" ) == "Basic dXNlcjpwYXNz"
75
+ assert (
76
+ record [0 ].message .args [0 ]
77
+ == "Embedding username and password in URL could be insecure, use ClientConfig instead"
78
+ )
74
79
75
80
76
81
def test_get_remote_connection_headers_adds_keep_alive_if_requested ():
@@ -126,13 +131,15 @@ def test_get_proxy_url_https_via_client_config():
126
131
proxy = Proxy ({"proxyType" : ProxyType .MANUAL , "sslProxy" : "https://admin:admin@http_proxy.com:8080" }),
127
132
)
128
133
remote_connection = RemoteConnection (client_config = client_config )
129
- proxy_url = remote_connection ._client_config .get_proxy_url ()
130
- assert proxy_url == "https://admin:admin@http_proxy.com:8080"
134
+ conn = remote_connection ._get_connection_manager ()
135
+ assert isinstance (conn , urllib3 .ProxyManager )
136
+ conn .proxy_url = "https://http_proxy.com:8080"
137
+ conn .connection_pool_kw ["proxy_headers" ] = urllib3 .make_headers (proxy_basic_auth = "admin:admin" )
131
138
132
139
133
140
def test_get_proxy_url_http_via_client_config ():
134
141
client_config = ClientConfig (
135
- remote_server_addr = "https ://localhost:4444" ,
142
+ remote_server_addr = "http ://localhost:4444" ,
136
143
proxy = Proxy (
137
144
{
138
145
"proxyType" : ProxyType .MANUAL ,
@@ -142,15 +149,19 @@ def test_get_proxy_url_http_via_client_config():
142
149
),
143
150
)
144
151
remote_connection = RemoteConnection (client_config = client_config )
145
- proxy_url = remote_connection ._client_config .get_proxy_url ()
146
- assert proxy_url == "https://admin:admin@http_proxy.com:8080"
152
+ conn = remote_connection ._get_connection_manager ()
153
+ assert isinstance (conn , urllib3 .ProxyManager )
154
+ conn .proxy_url = "http://http_proxy.com:8080"
155
+ conn .connection_pool_kw ["proxy_headers" ] = urllib3 .make_headers (proxy_basic_auth = "admin:admin" )
147
156
148
157
149
158
def test_get_proxy_direct_via_client_config ():
150
159
client_config = ClientConfig (
151
160
remote_server_addr = "http://localhost:4444" , proxy = Proxy ({"proxyType" : ProxyType .DIRECT })
152
161
)
153
162
remote_connection = RemoteConnection (client_config = client_config )
163
+ conn = remote_connection ._get_connection_manager ()
164
+ assert isinstance (conn , urllib3 .PoolManager )
154
165
proxy_url = remote_connection ._client_config .get_proxy_url ()
155
166
assert proxy_url is None
156
167
@@ -162,6 +173,8 @@ def test_get_proxy_system_matches_no_proxy_via_client_config():
162
173
remote_server_addr = "http://localhost:4444" , proxy = Proxy ({"proxyType" : ProxyType .SYSTEM })
163
174
)
164
175
remote_connection = RemoteConnection (client_config = client_config )
176
+ conn = remote_connection ._get_connection_manager ()
177
+ assert isinstance (conn , urllib3 .PoolManager )
165
178
proxy_url = remote_connection ._client_config .get_proxy_url ()
166
179
assert proxy_url is None
167
180
os .environ .pop ("HTTP_PROXY" )
0 commit comments