-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Use fixtures for test credentials and region name #10207
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
Conversation
182664f
to
b617a8f
Compare
b617a8f
to
0b505a3
Compare
0b505a3
to
d812bbb
Compare
@pytest.fixture(name="region", scope="session") | ||
def fixture_region(aws_client): | ||
if is_aws() or is_api_enabled("sts"): | ||
return aws_client.sts.meta.region_name | ||
else: | ||
return TEST_AWS_REGION_NAME |
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 is moved to localstack.testing.pytest.fixtures
alongside its companion fixtures
7278ca5
to
98d6f88
Compare
424a97c
to
934e5bd
Compare
934e5bd
to
db3fd2b
Compare
ex.AWSAccessKeyId = TEST_AWS_ACCESS_KEY_ID # todo maybe return access key used for the request | ||
ex.AWSAccessKeyId = ( | ||
constants.TEST_AWS_ACCESS_KEY_ID | ||
) # todo maybe return access key used for the request |
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.
In this and the other cases in this file, I'd suggest we just remove it completely (basically implementing the TODO)
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.
Yes, I plan to remove all uses of the TEST_*
variables outside of the tests themselves. I've made some of it in #8204, would it be okay if I take it forward there?
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.
For the presigned URLs, we will need a bit more logic especially when creating the Credentials to validate the URL and remove those constants. Right now, we explicitly say that we need the credentials to be test
/ test
in order to validate them (so technically the test should fail when using other credentials, which is why I believe we're using TEST_*
and not DEFAULT_*
).
The secret access key is not passed in the signature, so we will need a network request to fetch it like IAM does, in order to properly validate it. But I agree that implementing this TODO would be really great!
Let me know if there's anything I can do there.
|
||
@pytest.fixture(scope="session") | ||
def secondary_region_name(): | ||
return constants.SECONDARY_TEST_AWS_REGION_NAME |
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.
Not a particular fan of using the constants for the fixtures. One of the longer-running efforts will be moving to a state where we won't have access to localstack internals from the test code (e.g. because we're running LS in a container and test against that). I also think constants
should generally not be a place where we put values used in testing.
How about we use environment variables to configure these and falling back to a static default in the fixture?
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.
Actually, this value already gives precedence to the env variable
https://github.com/localstack/localstack/blob/unify-fixtures/localstack/constants.py#L159-L163
I admit that its place in localstack.constants
is misleading.
Would it be okay if I add a todo note and make the changes in a follow up PR, given how large this PR is already?
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.
LGTM, didn't spot any obvious issues.
I have a bit of a concern in terms of using this fixture for unit tests, though. I think keeping those static is fine
tests/unit/aws/test_connect.py
Outdated
region_name="us-east-1", | ||
region_name=region_name, |
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.
I'm not so sure we want to do this with unit tests. The behavior of the underlying region lookup seems to be not as well defined here 🤔
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.
You're right, I picked this from #8204 but I'm unable to reproduce the original reason for the change. Reverted for now, I'll revisit this if it reoccurs.
# Boto still does not support chunk encoding, which means we can't test with the client nor | ||
# aws_http_client_factory. See open issue: https://github.com/boto/boto3/issues/751 | ||
# Test for https://github.com/localstack/localstack/issues/1571 | ||
object_key = "data" | ||
body = "Hello\r\n\r\n\r\n\r\n" | ||
headers = { | ||
"Authorization": mock_aws_request_headers( | ||
"s3", aws_access_key_id=TEST_AWS_ACCESS_KEY_ID, region_name=TEST_AWS_REGION_NAME | ||
"s3", | ||
aws_access_key_id=TEST_AWS_ACCESS_KEY_ID, |
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.
we should be able to get this via STS as well,so might be worth to make this a fixture too
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.
Do you mean STS:GetSessionToken
? I'll make a note, thanks!
This reverts commit 97de34e.
Background
This PR makes some code improvements for test credentials and region.
Changes
Remove redundantAdded by Extract snapshot lib #10164is_aws()
helper and useis_aws_cloud()
everywhere.