public
Last active

part 5 - the Security test utils

  • Download Gist
SecurityUtil.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
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 );
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.