public void DefaultUniqueClaimTypes_NotPresent_Throws(object identity) { // Arrange ClaimsIdentity claimsIdentity = (ClaimsIdentity)identity; // Act & assert var ex = Assert.Throws <InvalidOperationException>(() => ClaimUidExtractor.GetUniqueIdentifierParameters(claimsIdentity, null)); Assert.Equal(@"A claim of type 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier' or 'http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider' was not present on the provided ClaimsIdentity. To enable anti-forgery token support with claims-based authentication, please verify that the configured claims provider is providing both of these claims on the ClaimsIdentity instances it generates. If the configured claims provider instead uses a different claim type as a unique identifier, it can be configured by setting the static property AntiForgeryConfig.UniqueClaimTypeIdentifier.", ex.Message); }
public void ExplicitUniqueClaimType_NotPresent_Throws(object identity) { // Arrange ClaimsIdentity claimsIdentity = (ClaimsIdentity)identity; // Act & assert var ex = Assert.Throws <InvalidOperationException>(() => ClaimUidExtractor.GetUniqueIdentifierParameters(claimsIdentity, "fooClaim")); Assert.Equal(@"A claim of type 'fooClaim' was not present on the provided ClaimsIdentity.", ex.Message); }
public void ExplicitUniqueClaimType_Present() { // Arrange MockClaimsIdentity identity = new MockClaimsIdentity(); identity.AddClaim("fooClaim", "fooClaimValue"); identity.AddClaim(ClaimUidExtractor.NameIdentifierClaimType, "nameIdentifierValue"); identity.AddClaim(ClaimUidExtractor.IdentityProviderClaimType, "identityProviderValue"); // Act var retVal = ClaimUidExtractor.GetUniqueIdentifierParameters(identity, "fooClaim"); // Assert Assert.Equal(new string[] { "fooClaim", "fooClaimValue" }, retVal); }