-
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.
* initial commit to improve obo * add test & experiment w/renaming a few private methods * Jennyf/merge from master (#390) * Fix nullable warnings. (#362) * fix userflow claims in addAccounToCacheFromAuthCode (#388) * make aadIssuerValidator public (#385) * Fixes Azure DevOps issue 1097354 (#387) Co-authored-by: pmaytak <34331512+pmaytak@users.noreply.github.com> Co-authored-by: jennyf19 <jeferrie@microsoft.com> * pr feedback Co-authored-by: Jean-Marc Prieur <jmprieur@microsoft.com> Co-authored-by: pmaytak <34331512+pmaytak@users.noreply.github.com>
- Loading branch information
1 parent
e44c5d7
commit 9fefbb3
Showing
6 changed files
with
197 additions
and
72 deletions.
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
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
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
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
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
83 changes: 83 additions & 0 deletions
83
tests/Microsoft.Identity.Web.Test/TokenAcquisitionAuthorityTests.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,83 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Globalization; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using Microsoft.Identity.Client; | ||
using Microsoft.Identity.Web.Test.Common; | ||
using Xunit; | ||
|
||
namespace Microsoft.Identity.Web.Test | ||
{ | ||
public class TokenAcquisitionAuthorityTests | ||
{ | ||
private TokenAcquisition _tokenAcquisition; | ||
private ServiceProvider _provider; | ||
private ConfidentialClientApplicationOptions _applicationOptions; | ||
|
||
private void InitializeTokenAcquisitionObjects() | ||
{ | ||
_tokenAcquisition = new TokenAcquisition( | ||
null, | ||
null, | ||
_provider.GetService<IOptions<MicrosoftIdentityOptions>>(), | ||
_provider.GetService<IOptions<ConfidentialClientApplicationOptions>>(), | ||
null, | ||
null, | ||
_provider); | ||
} | ||
|
||
private void BuildTheRequiredServices() | ||
{ | ||
var services = new ServiceCollection(); | ||
|
||
_applicationOptions = new ConfidentialClientApplicationOptions | ||
{ | ||
Instance = TestConstants.AadInstance, | ||
ClientId = TestConstants.ConfidentialClientId, | ||
ClientSecret = "cats", | ||
}; | ||
|
||
services.AddTokenAcquisition(); | ||
services.AddTransient( | ||
provider => Options.Create(new MicrosoftIdentityOptions | ||
{ | ||
Authority = TestConstants.AuthorityCommonTenant, | ||
ClientId = TestConstants.ConfidentialClientId, | ||
CallbackPath = string.Empty, | ||
})); | ||
services.AddTransient( | ||
provider => Options.Create(_applicationOptions)); | ||
_provider = services.BuildServiceProvider(); | ||
} | ||
|
||
[Theory] | ||
[InlineData(TestConstants.GuestTenantId)] | ||
[InlineData(TestConstants.HomeTenantId)] | ||
[InlineData(null)] | ||
[InlineData("")] | ||
public void VerifyCorrectAuthorityUsedInTokenAcquisitionTests(string tenant) | ||
{ | ||
BuildTheRequiredServices(); | ||
InitializeTokenAcquisitionObjects(); | ||
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder | ||
.CreateWithApplicationOptions(_applicationOptions) | ||
.WithAuthority(TestConstants.AuthorityCommonTenant).Build(); | ||
|
||
if (!string.IsNullOrEmpty(tenant)) | ||
{ | ||
Assert.Equal( | ||
string.Format( | ||
CultureInfo.InvariantCulture, "{0}/{1}/", TestConstants.AadInstance, tenant), | ||
_tokenAcquisition.CreateAuthorityBasedOnTenantIfProvided( | ||
app, | ||
tenant)); | ||
} | ||
else | ||
{ | ||
Assert.Equal(app.Authority, _tokenAcquisition.CreateAuthorityBasedOnTenantIfProvided(app, tenant)); | ||
} | ||
} | ||
} | ||
} |