Re: [rest-assured] Question on using same session

84 views
Skip to first unread message

Johan Haleby

unread,
May 10, 2013, 2:36:42 AM5/10/13
to rest-a...@googlegroups.com
REST Client probably maintains the session id in the subsequent request which RA doesn't do automatically. Either you would have to supply the authentication details in every request (use given().auth().form(..)) or you would have to extract the session id from the response and attach it to the next request(s). 

String sessionId = given().body("j_username=ken&j_password=xxxx&spring-security-redirect=%2F%23").expect().statusCode(200).when().post("/LoanApp/k_spring_security_check").andReturn().sessionId();
given().sessionId(sessionId).contentType("application/json").body(JSONpayload).expect().statusCode(201).post("/application/loanapplications?type=loanapplication");

You can also apply the session id statically or using response specifications. You could also write a custom filter that does this automatically (if you do please share so we can include it in REST Assured :)). 

Regards,
/Johan



On Thu, May 9, 2013 at 6:02 PM, Ken K <kenned...@gmail.com> wrote:
I'm testing this scenario and it works fine on a REST Client. But getting a 401 Error while using REST Assured. This is a legacy application I'm trying to automate. 
The issue seem like I'm able not able to use the same session for all the calls with RESTAssured. Any help to approach this issue would be appreciated.

Scenario: Create Object Test scenario
Given user user1 and password password1
When create object loan application with applicant_name ken and amt 10000
Then verify loan application is created with applicant_name ken and amt 10000

Using REST Client (Google or Firefox Plugin) - Everything works fine

1. Authenticate Step (POST): URI : /LoanApp/k_spring_security_check   Body :  k_username=ken&k_password=xxxx&spring-security-redirect=# 
2. Create Object Step (POST) : URI :  /LoanApp/application/loanapplications?type=_loanapplication Header :  Content-Type application/json, Request Body: {"\applicant_name"\:"\ken"\,"application_amt\":\"10000"}      Response : {"id":"1234xxxx"} 

3. Verify Object Step (GET): URI :  /LoanApp/application/loanapplications/1234xxxx  Response : {"\applicant_name"\:"\ken"\,"application_amt\":\"10000"} 


Using RESTAssured - Authentication works , rest of them fails

1. Authenticate Step (POST Works Fine) :given().body("j_username=ken&j_password=xxxx&spring-security-redirect=%2F%23").expect().statusCode(200).when().post("/LoanApp/k_spring_security_check") 
2. Create Object Step (POST fails with 401 unauhorized) : given().
         contentType("application/json").body(JSONpayload).expect().statusCode(201).post("/application/loanapplications?type=loanapplication");
3. Verify Object Step (GET fails with 401 unauthorized): given().get("/application/light_loanapplications/"+loanID);

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages