Exemplo n.º 1
0
        public void GetActAsTokenWithUserName_WithBootstrapInContext_FactoryAndRstConfiguredCorrectly()
        {
            // Arrange
            var bootstrapToken = new UserNameSecurityToken("doesnot", "matter");

            Thread.CurrentPrincipal = new ClaimsPrincipal(new[] { new ClaimsIdentity {
                                                                      BootstrapContext = bootstrapToken
                                                                  } });
            var client = new TestableWsTrustClient("fictive.adfs");

            // Act
            client.GetActAsToken("https://fictiverpidentifier/", "doesnot", "matter");

            // Assert
            AssertUsernameFactory(
                client: client,
                expectedFactoryEndpoint: "https://fictive.adfs/adfs/services/trust/13/usernamemixed",
                expectedUsername: "******",
                expectedPassword: "******");

            AssertActAsRst(
                client: client,
                expectedRstAppliesTo: "https://fictiverpidentifier/",
                bootstrap: bootstrapToken);
        }
Exemplo n.º 2
0
        private static void AssertRst(TestableWsTrustClient client, string expectedRstAppliesTo)
        {
            RequestSecurityToken rst = client.Rst;

            rst.Should().NotBeNull();
            rst.ActAs.Should().BeNull();
            rst.AppliesTo.Uri.AbsoluteUri.Should().BeEquivalentTo(expectedRstAppliesTo);
        }
Exemplo n.º 3
0
        private static void AssertUsernameFactory(TestableWsTrustClient client, string expectedFactoryEndpoint, string expectedUsername, string expectedPassword)
        {
            client.UsernameWSTrustChannelFactory.Should().NotBeNull();
            client.FactoryCreatingChannel.ShouldBeEquivalentTo(client.UsernameWSTrustChannelFactory);
            client.FactoryCreatingChannel.Endpoint.Address.Uri.AbsoluteUri.Should()
            .BeEquivalentTo(expectedFactoryEndpoint);

            ClientCredentials credentials = client.FactoryCreatingChannel.Credentials;

            credentials.Should().NotBeNull();
            Debug.Assert(credentials != null, "credentials != null");
            credentials.ClientCertificate.Certificate.Should().BeNull();
            credentials.UserName.Should().NotBeNull();
            credentials.UserName.UserName.Should().Be(expectedUsername);
            credentials.UserName.Password.Should().Be(expectedPassword);
        }
Exemplo n.º 4
0
        public void GetSecurityTokenWithUserName_FactoryAndRstConfiguredCorrectly()
        {
            // Arrange
            var client = new TestableWsTrustClient("fictive.adfs");

            // Act
            client.GetSecurityToken("https://fictiverpidentifier/", "doesnot", "matter");

            // Assert
            AssertUsernameFactory(
                client: client,
                expectedFactoryEndpoint: "https://fictive.adfs/adfs/services/trust/13/usernamemixed",
                expectedUsername: "******",
                expectedPassword: "******");
            AssertRst(
                client: client,
                expectedRstAppliesTo: "https://fictiverpidentifier/");
        }