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: diff --git a/python/pyarrow/tests/test_fs.py b/python/pyarrow/tests/test_fs.py index 58380f1652558..412daa2bd9ea1 100644 --- a/python/pyarrow/tests/test_fs.py +++ b/python/pyarrow/tests/test_fs.py @@ -1450,8 +1450,8 @@ def test_azurefs_options(pickle_module): fs3 = AzureFileSystem(account_name='fake-account', account_key='fakeaccount', blob_storage_authority='fake-blob-authority', dfs_storage_authority='fake-dfs-authority', - blob_storage_scheme='fake-blob-scheme', - dfs_storage_scheme='fake-dfs-scheme') + blob_storage_scheme='https', + dfs_storage_scheme='https') assert isinstance(fs3, AzureFileSystem) assert pickle_module.loads(pickle_module.dumps(fs3)) == fs3 assert fs3 != fs2