Skip to content

Commit

Permalink
Added unit test for Urllib3AWSV4SignerAuth adding headers.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Oct 23, 2023
1 parent 9e6b9aa commit e916060
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test_opensearchpy/test_connection/test_urllib3_http_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,29 @@ def test_http_auth_list(self):
con.headers,
)

@pytest.mark.skipif(
sys.version_info < (3, 6), reason="Urllib3AWSV4SignerAuth requires python3.6+"
)
@patch(
"urllib3.HTTPConnectionPool.urlopen",
return_value=Mock(status=200, headers=HTTPHeaderDict({}), data=b"{}"),
)
def test_aws_signer_as_http_auth_adds_headers(self, mock_open):
from opensearchpy.helpers.signer import Urllib3AWSV4SignerAuth

auth = Urllib3AWSV4SignerAuth(self.mock_session(), "us-west-2")
con = Urllib3HttpConnection(http_auth=auth, headers={"x": "y"})
con.perform_request("GET", "/")
self.assertEqual(mock_open.call_count, 1)
headers = mock_open.call_args[1]["headers"]
self.assertEqual(headers["x"], "y")
self.assertTrue(
headers["Authorization"].startswith("AWS4-HMAC-SHA256 Credential=")
)
self.assertIn("X-Amz-Date", headers)
self.assertIn("X-Amz-Security-Token", headers)
self.assertIn("X-Amz-Content-SHA256", headers)

@pytest.mark.skipif(
sys.version_info < (3, 6), reason="Urllib3AWSV4SignerAuth requires python3.6+"
)
Expand Down

0 comments on commit e916060

Please sign in to comment.