Skip to content

Commit

Permalink
replace combo of where and FirstOrDefault with only FirstOrDefault (#…
Browse files Browse the repository at this point in the history
…4509)

* replace combo of where and FirstOrDefault with only FirstOrDefault

* Update ClientCredentialWithCertTest.cs

* Update DeviceAuthenticationTests.cs
  • Loading branch information
SimonCropp authored Jan 19, 2024
1 parent 2a0aa37 commit f9b52d0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
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 @@ -48,9 +48,9 @@ public async Task PKeyAuthNonInteractiveTestAsync()

//Assert that the PKeyAuth header is used and the token response is successful
var (req, res) = factory.RequestsAndResponses
.Where(x => x.Item1.Headers.Authorization != null
&& x.Item1.Headers.Authorization.Scheme.Contains(PKeyAuthConstants.PKeyAuthName)
&& x.Item2.StatusCode == HttpStatusCode.OK).FirstOrDefault();
.FirstOrDefault(x => x.Item1.Headers.Authorization != null
&& x.Item1.Headers.Authorization.Scheme.Contains(PKeyAuthConstants.PKeyAuthName)
&& x.Item2.StatusCode == HttpStatusCode.OK);

Assert.IsNotNull(req);
Assert.IsNotNull(res);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ 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");
if (expectedX5C != null)
{
Assert.AreEqual("x5c", x5c.Key, "x5c should be present");
Assert.AreEqual(x5c.Value.ToString(), expectedX5C);
}
else
{
Assert.IsNull(x5c.Key);
Assert.IsNull(x5c.Value);
else
{
Assert.IsNull(x5c.Key);
Assert.IsNull(x5c.Value);
}
}
};
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

0 comments on commit f9b52d0

Please sign in to comment.