Skip to content

Commit e23f5d0

Browse files
authored
Fix Identity nightly tests (Azure#50514)
1 parent 1b81fe2 commit e23f5d0

20 files changed

+149
-35
lines changed

eng/Directory.Build.Common.props

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
<!-- Setup default project properties -->
3333
<PropertyGroup>
34+
<LtsTargetFramework>net8.0</LtsTargetFramework>
3435
<LangVersion>latest</LangVersion>
3536
<!--
3637
Disable NU5105 NuGet Pack warning that the version is SemVer 2.0.
@@ -108,7 +109,7 @@
108109
<GenerateAPIListing Condition="'$(GenerateAPIListing)' == '' AND '$(IsShippingClientLibrary)' == 'true'">true</GenerateAPIListing>
109110
<EnableSourceLink Condition="'$(EnableSourceLink)' == ''">true</EnableSourceLink>
110111
<DefineConstants Condition="'$(BuildSnippets)' == 'true'">$(DefineConstants);SNIPPET</DefineConstants>
111-
<ApiCompatBaselineTargetFramework Condition="'$(TargetFramework)' == 'net8.0'">netstandard2.0</ApiCompatBaselineTargetFramework>
112+
<ApiCompatBaselineTargetFramework Condition="'$(TargetFramework)' == '$(LtsTargetFramework)'">netstandard2.0</ApiCompatBaselineTargetFramework>
112113
</PropertyGroup>
113114

114115
<PropertyGroup Condition="'$(IsShippingClientLibrary)' == 'true' and '$(TF_BUILD)' == 'true'">
@@ -139,15 +140,15 @@
139140
<SupportsNetStandard20 Condition="'$(SupportsNetStandard20)' == ''">false</SupportsNetStandard20>
140141

141142
<RequiredTargetFrameworks>net452;net461;netstandard2.0</RequiredTargetFrameworks>
142-
<RequiredTargetFrameworks Condition="'$(SupportsNetStandard20)' == 'true' and '$(IsSourceGenerator)' != 'true'">net8.0;netstandard2.0</RequiredTargetFrameworks>
143-
<RequiredTargetFrameworks Condition="'$(IsGeneratorLibrary)' == 'true'">net8.0</RequiredTargetFrameworks>
143+
<RequiredTargetFrameworks Condition="'$(SupportsNetStandard20)' == 'true' and '$(IsSourceGenerator)' != 'true'">$(LtsTargetFramework);netstandard2.0</RequiredTargetFrameworks>
144+
<RequiredTargetFrameworks Condition="'$(IsGeneratorLibrary)' == 'true'">$(LtsTargetFramework)</RequiredTargetFrameworks>
144145
<RequiredTargetFrameworks Condition="'$(IsSourceGenerator)' == 'true'">netstandard2.0</RequiredTargetFrameworks>
145146
</PropertyGroup>
146147

147148
<PropertyGroup Condition="'$(IsGeneratorLibrary)' != 'true' and ('$(IsTestProject)' == 'true' or '$(IsTestSupportProject)' == 'true' or '$(IsSamplesProject)' == 'true' or '$(IsPerfProject)' == 'true' or '$(IsStressProject)' == 'true')">
148149
<IsPackable>false</IsPackable>
149150
<!-- List newest targets first so that recordings are made with latest, running tests from editor runs latest, etc. -->
150-
<RequiredTargetFrameworks>net9.0;net8.0;</RequiredTargetFrameworks>
151+
<RequiredTargetFrameworks>net9.0;$(LtsTargetFramework);</RequiredTargetFrameworks>
151152
<!-- Also test net462 on Windows. net461 is out of support as of 4/2022 and is not supported in version 4.4.x and beyond of NUnit3TestAdapter. -->
152153
<RequiredTargetFrameworks Condition="'$(OS)' == 'Windows_NT'">$(RequiredTargetFrameworks);net462</RequiredTargetFrameworks>
153154
<!-- But only build snippets for the latest. -->
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<PropertyGroup>
3+
<ExcludeFromCodeCoverage>true</ExcludeFromCodeCoverage>
4+
<ImportRepoCommonSettings>true</ImportRepoCommonSettings>
5+
<!-- Signal that integration projects are building in the repo -->
6+
<IsClientLibrary>true</IsClientLibrary>
7+
<IsPackable>true</IsPackable>
8+
<WarnOnPackingNonPackableProject>false</WarnOnPackingNonPackableProject>
9+
<NoWarn>
10+
$(NoWarn);
11+
NU5104;
12+
</NoWarn>
13+
</PropertyGroup>
14+
15+
<Import Project="..\Directory.Build.props" />
16+
17+
<PropertyGroup>
18+
<DefineConstants>$(DefineConstants);STRONGNAME_SIGNED</DefineConstants>
19+
<InheritDocEnabled>false</InheritDocEnabled>
20+
<IsShippingLibrary>false</IsShippingLibrary>
21+
</PropertyGroup>
22+
</Project>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., Directory.Build.props))\Directory.Build.props" />
3+
</Project>

sdk/identity/Azure.Identity/integration/Integration.Identity.Common/Integration.Identity.Common.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
4+
<TargetFramework>$(LtsTargetFramework)</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
</PropertyGroup>
88
<ItemGroup>
9-
<PackageReference Include="Azure.Storage.Blobs" Version="[12.23.0,)"/>
9+
<PackageReference Include="Azure.Storage.Blobs" />
1010
</ItemGroup>
1111
<ItemGroup>
1212
<ProjectReference Include="..\..\src\Azure.Identity.csproj" />

sdk/identity/Azure.Identity/integration/Integration.Identity.Common/ManagedIdentityTests.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
using Azure.Identity;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using Azure.Identity;
25
using Azure.Storage.Blobs;
36
using Azure.Core;
47

58
namespace Integration.Identity.Common;
69

10+
/// <summary>
11+
/// Tests for Managed Identity authentication.
12+
/// </summary>
713
public static class ManagedIdentityTests
814
{
15+
/// <summary>
16+
/// Authenticates to Azure Storage using Managed Identity.
17+
/// </summary>
918
public static void AuthToStorage()
1019
{
1120
string resourceId = Environment.GetEnvironmentVariable("IDENTITY_USER_DEFINED_IDENTITY")!;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., Directory.Build.props))\Directory.Build.props" />
3+
</Project>

sdk/identity/Azure.Identity/integration/Integration.Identity.Container/Integration.Identity.Container.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>net462;net8.0</TargetFrameworks>
5+
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>
66
</PropertyGroup>
77

88
<ItemGroup>

sdk/identity/Azure.Identity/integration/Integration.Identity.Container/Program.cs renamed to sdk/identity/Azure.Identity/integration/Integration.Identity.Container/MyProgram.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
// See https://aka.ms/new-console-template for more information
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
24
using System;
35
using Azure.Core;
46
using Azure.Identity;
57

6-
public class Program
8+
/// <summary>
9+
/// Program is a console application that demonstrates the use of Workload Identity Credential.
10+
/// </summary>
11+
public class MyProgram
712
{
13+
/// <summary>
14+
/// Main is the entry point of the console application.
15+
/// </summary>
16+
/// <param name="args"></param>
17+
/// <returns></returns>
818
public static async global::System.Threading.Tasks.Task Main(string[] args)
919
{
1020
try
1121
{
1222
var cred = new WorkloadIdentityCredential();
13-
var token = await cred.GetTokenAsync(new TokenRequestContext(new string[] { "https://management.azure.com//.default" }));
23+
var token = await cred.GetTokenAsync(new TokenRequestContext(new string[] { "https://management.azure.com//.default" })).ConfigureAwait(false);
1424
if (token.Token != null)
1525
Console.WriteLine("Passed!");
1626
}
@@ -19,4 +29,4 @@ public class Program
1929
Console.WriteLine(e);
2030
}
2131
}
22-
}
32+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., Directory.Build.props))\Directory.Build.props" />
3+
</Project>

sdk/identity/Azure.Identity/integration/Integration.Identity.Func/Function1.cs

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,58 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
14
using System;
2-
using System.IO;
5+
using System.Diagnostics.CodeAnalysis;
6+
using System.Net;
37
using System.Threading.Tasks;
4-
using Microsoft.AspNetCore.Mvc;
5-
using Microsoft.Azure.WebJobs;
6-
using Microsoft.Azure.WebJobs.Extensions.Http;
7-
using Microsoft.AspNetCore.Http;
8+
using Microsoft.Azure.Functions.Worker;
9+
using Microsoft.Azure.Functions.Worker.Http;
810
using Microsoft.Extensions.Logging;
9-
using Newtonsoft.Json;
1011
using Integration.Identity.Common;
1112

1213
namespace Integration.Identity.Func
1314
{
14-
public static class Function1
15+
/// <summary>
16+
/// Function1 is an Azure Function that demonstrates Managed Identity authentication.
17+
/// </summary>
18+
public class Function1
1519
{
16-
[FunctionName("Function1")]
17-
public static async Task<IActionResult> Run(
18-
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
19-
ILogger log)
20+
private readonly ILogger _logger;
21+
22+
/// <summary>
23+
/// Initializes a new instance of the Function1 class.
24+
/// </summary>
25+
/// <param name="loggerFactory">The logger factory.</param>
26+
public Function1(ILoggerFactory loggerFactory)
27+
{
28+
_logger = loggerFactory.CreateLogger<Function1>();
29+
}
30+
31+
/// <summary>
32+
/// HTTP trigger function that processes GET requests.
33+
/// </summary>
34+
/// <param name="req">The request</param>
35+
/// <returns></returns>
36+
[Function("Function1")]
37+
public async Task<HttpResponseData> Run(
38+
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequestData req)
2039
{
21-
log.LogInformation("C# HTTP trigger function processed a request.");
40+
_logger.LogInformation("C# HTTP trigger function processed a request.");
2241

2342
try
2443
{
2544
ManagedIdentityTests.AuthToStorage();
2645
await Task.Yield();
27-
return new OkObjectResult("Successfully acquired a token from ManagedIdentityCredential");
46+
47+
var response = req.CreateResponse(HttpStatusCode.OK);
48+
await response.WriteStringAsync("Successfully acquired a token from ManagedIdentityCredential").ConfigureAwait(false);
49+
return response;
2850
}
2951
catch (Exception ex)
3052
{
31-
return new BadRequestObjectResult(ex.ToString());
53+
var response = req.CreateResponse(HttpStatusCode.BadRequest);
54+
await response.WriteStringAsync(ex.ToString()).ConfigureAwait(false);
55+
return response;
3256
}
3357
}
3458
}

0 commit comments

Comments
 (0)