Add Invalid Username/Password to users sample

gh-49
This commit is contained in:
Rob Winch
2014-11-17 14:48:58 -06:00
parent 495d19982d
commit 3cd4364566
4 changed files with 28 additions and 1 deletions

View File

@@ -21,6 +21,26 @@ class UserTests extends GebReportingSpec {
!username
}
def 'invalid login'() {
setup:
def user = 'rob'
when:
login(user, user+'invalid')
then:
!username
error == 'Invalid username / password. Please ensure the username is the same as the password.'
}
def 'empty username'() {
setup:
def user = ''
when:
login(user, user)
then:
!username
error == 'Invalid username / password. Please ensure the username is the same as the password.'
}
def 'login single user'() {
setup:
def user = 'rob'

View File

@@ -12,6 +12,7 @@ class HomePage extends Page {
static at = { assert driver.title == 'Demonstrates Multi User Log In'; true}
static content = {
navLink { $('#navLink') }
error { $('#error').text() }
form { $('form') }
username(required:false) { $('#un').text() }
logout(required:false) { $('#logout') }

View File

@@ -32,10 +32,13 @@ public class LoginServlet extends HttpServlet {
String username = req.getParameter("username");
String password = req.getParameter("password");
if(username != null && username.equals(password)) {
if(username != null && !"".equals(username) && username.equals(password)) {
req.getSession().setAttribute("username", username);
String url = resp.encodeRedirectURL(req.getContextPath() + "/");
resp.sendRedirect(url);
} else {
String url = resp.encodeRedirectURL(req.getContextPath() + "/?error");
resp.sendRedirect(url);
}
}

View File

@@ -62,6 +62,9 @@
<li><b>Username</b> rob and <b>Password</b> rob</li>
<li><b>Username</b> luke and <b>Password</b> luke</li>
</ul>
<c:if test="${param.error != null}">
<div id="error" class="alert alert-warning">Invalid username / password. Please ensure the username is the same as the password.</div>
</c:if>
<c:url value="/login" var="loginUrl"/>
<form action="${loginUrl}" method="post">
<div class="form-group">