vinissimus / async-asgi-testclient

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

Request `Cookie` header is invalid #41

Closed druid8 closed 2 years ago

druid8 commented 2 years ago

Cookies from cookie jar are rendered in wrong way into Cookie request header. The HTTP request Cookie header should contain only cookie_name=cookie_value pairs delimited by semicolon (;). Currently whole cookie is rendered as for response Set-Cookie which cause than tested application sees cookies like Expires, Domain, Samesite etc... Moreover if more than one cookie is in cookie jar, generated header makes whole request malformed as rendered cookies are \r\n separated (which obviously ends request's Cookie header at first occurrence and the rest are rubbish)

issue is here: async_asgi_testclient/testing.py:

        if cookie_jar and cookie_jar.output(header=""):
            headers.add("Cookie", cookie_jar.output(header=""))

I will make a PR with a fix soon.