Skip to content

Commit

Permalink
Backport #24898 to 20.8: Fixed bug with declaring S3 disk at root of …
Browse files Browse the repository at this point in the history
…bucket
  • Loading branch information
robot-clickhouse committed Jun 10, 2021
1 parent 0b92812 commit 572a423
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
5 changes: 0 additions & 5 deletions src/IO/S3Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,6 @@ namespace S3
key = uri.getPath().substr(1);
}

if (key.empty() || key == "/")
throw Exception("Key name is empty in virtual hosted style S3 URI: " + key + " (" + uri.toString() + ")", ErrorCodes::BAD_ARGUMENTS);
boost::to_upper(name);
if (name != S3 && name != COS)
{
Expand All @@ -289,9 +287,6 @@ namespace S3
if (bucket.length() < 3 || bucket.length() > 63)
throw Exception(
"Bucket name length is out of bounds in path style S3 URI: " + bucket + " (" + uri.toString() + ")", ErrorCodes::BAD_ARGUMENTS);

if (key.empty() || key == "/")
throw Exception("Key name is empty in path style S3 URI: " + key + " (" + uri.toString() + ")", ErrorCodes::BAD_ARGUMENTS);
}
else
throw Exception("Bucket or key name are invalid in S3 URI: " + uri.toString(), ErrorCodes::BAD_ARGUMENTS);
Expand Down
24 changes: 21 additions & 3 deletions src/IO/tests/gtest_s3_uri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@ class S3UriTest : public testing::TestWithParam<std::string>

TEST(S3UriTest, validPatterns)
{
{
S3::URI uri(Poco::URI("https://jokserfn.s3.yandexcloud.net/"));
ASSERT_EQ("https://s3.yandexcloud.net", uri.endpoint);
ASSERT_EQ("jokserfn", uri.bucket);
ASSERT_EQ("", uri.key);
ASSERT_EQ(true, uri.is_virtual_hosted_style);
}
{
S3::URI uri(Poco::URI("https://s3.yandexcloud.net/jokserfn/"));
ASSERT_EQ("https://s3.yandexcloud.net", uri.endpoint);
ASSERT_EQ("jokserfn", uri.bucket);
ASSERT_EQ("", uri.key);
ASSERT_EQ(false, uri.is_virtual_hosted_style);
}
{
S3::URI uri(Poco::URI("https://yandexcloud.net/bucket/"));
ASSERT_EQ("https://yandexcloud.net", uri.endpoint);
ASSERT_EQ("bucket", uri.bucket);
ASSERT_EQ("", uri.key);
ASSERT_EQ(false, uri.is_virtual_hosted_style);
}
{
S3::URI uri(Poco::URI("https://jokserfn.s3.yandexcloud.net/data"));
ASSERT_EQ("https://s3.yandexcloud.net", uri.endpoint);
Expand Down Expand Up @@ -76,15 +97,12 @@ INSTANTIATE_TEST_SUITE_P(
S3UriTest,
testing::Values(
"https:///",
"https://jokserfn.s3.yandexcloud.net/",
"https://.s3.yandexcloud.net/key",
"https://s3.yandexcloud.net/key",
"https://jokserfn.s3yandexcloud.net/key",
"https://s3.yandexcloud.net/key/",
"https://s3.yandexcloud.net//",
"https://yandexcloud.net/",
"https://yandexcloud.net//",
"https://yandexcloud.net/bucket/",
"https://yandexcloud.net//key"));

}
Expand Down

0 comments on commit 572a423

Please sign in to comment.