diff --git a/cpp/src/arrow/filesystem/azurefs.cc b/cpp/src/arrow/filesystem/azurefs.cc index ca64486724733..a3aa2c8e837d9 100644 --- a/cpp/src/arrow/filesystem/azurefs.cc +++ b/cpp/src/arrow/filesystem/azurefs.cc @@ -366,6 +366,10 @@ Result> 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(AccountBlobUrl(account_name)); @@ -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( diff --git a/cpp/src/arrow/filesystem/azurefs_test.cc b/cpp/src/arrow/filesystem/azurefs_test.cc index 05ff3e551cd81..9a11a6f24995a 100644 --- a/cpp/src/arrow/filesystem/azurefs_test.cc +++ b/cpp/src/arrow/filesystem/azurefs_test.cc @@ -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(); } @@ -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: