Skip to content

Commit e2a37c2

Browse files
authored
VM managed identity integration test (Azure#38457)
1 parent bcdf23f commit e2a37c2

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

sdk/identity/Azure.Identity/tests/CredentialTestHelpers.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace Azure.Identity.Tests
2323
{
2424
internal static class CredentialTestHelpers
2525
{
26+
public static string[] DefaultScope = new string[] { "https://management.azure.com//.default" };
2627
private const string DiscoveryResponseBody =
2728
"{\"tenant_discovery_endpoint\": \"https://login.microsoftonline.com/c54fac88-3dd3-461f-a7c4-8a368e0340b3/v2.0/.well-known/openid-configuration\",\"api-version\": \"1.1\",\"metadata\":[{\"preferred_network\": \"login.microsoftonline.com\",\"preferred_cache\": \"login.windows.net\",\"aliases\":[\"login.microsoftonline.com\",\"login.windows.net\",\"login.microsoft.com\",\"sts.windows.net\"]},{\"preferred_network\": \"login.partner.microsoftonline.cn\",\"preferred_cache\": \"login.partner.microsoftonline.cn\",\"aliases\":[\"login.partner.microsoftonline.cn\",\"login.chinacloudapi.cn\"]},{\"preferred_network\": \"login.microsoftonline.de\",\"preferred_cache\": \"login.microsoftonline.de\",\"aliases\":[\"login.microsoftonline.de\"]},{\"preferred_network\": \"login.microsoftonline.us\",\"preferred_cache\": \"login.microsoftonline.us\",\"aliases\":[\"login.microsoftonline.us\",\"login.usgovcloudapi.net\"]},{\"preferred_network\": \"login-us.microsoftonline.com\",\"preferred_cache\": \"login-us.microsoftonline.com\",\"aliases\":[\"login-us.microsoftonline.com\"]}]}";
2829
public static (string Token, DateTimeOffset ExpiresOn, string Json) CreateTokenForAzureCli() => CreateTokenForAzureCli(TimeSpan.FromSeconds(30));

sdk/identity/Azure.Identity/tests/IdentityTestEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using System;
54
using System.IO;
65
using Azure.Core.TestFramework;
76
using NUnit.Framework;
@@ -39,6 +38,7 @@ public class IdentityTestEnvironment : TestEnvironment
3938
public string ServicePrincipalCertificatePemPath => GetOptionalVariable("IDENTITY_SP_CERT_PEM") ?? Path.Combine(TestContext.CurrentContext.TestDirectory, "Data", "cert.pem");
4039
public string ServicePrincipalSniCertificatePath => GetOptionalVariable("IDENTITY_SP_CERT_SNI") ?? Path.Combine(TestContext.CurrentContext.TestDirectory, "Data", "cert.pfx");
4140
public string IdentityTestWebName => GetRecordedVariable("IDENTITY_WEBAPP_NAME");
41+
public string VMUserAssignedManagedIdentityClientId => GetOptionalVariable("IDENTITY_VM_USER_ASSIGNED_MI_CLIENT_ID");
4242
public string IdentityTestAzFuncName => GetRecordedVariable("IDENTITY_FUNCTION_NAME");
4343
}
4444
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Threading.Tasks;
6+
using Azure.Core.Pipeline;
7+
using Azure.Core.TestFramework;
8+
using NUnit.Framework;
9+
10+
namespace Azure.Identity.Tests
11+
{
12+
public class ManagedIdentityVMIntegrationTests : IdentityRecordedTestBase
13+
{
14+
public ManagedIdentityVMIntegrationTests(bool isAsync) : base(isAsync)
15+
{ }
16+
17+
[Test]
18+
[LiveOnly]
19+
[Category("IdentityVM")]
20+
// This test leverages the test app found in Azure.Identity\integration\WebApp
21+
// It validates that ManagedIdentityCredential can acquire a token in an actual Azure Web App environment
22+
public async Task GetManagedIdentityToken()
23+
{
24+
var cred = new ManagedIdentityCredential(TestEnvironment.VMUserAssignedManagedIdentityClientId);
25+
var token = await cred.GetTokenAsync(new(CredentialTestHelpers.DefaultScope));
26+
Assert.NotNull(token.Token);
27+
}
28+
}
29+
}

sdk/identity/platform-matrix.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
{
2+
"displayNames": {
3+
"Public,Preview,Canary": ""
4+
},
25
"include": [
36
{
47
"Agent": {
8+
"msi_image": {
9+
"OSVmImage": "ubuntu-22.04",
10+
"Pool": "azsdk-pool-mms-ubuntu-2204-identitymsi",
11+
"AdditionalTestFilters": "TestCategory=IdentityVM"
12+
},
513
"ubuntu_keyring_container": {
614
"OSVmImage": "ubuntu-20.04",
715
"Pool": "Azure Pipelines",
@@ -12,4 +20,4 @@
1220
"SupportedClouds": "Public,Preview,Canary"
1321
}
1422
]
15-
}
23+
}

sdk/identity/tests.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ extends:
44
template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml
55
parameters:
66
TimeoutInMinutes: 120
7+
AdditionalMatrixConfigs:
8+
- Name: identity_msi
9+
Path: sdk/identity/platform-matrix.json
10+
Selection: sparse
11+
GenerateVMJobs: true
712
ServiceDirectory: identity
813
CloudConfig:
914
Public:

0 commit comments

Comments
 (0)