pyresttest icon indicating copy to clipboard operation
pyresttest copied to clipboard

Cookie extractor from Set-Cookie response.

Open danielatdattrixdotcom opened this issue 9 years ago • 5 comments

I needed this for working with an API that uses Django auth/sessions to work with CSRF cookie and X-CSRFToken header.

danielatdattrixdotcom avatar Mar 30 '16 04:03 danielatdattrixdotcom

Can one of the admins verify this patch?

svanoort-jenkins avatar Mar 30 '16 04:03 svanoort-jenkins

@danielatdattrixdotcom Thank you, this is a feature that I know is in fairly high demand. I've added a couple comments (small changes) before this is ready to be merged. It also needs some sort of small unit test in test_validators.py.

This weekend I'm going to play with it a bit more and look more closely at the format of output (it might make sense to add a few options).

You get kudos by the way for looking closely at how the other extractors are implemented and following that (and adding documentation as well)!

svanoort avatar Mar 30 '16 13:03 svanoort

@svanoort Let me know on the args/options to extractors in the YAML/JSON files and your thoughts on that and I'll make the updates and tests.

danielatdattrixdotcom avatar Mar 31 '16 02:03 danielatdattrixdotcom

Oh no, I had write the same feature code, but @danielatdattrixdotcom 's documents is nice. 😂

alswl avatar Apr 08 '16 07:04 alswl

@danielatdattrixdotcom Coming back to this now that the crunch period at work is settling down (spoiler: Jenkins, and specifically work on Pipeline Stage View plugin): I think it's not worth adding options to the extractor right now - I had a notion of eventually allowing use of regexes or other matchers in extraction, but it's not useful yet. We need support for templating with collections (or transformations on collections), and/or some embedded transformation language, if we're going to go down that route. It's planned in the future, but too far off to worry about now.

Added one comment about a Python 3 compatibility challenge (just an import change).

So, from my point of view, to get to merge, what we need are automated tests, covering a couple key edge cases: cookie doesn't exist, cookie exists with multiple values, normal cookie case. This means a unit test in test_validators.py, and a functional test in functionaltest.py -- the unit test just covers the extractor parsing and behavior (you can use some cookie info taken from a browser session).

The functional test needs to work with real HTTP requests; I'd prefer to add cookie-setting to the test Django-tastypie app (probably easiest done with the sessions middleware option), but if that proves hard we can just invoke a public API or site, as long as the request is trivial. I've been using GitHub for this in the past.

svanoort avatar Apr 09 '16 17:04 svanoort