-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ManagedIdentityClient uses AZURE_CLIENT_ID when available #19062
Closed
christothes
wants to merge
1
commit into
Azure:master
from
christothes:users/chriss/MIC-AZURE_CLIENT_ID
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
sdk/identity/Azure.Identity/tests/ManagedIdentityClientOptionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Azure.Identity.Tests; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.Identity.Tests | ||
{ | ||
public class ManagedIdentityClientOptionsTests | ||
{ | ||
public const string ExplicitClientId = "1234"; | ||
public const string ClientIdFromEnvironment = "4567"; | ||
|
||
[Test] | ||
public void ClientIdIsReadFromEnvironmentVariableWhenAvailable( | ||
[Values(null, ExplicitClientId)] string explicitClientId, | ||
[Values(null, ClientIdFromEnvironment)] string clientIdFromEnvironment) | ||
{ | ||
using (new TestEnvVar(new () | ||
{ | ||
{ "AZURE_CLIENT_ID", clientIdFromEnvironment } | ||
})) | ||
{ | ||
var options = new ManagedIdentityClientOptions(); | ||
if (explicitClientId != null) | ||
{ | ||
options.ClientId = explicitClientId; | ||
} | ||
|
||
string expectedClientId = explicitClientId switch | ||
{ | ||
null when clientIdFromEnvironment is null => null, | ||
null when clientIdFromEnvironment is not null => clientIdFromEnvironment, | ||
_ => explicitClientId, | ||
}; | ||
|
||
Assert.That(options.ClientId, Is.EqualTo(expectedClientId)); | ||
} | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
sdk/identity/Azure.Identity/tests/ManagedIdentityClientTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Azure.Identity.Tests; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.Identity.Tests | ||
{ | ||
public class ManagedIdentityClientTests | ||
{ | ||
public const string ClientIdFromCtor = "1234"; | ||
public const string ClientIdFromEnvironment = "4567"; | ||
|
||
[Test] | ||
public void ClientIdIsReadFromEnvironmentVariableWhenAvailable( | ||
[Values(null, ClientIdFromCtor)] string clientIdFromCtor, | ||
[Values(null, ClientIdFromEnvironment)] string clientIdFromEnvironment) | ||
{ | ||
using (new TestEnvVar(new () | ||
{ | ||
{ "AZURE_CLIENT_ID", clientIdFromEnvironment }})) | ||
{ | ||
var client = new ManagedIdentityClient(default, clientIdFromCtor); | ||
|
||
string expectedClientId = clientIdFromCtor switch | ||
{ | ||
null when clientIdFromEnvironment is null => null, | ||
null when clientIdFromEnvironment is not null => clientIdFromEnvironment, | ||
_ => clientIdFromCtor, | ||
}; | ||
|
||
Assert.That(client.ClientId, Is.EqualTo(expectedClientId)); | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to change this to read the environment variable. By design only the
DefaultAzureCredential
andEnvironmentCredential
are configurable through the environment.