Skip to content

Commit

Permalink
apacheGH-42134: [C++][FS][Azure] Validate AzureOptions::{blob,dfs}_st…
Browse files Browse the repository at this point in the history
…orage_scheme
  • Loading branch information
kou committed Jun 13, 2024
1 parent 40f9c26 commit adca6f6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cpp/src/arrow/filesystem/azurefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ Result<std::unique_ptr<Blobs::BlobServiceClient>> AzureOptions::MakeBlobServiceC
if (account_name.empty()) {
return Status::Invalid("AzureOptions doesn't contain a valid account name");
}
if (!(blob_storage_scheme == "http" || blob_storage_scheme == "https")) {
return Status::Invalid("AzureOptions::blob_storage_scheme must be http or https: ",
blob_storage_scheme);
}
switch (credential_kind_) {
case CredentialKind::kAnonymous:
return std::make_unique<Blobs::BlobServiceClient>(AccountBlobUrl(account_name));
Expand Down Expand Up @@ -393,6 +397,10 @@ AzureOptions::MakeDataLakeServiceClient() const {
if (account_name.empty()) {
return Status::Invalid("AzureOptions doesn't contain a valid account name");
}
if (!(dfs_storage_scheme == "http" || dfs_storage_scheme == "https")) {
return Status::Invalid("AzureOptions::dfs_storage_scheme must be http or https: ",
dfs_storage_scheme);
}
switch (credential_kind_) {
case CredentialKind::kAnonymous:
return std::make_unique<DataLake::DataLakeServiceClient>(
Expand Down
44 changes: 44 additions & 0 deletions cpp/src/arrow/filesystem/azurefs_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,38 @@ class TestAzureOptions : public ::testing::Test {
"unknown=invalid",
nullptr));
}

void TestMakeBlobServiceClientInvalidAccountName() {
AzureOptions options;
ASSERT_RAISES_WITH_MESSAGE(
Invalid, "Invalid: AzureOptions doesn't contain a valid account name",
options.MakeBlobServiceClient());
}

void TestMakeBlobServiceClientInvalidBlobStorageScheme() {
AzureOptions options;
options.account_name = "user";
options.blob_storage_scheme = "abfs";
ASSERT_RAISES_WITH_MESSAGE(
Invalid, "Invalid: AzureOptions::blob_storage_scheme must be http or https: abfs",
options.MakeBlobServiceClient());
}

void TestMakeDataLakeServiceClientInvalidAccountName() {
AzureOptions options;
ASSERT_RAISES_WITH_MESSAGE(
Invalid, "Invalid: AzureOptions doesn't contain a valid account name",
options.MakeDataLakeServiceClient());
}

void TestMakeDataLakeServiceClientInvalidDfsStorageScheme() {
AzureOptions options;
options.account_name = "user";
options.dfs_storage_scheme = "abfs";
ASSERT_RAISES_WITH_MESSAGE(
Invalid, "Invalid: AzureOptions::dfs_storage_scheme must be http or https: abfs",
options.MakeDataLakeServiceClient());
}
};

TEST_F(TestAzureOptions, FromUriBlobStorage) { TestFromUriBlobStorage(); }
Expand Down Expand Up @@ -764,6 +796,18 @@ TEST_F(TestAzureOptions, FromUriDfsStorageAuthority) { TestFromUriDfsStorageAuth
TEST_F(TestAzureOptions, FromUriInvalidQueryParameter) {
TestFromUriInvalidQueryParameter();
}
TEST_F(TestAzureOptions, MakeBlobServiceClientInvalidAccountName) {
TestMakeBlobServiceClientInvalidAccountName();
}
TEST_F(TestAzureOptions, MakeBlobServiceClientInvalidBlobStorageScheme) {
TestMakeBlobServiceClientInvalidBlobStorageScheme();
}
TEST_F(TestAzureOptions, MakeDataLakeServiceClientInvalidAccountName) {
TestMakeDataLakeServiceClientInvalidAccountName();
}
TEST_F(TestAzureOptions, MakeDataLakeServiceClientInvalidDfsStorageScheme) {
TestMakeDataLakeServiceClientInvalidDfsStorageScheme();
}

class TestAzureFileSystem : public ::testing::Test {
protected:
Expand Down

0 comments on commit adca6f6

Please sign in to comment.