Fix race condition in AWS request signers (#470)
* Fix race condition in AWS request signers Signed-off-by: Logan Attwood <[email protected]> * Conditionally expose get_frozen_credentials on mock_session Signed-off-by: Logan Attwood <[email protected]> * Use inheritance to make tests cleaner Signed-off-by: Logan Attwood <[email protected]> --------- Signed-off-by: Logan Attwood <[email protected]>
This commit is contained in:
@@ -26,11 +26,11 @@ class TestAsyncSigner:
|
||||
dummy_session.access_key = access_key
|
||||
dummy_session.secret_key = secret_key
|
||||
dummy_session.token = token
|
||||
|
||||
del dummy_session.get_frozen_credentials
|
||||
|
||||
return dummy_session
|
||||
|
||||
@pytest.mark.skipif(
|
||||
sys.version_info < (3, 6), reason="AWSV4SignerAsyncAuth requires python3.6+"
|
||||
)
|
||||
async def test_aws_signer_async_as_http_auth(self):
|
||||
region = "us-west-2"
|
||||
|
||||
@@ -85,3 +85,34 @@ class TestAsyncSigner:
|
||||
assert "X-Amz-Date" in headers
|
||||
assert "X-Amz-Security-Token" in headers
|
||||
assert "X-Amz-Content-SHA256" in headers
|
||||
|
||||
|
||||
class TestAsyncSignerWithFrozenCredentials(TestAsyncSigner):
|
||||
def mock_session(self, disable_get_frozen=True):
|
||||
access_key = uuid.uuid4().hex
|
||||
secret_key = uuid.uuid4().hex
|
||||
token = uuid.uuid4().hex
|
||||
dummy_session = Mock()
|
||||
dummy_session.access_key = access_key
|
||||
dummy_session.secret_key = secret_key
|
||||
dummy_session.token = token
|
||||
dummy_session.get_frozen_credentials = Mock(return_value=dummy_session)
|
||||
|
||||
return dummy_session
|
||||
|
||||
@pytest.mark.skipif(
|
||||
sys.version_info < (3, 6), reason="AWSV4SignerAsyncAuth requires python3.6+"
|
||||
)
|
||||
async def test_aws_signer_async_frozen_credentials_as_http_auth(self):
|
||||
region = "us-west-2"
|
||||
|
||||
from opensearchpy.helpers.asyncsigner import AWSV4SignerAsyncAuth
|
||||
|
||||
mock_session = self.mock_session()
|
||||
|
||||
auth = AWSV4SignerAsyncAuth(mock_session, region)
|
||||
headers = auth("GET", "http://localhost", {}, {})
|
||||
assert "Authorization" in headers
|
||||
assert "X-Amz-Date" in headers
|
||||
assert "X-Amz-Security-Token" in headers
|
||||
assert len(mock_session.get_frozen_credentials.mock_calls) == 1
|
||||
|
||||
Reference in New Issue
Block a user