"[W]hen all government, domestic and foreign, in little as in great things, shall be drawn to Washington as the center of all power, it will render powerless the checks provided of one government on another." --Thomas Jefferson, letter to Charles Hammond, 1821 |
I agree with the fact it would be a nice feature to have in Rest assured.
Nevertheless, I want it configurable and editable.I _personnaly_ often need to log in with several users during the same test (to test security accesses for example).
Implementation shouldn't be made in a static way (like RestAssured.* things) :)
First (simple) step would be to have utility methods to get/set session id from/to request/response specifications.With that in hand, we could be able to give this token on every requests.
String jsessionId = get("/x").cookie("jsessionid");
given().cookie("jsessionid", jsessionid).when().get("/x");I'm not sure how you could make it much simpler without making it less generic but suggestions are of course welcome :). Remember that not all sessionid's are named "jsessiond" (there's also "phpsessid" for example).
Thanks for your suggestions, really appreciated. I have some questions/comments below:For curiosity, could you explain why you need to login with several users in the same test? Wouldn't it be possible (and even better) to have one test case per "security validation" (something like "userWithPrivilegeXShouldHaveAccessToY")?
On 02/27/2012 07:56 PM, Frédéric Camblor wrote:I agree with the fact it would be a nice feature to have in Rest assured.
Nevertheless, I want it configurable and editable.I _personnaly_ often need to log in with several users during the same test (to test security accesses for example).
I would argue that it's quite simple already. This is how you make a request and get the jsessionid:Implementation shouldn't be made in a static way (like RestAssured.* things) :)
First (simple) step would be to have utility methods to get/set session id from/to request/response specifications.With that in hand, we could be able to give this token on every requests.
String jsessionId = get("/x").cookie("jsessionid");
Setting cookies is not much harder:
given().cookie("jsessionid", jsessionid).when().get("/x");I'm not sure how you could make it much simpler without making it less generic but suggestions are of course welcome :). Remember that not all sessionid's are named "jsessiond" (there's also "phpsessid" for example).
By writing your own filter (which can also be applied statically or using a RequestSpecBuilder) it should be possible to apply this more or less transparent. Theoretically it even ought to be possible to map each user to a jsessionid in a single filter which allows the filter to be applied statically as well. But I don't think it'll be possible to write a generic filter (that can be included by default in REST Assured) that solves this.