vinissimus / async-asgi-testclient

A framework-agnostic library for testing ASGI web applications
MIT License
160 stars 20 forks source link

fix Cookie header rendering in requests #42

Closed druid8 closed 2 years ago

druid8 commented 2 years ago

I made a fix which renders cookies correctly in request header. In the previous code cookie_jar.output(headers="") was rendering cookies as for Set-Cookie response header, which means that additional flags like Expires, Max-Age, SameSite etc was added.

Why it was working?

Because both tested framework - Quart and Starlette, in versions specified in requirements, uses same library and SimpleCookie to parse this header. So even with Set-Cookie syntax in the header, all tests were passing as SimpleCookie.load method supports both: Cookie and Set-Cookie

However, Starlette in the current version has custom cookie parsing mechanism and updating starlette cause tests failing.

What has been changed

I've changed Cookie request header rendering, so only cookie name and value are rendered now. Also multiple cookies are correctly separated by ; not \r\n. I've add a new /cookie-raw endpoint in both frameworks to make sure that Cookie header seen by the asgi app is correct. I was NOT updating Starlette.

This PR closes https://github.com/vinissimus/async-asgi-testclient/issues/41

masipcat commented 2 years ago

Thank you very much for the fix!

masipcat commented 2 years ago

v1.4.8 released

druid8 commented 2 years ago

@masipcat Thank you for PR approve and very quick fix release! I really appreciate that.