Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Allow providing credentials to HTTPS_PROXY #9657

Merged
merged 7 commits into from
Mar 22, 2021
Merged
Changes from 1 commit
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
23 changes: 22 additions & 1 deletion tests/http/test_proxyagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import base64
import logging
import os
from unittest.mock import patch
Expand Down Expand Up @@ -240,7 +241,10 @@ def test_http_request_via_proxy(self):
body = self.successResultOf(treq.content(resp))
self.assertEqual(body, b"result")

@patch.dict(os.environ, {"https_proxy": "proxy.com", "no_proxy": "unused.com"})
@patch.dict(
os.environ,
{"https_proxy": "bob:[email protected]", "no_proxy": "unused.com"},
)
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
def test_https_request_via_proxy(self):
agent = ProxyAgent(
self.reactor,
Expand Down Expand Up @@ -278,6 +282,16 @@ def test_https_request_via_proxy(self):
self.assertEqual(request.method, b"CONNECT")
self.assertEqual(request.path, b"test.com:443")

# Check that credentials have been supplied for the proxy
proxy_auth_header_values = request.requestHeaders.getRawHeaders(
b"Proxy-Authorization"
)

# Compute the correct header value for Proxy-Authorization
encoded_credentials = base64.b64encode(b"bob:pinkponies")
expected_header_value = b"Basic " + encoded_credentials
self.assertIn(expected_header_value, proxy_auth_header_values)

# tell the proxy server not to close the connection
proxy_server.persistent = True

Expand Down Expand Up @@ -312,6 +326,13 @@ def test_https_request_via_proxy(self):
self.assertEqual(request.method, b"GET")
self.assertEqual(request.path, b"/abc")
self.assertEqual(request.requestHeaders.getRawHeaders(b"host"), [b"test.com"])

# Check that the destination server DID NOT receive proxy credentials
proxy_auth_header_values = request.requestHeaders.getRawHeaders(
b"Proxy-Authorization"
)
self.assertIsNone(proxy_auth_header_values)

request.write(b"result")
request.finish()

Expand Down