Skip to content

Commit 141bae7

Browse files
authored
First iteration of a simple ManagedIdentity integration test (#33017)
* First iteration of a simple ManagedIdentity integration test
1 parent a7a6b0b commit 141bae7

18 files changed

+362
-46
lines changed

eng/.docsettings.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ omitted_paths:
99
- samples/*
1010
- sdk/*/*.Management.*/*
1111
- sdk/*/*/perf/*
12+
- sdk/*/*/integration/*
1213
- sdk/*/*/tests/Samples/*
1314
- sdk/*/*/tests/samples/*
1415
- sdk/*/*/samples/*
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Linq;
3+
using Azure.Core;
4+
using Azure.Identity;
5+
using Azure.Storage.Blobs;
6+
using Microsoft.AspNetCore.Mvc;
7+
8+
namespace WebApp.Controllers
9+
{
10+
11+
[ApiController]
12+
[Route("[controller]")]
13+
public class TestController : ControllerBase
14+
{
15+
16+
[HttpGet(Name = "GetTest")]
17+
public IActionResult Get()
18+
{
19+
string resourceId = Environment.GetEnvironmentVariable("IDENTITY_WEBAPP_USER_DEFINED_IDENTITY")!;
20+
string account1 = Environment.GetEnvironmentVariable("IDENTITY_STORAGE_NAME_1")!;
21+
string account2 = Environment.GetEnvironmentVariable("IDENTITY_STORAGE_NAME_2")!;
22+
23+
var credential1 = new ManagedIdentityCredential();
24+
var credential2 = new ManagedIdentityCredential(new ResourceIdentifier(resourceId));
25+
var client1 = new BlobServiceClient(new Uri($"https://{account1}.blob.core.windows.net/"), credential1);
26+
var client2 = new BlobServiceClient(new Uri($"https://{account2}.blob.core.windows.net/"), credential2);
27+
try
28+
{
29+
var results = client1.GetBlobContainers().ToList();
30+
results = client2.GetBlobContainers().ToList();
31+
return Ok("Successfully acquired a token from ManagedIdentityCredential");
32+
}
33+
catch (Exception ex)
34+
{
35+
return BadRequest(ex.ToString());
36+
}
37+
}
38+
}
39+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Azure.Storage.Blobs" />
11+
</ItemGroup>
12+
<ItemGroup>
13+
<ProjectReference Include="..\..\src\Azure.Identity.csproj" />
14+
</ItemGroup>
15+
16+
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.Extensions.DependencyInjection;
3+
4+
var builder = WebApplication.CreateBuilder(args);
5+
6+
// Add services to the container.
7+
8+
builder.Services.AddControllers();
9+
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
10+
builder.Services.AddEndpointsApiExplorer();
11+
12+
var app = builder.Build();
13+
14+
// Configure the HTTP request pipeline.
15+
app.UseHttpsRedirection();
16+
17+
app.UseAuthorization();
18+
19+
app.MapControllers();
20+
21+
app.Run();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*"
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<config>
4+
<!--
5+
<add key="repositoryPath" value="./NugetInstall" />
6+
<add key="globalPackagesFolder" value="./Nuget" />
7+
-->
8+
<add key="repositoryPath" value="%AGENT_WORKFOLDER%/NugetInstall" />
9+
<add key="globalPackagesFolder" value="%AGENT_WORKFOLDER%/Nuget" />
10+
</config>
11+
<packageSources>
12+
<add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" />
13+
</packageSources>
14+
</configuration>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Azure.Core;
88
using Azure.Core.TestFramework;
99
using Microsoft.Identity.Client;
10+
using Moq;
1011
using NUnit.Framework;
1112

1213
namespace Azure.Identity.Tests

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ public static TestFileSystemService CreateFileSystemForVisualStudioCode(Identity
8282
{
8383
var sb = new StringBuilder("{");
8484

85-
if (testEnvironment.TestTenantId != default)
85+
if (testEnvironment.IdentityTenantId != default)
8686
{
87-
sb.AppendFormat("\"azure.tenant\": \"{0}\"", testEnvironment.TestTenantId);
87+
sb.AppendFormat("\"azure.tenant\": \"{0}\"", testEnvironment.IdentityTenantId);
8888
}
8989

90-
if (testEnvironment.TestTenantId != default && cloudName != default)
90+
if (testEnvironment.IdentityTenantId != default && cloudName != default)
9191
{
9292
sb.Append(',');
9393
}
@@ -117,7 +117,7 @@ public static async ValueTask<AuthenticationRecord> GetAuthenticationRecordAsync
117117

118118
var username = testEnvironment.Username;
119119
var password = testEnvironment.Password;
120-
var tenantId = testEnvironment.TestTenantId;
120+
var tenantId = testEnvironment.IdentityTenantId;
121121

122122
var result = await PublicClientApplicationBuilder.Create(clientId)
123123
.WithTenantId(tenantId)
@@ -138,7 +138,7 @@ public static async Task<string> GetRefreshTokenAsync(IdentityTestEnvironment te
138138
var clientId = "aebc6443-996d-45c2-90f0-388ff96faa56";
139139
var username = testEnvironment.Username;
140140
var password = testEnvironment.Password;
141-
var authorityUri = new Uri(new Uri(testEnvironment.AuthorityHostUrl), testEnvironment.TestTenantId).ToString();
141+
var authorityUri = new Uri(new Uri(testEnvironment.AuthorityHostUrl), testEnvironment.IdentityTenantId).ToString();
142142

143143
var client = PublicClientApplicationBuilder.Create(clientId)
144144
.WithAuthority(authorityUri)

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public async Task DefaultAzureCredential_UseVisualStudioCredential()
6262

6363
[RecordedTest]
6464
[RunOnlyOnPlatforms(Windows = true, OSX = true, ContainerNames = new[] { "ubuntu_netcore_keyring" })]
65+
[Ignore("https://github.com/Azure/azure-sdk-for-net/issues/27263")]
6566
public async Task DefaultAzureCredential_UseVisualStudioCodeCredential()
6667
{
6768
var options = InstrumentClientOptions(new DefaultAzureCredentialOptions
@@ -73,7 +74,7 @@ public async Task DefaultAzureCredential_UseVisualStudioCodeCredential()
7374
ExcludeVisualStudioCredential = true,
7475
ExcludeAzureCliCredential = true,
7576
ExcludeVisualStudioCodeCredential = false,
76-
VisualStudioCodeTenantId = TestEnvironment.TestTenantId
77+
VisualStudioCodeTenantId = TestEnvironment.IdentityTenantId
7778
});
7879

7980
var cloudName = Guid.NewGuid().ToString();
@@ -102,6 +103,7 @@ public async Task DefaultAzureCredential_UseVisualStudioCodeCredential()
102103

103104
[RecordedTest]
104105
[RunOnlyOnPlatforms(Windows = true, OSX = true, ContainerNames = new[] { "ubuntu_netcore_keyring" })]
106+
[Ignore("https://github.com/Azure/azure-sdk-for-net/issues/27263")]
105107
public async Task DefaultAzureCredential_UseVisualStudioCodeCredential_ParallelCalls()
106108
{
107109
var options = InstrumentClientOptions(new DefaultAzureCredentialOptions
@@ -112,7 +114,7 @@ public async Task DefaultAzureCredential_UseVisualStudioCodeCredential_ParallelC
112114
ExcludeManagedIdentityCredential = true,
113115
ExcludeAzureCliCredential = true,
114116
ExcludeVisualStudioCodeCredential = false,
115-
VisualStudioCodeTenantId = TestEnvironment.TestTenantId
117+
VisualStudioCodeTenantId = TestEnvironment.IdentityTenantId
116118
});
117119

118120
var cloudName = Guid.NewGuid().ToString();
@@ -149,7 +151,7 @@ public async Task DefaultAzureCredential_UseAzureCliCredential()
149151
ExcludeSharedTokenCacheCredential = true,
150152
ExcludeManagedIdentityCredential = true,
151153
ExcludeVisualStudioCodeCredential = false,
152-
VisualStudioCodeTenantId = TestEnvironment.TestTenantId
154+
VisualStudioCodeTenantId = TestEnvironment.IdentityTenantId
153155
});
154156

155157
var (expectedToken, expectedExpiresOn, processOutput) = CredentialTestHelpers.CreateTokenForAzureCli();
@@ -188,7 +190,7 @@ public async Task DefaultAzureCredential_UseAzureCliCredential_ParallelCalls()
188190
ExcludeSharedTokenCacheCredential = true,
189191
ExcludeManagedIdentityCredential = true,
190192
ExcludeVisualStudioCodeCredential = false,
191-
VisualStudioCodeTenantId = TestEnvironment.TestTenantId
193+
VisualStudioCodeTenantId = TestEnvironment.IdentityTenantId
192194
});
193195

194196
var (expectedToken, expectedExpiresOn, processOutput) = CredentialTestHelpers.CreateTokenForAzureCli();

0 commit comments

Comments
 (0)