Example #1
0
        public async Task ExecuteAsync_Should_Return_LoggedOutOutput_When_Identity_Provider_Is_Not_Local_And_Scheme_Supports_Sign_Out()
        {
            var logoutId = string.Empty;
            var claims   = new List <Claim>
            {
                new Claim(ClaimTypes.Email, "*****@*****.**")
            };
            var          claimsIdentity = new ClaimsIdentity(claims, "authType");
            var          cp             = new ClaimsPrincipal(claimsIdentity);
            var          logoutRequest  = new LogoutRequest(true, string.Empty, string.Empty, Guid.NewGuid(), Guid.NewGuid());
            const string idp            = "Google";
            var          logoutContext  = Guid.NewGuid().ToString();
            var          expectedResult = new LoggedOutOutput(logoutContext, logoutRequest.PostLogoutRedirectUri,
                                                              logoutRequest.SignOutIFrameUrl, logoutRequest.ClientId, idp);

            _logoutServiceMock.Setup(x => x.GetLogoutRequestAsync(It.IsAny <string>()))
            .ReturnsAsync(logoutRequest);
            _claimsPrincipalServiceMock.Setup(x => x.GetClaimsPrincipal()).Returns(cp);
            _signOutServiceMock.Setup(x => x.SignOutAsync()).Returns(Task.CompletedTask);
            _persistedGrantRepositoryMock.Setup(x => x.DeleteAllBySubjectIdAsync(It.IsAny <Guid>()))
            .Returns(Task.CompletedTask);
            _claimsPrincipalServiceMock.Setup(x => x.GetNonLocalIdentityProvider(It.IsAny <ClaimsPrincipal>()))
            .Returns(idp);
            _schemeServiceMock.Setup(x => x.SchemeSupportsSignOutAsync(It.IsAny <string>())).ReturnsAsync(true);
            _logoutServiceMock.Setup(x => x.CreateLogoutContextAsync()).ReturnsAsync(logoutContext);

            var result = await _interactor.ExecuteAsync(logoutId);

            result.Should().BeEquivalentTo(expectedResult);
        }
Example #2
0
        public async Task Logout_Should_Return_SignOutResult_When_TriggerExternalSignOut_Is_True()
        {
            const string logoutId             = "logoutId";
            const string authenticationScheme = "Google";
            var          loggedOutOutput      = new LoggedOutOutput(logoutId, "postLogoutRedirectUri", "signOutIframeUrl",
                                                                    Guid.NewGuid(), authenticationScheme);
            var loggedOutViewModel = new LoggedOutViewModel(loggedOutOutput.LogoutId,
                                                            loggedOutOutput.PostLogoutRedirectUri, loggedOutOutput.SignOutIframeUrl, loggedOutOutput.ClientId,
                                                            loggedOutOutput.ExternalAuthenticationScheme);
            var          urlHelperMock          = new Mock <IUrlHelper>(MockBehavior.Strict);
            const string redirectUrl            = "http://localhost:5000/auth/logout";
            var          expectedAuthProperties = new AuthenticationProperties {
                RedirectUri = redirectUrl
            };

            _mapperMock.Setup(x => x.Map <LoggedOutOutput, LoggedOutViewModel>(It.IsAny <LoggedOutOutput>()))
            .Returns(loggedOutViewModel);
            _loggedOutInteractorMock.Setup(x => x.ExecuteAsync(It.IsAny <string>())).ReturnsAsync(loggedOutOutput);
            urlHelperMock.Setup(x => x.Action(It.IsAny <UrlActionContext>())).Returns(redirectUrl);
            _controller.Url = urlHelperMock.Object;

            var result = await _controller.Logout(logoutId, "true");

            var signOutResult = result.As <SignOutResult>();

            signOutResult.Properties.Should().BeEquivalentTo(expectedAuthProperties);
            signOutResult.AuthenticationSchemes.Should().Contain(authenticationScheme);
        }
Example #3
0
        public async Task ExecuteAsync_Should_Return_LoggedOutOutput_When_Account_Is_Not_Authenticated()
        {
            const string logoutId       = "logoutId";
            var          cp             = new ClaimsPrincipal();
            var          logoutRequest  = new LogoutRequest(true, string.Empty, string.Empty, Guid.NewGuid(), Guid.NewGuid());
            var          expectedResult = new LoggedOutOutput(logoutId, logoutRequest.PostLogoutRedirectUri,
                                                              logoutRequest.SignOutIFrameUrl, logoutRequest.ClientId, null);

            _logoutServiceMock.Setup(x => x.GetLogoutRequestAsync(It.IsAny <string>()))
            .ReturnsAsync(logoutRequest);
            _claimsPrincipalServiceMock.Setup(x => x.GetClaimsPrincipal()).Returns(cp);

            var result = await _interactor.ExecuteAsync(logoutId);

            result.Should().BeEquivalentTo(expectedResult);
        }
Example #4
0
        public async Task Logout_Should_Return_ViewResult_When_TriggerExternalSignOut_Is_False()
        {
            const string logoutId             = "logoutId";
            const string authenticationScheme = null;
            var          loggedOutOutput      = new LoggedOutOutput(logoutId, "postLogoutRedirectUri", "signOutIframeUrl",
                                                                    Guid.NewGuid(), authenticationScheme);
            var loggedOutViewModel = new LoggedOutViewModel(loggedOutOutput.LogoutId,
                                                            loggedOutOutput.PostLogoutRedirectUri, loggedOutOutput.SignOutIframeUrl, loggedOutOutput.ClientId,
                                                            loggedOutOutput.ExternalAuthenticationScheme);

            _mapperMock.Setup(x => x.Map <LoggedOutOutput, LoggedOutViewModel>(It.IsAny <LoggedOutOutput>()))
            .Returns(loggedOutViewModel);
            _loggedOutInteractorMock.Setup(x => x.ExecuteAsync(It.IsAny <string>())).ReturnsAsync(loggedOutOutput);

            var result = await _controller.Logout(logoutId, "true");

            var viewResult = result.As <ViewResult>();

            viewResult.Should().NotBeNull();
            viewResult.ViewName.Should().BeEquivalentTo("LoggedOut");
            viewResult.ViewData.Model.Should().BeEquivalentTo(loggedOutViewModel);
        }