Hi Everyone,
I've been having trouble with form authentication in rest-assured. In a browser, I am able to login and use the site. In rest-assured, my get will not authorize me to let me past the login screen.
This is my bare-bones authentication test...
RestAssured.authentication = form("theuser", "thepassword", new FormAuthConfig("/j_security_check", "j_username", "j_password"));
expect().body(not(containsString("j_security_check"))).body(containsString("the event")).get("/s/events/today/");
When the second line is executed, the get returns my login form, failing my "not" constraint.
I thought I got a bit farther when I did something like this (and variations of it)…
String sessionId = given().auth().form("theuser", "thepassword", new FormAuthConfig("/j_security_check", "j_username", "j_password")).get("/s/events/today/").sessionId();
given().sessionId(sessionId).expect().body(not(containsString("j_security_check"))).body(containsString("the event")).get("/s/events/today/");
And that works when I hard-code the sessionID in the second line to one I pull from a cookie in chrome, but for the life of me I can't get this working when I programmatically login.
Thinking it might be an issue with JAX-RS or something, I've disabled everything in web.xml that I thought could cause this, and it now boils down to this…
<security-constraint>
<web-resource-collection>
<web-resource-name>Restricted</web-resource-name>
<url-pattern>/s/*</url-pattern>
<http-method>DELETE</http-method>
<http-method>PUT</http-method>
<http-method>HEAD</http-method>
<http-method>OPTIONS</http-method>
<http-method>TRACE</http-method>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
<role-name>sales</role-name>
<role-name>manager</role-name>
<role-name>chair</role-name>
<role-name>employee</role-name>
<role-name>attendee</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login/login.jsp</form-login-page>
<form-error-page>/login/login_err.jsp</form-error-page>
</form-login-config>
</login-config>
<security-role>
<role-name>admin</role-name>
</security-role>
<security-role>
<role-name>sales</role-name>
</security-role>
<security-role>
<role-name>manager</role-name>
</security-role>
<security-role>
<role-name>chair</role-name>
</security-role>
<security-role>
<role-name>employee</role-name>
</security-role>
<security-role>
<role-name>attendee</role-name>
</security-role>
I can still login to a browser, but now my page 404s because I've disabled my servlet. However, in my tests, the get still returns the login form.Thanks in advance for your help.
RichP.S. I installed 1.7.2 yesterday to no avail.P.P.S. I'm not sure it matters, but here is my context.xml…
<Resource name="jdbc/testdb" auth="Container" type="javax.sql.DataSource"
username="root" password="" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/testdb"
maxActive="100" maxIdle="30" maxWait="10000"
testConnectionOnCheckout="true" testOnBorrow="true" validationQuery="select 1"
/>
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/testdb"
connectionName="root" connectionPassword=""
userTable="tc_realm_users" userNameCol="username" userCredCol="passwordhash"
userRoleTable="tc_realm_groups" roleNameCol="groupname" digest="sha-256" />
<label for="j_username">User Name:</label>
<div class="clear">
<input type="text" name="j_username" id="j_username" autocapitalize="off" autocomplete="off" autocorrect="off" />
<div class="clear">
<label for="j_password">Password:</label>
<div class="clear">
<input type="password" name="j_password" id="j_password" />
<div class="clear">
<input class="btn" type="submit" name="submit" id="submit" value="Go" data-theme="b" />
</form>
Rich
<meta http-equiv="Cache-Control" content="no-store,no-cache,must-revalidate"><meta http-equiv="Pragma" content="no-cache"><meta http-equiv="Expires" content="-1">
For c, I tried changing the form's submit to have a value of "Login", but that did nothing.
For d, I couldn't figure out how to include the JSESSIONID cookie in the post to /j_security_check
I also tried setting my server's RequestTimeout to 60000, to no avail.
String sessionId = get("/s/events/Today/").sessionId();
RestAssured.sessionId = sessionId;
RestAssured.authentication = form("theuser", "thepassword", new FormAuthConfig("/j_security_check", "j_username", "j_password"));
given().expect().body(not(containsString("j_security_check"))).body(containsString("RMH")).get("/s/events/Today/");
However, if I follow that up with this line, it again prompts me for the login.
given().expect().body(not(containsString("j_security_check"))).body(containsString("RMH")).get("/s/events/Yesterday/");
I have to do this to get yesterday to work:
String sessionId = get("/s/events/Yesterday/").sessionId();
RestAssured.sessionId = sessionId;
RestAssured.authentication = form("theuser", "thepassword", new FormAuthConfig("/j_security_check", "j_username", "j_password"));
given().expect().body(not(containsString("j_security_check"))).body(containsString("RMH")).get("/s/events/Yesterday/");