Beispiel #1
0
        public void Saml2AuthenticationRequest_ToXElement_RootNode()
        {
            var subject = new Saml2AuthenticationRequest().ToXElement();

            subject.Should().NotBeNull().And.Subject.Name.Should().Be(
                Saml2Namespaces.Saml2P + "AuthnRequest");
        }
        public void Saml2AuthenticationRequest_ToXElement_RootNode()
        {
            var x = new Saml2AuthenticationRequest().ToXElement();

            x.Should().NotBeNull().And.Subject.Name.Should().Be(
                Saml2Namespaces.Saml2P + "AuthnRequest");
        }
Beispiel #3
0
        public void Saml2AuthenticationRequest_ForceAuthentication_OmittedIfFalse()
        {
            var subject = new Saml2AuthenticationRequest()
            {
                ForceAuthentication = false
            }.ToXElement();

            subject.Should().NotBeNull().And.Subject.Attribute("ForceAuthn").Should().BeNull();
        }
Beispiel #4
0
        public void SignInCommand_Run_Calls_Notifications()
        {
            var options   = StubFactory.CreateOptions();
            var idp       = options.IdentityProviders.Default;
            var relayData = new Dictionary <string, string>();

            options.SPOptions.DiscoveryServiceUrl = null;

            var request = new HttpRequestData("GET",
                                              new Uri("http://sp.example.com"));

            var selectedIdpCalled = false;

            options.Notifications.SelectIdentityProvider =
                (ei, r) =>
            {
                ei.Should().BeSameAs(idp.EntityId);
                r.Should().BeSameAs(relayData);
                selectedIdpCalled = true;
                return(null);
            };

            Saml2AuthenticationRequest saml2AuthenticationRequest = null;

            options.Notifications.AuthenticationRequestCreated = (a, i, r) =>
            {
                a.Should().NotBeNull();
                i.Should().BeSameAs(idp);
                r.Should().BeSameAs(relayData);
                saml2AuthenticationRequest = a;
            };

            CommandResult notifiedCommandResult = null;

            options.Notifications.SignInCommandResultCreated = (cr, r) =>
            {
                notifiedCommandResult = cr;
                r.Should().BeSameAs(relayData);
            };

            bool authenticationRequestXmlCreatedCalled = false;

            options.Notifications.AuthenticationRequestXmlCreated = (ar, xd, bt) =>
            {
                authenticationRequestXmlCreatedCalled = true;
                ar.Should().BeSameAs(saml2AuthenticationRequest);
                bt.Should().Be(Saml2BindingType.HttpRedirect);
            };

            SignInCommand.Run(idp.EntityId, null, request, options, relayData)
            .Should().BeSameAs(notifiedCommandResult);

            saml2AuthenticationRequest.Should().NotBeNull("the AuthenticationRequestCreated notification should have been called");
            selectedIdpCalled.Should().BeTrue("the SelectIdentityProvider notification should have been called.");
            authenticationRequestXmlCreatedCalled.Should().BeTrue("the AuthenticationedRequestXmlCreated should have been called.");
        }
Beispiel #5
0
        public void Saml2AuthenticationRequest_ForceAuthentication()
        {
            var subject = new Saml2AuthenticationRequest()
            {
                ForceAuthentication = true
            }.ToXElement();

            subject.Should().NotBeNull().And.Subject.Attribute("ForceAuthn")
            .Should().NotBeNull().And.Subject.Value.Should().Be("true");
        }
        public void Saml2AuthenticationRequest_ToXElement_AddsRequestBaseFields()
        {
            // Just checking for the id field and assuming that means that the
            // base fields are added. The details of the fields are tested
            // by Saml2RequestBaseTests.

            var x = new Saml2AuthenticationRequest().ToXElement();

            x.Should().NotBeNull().And.Subject.Attribute("ID").Should().NotBeNull();
        }
        public void Saml2AuthenticationRequest_IsPassive()
        {
            var subject = new Saml2AuthenticationRequest()
            {
                IsPassive = true
            }.ToXElement();

            subject.Should().NotBeNull().And.Subject.Attribute("IsPassive")
            .Should().NotBeNull().And.Subject.Value.Should().Be("true");
        }
Beispiel #8
0
        public void Saml2AuthenticationRequest_ToXElement_ShouldHandleNullAcsUri()
        {
            var subject = new Saml2AuthenticationRequest()
            {
                AssertionConsumerServiceUrl = null
            }.ToXElement();

            subject.Should().NotBeNull().And.Subject.Attribute("AssertionConsumerServiceURL")
            .Should().BeNull();
        }
        public void Saml2AuthenticationRequest_ToXElement_AddsRequestBaseFields()
        {
            // Just checking for the id field and assuming that means that the
            // base fields are added. The details of the fields are tested
            // by Saml2RequestBaseTests.

            var x = new Saml2AuthenticationRequest().ToXElement();

            x.Should().NotBeNull().And.Subject.Attribute("ID").Should().NotBeNull();
        }
Beispiel #10
0
        public void Saml2AuthenticationRequest_AssertionConsumerServiceUrl()
        {
            string url     = "http://some.example.com/Saml2AuthenticationModule/acs";
            var    subject = new Saml2AuthenticationRequest()
            {
                AssertionConsumerServiceUrl = new Uri(url)
            }.ToXElement();

            subject.Should().NotBeNull().And.Subject.Attribute("AssertionConsumerServiceURL")
            .Should().NotBeNull().And.Subject.Value.Should().Be(url);
        }
Beispiel #11
0
        public void Saml2AuthenticationRequest_ToXElement_ShouldCorrectSerializeAcsUri()
        {
            var url     = "http://some.example.com/Saml2AuthenticationModule/acs?RelayState=https%3A%2F%2Fmy.relaystate.nl";
            var subject = new Saml2AuthenticationRequest()
            {
                AssertionConsumerServiceUrl = new Uri(url)
            }.ToXElement();

            subject.Should().NotBeNull().And.Subject.Attribute("AssertionConsumerServiceURL")
            .Should().NotBeNull().And.Subject.Value.Should().Be(url);
        }
        public void Saml2AuthenticationRequest_AssertionConsumerServiceUrl()
        {
            string url = "http://some.example.com/Saml2AuthenticationModule/acs";
            var x = new Saml2AuthenticationRequest()
            {
                AssertionConsumerServiceUrl = new Uri(url)
            }.ToXElement();

            x.Should().NotBeNull().And.Subject.Attribute("AssertionConsumerServiceURL")
                .Should().NotBeNull().And.Subject.Value.Should().Be(url);
        }
Beispiel #13
0
        public void Saml2AuthenticationRequest_ToXElement_Scoping_NullContents_EmptyScoping()
        {
            var subject = new Saml2AuthenticationRequest()
            {
                AssertionConsumerServiceUrl = new Uri("http://destination.example.com"),
                Scoping = new Saml2Scoping()
            }.ToXElement().Element(Saml2Namespaces.Saml2P + "Scoping");

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

            subject.Should().BeEquivalentTo(expected);
        }
        public void Saml2AuthenticationRequest_ToXElement_AddsElementSaml2NameIdPolicy()
        {
            var subject = new Saml2AuthenticationRequest()
            {
                AssertionConsumerServiceUrl = new Uri("http://destination.example.com"),
                NameIdPolicy = new Saml2NameIdPolicy {
                    AllowCreate = false, Format = NameIdFormat.EmailAddress
                }
            }.ToXElement();

            XNamespace ns = "urn:oasis:names:tc:SAML:2.0:protocol";

            subject.Attribute("AttributeConsumingServiceIndex").Should().BeNull();
            subject.Should().NotBeNull().And.Subject.Element(ns + "NameIDPolicy").Should().NotBeNull();
        }