Skip to content

Commit 9ed0eb9

Browse files
jmprieurKeegan Caruso
authored andcommitted
Adding E2E test (#3476)
1 parent 1bb416e commit 9ed0eb9

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

Microsoft.Identity.Web.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "daemon-app-msi", "tests\Dev
172172
EndProject
173173
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Identity.Web.Sidecar", "src\Microsoft.Identity.Web.Sidecar\Microsoft.Identity.Web.Sidecar.csproj", "{55C81F88-0FFA-491C-A1D7-0ACA7212B59C}"
174174
EndProject
175+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sidecar.Tests", "tests\E2E Tests\Sidecar.Tests\Sidecar.Tests.csproj", "{946E6BED-2A06-4FF4-3E39-22ACEB44A984}"
176+
EndProject
175177
Global
176178
GlobalSection(SolutionConfigurationPlatforms) = preSolution
177179
Debug|Any CPU = Debug|Any CPU
@@ -411,6 +413,10 @@ Global
411413
{55C81F88-0FFA-491C-A1D7-0ACA7212B59C}.Debug|Any CPU.Build.0 = Debug|Any CPU
412414
{55C81F88-0FFA-491C-A1D7-0ACA7212B59C}.Release|Any CPU.ActiveCfg = Release|Any CPU
413415
{55C81F88-0FFA-491C-A1D7-0ACA7212B59C}.Release|Any CPU.Build.0 = Release|Any CPU
416+
{946E6BED-2A06-4FF4-3E39-22ACEB44A984}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
417+
{946E6BED-2A06-4FF4-3E39-22ACEB44A984}.Debug|Any CPU.Build.0 = Debug|Any CPU
418+
{946E6BED-2A06-4FF4-3E39-22ACEB44A984}.Release|Any CPU.ActiveCfg = Release|Any CPU
419+
{946E6BED-2A06-4FF4-3E39-22ACEB44A984}.Release|Any CPU.Build.0 = Release|Any CPU
414420
EndGlobalSection
415421
GlobalSection(SolutionProperties) = preSolution
416422
HideSolutionNode = FALSE
@@ -489,6 +495,7 @@ Global
489495
{C14780ED-5756-2A09-C6A7-5DDA433D1E86} = {1DDE1AAC-5AE6-4725-94B6-A26C58D3423F}
490496
{A8181404-23E0-D38B-454C-D16ECDB18B9F} = {E37CDBC1-18F6-4C06-A3EE-532C9106721F}
491497
{55C81F88-0FFA-491C-A1D7-0ACA7212B59C} = {1DDE1AAC-5AE6-4725-94B6-A26C58D3423F}
498+
{946E6BED-2A06-4FF4-3E39-22ACEB44A984} = {45B20A78-91F8-4DD2-B9AD-F12D3A93536C}
492499
EndGlobalSection
493500
GlobalSection(ExtensibilityGlobals) = postSolution
494501
SolutionGuid = {104367F1-CE75-4F40-B32F-F14853973187}

src/Microsoft.Identity.Web.Sidecar/Microsoft.Identity.Web.Sidecar.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<GenerateDocumentationFile>False</GenerateDocumentationFile>
99
<IsPackable>false</IsPackable>
1010
<EnablePackageValidation>false</EnablePackageValidation>
11+
<NoWarn>$(NoWarn); RS0016</NoWarn>
1112
</PropertyGroup>
1213

1314
<PropertyGroup>

src/Microsoft.Identity.Web.Sidecar/Program.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
3+
#pragma warning disable RS0016 // Public API
34

45
using System.Diagnostics;
56
using Microsoft.AspNetCore.Authentication.JwtBearer;
@@ -48,3 +49,7 @@
4849
app.AddValidateRequestEndpoints();
4950

5051
app.Run();
52+
53+
54+
// Added for test project WebApplicationFactory discovery
55+
public partial class Program { }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFrameworks>net9.0</TargetFrameworks>
4+
<IsPackable>false</IsPackable>
5+
<RootNamespace>Sidecar.Tests</RootNamespace>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<NoWarn>$(NoWarn); CS1591;RS0037</NoWarn>
9+
<AssemblyOriginatorKeyFile>../../../build/MSAL.snk</AssemblyOriginatorKeyFile>
10+
11+
</PropertyGroup>
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.0" />
14+
<PackageReference Include="xunit" Version="2.9.0" />
15+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
17+
<PackageReference Include="coverlet.collector" Version="6.0.0" />
18+
</ItemGroup>
19+
<ItemGroup>
20+
<ProjectReference Include="..\..\..\src\Microsoft.Identity.Web.Sidecar\Microsoft.Identity.Web.Sidecar.csproj" />
21+
</ItemGroup>
22+
</Project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Net.Http.Headers;
5+
using System.Security.Claims;
6+
using System.Text;
7+
using System.Text.Encodings.Web;
8+
using Microsoft.AspNetCore.Authentication;
9+
using Microsoft.AspNetCore.Authentication.JwtBearer;
10+
using Microsoft.AspNetCore.Mvc.Testing;
11+
using Microsoft.Extensions.DependencyInjection;
12+
using Microsoft.Extensions.Logging;
13+
using Microsoft.Extensions.Options;
14+
using Xunit;
15+
16+
namespace Sidecar.Tests;
17+
18+
public class SidecarApiFactory : WebApplicationFactory<Program>
19+
{
20+
protected override void ConfigureWebHost(Microsoft.AspNetCore.Hosting.IWebHostBuilder builder)
21+
{
22+
builder.ConfigureServices(services =>
23+
{
24+
});
25+
}
26+
}
27+
28+
public class ValidateEndpointTests : IClassFixture<SidecarApiFactory>
29+
{
30+
private readonly SidecarApiFactory _factory;
31+
32+
public ValidateEndpointTests(SidecarApiFactory factory) => _factory = factory;
33+
34+
[Fact]
35+
public async Task Validate_WhenBadTokenAsync()
36+
{
37+
var client = _factory.CreateClient();
38+
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "dummy-token");
39+
var response = await client.GetAsync("/Validate");
40+
Assert.Equal(System.Net.HttpStatusCode.Unauthorized, response.StatusCode);
41+
var content = await response.Content.ReadAsStringAsync();
42+
Assert.Contains("invalid_token", response.Headers.WwwAuthenticate.ToString(), StringComparison.CurrentCultureIgnoreCase);
43+
}
44+
}

0 commit comments

Comments
 (0)