Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace combo of where and FirstOrDefault with only FirstOrDefault #4509

Merged
merged 10 commits into from
Jan 19, 2024
12 changes: 5 additions & 7 deletions src/client/Microsoft.Identity.Client/WsTrust/MexDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,11 @@ private MexPolicy SelectPolicy(UserAuthType userAuthType)
{
//try ws-trust 1.3 first
return _policies
.Values
.Where(p => p.Url != null && p.AuthType == userAuthType && p.Version == WsTrustVersion.WsTrust13)
.FirstOrDefault() ??
_policies
.Values
.Where(p => p.Url != null && p.AuthType == userAuthType)
.FirstOrDefault();
.Values
.FirstOrDefault(p => p.Url != null && p.AuthType == userAuthType && p.Version == WsTrustVersion.WsTrust13) ??
_policies
.Values
.FirstOrDefault(p => p.Url != null && p.AuthType == userAuthType);
}

private void ReadPolicies(XContainer mexDocument)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ private static MockHttpMessageHandler CreateTokenResponseHttpHandlerWithX5CValid
// Check presence and value of x5c cert claim.
var handler = new JwtSecurityTokenHandler();
var jsonToken = handler.ReadJwtToken(encodedJwt);
var x5c = jsonToken.Header.Where(header => header.Key == "x5c").FirstOrDefault();
if (expectedX5C != null)
{
Assert.AreEqual("x5c", x5c.Key, "x5c should be present");
Assert.AreEqual(x5c.Value.ToString(), expectedX5C);
var x5c = jsonToken.Header.FirstOrDefault(header => header.Key == "x5c");
SimonCropp marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,8 @@ public async Task ConfidentialClientUsingClientAssertionClaimsTestAsync()
var jsonToken = handler.ReadJwtToken(actualAssertion);
var claims = jsonToken.Claims;
//checked if additional claim is in signed assertion
var audclaim = TestConstants.s_clientAssertionClaims.Where(x => x.Key == "aud").FirstOrDefault();
var validClaim = claims.Where(x => x.Type == audclaim.Key && x.Value == audclaim.Value).FirstOrDefault();
var audclaim = TestConstants.s_clientAssertionClaims.FirstOrDefault(x => x.Key == "aud");
var validClaim = claims.FirstOrDefault(x => x.Type == audclaim.Key && x.Value == audclaim.Value);
Assert.IsNotNull(validClaim);
}
}
Expand Down
Loading