-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixes #2410
- Loading branch information
Showing
2 changed files
with
47 additions
and
1 deletion.
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
46 changes: 46 additions & 0 deletions
46
tests/Microsoft.Identity.Web.Test/TestTokenAcquisitionHost.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,46 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Linq; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Xunit; | ||
|
||
namespace Microsoft.Identity.Web.Test | ||
{ | ||
public class TestTokenAcquisitionHost | ||
{ | ||
[Fact] | ||
public void TestTokenAcquisitionHostNotAspNetCore() | ||
{ | ||
// When not adding Services.AddAuthentication, the host should be | ||
TokenAcquirerFactory tokenAcquirerFactory = TokenAcquirerFactory.GetDefaultInstance(); | ||
var host = tokenAcquirerFactory.Services.First(s => s.ServiceType.FullName == "Microsoft.Identity.Web.ITokenAcquisitionHost"); | ||
Assert.True(host.ImplementationType!.FullName == "Microsoft.Identity.Web.Hosts.DefaultTokenAcquisitionHost"); | ||
} | ||
|
||
[Fact] | ||
public void TestTokenAcquisitionAspNetCoreBuilderNoAuth() | ||
{ | ||
// When not adding Services.AddAuthentication, the host should be | ||
var builder = WebApplication.CreateBuilder(); | ||
builder.Services.AddTokenAcquisition(); | ||
var host = builder.Services.First(s => s.ServiceType.FullName == "Microsoft.Identity.Web.ITokenAcquisitionHost"); | ||
Assert.True(host.ImplementationType!.FullName == "Microsoft.Identity.Web.Hosts.DefaultTokenAcquisitionHost"); | ||
} | ||
|
||
|
||
[Fact] | ||
public void TestTokenAcquisitionAspNetCoreBuilderAuth() | ||
{ | ||
// When not adding Services.AddAuthentication, the host should be | ||
var builder = WebApplication.CreateBuilder(); | ||
builder.Services.AddAuthentication() | ||
.AddMicrosoftIdentityWebApi(builder.Configuration) | ||
.EnableTokenAcquisitionToCallDownstreamApi(); | ||
|
||
var host = builder.Services.First(s => s.ServiceType.FullName == "Microsoft.Identity.Web.ITokenAcquisitionHost"); | ||
Assert.True(host.ImplementationType!.FullName == "Microsoft.Identity.Web.TokenAcquisitionAspnetCoreHost"); | ||
} | ||
} | ||
} |