public void Basic_Login_Post_2()
        {
            var loginModel = new LoginModel
            {
                EmailAddress = It.IsAny<string>(),
                Password = It.IsAny<string>()
            };

            var result = _homeController.Login(loginModel, string.Empty) as ViewResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(result.ViewName, string.Empty);
            Assert.False(_homeController.ModelState.IsValid);
            Assert.AreEqual(_homeController.ModelState[string.Empty].Errors[0].ErrorMessage, "The email address and/or password provided is incorrect.");
        }
Example #2
0
        public ActionResult Login(
            LoginModel loginModel,
            string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (_authenticateService.ValidateUser(loginModel.EmailAddress, loginModel.Password))
                {
                    Login(HttpContext, loginModel.RememberMe);

                    _userLogService.LoginSuccessful(UserId);

                    // Handle open redirection attacks by checking if the return URL is local.
                    if (!string.IsNullOrWhiteSpace(returnUrl))
                    {
                        if (Url.IsLocalUrl(returnUrl))
                        {
                            return Redirect(returnUrl);
                        }

                        // Log the exception in ELMAH and redirect the user to an error page.
                        ErrorSignal.FromCurrentContext().Raise(
                            new System.Security.SecurityException(string.Format("An open redirect attack to \"{0}\" was detected.", returnUrl)));

                        return RedirectToAction("Error", "Home");
                    }

                    return RedirectToAction("Index", "Home", new { Area = "Secure" });
                }

                _userLogService.LoginUnsuccessful(loginModel.EmailAddress);

                ModelState.AddModelError("The email address and/or password provided is incorrect.");
            }

            // If we got this far, something failed, redisplay form.
            return View(loginModel);
        }
        public void Basic_Login_Post_3()
        {
            _mockAuthenticateService
                .Setup(m => m.ValidateUser(It.IsAny<string>(), It.IsAny<string>()))
                .Returns(true);

            var mockHomeController = new Mock<HomeController>();

            // mockHomeController.Setup(m => m.Login(It.IsAny<string>(), null);

            var loginModel = new LoginModel
            {
                EmailAddress = It.IsAny<string>(),
                Password = It.IsAny<string>()
            };

            var result = _homeController.Login(loginModel, string.Empty) as RedirectToRouteResult;

            // Multiple Asserts to handle a null result.
            Assert.IsNotNull(result);
            Assert.AreEqual("X", result.RouteValues["action"]);
        }