Skip to content

Commit

Permalink
open-tunnel: respect None NO_PROXY env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Harbhajan Singh authored and kyleknap committed Jul 19, 2023
1 parent 8dd9a23 commit 13c9e77
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changes/next-release/bugfix-ec2instanceconnectssh-67721.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "``ec2-instance-connect ssh``",
"description": "Fix runtime error when HTTP_PROXY environment variable is set and NO_PROXY is not set for eice connection type `#8023 <https://github.com/aws/aws-cli/issues/8023>`__"
}

2 changes: 1 addition & 1 deletion awscli/customizations/ec2instanceconnect/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def connect(self, url, user_agent=None):
environment = os.environ.copy()
proxy_options = None
proxy_url = environment.get("HTTP_PROXY") or environment.get("HTTPS_PROXY")
no_proxy = environment.get("NO_PROXY")
no_proxy = environment.get("NO_PROXY", "")
if proxy_url and parsed_url.hostname not in no_proxy:
parsed_proxy_url = urlparse(proxy_url)
logger.debug(f"Using the following proxy: {parsed_proxy_url.hostname}")
Expand Down
35 changes: 35 additions & 0 deletions tests/unit/customizations/ec2instanceconnect/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,41 @@ def test_connect_with_proxy(

assert mock_on_connection_event.wait.called

@patch.object(websocket, "connect")
@patch.object(websocket, "create_handshake_request")
@mock.patch.dict(os.environ, {"HTTPS_PROXY": "http://user1:pass1@localhost:8989"})
def test_connect_with_proxy_but_no_proxy_env_empty(
self, mock_handshake, mock_connect, mock_on_connection_event,
mock_tls_connection_options, web_socket, websocket_url
):
parsed_url = urlparse(websocket_url)
host = parsed_url.hostname
path = parsed_url.path + "?" + parsed_url.query
mock_handshake.return_value = mock_handshake_request

web_socket.connect(websocket_url)

mock_handshake.assert_called_with(host=host, path=path)
mock_tls_connection_options.set_server_name.assert_called_with(host)
mock_connect.assert_called_with(
host=host,
handshake_request=mock_handshake_request,
port=443,
tls_connection_options=mock_tls_connection_options,
proxy_options=mock.ANY,
on_connection_setup=mock.ANY,
on_connection_shutdown=mock.ANY,
on_incoming_frame_payload=mock.ANY,
on_incoming_frame_complete=mock.ANY
)
assert "localhost" == mock_connect.call_args.kwargs['proxy_options'].host_name
assert 8989 == mock_connect.call_args.kwargs['proxy_options'].port
assert HttpProxyAuthenticationType.Basic == mock_connect.call_args.kwargs['proxy_options'].auth_type
assert "user1" == mock_connect.call_args.kwargs['proxy_options'].auth_username
assert "pass1" == mock_connect.call_args.kwargs['proxy_options'].auth_password

assert mock_on_connection_event.wait.called

@patch.object(websocket, "connect")
@patch.object(websocket, "create_handshake_request")
@mock.patch.dict(os.environ,
Expand Down

0 comments on commit 13c9e77

Please sign in to comment.