Skip to content

Instantly share code, notes, and snippets.

@eugenp
Created November 5, 2011 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eugenp/1341570 to your computer and use it in GitHub Desktop.
Save eugenp/1341570 to your computer and use it in GitHub Desktop.
part 5 - the Security test utils
public String authenticateAsAdmin(){
return this.authenticate( "eparaschiv", "eparaschiv" );
}
public String authenticate( String username, String password ){
Response response = RestAssured.given().
.param( UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_USERNAME_KEY, username )
.param( UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_PASSWORD_KEY, password )
.post( this.examplePaths.getLoginURL() );
Preconditions.checkState( response.getStatusCode() == 302 );
return JSESSIONID + "=" + response.getCookie( JSESSIONID );
}
public RequestSpecification givenAuthenticated( String cookie ){
return RestAssured.given().header( COOKIE_HEADER, cookie );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment