Skip to content
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

throw exception on redirect limit in S3 request #12256

Merged
merged 1 commit into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/IO/S3/PocoHTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
#include <Poco/Net/HTTPResponse.h>
#include <common/logger_useful.h>

namespace DB::ErrorCodes
{
extern const int TOO_MANY_REDIRECTS;
}

namespace DB::S3
{
PocoHTTPClient::PocoHTTPClient(const Aws::Client::ClientConfiguration & clientConfiguration)
Expand Down Expand Up @@ -153,8 +158,10 @@ void PocoHTTPClient::MakeRequestInternal(
else
response->GetResponseStream().SetUnderlyingStream(std::make_shared<PocoHTTPResponseStream>(session, response_body_stream));

break;
return;
}
throw Exception(String("Too many redirects while trying to access ") + request.GetUri().GetURIString(),
ErrorCodes::TOO_MANY_REDIRECTS);
}
catch (...)
{
Expand Down
9 changes: 8 additions & 1 deletion tests/integration/test_storage_s3/s3_mock/mock_s3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from bottle import abort, route, run, request
from bottle import abort, route, run, request, response


@route('/redirected/<_path>')
def infinite_redirect(_path):
response.set_header("Location", request.url)
response.status = 307
return 'Redirected'


@route('/<_bucket>/<_path>')
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/test_storage_s3/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,19 @@ def test_get_csv_default(cluster):
instance = cluster.instances["dummy"] # type: ClickHouseInstance
result = run_query(instance, get_query)
assert result == '1\t2\t3\n'


def test_infinite_redirect(cluster):
bucket = "redirected"
table_format = "column1 UInt32, column2 UInt32, column3 UInt32"
filename = "test.csv"
get_query = "select * from s3('http://resolver:8080/{bucket}/{file}', 'CSV', '{table_format}')".format(
bucket="redirected",
file=filename,
table_format=table_format)
instance = cluster.instances["dummy"] # type: ClickHouseInstance
try:
result = run_query(instance, get_query)
except Exception as e:
assert str(e).find("Too many redirects while trying to access") != -1