예제 #1
0
        public void CompareClaimsIdentities()
        {
            TestUtilities.WriteHeader($"{this}.CompareClaimsIdentities", true);
            var context = new CompareContext($"{this}.CompareClaimsIdentities");

            var originalClaims = new List <Claim>()
            {
                new Claim(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()),
                new Claim(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()),
            };

            var claims2 = new List <Claim>()
            {
                new Claim(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()),
                new Claim(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()),
            };

            var originalAuthenticationType = Guid.NewGuid().ToString();
            var originalNameType           = Guid.NewGuid().ToString();
            var originalRoleType           = Guid.NewGuid().ToString();
            var originalBootstrapContext   = Guid.NewGuid().ToString();
            var originalLabel = Guid.NewGuid().ToString();
            var originalActor = new ClaimsIdentity(Guid.NewGuid().ToString());

            // Base ClaimsIdentity to use for all future comparisons.
            var originalClaimsIdentity = CreateClaimsIdentity(originalClaims, originalAuthenticationType,
                                                              originalNameType, originalRoleType, originalLabel, originalBootstrapContext, originalActor);

            // ClaimsIdentity with different Claims.
            var claimsIdentityDiffClaims = CreateClaimsIdentity(claims2, originalAuthenticationType,
                                                                originalNameType, originalRoleType, originalLabel, originalBootstrapContext, originalActor);

            // ClaimsIdentity with different AuthenticationType.
            var claimsIdentityDiffAuthenticationType = CreateClaimsIdentity(originalClaims, Guid.NewGuid().ToString(),
                                                                            originalNameType, originalRoleType, originalLabel, originalBootstrapContext, originalActor);

            // ClaimsIdentity with different NameClaimType.
            var claimsIdentityDiffNameType = CreateClaimsIdentity(originalClaims, originalAuthenticationType,
                                                                  Guid.NewGuid().ToString(), originalRoleType, originalLabel, originalBootstrapContext, originalActor);

            // ClaimsIdentity with different RoleClaimType.
            var claimsIdentityDiffRoleType = CreateClaimsIdentity(originalClaims, originalAuthenticationType,
                                                                  originalNameType, Guid.NewGuid().ToString(), originalLabel, originalBootstrapContext, originalActor);

            // ClaimsIdentity with different Label.
            var claimsIdentityDiffLabel = CreateClaimsIdentity(originalClaims, originalAuthenticationType,
                                                               originalNameType, originalRoleType, Guid.NewGuid().ToString(), originalBootstrapContext, originalActor);

            // ClaimsIdentity with different BootstrapContext.
            var claimsIdentityDiffBootstrapContext = CreateClaimsIdentity(originalClaims, originalAuthenticationType,
                                                                          originalNameType, originalRoleType, originalLabel, Guid.NewGuid().ToString(), originalActor);

            // ClaimsIdentity with null Actor.
            var claimsIdentityDiffActor = CreateClaimsIdentity(originalClaims, originalAuthenticationType,
                                                               originalNameType, originalRoleType, originalLabel, originalBootstrapContext, null);

            var claimsIdentitiesToCompare = new List <ClaimsIdentity>()
            {
                claimsIdentityDiffClaims,
                claimsIdentityDiffAuthenticationType,
                claimsIdentityDiffNameType,
                claimsIdentityDiffRoleType,
                claimsIdentityDiffLabel,
                claimsIdentityDiffBootstrapContext,
                claimsIdentityDiffActor,
            };

            foreach (var claimsIdentity in claimsIdentitiesToCompare)
            {
                IdentityComparer.AreEqual(originalClaimsIdentity, claimsIdentity, context);
            }

            // Lists all the properties which should have been marked as different in the compareContext.
            var propertiesToTest = new string[] { "Claims:", "AuthenticationType:", "NameClaimType:", "RoleClaimType:", "Label:", "BootstrapContext:", "Actor:" };

            // Make sure that differences have been found for each of the properties listed above.
            Assert.True(propertiesToTest.ToList().Aggregate(0, (sum, next) => context.Diffs.Contains(next) ? sum + 1 : sum) == 7);
        }
예제 #2
0
 public void ProcessException(Exception exception, CompareContext context)
 {
     ProcessException(exception, context.Diffs);
 }