Skip to content

Commit

Permalink
Storage/STG94 Add Queues bearer challenge test case (Azure#5556)
Browse files Browse the repository at this point in the history
* Add test for queue bearer challenge

* update test case

* update var name

* update test case

* fix clang format
  • Loading branch information
microzchang authored Apr 25, 2024
1 parent b1286f5 commit fc126c4
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sdk/storage/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "cpp",
"TagPrefix": "cpp/storage",
"Tag": "cpp/storage_ff69c43232"
"Tag": "cpp/storage_94115793d6"
}
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,73 @@ namespace Azure { namespace Storage { namespace Test {
= Queues::QueueServiceClient(m_queueServiceClient->GetUrl(), credential, clientOptions);
EXPECT_THROW(queueServiceClient.GetProperties(), StorageException);
}

TEST_F(QueueServiceClientTest, BearerChallengeWorks)
{
auto clientOptions = InitStorageClientOptions<Queues::QueueClientOptions>();
auto options = InitStorageClientOptions<Azure::Identity::ClientSecretCredentialOptions>();

// With tenantId
clientOptions.EnableTenantDiscovery = true;
options.AdditionallyAllowedTenants = {"*"};
auto queueServiceClient = Queues::QueueServiceClient(
m_queueServiceClient->GetUrl(),
std::make_shared<Azure::Identity::ClientSecretCredential>(
AadTenantId(), AadClientId(), AadClientSecret(), options),
clientOptions);
EXPECT_NO_THROW(queueServiceClient.GetProperties());

// Without tenantId
clientOptions.EnableTenantDiscovery = true;
options.AdditionallyAllowedTenants = {"*"};
queueServiceClient = Queues::QueueServiceClient(
m_queueServiceClient->GetUrl(),
std::make_shared<Azure::Identity::ClientSecretCredential>(
"", AadClientId(), AadClientSecret(), options),
clientOptions);
EXPECT_NO_THROW(queueServiceClient.GetProperties());

// With custom audience
auto queueUrl = Azure::Core::Url(m_queueServiceClient->GetUrl());
clientOptions.Audience
= Queues::QueueAudience(queueUrl.GetScheme() + "://" + queueUrl.GetHost());
queueServiceClient = Queues::QueueServiceClient(
m_queueServiceClient->GetUrl(),
std::make_shared<Azure::Identity::ClientSecretCredential>(
"", AadClientId(), AadClientSecret(), options),
clientOptions);
EXPECT_NO_THROW(queueServiceClient.GetProperties());
clientOptions.Audience.Reset();

// With error tenantId
clientOptions.EnableTenantDiscovery = true;
options.AdditionallyAllowedTenants = {"*"};
queueServiceClient = Queues::QueueServiceClient(
m_queueServiceClient->GetUrl(),
std::make_shared<Azure::Identity::ClientSecretCredential>(
"test", AadClientId(), AadClientSecret(), options),
clientOptions);
EXPECT_NO_THROW(queueServiceClient.GetProperties());

// Disable Tenant Discovery and without tenantId
clientOptions.EnableTenantDiscovery = false;
queueServiceClient = Queues::QueueServiceClient(
m_queueServiceClient->GetUrl(),
std::make_shared<Azure::Identity::ClientSecretCredential>(
"", AadClientId(), AadClientSecret(), options),
clientOptions);
EXPECT_THROW(
queueServiceClient.GetProperties(), Azure::Core::Credentials::AuthenticationException);

// Don't allow additional tenants
clientOptions.EnableTenantDiscovery = true;
options.AdditionallyAllowedTenants = {};
queueServiceClient = Queues::QueueServiceClient(
m_queueServiceClient->GetUrl(),
std::make_shared<Azure::Identity::ClientSecretCredential>(
"", AadClientId(), AadClientSecret(), options),
clientOptions);
EXPECT_THROW(
queueServiceClient.GetProperties(), Azure::Core::Credentials::AuthenticationException);
}
}}} // namespace Azure::Storage::Test

0 comments on commit fc126c4

Please sign in to comment.