Skip to content

Commit b5c3c49

Browse files
authored
Do not throw an exception during AzureCliCredential construction, but rather delay it on GetToken() call. (#4979)
* Do not throw an exception during `AzureCliCredential` construction, but rather delay it on GetToken() call. * Update az cli unsafe chars test.
1 parent 9a2c2e1 commit b5c3c49

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

sdk/identity/azure-identity/src/azure_cli_credential.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ AzureCliCredential::AzureCliCredential(
9292
{
9393
static_cast<void>(options);
9494

95-
ThrowIfNotSafeCmdLineInput(m_tenantId, "TenantID");
96-
9795
IdentityLog::Write(
9896
IdentityLog::Level::Informational,
9997
GetCredentialName()
@@ -123,6 +121,7 @@ std::string AzureCliCredential::GetAzCommand(std::string const& scopes, std::str
123121
const
124122
{
125123
ThrowIfNotSafeCmdLineInput(scopes, "Scopes");
124+
ThrowIfNotSafeCmdLineInput(m_tenantId, "TenantID");
126125
std::string command = "az account get-access-token --output json --scope \"" + scopes + "\"";
127126

128127
if (!tenantId.empty())

sdk/identity/azure-identity/test/ut/azure_cli_credential_test.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,11 @@ TEST(AzureCliCredential, UnsafeChars)
325325
AzureCliCredentialOptions options;
326326
options.TenantId = "01234567-89AB-CDEF-0123-456789ABCDEF";
327327
options.TenantId += Exploit;
328+
AzureCliCredential azCliCred(options);
328329

329-
EXPECT_THROW(
330-
static_cast<void>(std::make_unique<AzureCliCredential>(options)), AuthenticationException);
330+
TokenRequestContext trc;
331+
trc.Scopes.push_back(std::string("https://storage.azure.com/.default"));
332+
EXPECT_THROW(static_cast<void>(azCliCred.GetToken(trc, {})), AuthenticationException);
331333
}
332334

333335
{

0 commit comments

Comments
 (0)