-
Notifications
You must be signed in to change notification settings - Fork 4.6k
[v2] Add blackbox tests #10591
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
Open
Open
[v2] Add blackbox tests #10591
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
135baaa
Implement blackbox tests.
aemous 7799ba5
Rewrite s3 assertion helper functions without using C2J model.
aemous 93f676a
Add safeguard to verify the CLI respects the HTTPS_PROXY env var.
aemous 9a9d3de
Add type coercion when XML protocol is used in blackbox tests.
aemous bedb13f
Add new blackbox requirements file and update regenerate-lock-files s…
aemous File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| pytest==8.4.0 | ||
| pytest-xdist==3.6.1 | ||
| pip-tools==7.6.1 | ||
| # localstub is a required dependency of | ||
| # blackbox tests. | ||
| localstub==0.0.3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| """Shared fixtures for blackbox tests.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import asyncio | ||
| import os | ||
| import shutil | ||
|
|
||
| import pytest | ||
|
|
||
| from tests.blackbox.utils import cli_env, mock_server, run_cli | ||
| from localstub.server import HTTPResponse | ||
|
|
||
|
|
||
| def pytest_configure(config): | ||
| """Heuristic to verify if the CLI binary routes traffic through | ||
| HTTPS_PROXY before any test runs. | ||
|
|
||
| If the proxy receives no request, the binary under test does not support | ||
| HTTPS_PROXY and all tests would be invalid — fail the session immediately. | ||
| """ | ||
| command = os.environ.get("AWS_TEST_COMMAND") or shutil.which("aws") | ||
| if command is None: | ||
| pytest.exit( | ||
| "No AWS CLI binary found: set AWS_TEST_COMMAND to its path or " | ||
| "make `aws` available on PATH.", | ||
| returncode=1, | ||
| ) | ||
|
|
||
| async def _verify(): | ||
|
|
||
| async with mock_server() as (server, proxy): | ||
| server.set_response_sequence([ | ||
| HTTPResponse.raw( | ||
| b'<?xml version="1.0" ?>' | ||
| b"<Error><Code>AccessDenied</Code>" | ||
| b"<Message>Test</Message></Error>", | ||
| status=403, | ||
| headers={"Content-Type": "application/xml"}, | ||
| ), | ||
| ]) | ||
| env = cli_env(proxy) | ||
| await run_cli(command, ["s3", "ls"], env) | ||
| return len(server.requests) > 0 | ||
|
|
||
| proxy_works = asyncio.run(_verify()) | ||
| if not proxy_works: | ||
| pytest.exit( | ||
| f"CLI binary {command!r} does not route traffic through " | ||
| f"HTTPS_PROXY. All blackbox tests require proxy support to " | ||
| f"prevent accidental calls to production AWS endpoints.", | ||
| returncode=1, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def aws_cli() -> str: | ||
| command = os.environ.get("AWS_TEST_COMMAND") or shutil.which("aws") | ||
| if command is None: | ||
| pytest.fail( | ||
| "No AWS CLI binary found: set AWS_TEST_COMMAND to its path or " | ||
| "make `aws` available on PATH." | ||
| ) | ||
| return command | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def aws_config(tmp_path): | ||
| """Factory fixture that writes an AWS config file and returns its path.""" | ||
|
|
||
| def _make(config_dict: dict[str, dict[str, str]]) -> str: | ||
| lines = [] | ||
| for section, values in config_dict.items(): | ||
| lines.append(f"[{section}]") | ||
| for key, val in values.items(): | ||
| lines.append(f"{key} = {val}") | ||
| lines.append("") | ||
| path = tmp_path / "config" | ||
| path.write_text("\n".join(lines)) | ||
| return str(path) | ||
|
|
||
| return _make | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.