Example #1
0
        public async Task LoginControllerReconnectInActive()
        {
            var data  = new LoginDataHandler();
            var logic = new CoreApiLogicHandler();

            var model = UserData.GetFirst();

            model.IsActive = false;

            var reconnect = LoginData.GetReconnect();

            data.Result.Setup(m => m.Execute(It.IsAny <UserById>())).Returns(model);

            var controller = new LoginController(data, Cloud, logic);
            var result     = await controller.Reconnect(reconnect) as OkObjectResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <OkObjectResult>();

            logic.HasExecuted.Should().BeFalse();
            logic.Result.Verify(s => s.Execute(It.IsAny <SigninAuth>()), Times.Never);

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeFalse();
            data.Result.Verify(s => s.Execute(It.IsAny <UserById>()), Times.Once);
        }
Example #2
0
        public async Task SignupUserLogicMissingEntry()
        {
            var data  = new LoginDataHandler();
            var logic = new CoreApiLogicHandler();
            var cloud = new FakeCloudHandler();

            var viewModel = LoginData.GetSignup();

            data.Result.Setup(m => m.Execute(It.IsAny <Loader <Tenant> >())).Returns(null);

            var command = new SignupUser
            {
                DataHandler  = data,
                CloudHandler = cloud,
                LogicHandler = logic,
                Input        = viewModel,
                Result       = ActionConfirm.CreateFailure("Failed")
            };

            await command.Execute();

            command.Result.Success.Should().BeFalse();

            logic.HasExecuted.Should().BeFalse();
            logic.Result.Verify(s => s.Execute(It.IsAny <SimpleNotify>()), Times.Never());

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeFalse();
            data.Result.Verify(s => s.Execute(It.IsAny <Loader <Tenant> >()), Times.Once());
            data.Result.Verify(s => s.Execute(It.IsAny <UserSave>()), Times.Never());
        }
Example #3
0
        public async Task LoginControllerAuthTwoFactor()
        {
            var data  = new LoginDataHandler();
            var logic = new CoreApiLogicHandler();

            data.ResultConfig = new UserConfig()
            {
                IsTwoFactor = true
            };

            var login   = LoginData.GetLogin();
            var confirm = ModelConfirm <UserConfig> .CreateSuccess(data.ResultConfig);

            data.Result.Setup(m => m.Execute(It.IsAny <UserByEmail>())).Returns(StandardUser);
            data.Result.Setup(m => m.Execute(It.IsAny <Persist <UserConfig> >())).Returns(confirm);
            logic.Result.Setup(m => m.Execute(It.IsAny <SimpleNotify>())).Returns(ActionConfirm.CreateSuccess("ok"));

            var controller = new LoginController(data, Cloud, logic);
            var result     = await controller.Auth(login) as OkObjectResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <OkObjectResult>();

            logic.HasExecuted.Should().BeTrue();
            logic.Result.Verify(s => s.Execute(It.IsAny <SigninAuth>()), Times.Never);
            logic.Result.Verify(s => s.Execute(It.IsAny <SimpleNotify>()), Times.Once);

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeTrue();
            data.Result.Verify(s => s.Execute(It.IsAny <UserByEmail>()), Times.Once);
        }
Example #4
0
        public async Task LoginControllerReconnect()
        {
            var data  = new LoginDataHandler();
            var logic = new CoreApiLogicHandler();

            var auth      = LoginData.GetAuth();
            var reconnect = LoginData.GetReconnect();

            data.Result.Setup(m => m.Execute(It.IsAny <UserById>())).Returns(StandardUser);
            logic.Result.Setup(m => m.Execute(It.IsAny <SigninAuth>())).Returns(auth);

            var controller = new LoginController(data, Cloud, logic);
            var result     = await controller.Reconnect(reconnect) as OkObjectResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <OkObjectResult>();

            logic.HasExecuted.Should().BeTrue();
            logic.Result.Verify(s => s.Execute(It.IsAny <SigninAuth>()), Times.Once);

            reconnect.Verification.Should().BeNullOrEmpty();
            reconnect.Id.Should().NotBeEmpty();
            reconnect.Key.Should().NotBeEmpty();

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeFalse();
            data.Result.Verify(s => s.Execute(It.IsAny <UserById>()), Times.Once);
        }
Example #5
0
        public async Task LoginControllerTwoFactorFailWrongCode()
        {
            var data  = new LoginDataHandler();
            var logic = new CoreApiLogicHandler();

            data.ResultConfig = new UserConfig()
            {
                IsTwoFactor = true, TwoFactorAuth = "654321", IsTwoFactorActive = true
            };

            var login   = LoginData.GetTwoFactor();
            var confirm = ModelConfirm <UserConfig> .CreateSuccess(data.ResultConfig);

            data.Result.Setup(m => m.Execute(It.IsAny <UserById>())).Returns(StandardUser);
            data.Result.Setup(m => m.Execute(It.IsAny <Persist <UserConfig> >())).Returns(confirm);

            var controller = new LoginController(data, Cloud, logic);
            var result     = await controller.TwoFactor(login) as OkObjectResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <OkObjectResult>();

            logic.HasExecuted.Should().BeFalse();

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeFalse();
            data.Result.Verify(s => s.Execute(It.IsAny <UserById>()), Times.Once);
        }
Example #6
0
        public async Task LoginControllerTwoFactorFailNoUser()
        {
            var data  = new LoginDataHandler();
            var logic = new CoreApiLogicHandler();

            data.ResultConfig = new UserConfig()
            {
                IsTwoFactor = true, TwoFactorAuth = "123456", IsTwoFactorActive = true
            };

            var login = LoginData.GetTwoFactor();

            data.Result.Setup(m => m.Execute(It.IsAny <UserById>())).Returns(null);

            var controller = new LoginController(data, Cloud, logic);
            var result     = await controller.TwoFactor(login) as OkObjectResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <OkObjectResult>();

            logic.HasExecuted.Should().BeFalse();

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeFalse();
            data.Result.Verify(s => s.Execute(It.IsAny <UserById>()), Times.Once);
        }
        public bool Validate(string id)
        {
            LoginDataHandler loginDataHandler     = new LoginDataHandler();
            string           passwordFromDatabase = loginDataHandler.GetPassword(id);

            if (passwordFromDatabase == password)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #8
0
        public async Task LoginControllerAuthFail()
        {
            var data  = new LoginDataHandler();
            var logic = new CoreApiLogicHandler();

            var login = LoginData.GetLogin();

            data.Result.Setup(m => m.Execute(It.IsAny <UserByEmail>())).Returns(null);

            var controller = new LoginController(data, Cloud, logic);
            var result     = await controller.Auth(login) as OkObjectResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <OkObjectResult>();

            logic.HasExecuted.Should().BeFalse();
            logic.Result.Verify(s => s.Execute(It.IsAny <SigninAuth>()), Times.Never);

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeFalse();
            data.Result.Verify(s => s.Execute(It.IsAny <UserByEmail>()), Times.Once);
        }
Example #9
0
        public async Task LoginControllerAuth()
        {
            var data  = new LoginDataHandler();
            var logic = new CoreApiLogicHandler();

            data.ResultConfig = new UserConfig();

            var login = LoginData.GetLogin();
            var auth  = LoginData.GetAuth();

            data.Result.Setup(m => m.Execute(It.IsAny <UserByEmail>())).Returns(StandardUser);
            logic.Result.Setup(m => m.Execute(It.IsAny <SigninAuth>())).Returns(auth);

            var controller = new LoginController(data, Cloud, logic);
            var result     = await controller.Auth(login) as OkObjectResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <OkObjectResult>();

            logic.HasExecuted.Should().BeTrue();
            logic.Result.Verify(s => s.Execute(It.IsAny <SigninAuth>()), Times.Once);

            auth.Id.Should().NotBeEmpty();
            auth.IsTwoFactor.Should().BeFalse();
            auth.User.ClientHasProfile.Should().BeFalse();
            auth.User.ClientProfileThumbUrl.Should().BeEmpty();
            auth.User.ProfileThumbUrl.Should().BeEmpty();
            auth.User.Email.Should().BeEmpty();
            auth.User.HasPhone.Should().BeFalse();
            auth.User.HasProfile.Should().BeFalse();
            auth.User.Name.Should().BeEmpty();
            auth.User.TenantId.Should().BeEmpty();
            auth.User.TenantName.Should().BeEmpty();
            auth.Right.Should().NotBeNull();

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeFalse();
            data.Result.Verify(s => s.Execute(It.IsAny <UserByEmail>()), Times.Once);
        }