-
Notifications
You must be signed in to change notification settings - Fork 0
chore: disable ranged gets #178
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,72 @@ | ||
| # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| """Integration test for ranged get (Range parameter on get_object). | ||
|
|
||
| The S3 Encryption Client does not support ranged gets because decryption | ||
| requires the full ciphertext (IV, encrypted data, and auth tag). Passing | ||
| a Range parameter retrieves only a slice of the ciphertext, which causes | ||
| decryption to fail. | ||
| """ | ||
|
|
||
| import os | ||
| from datetime import datetime | ||
|
|
||
| import boto3 | ||
| import pytest | ||
|
|
||
| from s3_encryption import S3EncryptionClient, S3EncryptionClientConfig | ||
| from s3_encryption.exceptions import S3EncryptionClientError | ||
| from s3_encryption.materials.kms_keyring import KmsKeyring | ||
| from s3_encryption.materials.materials import AlgorithmSuite, CommitmentPolicy | ||
|
|
||
| bucket = os.environ.get("CI_S3_BUCKET", "s3ec-python-github-test-bucket") | ||
| region = os.environ.get("CI_AWS_REGION", "us-west-2") | ||
| kms_key_id = os.environ.get( | ||
| "CI_KMS_KEY_ALIAS", "arn:aws:kms:us-west-2:370957321024:alias/S3EC-Python-Github-KMS-Key" | ||
| ) | ||
|
|
||
|
|
||
| def _make_client(algorithm_suite, commitment_policy): | ||
| """Create an S3EncryptionClient with the given algorithm config.""" | ||
| kms_client = boto3.client("kms", region_name=region) | ||
| keyring = KmsKeyring(kms_client, kms_key_id) | ||
| wrapped_client = boto3.client("s3") | ||
| config = S3EncryptionClientConfig( | ||
| keyring, | ||
| encryption_algorithm=algorithm_suite, | ||
| commitment_policy=commitment_policy, | ||
| ) | ||
| return S3EncryptionClient(wrapped_client, config) | ||
|
|
||
|
|
||
| def _unique_key(prefix): | ||
| """Generate a unique S3 key with a timestamp suffix.""" | ||
| return prefix + datetime.now().strftime("%Y-%m-%d-%H:%M:%S-%f") | ||
|
|
||
|
|
||
| ALGORITHM_CONFIGS = [ | ||
| pytest.param( | ||
| AlgorithmSuite.ALG_AES_256_GCM_IV12_TAG16_NO_KDF, | ||
| CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT, | ||
| id="AES_GCM", | ||
| ), | ||
| pytest.param( | ||
| AlgorithmSuite.ALG_AES_256_GCM_HKDF_SHA512_COMMIT_KEY, | ||
| CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT, | ||
| id="KC_GCM", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize(("algorithm_suite", "commitment_policy"), ALGORITHM_CONFIGS) | ||
| def test_ranged_get_fails(algorithm_suite, commitment_policy): | ||
| """Ranged gets are rejected with a clear error.""" | ||
| key = _unique_key("ranged-get-") | ||
| data = b"A" * 1024 | ||
|
|
||
| s3ec = _make_client(algorithm_suite, commitment_policy) | ||
| s3ec.put_object(Bucket=bucket, Key=key, Body=data) | ||
|
|
||
| # Attempt a ranged get — should raise immediately with a clear message | ||
| with pytest.raises(S3EncryptionClientError, match="Ranged gets are currently not supported"): | ||
| s3ec.get_object(Bucket=bucket, Key=key, Range="bytes=0-255") | ||
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.
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.
super nit: could be something in a fixtures file?