示例#1
0
        public void Saml2AuthenticationRequest_ToXElement_OmitsRequestedAuthnContext_OnNullClassRef()
        {
            var subject = new Saml2AuthenticationRequest()
            {
                AssertionConsumerServiceUrl = new Uri("http://destination.example.com"),
                RequestedAuthnContext       = new Saml2RequestedAuthnContext(null, AuthnContextComparisonType.Exact)
            }.ToXElement();

            subject.Element(Saml2Namespaces.Saml2P + "RequestedAuthnContext").Should().BeNull();
        }
示例#2
0
        public void Saml2AuthenticationRequest_ToXElement_AddsElementSaml2NameIdPolicy_ForNameIdFormat()
        {
            var subject = new Saml2AuthenticationRequest()
            {
                AssertionConsumerServiceUrl = new Uri("http://destination.example.com"),
                NameIdPolicy = new Saml2NameIdPolicy(null, NameIdFormat.EmailAddress)
            }.ToXElement();

            var expected = new XElement(Saml2Namespaces.Saml2P + "root",
                                        new XAttribute(XNamespace.Xmlns + "saml2p", Saml2Namespaces.Saml2P),
                                        new XElement(Saml2Namespaces.Saml2P + "NameIDPolicy",
                                                     new XAttribute("Format", "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress")))
                           .Elements().Single();

            subject.Element(Saml2Namespaces.Saml2P + "NameIDPolicy")
            .Should().BeEquivalentTo(expected);
        }
示例#3
0
        public void Saml2AuthenticationRequest_ToXElement_AddsElementSaml2NameIdPolicy_ForAllowCreate()
        {
            var subject = new Saml2AuthenticationRequest()
            {
                AssertionConsumerServiceUrl = new Uri("http://destination.example.com"),
                NameIdPolicy = new Saml2NameIdPolicy(false, NameIdFormat.NotConfigured)
            }.ToXElement();

            var expected = new XElement(Saml2Namespaces.Saml2P + "root",
                                        new XAttribute(XNamespace.Xmlns + "saml2p", Saml2Namespaces.Saml2P),
                                        new XElement(Saml2Namespaces.Saml2P + "NameIDPolicy",
                                                     new XAttribute("AllowCreate", false)))
                           .Elements().Single();

            subject.Attribute("AttributeConsumingServiceIndex").Should().BeNull();
            subject.Element(Saml2Namespaces.Saml2P + "NameIDPolicy")
            .Should().BeEquivalentTo(expected);
        }
示例#4
0
        private void Saml2AuthenticationRequest_ToXElement_AddsRequestedAuthnContextUtil(AuthnContextComparisonType comparisonType, string expectedComparisonType)
        {
            var classRef = "http://www.kentor.se";
            var subject  = new Saml2AuthenticationRequest()
            {
                AssertionConsumerServiceUrl = new Uri("http://destination.example.com"),
                RequestedAuthnContext       = new Saml2RequestedAuthnContext(new Uri(classRef), comparisonType)
            }.ToXElement();

            var expected = new XElement(Saml2Namespaces.Saml2P + "root",
                                        new XAttribute(XNamespace.Xmlns + "saml2p", Saml2Namespaces.Saml2P),
                                        new XAttribute(XNamespace.Xmlns + "saml2", Saml2Namespaces.Saml2),
                                        new XElement(Saml2Namespaces.Saml2P + "RequestedAuthnContext",
                                                     new XAttribute("Comparison", expectedComparisonType),
                                                     new XElement(Saml2Namespaces.Saml2 + "AuthnContextClassRef", classRef)))
                           .Elements().Single();

            var actual = subject.Element(Saml2Namespaces.Saml2P + "RequestedAuthnContext");

            actual.Should().BeEquivalentTo(expected);
        }