djangid / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

Add support for sessions #28

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
E.g. 

Session session = createSession();
session.expect().body("x.y.z", equalTo("xyz")).when().get("/xyz");
session.expect().body("z.y.x", equalTo("zyx")).when().get("/zyx");
session.close();

RA should automatically extract the session id from the header and pass it 
along to the next request.

Original issue reported on code.google.com by johan.ha...@gmail.com on 13 Feb 2011 at 10:17

GoogleCodeExporter commented 8 years ago
Will this be handled automatically by httpbuilder if we reuse the http builder?

Original comment by johan.ha...@gmail.com on 16 Feb 2011 at 10:46

GoogleCodeExporter commented 8 years ago
Hi, 

Not sure that I quite catch the idea of the Session object, but in scope of our 
project we need to have some kind of support for sessions. Here is what I mean: 
1. Test scenario log-ins using special REST service and gets cookies JSESSIONID 
parameter (this is typical name that is specified in Java servlet spec. 
2. All subsequent requests should be sent with this cookies parameter.

This is necessary to test services that requires authentication. 
Does this issue cover our needs? Is it possible to implement all these stuff 
using existing API? 

Original comment by mikhail....@gmail.com on 26 Jan 2012 at 2:08

GoogleCodeExporter commented 8 years ago
Hi, 

Yes this is what I meant by sessions and the purpose of this issue but I'm not 
sure if it's valid anymore. 

What you should do is to create a custom filter (see documentation) that logs 
in to the server and extracts the jsessionid from the response and redo the 
request with this session id set. 

Have a look at com.jayway.restassured.internal.filter.FormAuthFilter or 
com.jayway.restassured.itest.java.presentation.filter.CustomAuthFilter (located 
in the rest-assured-itest-java project at github). For an example on how to use 
the CustomAuthFilter filter refer to CustomAuthDemoITest in the same project.

/Johan

Original comment by johan.ha...@gmail.com on 26 Jan 2012 at 3:25

GoogleCodeExporter commented 8 years ago
Thanks a lot. 
I did some research by myself and found the following issue:
http://code.google.com/p/rest-assured/issues/detail?id=149
As far as I understand all that I need is to set 
 RestAssured.config = config().httpClient( new HttpClientConfig().setParam("http.protocol.cookie-policy", CookiePolicy.DEFAULT));
and all cookies from the previous request will be sent in subsequent requests 
(what was considered as a defect :) )
Am I right

Original comment by mikhail....@gmail.com on 26 Jan 2012 at 3:34

GoogleCodeExporter commented 8 years ago
I'm actually not sure about that but I don't think so. CookiePolicy.DEFAULT is 
actually what's used in version 1.5 (I assume since we don't set the 
http.protocol.cookie-policy property by in the REST Assured configuration in 
version 1.5).

Original comment by johan.ha...@gmail.com on 26 Jan 2012 at 3:38

GoogleCodeExporter commented 8 years ago
For more discussion see: 
http://groups.google.com/group/rest-assured/browse_thread/thread/dcbcc14d4cfd030
f

Original comment by johan.ha...@gmail.com on 28 Feb 2012 at 7:33

GoogleCodeExporter commented 8 years ago

Original comment by johan.ha...@gmail.com on 18 Mar 2012 at 5:53