public void DefaultUniqueClaimTypes_NotPresent_SerializesAllClaimTypes() { var identity = new MockClaimsIdentity(); identity.AddClaim(ClaimTypes.Email, "*****@*****.**"); identity.AddClaim(ClaimTypes.GivenName, "some"); identity.AddClaim(ClaimTypes.Surname, "one"); identity.AddClaim(ClaimTypes.NameIdentifier, String.Empty); // Arrange var claimsIdentity = (ClaimsIdentity)identity; // Act var identiferParameters = DefaultClaimUidExtractor.GetUniqueIdentifierParameters(claimsIdentity) .ToArray(); var claims = claimsIdentity.Claims.ToList(); claims.Sort((a, b) => string.Compare(a.Type, b.Type, StringComparison.Ordinal)); // Assert int index = 0; foreach (var claim in claims) { Assert.True(String.Equals(identiferParameters[index++], claim.Type, StringComparison.Ordinal)); Assert.True(String.Equals(identiferParameters[index++], claim.Value, StringComparison.Ordinal)); } }
public void GetUniqueIdentifierParameters_NoKnownClaimTypesFound_SortsAndReturnsAllClaimsFromAuthenticatedIdentities() { // Arrange var identity1 = new ClaimsIdentity(); // no authentication identity1.AddClaim(new Claim("sub", "subClaimValue")); var identity2 = new ClaimsIdentity("someAuthentication"); identity2.AddClaim(new Claim(ClaimTypes.Email, "*****@*****.**")); var identity3 = new ClaimsIdentity("someAuthentication"); identity3.AddClaim(new Claim(ClaimTypes.Country, "countryValue")); var identity4 = new ClaimsIdentity("someAuthentication"); identity4.AddClaim(new Claim(ClaimTypes.Name, "claimName")); // Act var uniqueIdentifierParameters = DefaultClaimUidExtractor.GetUniqueIdentifierParameters( new ClaimsIdentity[] { identity1, identity2, identity3, identity4 }); // Assert Assert.Equal(new List <string> { ClaimTypes.Country, "countryValue", "LOCAL AUTHORITY", ClaimTypes.Email, "*****@*****.**", "LOCAL AUTHORITY", ClaimTypes.Name, "claimName", "LOCAL AUTHORITY", }, uniqueIdentifierParameters); }
public void DefaultUniqueClaimTypes_Present() { // Arrange var identity = new MockClaimsIdentity(); identity.AddClaim("fooClaim", "fooClaimValue"); identity.AddClaim(ClaimTypes.NameIdentifier, "nameIdentifierValue"); // Act var uniqueIdentifierParameters = DefaultClaimUidExtractor.GetUniqueIdentifierParameters(identity); // Assert Assert.Equal(new string[] { ClaimTypes.NameIdentifier, "nameIdentifierValue", }, uniqueIdentifierParameters); }
public void DefaultUniqueClaimTypes_Present() { // Arrange var identity = new ClaimsIdentity("someAuthentication"); identity.AddClaim(new Claim("fooClaim", "fooClaimValue")); identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "nameIdentifierValue")); // Act var uniqueIdentifierParameters = DefaultClaimUidExtractor.GetUniqueIdentifierParameters(new ClaimsIdentity[] { identity }); // Assert Assert.Equal(new string[] { ClaimTypes.NameIdentifier, "nameIdentifierValue", "LOCAL AUTHORITY", }, uniqueIdentifierParameters); }
public void GetUniqueIdentifierParameters_PrefersSubClaimOverNameIdentifierAndUpn() { // Arrange var identity = new ClaimsIdentity("someAuthentication"); identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "nameIdentifierValue")); identity.AddClaim(new Claim("sub", "subClaimValue")); identity.AddClaim(new Claim(ClaimTypes.Upn, "upnClaimValue")); // Act var uniqueIdentifierParameters = DefaultClaimUidExtractor.GetUniqueIdentifierParameters(new ClaimsIdentity[] { identity }); // Assert Assert.Equal(new string[] { "sub", "subClaimValue", "LOCAL AUTHORITY", }, uniqueIdentifierParameters); }
public void GetUniqueIdentifierParameters_MultipleIdentities_UsesOnlyAuthenticatedIdentities() { // Arrange var identity1 = new ClaimsIdentity(); // no authentication identity1.AddClaim(new Claim("sub", "subClaimValue")); var identity2 = new ClaimsIdentity("someAuthentication"); identity2.AddClaim(new Claim(ClaimTypes.NameIdentifier, "nameIdentifierValue")); // Act var uniqueIdentifierParameters = DefaultClaimUidExtractor.GetUniqueIdentifierParameters(new ClaimsIdentity[] { identity1, identity2 }); // Assert Assert.Equal(new string[] { ClaimTypes.NameIdentifier, "nameIdentifierValue", "LOCAL AUTHORITY", }, uniqueIdentifierParameters); }
public void GetUniqueIdentifierParameters_PrefersUpnFromFirstIdentity_OverNameFromSecondIdentity() { // Arrange var identity1 = new ClaimsIdentity("someAuthentication"); identity1.AddClaim(new Claim(ClaimTypes.Upn, "upnValue")); var identity2 = new ClaimsIdentity("someAuthentication"); identity2.AddClaim(new Claim(ClaimTypes.NameIdentifier, "nameIdentifierValue")); // Act var uniqueIdentifierParameters = DefaultClaimUidExtractor.GetUniqueIdentifierParameters( new ClaimsIdentity[] { identity1, identity2 }); // Assert Assert.Equal(new string[] { ClaimTypes.Upn, "upnValue", "LOCAL AUTHORITY", }, uniqueIdentifierParameters); }