Example #1
0
            [Ignore]    // TODO: test data needs fixing
            public void AddAttribute()
            {
                // Arrange
                var assertion  = new Saml20Assertion(AssertionUtil.LoadXmlDocument(@"Assertions\Saml2Assertion_01").DocumentElement, null, false, TestConfiguration.Configuration);
                var attributes = assertion.Attributes;

                // This needs to be addressed and is why the test is ignored. See the original Hg project
                attributes.Add(new SamlAttribute());

                var cert = AssertionUtil.GetCertificate();

                assertion.Sign(cert, null);

                assertion.CheckValid(new[] { cert.PublicKey.Key });

                // Verify that the modified assertion can survive complete serialization and deserialization.
                var assertionString = assertion.GetXml().OuterXml;

                var deserializedAssertionDoc = new XmlDocument {
                    PreserveWhitespace = true
                };

                deserializedAssertionDoc.Load(new StringReader(assertionString));

                var deserializedAssertion = new Saml20Assertion(deserializedAssertionDoc.DocumentElement, null, false, TestConfiguration.Configuration);

                Assert.IsNotNull(deserializedAssertion.GetSignatureKeys(), "Signing keys must be present");
                deserializedAssertion.CheckValid(new[] { cert.PublicKey.Key });
            }
Example #2
0
        public void HasNoAssertionBeforeDecrypt()
        {
            // Arrange
            var doc  = AssertionUtil.LoadXmlDocument(@"Assertions\EncryptedAssertion_01");
            var cert = new X509Certificate2(@"Certificates\sts_dev_certificate.pfx", "test1234");

            // Act
            var encryptedAssertion = new Saml20EncryptedAssertion((RSA)cert.PrivateKey, doc);

            // Assert
            Assert.IsNull(encryptedAssertion.Assertion);
        }
Example #3
0
            public void CanReadAttributes()
            {
                // Act
                var assertion = new Saml20Assertion(AssertionUtil.LoadXmlDocument(@"Assertions\Saml2Assertion_01").DocumentElement, null, false, TestConfiguration.Configuration);

                // Assert
                CollectionAssert.IsNotEmpty(assertion.Attributes);
                Assert.AreEqual(4, assertion.Attributes.Count);
                foreach (var sa in assertion.Attributes)
                {
                    Assert.That(sa.AttributeValue.Length != 0, "Attribute should have a value");
                }
            }
Example #4
0
            public void CanDecryptAssertionWithPeerIncludedKeysWithoutSpecifiedEncryptionMethod()
            {
                // Arrange
                var doc  = AssertionUtil.LoadXmlDocument(@"Assertions\EncryptedAssertion_03");
                var cert = new X509Certificate2(@"Certificates\sts_dev_certificate.pfx", "test1234");
                var encryptedAssertion = new Saml20EncryptedAssertion((RSA)cert.PrivateKey, doc);

                // Act
                encryptedAssertion.Decrypt();

                // Assert
                Assert.IsNotNull(encryptedAssertion.Assertion);
            }
Example #5
0
            public void CanDecryptAssertionWithPeerIncludedAesKeys()
            {
                // Arrange
                var doc  = AssertionUtil.LoadXmlDocument(@"Assertions\EncryptedAssertion_05");
                var cert = new X509Certificate2(@"Certificates\sts_dev_certificate.pfx", "test1234");
                var encryptedAssertion = new Saml20EncryptedAssertion((RSA)cert.PrivateKey, doc);

                // Act
                encryptedAssertion.Decrypt();

                // Assert
                Assert.IsNotNull(encryptedAssertion.Assertion);
                Assert.AreEqual(1, encryptedAssertion.Assertion.GetElementsByTagName(Assertion.ElementName, Saml20Constants.Assertion).Count);
            }
Example #6
0
            public void CanDecryptAssertion()
            {
                // Arrange
                var doc  = AssertionUtil.LoadXmlDocument(@"Assertions\EncryptedAssertion_01");
                var cert = new X509Certificate2(@"Certificates\sts_dev_certificate.pfx", "test1234");
                var encryptedAssertion = new Saml20EncryptedAssertion((RSA)cert.PrivateKey, doc);

                // Act
                encryptedAssertion.Decrypt();
                var assertion = new Saml20Assertion(encryptedAssertion.Assertion.DocumentElement, null, false, TestConfiguration.Configuration);

                // Assert
                Assert.IsNotNull(encryptedAssertion.Assertion);
            }