public void CompareTokenValidationParameters() { TestUtilities.WriteHeader($"{this}.CompareTokenValidationParameters", true); var context = new CompareContext($"{this}.CompareTokenValidationParameters"); var tokenValidationParameters1 = new TokenValidationParameters { AuthenticationType = Guid.NewGuid().ToString() }; var tokenValidationParameters2 = new TokenValidationParameters() { AuthenticationType = Guid.NewGuid().ToString() }; IdentityComparer.AreEqual(tokenValidationParameters1, tokenValidationParameters2, context); Assert.True(context.Diffs.Count(s => s == "AuthenticationType:") == 1); }
/// <summary> /// Sets a property, then checks it, checking for an expected exception. /// </summary> /// <param name="obj">object that has a 'setter'.</param> /// <param name="property">the name of the property.</param> /// <param name="propertyValue">value to set on the property.</param> /// <param name="expectedException">checks that exception is correct.</param> public static void SetGet(object obj, string property, object propertyValue, ExpectedException expectedException, GetSetContext context) { if (obj == null) { throw new TestException("obj == null"); } if (string.IsNullOrWhiteSpace(property)) { throw new TestException("string.IsNullOrWhiteSpace(property)"); } Type type = obj.GetType(); PropertyInfo propertyInfo = type.GetProperty(property); if (propertyInfo == null) { context.Errors.Add("'get is not found for property: '" + property + "', type: '" + type.ToString() + "'"); return; } if (!propertyInfo.CanWrite) { context.Errors.Add("can not write to property: '" + property + "', type: '" + type.ToString() + "'"); return; } var compareContext = new CompareContext(); try { propertyInfo.SetValue(obj, propertyValue); object retval = propertyInfo.GetValue(obj); IdentityComparer.AreEqual(propertyValue, retval, compareContext); expectedException.ProcessNoException(compareContext); } catch (Exception exception) { // look for InnerException as exception is a wrapped exception. expectedException.ProcessException(exception.InnerException, compareContext); } context.Errors.AddRange(compareContext.Diffs); }
public void CompareSamlAssertions() { TestUtilities.WriteHeader($"{this}.CompareSamlAssertions", true); var context = new CompareContext($"{this}.CompareSamlAssertions"); var samlAssertion1 = new SamlAssertion(Guid.NewGuid().ToString(), Default.Issuer, DateTime.Parse(Default.IssueInstantString), null, new SamlAdvice(), new List <SamlStatement> { new SamlAttributeStatement(new SamlSubject(), new List <SamlAttribute> { new SamlAttribute("1", "2", "3") }) }); var samlAssertion2 = new SamlAssertion(Guid.NewGuid().ToString(), Default.Issuer, DateTime.Parse(Default.IssueInstantString), null, new SamlAdvice(), new List <SamlStatement> { new SamlAttributeStatement(new SamlSubject(), new List <SamlAttribute> { new SamlAttribute("1", "2", "3") }) }); IdentityComparer.AreEqual(samlAssertion1, samlAssertion2, context); Assert.True(context.Diffs.Count(s => s == "AssertionId:") == 1); }
public void TestStubTest1(TestStubTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.TestStubTest1", theoryData); try { var obj = new object(); theoryData.ExpectedException.ProcessNoException(context); if (theoryData.CompareTo != null) { IdentityComparer.AreEqual(obj, theoryData.CompareTo, context); } } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }
public void CompareSamlAuthorizationDecisionStatements() { TestUtilities.WriteHeader($"{this}.CompareSamlAuthorizationDecisionStatements", true); var context = new CompareContext($"{this}.CompareSamlAuthorizationDecisionStatements"); var samlAction = new SamlAction(Guid.NewGuid().ToString()); var samlAttributeStatement1 = new SamlAuthorizationDecisionStatement(new SamlSubject(), Guid.NewGuid().ToString(), Default.SamlAccessDecision, new List <SamlAction> { samlAction }); var samlAttributeStatement2 = new SamlAuthorizationDecisionStatement(new SamlSubject(), Guid.NewGuid().ToString(), Default.SamlAccessDecision, new List <SamlAction> { samlAction }); IdentityComparer.AreEqual(samlAttributeStatement1, samlAttributeStatement2, context); Assert.True(context.Diffs.Count(s => s == "Resource:") == 1); }
public void CompareX509Certificate2() { TestUtilities.WriteHeader($"{this}.CompareX509Certificate2", true); var context = new CompareContext($"{this}.CompareX509Certificate2"); var certificate = new X509Certificate2(Convert.FromBase64String(KeyingMaterial.DefaultX509Data_Public_2048)); var certificateSame = new X509Certificate2(Convert.FromBase64String(KeyingMaterial.DefaultX509Data_Public_2048)); var certificateDifferent = KeyingMaterial.CertSelfSigned1024_SHA256; IdentityComparer.AreEqual(certificate, certificateSame, context); Assert.True(context.Diffs.Count(s => s == "X509Certificate2:") == 0); IdentityComparer.AreEqual(certificate, certificateDifferent, context); Assert.True(context.Diffs.Count(s => s == "X509Certificate2:") == 1); context.Diffs.Clear(); IdentityComparer.AreX509Certificate2Equal(certificate, null, context); Assert.True(context.Diffs.Count(s => s == "X509Certificate2:") == 1); context.Diffs.Clear(); IdentityComparer.AreX509Certificate2Equal(null, certificate, context); Assert.True(context.Diffs.Count(s => s == "X509Certificate2:") == 1); }
public void CompareSamlAuthenticationStatements() { TestUtilities.WriteHeader($"{this}.CompareSamlAuthenticationStatements", true); var context = new CompareContext($"{this}.CompareSamlAuthenticationStatements"); var samlAttributeStatement1 = new SamlAuthenticationStatement(new SamlSubject(), Guid.NewGuid().ToString(), DateTime.Parse(Default.AuthenticationInstant), null, null, new List <SamlAuthorityBinding> { new SamlAuthorityBinding(new System.Xml.XmlQualifiedName(Default.AuthorityKind), Default.Location, Default.Binding) }); var samlAttributeStatement2 = new SamlAuthenticationStatement(new SamlSubject(), Guid.NewGuid().ToString(), DateTime.Parse(Default.AuthenticationInstant), null, null, new List <SamlAuthorityBinding> { new SamlAuthorityBinding(new System.Xml.XmlQualifiedName(Default.AuthorityKind), Default.Location, Default.Binding) }); IdentityComparer.AreEqual(samlAttributeStatement1, samlAttributeStatement2, context); Assert.True(context.Diffs.Count(s => s == "AuthenticationMethod:") == 1); }
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); }