-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix race condition in AWS request signers #470
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,19 +18,38 @@ | |
|
||
|
||
class TestAsyncSigner: | ||
def mock_session(self): | ||
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) | ||
|
||
if disable_get_frozen: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's probably a cleaner way to do this, if you care, by inheriting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hrm. The issue is the checks for the |
||
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_frozen_credentials_as_http_auth(self): | ||
region = "us-west-2" | ||
|
||
from opensearchpy.helpers.asyncsigner import AWSV4SignerAsyncAuth | ||
|
||
mock_session = self.mock_session(disable_get_frozen=False) | ||
|
||
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 | ||
|
||
async def test_aws_signer_async_as_http_auth(self): | ||
region = "us-west-2" | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This showed up because my local
vim
doesn't like it when a file doesn't end in a newline- I'm guessing most the devs on this project are using VSCodeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine.