Skip to content

Commit

Permalink
inline some out variables (#4560)
Browse files Browse the repository at this point in the history
* inline some out variables

* .
  • Loading branch information
SimonCropp authored Jan 23, 2024
1 parent a62e915 commit c48b182
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ public static async Task<OidcMetadata> GetOidcAsync(
string authority,
RequestContext requestContext)
{
OidcMetadata configuration;

if (s_cache.TryGetValue(authority, out configuration))
if (s_cache.TryGetValue(authority, out OidcMetadata configuration))
{
requestContext.Logger.Verbose(() => $"[OIDC Discovery] OIDC discovery found a cached entry for {authority}");
return configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public static KerberosSupplementalTicket FromIdToken(string idToken)

// parse the JSON data and find the included Kerberos Ticket claim.
JObject payloadJson = JsonHelper.ParseIntoJsonObject(payload);
JToken claimValue;
if (!JsonHelper.TryGetValue(payloadJson, KerberosClaimType, out claimValue))
if (!JsonHelper.TryGetValue(payloadJson, KerberosClaimType, out JToken claimValue))
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ private static bool DictionariesAreEqual<TKey, TValue>(

foreach (var kvp in dict1)
{
TValue value2;
if (!dict2.TryGetValue(kvp.Key, out value2))
if (!dict2.TryGetValue(kvp.Key, out TValue value2))
return false;
if (!valueComparer.Equals(kvp.Value, value2))
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,12 @@ private async Task<AuthenticationResult> RunTestForUserAsync(string appId, LabRe
IConfidentialClientApplication cca;
redirectUri = redirectUri ?? SeleniumWebUI.FindFreeLocalhostRedirectUri();

HttpSnifferClientFactory factory;

cca = ConfidentialClientApplicationBuilder
.Create(appId)
.WithAuthority(authority)
.WithCertificate(cert)
.WithRedirectUri(redirectUri)
.WithTestLogging(out factory)
.WithTestLogging(out HttpSnifferClientFactory factory)
.Build();

var cacheAccess = (cca as ConfidentialClientApplication).UserTokenCache.RecordAccess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using Microsoft.Identity.Client;
using Microsoft.Identity.Client.Extensibility;
using Microsoft.Identity.Client.Internal;
using Microsoft.Identity.Client.Kerberos;
using Microsoft.Identity.Client.Kerberos;
using Microsoft.Identity.Client.Utils;
using Microsoft.Identity.Test.Common;
using Microsoft.Identity.Test.Common.Core.Helpers;
Expand Down Expand Up @@ -51,8 +51,8 @@ public async Task Interactive_AADAsync()
// Arrange
LabResponse labResponse = await LabUserHelper.GetDefaultUserAsync().ConfigureAwait(false);
var result = await RunTestForUserAsync(labResponse).ConfigureAwait(false);
}

}

[RunOn(TargetFrameworks.NetCore)]
[TestCategory(TestCategories.Arlington)]
public async Task Arlington_Interactive_AADAsync()
Expand Down Expand Up @@ -110,7 +110,7 @@ public async Task Interactive_Arlington_MultiCloudSupport_AADAsync()
IPublicClientApplication pca = PublicClientApplicationBuilder
.Create(labResponse.App.AppId)
.WithRedirectUri(SeleniumWebUI.FindFreeLocalhostRedirectUri())
.WithAuthority("https://login.microsoftonline.com/common")
.WithAuthority("https://login.microsoftonline.com/common")
.WithMultiCloudSupport(true)
.WithTestLogging()
.Build();
Expand All @@ -130,8 +130,8 @@ public async Task Interactive_Arlington_MultiCloudSupport_AADAsync()
Assert.IsTrue(labResponse.Lab.Authority.Contains(result.Account.Environment));

Trace.WriteLine("Part 2 - Get Accounts");
var accounts = await pca.GetAccountsAsync().ConfigureAwait(false);

var accounts = await pca.GetAccountsAsync().ConfigureAwait(false);

Assert.IsNotNull(accounts);
Assert.IsNotNull(accounts.Single());

Expand All @@ -149,12 +149,12 @@ public async Task Interactive_Arlington_MultiCloudSupport_AADAsync()
.ConfigureAwait(false);

Assert.IsNotNull(result);
Assert.IsNotNull(result.Account);
Assert.IsNotNull(result.Account);
Assert.IsNotNull(result.Account.GetTenantProfiles());
Assert.IsTrue(result.Account.GetTenantProfiles().Any());
Assert.IsTrue(labResponse.Lab.Authority.Contains(result.Account.Environment));
}


[RunOn(TargetFrameworks.NetCore)]
[TestCategory(TestCategories.ADFS)]
public async Task Interactive_AdfsV2019_DirectAsync()
Expand All @@ -166,14 +166,13 @@ public async Task Interactive_AdfsV2019_DirectAsync()
[RunOn(TargetFrameworks.NetCore)]
public async Task ValidateCcsHeadersForInteractiveAuthCodeFlowAsync()
{
HttpSnifferClientFactory factory = null;
LabResponse labResponse = await LabUserHelper.GetDefaultUserAsync().ConfigureAwait(false);

var pca = PublicClientApplicationBuilder
.Create(labResponse.App.AppId)
.WithDefaultRedirectUri()
.WithRedirectUri(SeleniumWebUI.FindFreeLocalhostRedirectUri())
.WithTestLogging(out factory)
.WithTestLogging(out HttpSnifferClientFactory factory)
.Build();

AuthenticationResult authResult = await pca
Expand All @@ -194,25 +193,25 @@ public async Task ValidateCcsHeadersForInteractiveAuthCodeFlowAsync()

private async Task<AuthenticationResult> RunTestForUserAsync(LabResponse labResponse, bool directToAdfs = false)
{
HttpSnifferClientFactory factory = null;
IPublicClientApplication pca;
if (directToAdfs)
{
pca = PublicClientApplicationBuilder
.Create(Adfs2019LabConstants.PublicClientId)
.WithRedirectUri(Adfs2019LabConstants.ClientRedirectUri)
.WithAdfsAuthority(Adfs2019LabConstants.Authority)
.WithTestLogging()
.Build();
}
else
{
pca = PublicClientApplicationBuilder
.Create(labResponse.App.AppId)
.WithRedirectUri(SeleniumWebUI.FindFreeLocalhostRedirectUri())
.WithAuthority(labResponse.Lab.Authority + "common")
.WithTestLogging(out factory)
.Build();
HttpSnifferClientFactory factory = null;
IPublicClientApplication pca;
if (directToAdfs)
{
pca = PublicClientApplicationBuilder
.Create(Adfs2019LabConstants.PublicClientId)
.WithRedirectUri(Adfs2019LabConstants.ClientRedirectUri)
.WithAdfsAuthority(Adfs2019LabConstants.Authority)
.WithTestLogging()
.Build();
}
else
{
pca = PublicClientApplicationBuilder
.Create(labResponse.App.AppId)
.WithRedirectUri(SeleniumWebUI.FindFreeLocalhostRedirectUri())
.WithAuthority(labResponse.Lab.Authority + "common")
.WithTestLogging(out factory)
.Build();
}

var userCacheAccess = pca.UserTokenCache.RecordAccess();
Expand All @@ -229,7 +228,7 @@ private async Task<AuthenticationResult> RunTestForUserAsync(LabResponse labResp
TestCommon.ValidateNoKerberosTicketFromAuthenticationResult(result);

userCacheAccess.AssertAccessCounts(0, 1);
IAccount account = await MsalAssert.AssertSingleAccountAsync(labResponse, pca, result).ConfigureAwait(false);
IAccount account = await MsalAssert.AssertSingleAccountAsync(labResponse, pca, result).ConfigureAwait(false);

userCacheAccess.AssertAccessCounts(1, 1); // the assert calls GetAccounts
Assert.IsFalse(userCacheAccess.LastAfterAccessNotificationArgs.IsApplicationCache);
Expand Down Expand Up @@ -271,16 +270,16 @@ private async Task<AuthenticationResult> RunTestForUserAsync(LabResponse labResp
result = await pca
.AcquireTokenSilent(s_scopes, account)
.ExecuteAsync(CancellationToken.None)
.ConfigureAwait(false);
.ConfigureAwait(false);

TestCommon.ValidateNoKerberosTicketFromAuthenticationResult(result);

Trace.WriteLine("Part 5 - Acquire a token silently with force refresh");
Trace.WriteLine("Part 5 - Acquire a token silently with force refresh");
result = await pca
.AcquireTokenSilent(s_scopes, account)
.WithForceRefresh(true)
.ExecuteAsync(CancellationToken.None)
.ConfigureAwait(false);
.ConfigureAwait(false);

await MsalAssert.AssertSingleAccountAsync(labResponse, pca, result).ConfigureAwait(false);
Assert.IsFalse(userCacheAccess.LastAfterAccessNotificationArgs.IsApplicationCache);
Expand Down Expand Up @@ -369,12 +368,11 @@ private async Task<AuthenticationResult> KerberosRunTestForUserAsync(
LabResponse labResponse,
KerberosTicketContainer ticketContainer)
{
HttpSnifferClientFactory factory = null;
IPublicClientApplication pca = PublicClientApplicationBuilder
.Create(labResponse.App.AppId)
.WithRedirectUri(SeleniumWebUI.FindFreeLocalhostRedirectUri())
.WithAuthority(labResponse.Lab.Authority + "common")
.WithTestLogging(out factory)
.WithTestLogging(out HttpSnifferClientFactory factory)
.WithTenantId(labResponse.Lab.TenantId)
.WithClientId(TestConstants.KerberosTestApplicationId)
.WithKerberosTicketClaim(TestConstants.KerberosServicePrincipalName, ticketContainer)
Expand Down Expand Up @@ -423,7 +421,7 @@ private async Task<AuthenticationResult> KerberosRunTestForUserAsync(
.WithLoginHint(labResponse.User.Upn)
.ExecuteAsync(new CancellationTokenSource(_interactiveAuthTimeout).Token)
.ConfigureAwait(false);
userCacheAccess.AssertAccessCounts(2, 3);
userCacheAccess.AssertAccessCounts(2, 3);
AssertCcsRoutingInformationIsSent(factory, labResponse);
ticket = TestCommon.GetValidatedKerberosTicketFromAuthenticationResult(
result,
Expand Down Expand Up @@ -459,7 +457,7 @@ private async Task<AuthenticationResult> KerberosRunTestForUserAsync(
.ConfigureAwait(false);

await MsalAssert.AssertSingleAccountAsync(labResponse, pca, result).ConfigureAwait(false);
Assert.IsFalse(userCacheAccess.LastAfterAccessNotificationArgs.IsApplicationCache);
Assert.IsFalse(userCacheAccess.LastAfterAccessNotificationArgs.IsApplicationCache);
AssertCcsRoutingInformationIsSent(factory, labResponse);

ticket = TestCommon.GetValidatedKerberosTicketFromAuthenticationResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ public async Task GetRemovesExpired_Async()

// Act
await Task.Delay(1).ConfigureAwait(false);
MsalServiceException foundEx1, foundEx2;
bool isFound1 = cache.TryGetOrRemoveExpired("k1", _logger, out foundEx1);
bool isFound2 = cache.TryGetOrRemoveExpired("k2", _logger, out foundEx2);
bool isFound1 = cache.TryGetOrRemoveExpired("k1", _logger, out MsalServiceException foundEx1);
bool isFound2 = cache.TryGetOrRemoveExpired("k2", _logger, out MsalServiceException foundEx2);

// Assert
Assert.IsFalse(isFound1, "Should have been removed as it is expired");
Expand All @@ -53,9 +52,8 @@ public async Task TestCleanup_Async()
cache.AddAndCleanup("k3", new ThrottlingCacheEntry(_ex2, TimeSpan.FromMilliseconds(1000)), _logger);

// Assert
MsalServiceException foundEx1, foundEx2;
bool isFound1 = cache.TryGetOrRemoveExpired("k1", _logger, out foundEx1);
bool isFound2 = cache.TryGetOrRemoveExpired("k2", _logger, out foundEx2);
bool isFound1 = cache.TryGetOrRemoveExpired("k1", _logger, out MsalServiceException foundEx1);
bool isFound2 = cache.TryGetOrRemoveExpired("k2", _logger, out MsalServiceException foundEx2);

Assert.IsFalse(isFound1, "Should have been removed by cleanup");
Assert.IsTrue(isFound2, "Should have been found as it is not expired");
Expand Down

0 comments on commit c48b182

Please sign in to comment.