예제 #1
0
            //ExpectedMessage = "Type attribute of EncryptedData MUST have value " + Saml20Constants.Xenc + "Element" + " if it is present")]
            public void ThrowsExceptionWhenXmlAttributeStatementEncryptedAttributeWrongType()
            {
                // Arrange
                var saml20Assertion    = AssertionUtil.GetBasicAssertion();
                var statements         = new List <StatementAbstract>(saml20Assertion.Items);
                var attributeStatments = (AttributeStatement)statements.Find(x => x is AttributeStatement);

                var attributes = new List <object>(attributeStatments.Items);
                var ee         = new EncryptedElement
                {
                    EncryptedData = new EncryptedData
                    {
                        Type = "SomeWrongType"
                    }
                };

                attributes.Add(ee);
                attributeStatments.Items = attributes.ToArray();
                saml20Assertion.Items    = statements.ToArray();

                // Act
                Assert.Throws(typeof(Saml20FormatException), () =>
                {
                    var assertion = new Saml20Assertion(AssertionUtil.ConvertAssertionToXml(saml20Assertion).DocumentElement, null, false, TestConfiguration.Configuration);
                });
            }
예제 #2
0
            //ExpectedMessage = "SubjectConfirmation element has Method attribute which is not a wellformed absolute uri."
            public void ThrowsWhenSubjectMethodIsNotWellFormedUri()
            {
                // Arrange
                var saml20Assertion     = AssertionUtil.GetBasicAssertion();
                var subjectConfirmation = (SubjectConfirmation)Array.Find(saml20Assertion.Subject.Items, item => item is SubjectConfirmation);

                subjectConfirmation.Method = "IllegalMethod";

                // Act
                Assert.Throws(typeof(Saml20FormatException), () =>
                {
                    var assertion = new Saml20Assertion(AssertionUtil.ConvertAssertionToXml(saml20Assertion).DocumentElement, null, false, TestConfiguration.Configuration);
                });
            }
예제 #3
0
            //ExpectedMessage = "AttributeStatement MUST contain at least one Attribute or EncryptedAttribute"
            public void ThrowsExceptionWhenNoItemsArePresent()
            {
                // Arrange
                var saml20Assertion    = AssertionUtil.GetBasicAssertion();
                var attributeStatement = (AttributeStatement)Array.Find(saml20Assertion.Items, x => x is AttributeStatement);

                // Clear all the attributes.
                attributeStatement.Items = new object[0];

                // Act
                Assert.Throws(typeof(Saml20FormatException), () =>
                {
                    var assertion = new Saml20Assertion(AssertionUtil.ConvertAssertionToXml(saml20Assertion).DocumentElement, null, false, TestConfiguration.Configuration);
                });
            }
예제 #4
0
            //ExpectedMessage = "AuthnStatement, AuthzDecisionStatement and AttributeStatement require a subject."
            public void ThrowsWhenSubjectElementIsNotPresent()
            {
                // Arrange
                var saml20Assertion     = AssertionUtil.GetBasicAssertion();
                var subjectConfirmation = (SubjectConfirmation)Array.Find(saml20Assertion.Subject.Items, item => item is SubjectConfirmation);

                subjectConfirmation.SubjectConfirmationData.NotOnOrAfter = DateTime.UtcNow;
                subjectConfirmation.SubjectConfirmationData.NotBefore    = null;
                saml20Assertion.Subject = null;

                // Act
                Assert.Throws(typeof(Saml20FormatException), () =>
                {
                    var assertion = new Saml20Assertion(AssertionUtil.ConvertAssertionToXml(saml20Assertion).DocumentElement, null, false, TestConfiguration.Configuration);
                });
            }
예제 #5
0
            //ExpectedMessage = "AuthnContextClassRef has a value which is not a wellformed absolute uri")]
            public void ThrowsWhenAuthnContextClassRefIsNotWellFormedUri()
            {
                // Arrange
                var saml20Assertion = AssertionUtil.GetBasicAssertion();
                var authnStatement  = (AuthnStatement)Array.Find(saml20Assertion.Items, stmnt => stmnt is AuthnStatement);

                var index = Array.FindIndex(authnStatement.AuthnContext.Items, o => o is string && o.ToString() == "urn:oasis:names:tc:SAML:2.0:ac:classes:X509");

                authnStatement.AuthnContext.Items[index] = "Hallelujagobble!!";

                // Act
                Assert.Throws(typeof(Saml20FormatException), () =>
                {
                    var assertion = new Saml20Assertion(AssertionUtil.ConvertAssertionToXml(saml20Assertion).DocumentElement, null, false, TestConfiguration.Configuration);
                });
            }
예제 #6
0
            //ExpectedMessage = "Attribute extension xml attributes MUST BE namespace qualified"
            public void ThrowsExceptionWhenXmlAttributeStatementAttributeAnyAttrUnqualified()
            {
                // Arrange
                var saml20Assertion    = AssertionUtil.GetBasicAssertion();
                var statements         = new List <StatementAbstract>(saml20Assertion.Items);
                var attributeStatments = (AttributeStatement)statements.Find(x => x is AttributeStatement);
                var attribute          = (SamlAttribute)attributeStatments.Items[0];

                var doc = new XmlDocument();

                attribute.AnyAttr = new[] { doc.CreateAttribute(string.Empty, "Nonqualified", string.Empty) };

                saml20Assertion.Items = statements.ToArray();

                // Act
                Assert.Throws(typeof(Saml20FormatException), () =>
                {
                    new Saml20Assertion(AssertionUtil.ConvertAssertionToXml(saml20Assertion).DocumentElement, null, false, TestConfiguration.Configuration);
                });
            }
예제 #7
0
            public void ThrowsExceptionWhenXmlAttributeStatementAttributeAnyAttrSamlQualified()
            {
                // Arrange
                var saml20Assertion    = AssertionUtil.GetBasicAssertion();
                var statements         = new List <StatementAbstract>(saml20Assertion.Items);
                var attributeStatments = (AttributeStatement)statements.Find(x => x is AttributeStatement);
                var attribute          = (SamlAttribute)attributeStatments.Items[0];

                var doc = new XmlDocument();

                saml20Assertion.Items = statements.ToArray();

                foreach (var samlns in Saml20Constants.SamlNamespaces)
                {
                    attribute.AnyAttr = new[] { doc.CreateAttribute("someprefix", "SamlQualified", samlns) };

                    Assert.Throws(typeof(Saml20FormatException), () =>
                    {
                        //"Attribute extension xml attributes MUST NOT use a namespace reserved by SAML"
                        var assertion = new Saml20Assertion(AssertionUtil.ConvertAssertionToXml(saml20Assertion).DocumentElement, null, false, TestConfiguration.Configuration);
                    });
                }
            }