Skip to content

Commit

Permalink
Fix inadvertent pytest fixture session token usage
Browse files Browse the repository at this point in the history
This commit will correct the two failing tests:

```text
FAILED tests/cloud/test_object_storage.py::TestObjectStorageClientUnit::
test_generate_presigned_url_example[False]

FAILED tests/cloud/test_object_storage.py::TestObjectStorageClientUnit::
test_generate_presigned_post_example[False]
```

The `False` parameter output means that `use_session_token` was `False`
in the corresponding fixtures in conftest.py:

- `object_storage_config_for_presigned_url_example`
- `object_storage_config_for_presigned_post_example`

There may be situations, such as tests in a GitHub Actions workflow, in
which multiple sets of credentials are present. In these situations,
there may be environment variables such as `AWS_SESSION_TOKEN` that are
set, but should not be used in certain `ObjectStorageConfig` instances.
Setting `session_token` to an empty string (`session_token=""`) prevents
`class ObjectStorageConfig` from using the environment variable value.

There is a unit test, `test_config_with_environment_variable_overrides`
in `tests/cloud/test_object_storage.py`, which verifies the correct
behavior. However, the pytest fixtures listed above were still setting
`session_token=None`, which then was making their `ObjectStorageConfig`
instances inadvertently pick up `AWS_SESSION_TOKEN`. The fix is just to
set `session_token=""` when `use_session_token=False` in those fixtures.
  • Loading branch information
br3ndonland committed Apr 11, 2022
1 parent 176278a commit 608aad9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def object_storage_config_for_presigned_url_example(
quoted_session_token
)
else:
session_token = None
session_token = ""
try:
object_storage_config = fastenv.cloud.object_storage.ObjectStorageConfig(
access_key="AKIAIOSFODNN7EXAMPLE",
Expand Down Expand Up @@ -229,7 +229,7 @@ def object_storage_config_for_presigned_post_example(
quoted_session_token
)
else:
session_token = None
session_token = ""
try:
object_storage_config = fastenv.cloud.object_storage.ObjectStorageConfig(
access_key="AKIAIOSFODNN7EXAMPLE",
Expand Down

0 comments on commit 608aad9

Please sign in to comment.