public async Task ExecuteAsync_Should_Return_LocalLoginOutput_With_LocalLoginEnabled_False_When_When_Identity_Provider_And_ClientId_Are_Provided_But_Scheme_Is_Null() { const string redirectUri = "http://localhost"; var identityProviderRestrictions = new List <string> { "Google" }; var client = Client.Builder() .SetId(Guid.NewGuid()) .SetEnabled(true) .SetEnableLocalLogin(false) .SetRequirePkce(false) .SetIdentityProviderRestrictions(identityProviderRestrictions) .Build(); var authRequest = new AuthorizationRequest("idP", client.Id.ToString(), redirectUri); var schemes = new List <AuthenticationScheme> { new AuthenticationScheme("Google", "Google"), new AuthenticationScheme("Facebook", "Facebook") }; var externalProviders = schemes .Where(scheme => client.IdentityProviderRestrictions.Contains(scheme.DisplayName)).Select(scheme => new LocalLoginExternalProviderOutput(scheme.DisplayName, scheme.Name)); var expectedResult = new LocalLoginOutput(client.EnableLocalLogin, externalProviders); _authorizationServiceMock.Setup(x => x.GetAuthorizationRequestAsync(It.IsAny <string>())) .ReturnsAsync(authRequest); _schemeServiceMock.Setup(x => x.GetSchemeAsync(It.IsAny <string>())) .Returns(Task.FromResult <AuthenticationScheme>(null)); _schemeServiceMock.Setup(x => x.GetAllSchemesAsync()).ReturnsAsync(schemes); _clientRepositoryMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(client); var result = await _localLoginInteractor.ExecuteAsync("http://localhost"); result.Should().BeEquivalentTo(expectedResult); }
public async Task ExecuteAsync_Should_Return_LocalLoginOutput_With_LocalLoginEnabled_True_And_Empty_External_Providers_When_Idenity_Provider_Exists_And_Is_Local_() { const string redirectUri = "http://localhost"; var authRequest = new AuthorizationRequest(AuthConstants.LocalIdentityProvider, "clientId", redirectUri); var scheme = new AuthenticationScheme("Google", "Google"); var expectedResult = new LocalLoginOutput(true, new List <LocalLoginExternalProviderOutput>()); _authorizationServiceMock.Setup(x => x.GetAuthorizationRequestAsync(It.IsAny <string>())) .ReturnsAsync(authRequest); _schemeServiceMock.Setup(x => x.GetSchemeAsync(It.IsAny <string>())).ReturnsAsync(scheme); var result = await _localLoginInteractor.ExecuteAsync(redirectUri); result.Should().BeEquivalentTo(expectedResult); }
private LocalLoginViewModel BuildLoginViewModel(LocalLoginOutput localLoginOutput, string returnUrl) { var googleLoginEnabled = localLoginOutput.ExternalProviders.Any(x => x.AuthenticationScheme == AuthenticationExtension.GoogleAuthScheme); var facebookLoginEnabled = localLoginOutput.ExternalProviders.Any(x => x.AuthenticationScheme == AuthenticationExtension.FacebookAuthScheme); return(new LocalLoginViewModel(localLoginOutput.LocalLoginEnabled, googleLoginEnabled, facebookLoginEnabled, _applicationUrlsAppSettings.RivaWebRegistrationUrl, _applicationUrlsAppSettings.RivaWebRequestRegistrationConfirmationEmailUrl, _applicationUrlsAppSettings.RivaWebRequestPasswordResetEmailUrl) { ReturnUrl = returnUrl }); }
public async Task Login_Should_Return_ViewResult_With_Errors_After_Unsuccessful_Credentials_Verification_When_Account_Is_Not_Found() { var localLoginRequest = new LocalLoginRequest { Email = "*****@*****.**", Password = "******", RememberLogin = false, ReturnUrl = "~/" }; var localLoginResultOutputErrors = new Collection <IError> { new Error(AccountErrorCodeEnumeration.NotFound, AccountErrorMessage.NotFound) }; var localLoginResultOutput = LocalLoginResultOutput.Fail(false, localLoginResultOutputErrors); var externalProviders = new List <LocalLoginExternalProviderOutput> { new LocalLoginExternalProviderOutput("google", AuthenticationExtension.GoogleAuthScheme), new LocalLoginExternalProviderOutput("facebook", AuthenticationExtension.FacebookAuthScheme) }; var localLoginOutput = new LocalLoginOutput(true, externalProviders); var expectedLocalLoginViewModel = new LocalLoginViewModel(true, true, true, string.Empty, string.Empty, string.Empty) { ReturnUrl = localLoginRequest.ReturnUrl, Email = localLoginRequest.Email, Password = localLoginRequest.Password, RememberLogin = localLoginRequest.RememberLogin }; var localLoginViewModelErrors = new List <string> { LocalLoginErrorMessage.InvalidCredentials }; expectedLocalLoginViewModel.SetErrors(localLoginViewModelErrors); _localLoginInteractorMock .Setup(x => x.ExecuteAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <string>())).ReturnsAsync(localLoginResultOutput); _localLoginInteractorMock.Setup(x => x.ExecuteAsync(It.IsAny <string>())).ReturnsAsync(localLoginOutput); var result = await _controller.Login(localLoginRequest); var viewResult = result.As <ViewResult>(); viewResult.Model.Should().BeEquivalentTo(expectedLocalLoginViewModel); }
public async Task Login_Should_Return_ViewResult_With_Errors_When_IsInTheContextOfAuthorizationRequest_And_IsNativeClient_Are_False_And_ReturnUrl_Is_Invalid() { var localLoginRequest = new LocalLoginRequest { Email = "*****@*****.**", Password = "******", RememberLogin = false, ReturnUrl = "http://nonEmptyNonLocalUrl.com" }; var localLoginResultOutput = LocalLoginResultOutput.Ok(false, false); var urlHelperMock = new Mock <IUrlHelper>(MockBehavior.Strict); _controller.Url = urlHelperMock.Object; var externalProviders = new List <LocalLoginExternalProviderOutput> { new LocalLoginExternalProviderOutput("google", AuthenticationExtension.GoogleAuthScheme), new LocalLoginExternalProviderOutput("facebook", AuthenticationExtension.FacebookAuthScheme) }; var localLoginOutput = new LocalLoginOutput(true, externalProviders); var expectedLocalLoginViewModel = new LocalLoginViewModel(true, true, true, string.Empty, string.Empty, string.Empty) { ReturnUrl = localLoginRequest.ReturnUrl, Email = localLoginRequest.Email, Password = localLoginRequest.Password, RememberLogin = localLoginRequest.RememberLogin }; var localLoginViewModelErrors = new List <string> { LocalLoginErrorMessage.InvalidReturnUrl }; expectedLocalLoginViewModel.SetErrors(localLoginViewModelErrors); _localLoginInteractorMock .Setup(x => x.ExecuteAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <string>())).ReturnsAsync(localLoginResultOutput); urlHelperMock.Setup(x => x.IsLocalUrl(It.IsAny <string>())).Returns(false); _localLoginInteractorMock.Setup(x => x.ExecuteAsync(It.IsAny <string>())).ReturnsAsync(localLoginOutput); var result = await _controller.Login(localLoginRequest); var viewResult = result.As <ViewResult>(); viewResult.Model.Should().BeEquivalentTo(expectedLocalLoginViewModel); }
public async Task Login_Should_Return_RedirectToActionResult_After_Get_Request() { const string returnUrl = "http://returnUrl.com"; var externalProviders = new List <LocalLoginExternalProviderOutput> { new LocalLoginExternalProviderOutput(AuthenticationExtension.GoogleAuthScheme, AuthenticationExtension.GoogleAuthScheme) }; var localLoginOutput = new LocalLoginOutput(false, externalProviders); var expectedRouteValues = new RouteValueDictionary(new { scheme = localLoginOutput.ExternalLoginScheme, returnUrl }); _localLoginInteractorMock.Setup(x => x.ExecuteAsync(It.IsAny <string>())).ReturnsAsync(localLoginOutput); var result = await _controller.Login(returnUrl); var redirectToActionResult = result.As <RedirectToActionResult>(); redirectToActionResult.ControllerName.Should().BeEquivalentTo("ExternalLogin"); redirectToActionResult.ActionName.Should().BeEquivalentTo("Challenge"); redirectToActionResult.RouteValues.Should().BeEquivalentTo(expectedRouteValues); }
public async Task ExecuteAsync_Should_Return_LocalLoginOutput_With_LocalLoginEnabled_False_When_When_Identity_Provider_And_ClientId_Are_Not_Provided() { const string redirectUri = "http://localhost"; var authRequest = new AuthorizationRequest(null, null, redirectUri); var schemes = new List <AuthenticationScheme> { new AuthenticationScheme("Google", "Google"), new AuthenticationScheme("Facebook", "Facebook") }; var externalProviders = schemes.Select(scheme => new LocalLoginExternalProviderOutput(scheme.DisplayName ?? scheme.Name, scheme.Name)); var expectedResult = new LocalLoginOutput(true, externalProviders); _authorizationServiceMock.Setup(x => x.GetAuthorizationRequestAsync(It.IsAny <string>())) .ReturnsAsync(authRequest); _schemeServiceMock.Setup(x => x.GetAllSchemesAsync()).ReturnsAsync(schemes); _clientRepositoryMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).Returns(Task.FromResult <Client>(null)); var result = await _localLoginInteractor.ExecuteAsync("http://localhost"); result.Should().BeEquivalentTo(expectedResult); }
public async Task Login_Should_Return_ViewResult_After_Get_Request() { const string returnUrl = "http://returnUrl.com"; var externalProviders = new List <LocalLoginExternalProviderOutput> { new LocalLoginExternalProviderOutput("google", AuthenticationExtension.GoogleAuthScheme), new LocalLoginExternalProviderOutput("facebook", AuthenticationExtension.FacebookAuthScheme) }; var localLoginOutput = new LocalLoginOutput(true, externalProviders); var expectedLocalLoginViewModel = new LocalLoginViewModel(true, true, true, string.Empty, string.Empty, string.Empty) { ReturnUrl = returnUrl }; _localLoginInteractorMock.Setup(x => x.ExecuteAsync(It.IsAny <string>())).ReturnsAsync(localLoginOutput); var result = await _controller.Login(returnUrl); var viewResult = result.As <ViewResult>(); viewResult.Model.Should().BeEquivalentTo(expectedLocalLoginViewModel); }