Exemplo n.º 1
0
        public async Task ShouldGenerateWsTrustResponseFromGet()
        {
            var responseGenerator = new SignInResponseGenerator(new NullLogger <SignInResponseGenerator>(),
                                                                _relyingPartyStore,
                                                                _profileManager,
                                                                _keyManager,
                                                                _options
                                                                );

            var middleware = new WsFedMiddleware(
                next: (innerHttpContext) =>
            {
                return(Task.CompletedTask);
            },
                _logger,
                _relyingPartyStore,
                responseGenerator,
                new Core.Messaging.WsTrust.WsTrustSerializer(),
                _options
                );

            var context = new DefaultHttpContext();

            context.Request.Path        = "/wsfed/";
            context.Request.QueryString = new QueryString("?wa=wsignin1.0&wtrealm=urn:test");
            context.Request.Method      = "GET";
            context.Response.Body       = new MemoryStream();

            context.User = new ClaimsPrincipal(new List <ClaimsIdentity>
            {
                new ClaimsIdentity(new List <Claim>
                {
                    new Claim(ClaimTypes.NameIdentifier, "john foo")
                }, "federated")
            });

            await middleware.Invoke(context);

            var body = ((MemoryStream)context.Response.Body).ToArray();

            Assert.Equal(200, context.Response.StatusCode);
            Assert.True(body.Length > 0);
        }
Exemplo n.º 2
0
        public async Task ShouldRedirectIfUserNotAuthenticated()
        {
            var serviceProviderMock = new Mock <IServiceProvider>();

            serviceProviderMock
            .Setup(_ => _.GetService(typeof(IAuthenticationService)))
            .Returns(new MyAuthenticationService());

            var responseGenerator = new SignInResponseGenerator(new NullLogger <SignInResponseGenerator>(),
                                                                _relyingPartyStore,
                                                                _profileManager,
                                                                _keyManager,
                                                                _options
                                                                );

            var middleware = new WsFedMiddleware(
                next: (innerHttpContext) =>
            {
                return(Task.CompletedTask);
            },
                _logger,
                _relyingPartyStore,
                responseGenerator,
                new Core.Messaging.WsTrust.WsTrustSerializer(),
                _options
                );

            var context = new DefaultHttpContext
            {
                RequestServices = serviceProviderMock.Object
            };

            context.Request.Path        = "/wsfed/";
            context.Request.QueryString = new QueryString("?wa=wsignin1.0&wtrealm=urn:test");
            context.Request.Method      = "GET";
            context.Response.Body       = new MemoryStream();

            await middleware.Invoke(context);

            Assert.Equal(301, context.Response.StatusCode);
        }