-
Notifications
You must be signed in to change notification settings - Fork 559
Try to fix access to S3 object that has question mark in the object name #1155
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
speeddragon
wants to merge
3
commits into
ex-aws:main
Choose a base branch
from
speeddragon:fix_object_encoding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 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
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
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 |
---|---|---|
|
@@ -3,6 +3,8 @@ defmodule ExAws.Operation.S3Test do | |
|
||
alias Elixir.ExAws.Operation.ExAws.Operation.S3 | ||
|
||
import Mox | ||
|
||
def s3_operation(bucket \\ "my-bucket-1") do | ||
%ExAws.Operation.S3{ | ||
body: "", | ||
|
@@ -80,4 +82,109 @@ defmodule ExAws.Operation.S3Test do | |
{processed_operation, _processed_config} = S3.add_bucket_to_path(operation, config) | ||
assert processed_operation.path == "/folder/" | ||
end | ||
|
||
test "S3 object encoding with query parameter seperator (?)" do | ||
config = %{ | ||
http_client: ExAws.Request.HttpMock, | ||
json_codec: JSX, | ||
access_key_id: "AKIAIOSFODNN7EXAMPLE", | ||
secret_access_key: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", | ||
region: "us-east-1", | ||
retries: [ | ||
max_attempts: 5, | ||
base_backoff_in_ms: 1, | ||
max_backoff_in_ms: 20 | ||
], | ||
normalize_path: false, | ||
scheme: "https://", | ||
host: "s3.amazonaws.com", | ||
virtual_host: true, | ||
port: 443 | ||
} | ||
Comment on lines
+87
to
+103
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. This was put together just to check if the test is valid. This should be improved and moved to a separate test. |
||
|
||
headers = %{ | ||
"x-amz-bucket-region" => "us-east-1", | ||
"x-amz-content-sha256" => ExAws.Auth.Utils.hash_sha256(""), | ||
"content-length" => byte_size("") | ||
} | ||
|
||
expect( | ||
ExAws.Request.HttpMock, | ||
:request, | ||
fn _method, url, _body, _headers, _opts -> | ||
assert url == "https://examplebucket.s3.amazonaws.com/test%20hello%20%233.txt%3Facl%3D21" | ||
{:ok, %{status_code: 200}} | ||
end | ||
) | ||
|
||
operation = %ExAws.Operation.S3{ | ||
s3_operation() | ||
| path: "test hello #3.txt?acl=21", | ||
headers: headers, | ||
bucket: "examplebucket" | ||
} | ||
|
||
assert {:ok, %{status_code: 200}} == S3.perform(operation, config) | ||
end | ||
|
||
test "S3 object encoding with query parameter seperator (?) and version_id" do | ||
config = %{ | ||
http_client: ExAws.Request.HttpMock, | ||
json_codec: JSX, | ||
access_key_id: "AKIAIOSFODNN7EXAMPLE", | ||
secret_access_key: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", | ||
region: "us-east-1", | ||
retries: [ | ||
max_attempts: 5, | ||
base_backoff_in_ms: 1, | ||
max_backoff_in_ms: 20 | ||
], | ||
normalize_path: false, | ||
scheme: "https://", | ||
host: "s3.amazonaws.com", | ||
virtual_host: true, | ||
port: 443 | ||
} | ||
|
||
headers = %{ | ||
"x-amz-bucket-region" => "us-east-1", | ||
"x-amz-content-sha256" => ExAws.Auth.Utils.hash_sha256(""), | ||
"content-length" => byte_size("") | ||
} | ||
|
||
expect( | ||
ExAws.Request.HttpMock, | ||
:request, | ||
fn _method, url, _body, _headers, _opts -> | ||
assert url == | ||
"https://examplebucket.s3.amazonaws.com/test%20hello%20%233.txt%3Facl%3D21?version-id=v1" | ||
|
||
{:ok, %{status_code: 200}} | ||
end | ||
) | ||
|
||
operation = %ExAws.Operation.S3{ | ||
s3_operation() | ||
| path: "test hello #3.txt?acl=21", | ||
headers: headers, | ||
bucket: "examplebucket", | ||
params: %{"version-id" => "v1"} | ||
} | ||
|
||
assert {:ok, %{status_code: 200}} == S3.perform(operation, config) | ||
end | ||
|
||
describe "encode_path_query_fragment_into_path" do | ||
test "fetch object ending in question mark (?)" do | ||
%{path: "object.txt%3F"} = | ||
%ExAws.Operation.S3{path: "object.txt?"} | ||
|> S3.encode_path_query_fragment_into_path() | ||
end | ||
|
||
test "fetch object with name contains query parameters" do | ||
%{path: "object.txt%3Fid%3D3"} = | ||
%ExAws.Operation.S3{path: "object.txt?id=3"} | ||
|> S3.encode_path_query_fragment_into_path() | ||
end | ||
end | ||
end |
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
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.
This is needed to support
text.txt?
object, since if the object name ends with the question mark, theURI.to_string
will add another question mark and theString.trim_trailing/2
will remove both.