Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix quoted cookie #5398

Closed
wants to merge 6 commits into from
Closed

Fix quoted cookie #5398

wants to merge 6 commits into from

Conversation

Dreamsorcerer
Copy link
Member

@Dreamsorcerer Dreamsorcerer commented Jan 11, 2021

Fixes #5397

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Jan 11, 2021
@asvetlov
Copy link
Member

asvetlov commented Nov 1, 2021

Looks like a draft, converting

@asvetlov asvetlov marked this pull request as draft November 1, 2021 10:58
@Dreamsorcerer
Copy link
Member Author

Yes, but I also don't see how to fix this, without breaking another of the test cases:
#5397 (comment)

Copy link

codecov bot commented Sep 9, 2024

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
3294 1 3293 24
View the top 1 failed tests by shortest run time
tests.test_cookiejar test_quotes_correctly_based_on_input[pyloop-pre-quoted cookie]
Stack Traces | 0.032s run time
loop = <_UnixSelectorEventLoop running=False closed=False debug=False>
cookies = 'foo="quoted_value"', expected = 'Cookie: foo="quoted_value"'
quote_bool = True

    #x1B[0m#x1B[37m@pytest#x1B[39;49;00m.mark.parametrize(#x1B[90m#x1B[39;49;00m
        (#x1B[33m"#x1B[39;49;00m#x1B[33mcookies#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, #x1B[33m"#x1B[39;49;00m#x1B[33mexpected#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, #x1B[33m"#x1B[39;49;00m#x1B[33mquote_bool#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m),#x1B[90m#x1B[39;49;00m
        [#x1B[90m#x1B[39;49;00m
            (#x1B[90m#x1B[39;49;00m
                #x1B[33m"#x1B[39;49;00m#x1B[33mshared-cookie=first; ip-cookie=second; Domain=127.0.0.1;#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m,#x1B[90m#x1B[39;49;00m
                #x1B[33m"#x1B[39;49;00m#x1B[33mCookie: ip-cookie=second#x1B[39;49;00m#x1B[33m\r#x1B[39;49;00m#x1B[33m\n#x1B[39;49;00m#x1B[33mCookie: shared-cookie=first#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m,#x1B[90m#x1B[39;49;00m
                #x1B[94mTrue#x1B[39;49;00m,#x1B[90m#x1B[39;49;00m
            ),#x1B[90m#x1B[39;49;00m
            (#x1B[33m'#x1B[39;49;00m#x1B[33mip-cookie=#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m#x1B[33msecond#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m#x1B[33m; Domain=127.0.0.1;#x1B[39;49;00m#x1B[33m'#x1B[39;49;00m, #x1B[33m'#x1B[39;49;00m#x1B[33mCookie: ip-cookie=#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m#x1B[33msecond#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m#x1B[33m'#x1B[39;49;00m, #x1B[94mTrue#x1B[39;49;00m),#x1B[90m#x1B[39;49;00m
            (#x1B[33m"#x1B[39;49;00m#x1B[33mcustom-cookie=value/one;#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, #x1B[33m'#x1B[39;49;00m#x1B[33mCookie: custom-cookie=#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m#x1B[33mvalue/one#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m#x1B[33m'#x1B[39;49;00m, #x1B[94mTrue#x1B[39;49;00m),#x1B[90m#x1B[39;49;00m
            (#x1B[33m"#x1B[39;49;00m#x1B[33mcustom-cookie=value1;#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, #x1B[33m"#x1B[39;49;00m#x1B[33mCookie: custom-cookie=value1#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, #x1B[94mTrue#x1B[39;49;00m),#x1B[90m#x1B[39;49;00m
            (#x1B[33m"#x1B[39;49;00m#x1B[33mcustom-cookie=value/one;#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, #x1B[33m"#x1B[39;49;00m#x1B[33mCookie: custom-cookie=value/one#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, #x1B[94mFalse#x1B[39;49;00m),#x1B[90m#x1B[39;49;00m
            (#x1B[33m'#x1B[39;49;00m#x1B[33mfoo=#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m#x1B[33mquoted_value#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m#x1B[33m'#x1B[39;49;00m, #x1B[33m'#x1B[39;49;00m#x1B[33mCookie: foo=#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m#x1B[33mquoted_value#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m#x1B[33m'#x1B[39;49;00m, #x1B[94mTrue#x1B[39;49;00m),#x1B[90m#x1B[39;49;00m
            (#x1B[33m'#x1B[39;49;00m#x1B[33mfoo=#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m#x1B[33mquoted_value#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m#x1B[33m; domain=127.0.0.1#x1B[39;49;00m#x1B[33m'#x1B[39;49;00m, #x1B[33m'#x1B[39;49;00m#x1B[33mCookie: foo=#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m#x1B[33mquoted_value#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m#x1B[33m'#x1B[39;49;00m, #x1B[94mTrue#x1B[39;49;00m),#x1B[90m#x1B[39;49;00m
        ],#x1B[90m#x1B[39;49;00m
        ids=(#x1B[90m#x1B[39;49;00m
            #x1B[33m"#x1B[39;49;00m#x1B[33mIP domain preserved#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m,#x1B[90m#x1B[39;49;00m
            #x1B[33m"#x1B[39;49;00m#x1B[33mno shared cookie#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m,#x1B[90m#x1B[39;49;00m
            #x1B[33m"#x1B[39;49;00m#x1B[33mquoted cookie with special char#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m,#x1B[90m#x1B[39;49;00m
            #x1B[33m"#x1B[39;49;00m#x1B[33mquoted cookie w/o special char#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m,#x1B[90m#x1B[39;49;00m
            #x1B[33m"#x1B[39;49;00m#x1B[33munquoted cookie with special char#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m,#x1B[90m#x1B[39;49;00m
            #x1B[33m"#x1B[39;49;00m#x1B[33mpre-quoted cookie#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m,#x1B[90m#x1B[39;49;00m
            #x1B[33m"#x1B[39;49;00m#x1B[33mpre-quoted cookie with domain#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m,#x1B[90m#x1B[39;49;00m
        ),#x1B[90m#x1B[39;49;00m
    )#x1B[90m#x1B[39;49;00m
    #x1B[94masync#x1B[39;49;00m #x1B[94mdef#x1B[39;49;00m #x1B[92mtest_quotes_correctly_based_on_input#x1B[39;49;00m(#x1B[90m#x1B[39;49;00m
        loop: asyncio.AbstractEventLoop, cookies: #x1B[96mstr#x1B[39;49;00m, expected: #x1B[96mstr#x1B[39;49;00m, quote_bool: #x1B[96mbool#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
    ) -> #x1B[94mNone#x1B[39;49;00m:#x1B[90m#x1B[39;49;00m
        jar = CookieJar(unsafe=#x1B[94mTrue#x1B[39;49;00m, quote_cookie=quote_bool)#x1B[90m#x1B[39;49;00m
        jar.update_cookies(SimpleCookie(cookies))#x1B[90m#x1B[39;49;00m
        cookies_sent = jar.filter_cookies(URL(#x1B[33m"#x1B[39;49;00m#x1B[33mhttp://127.0.0.1/#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m)).output(header=#x1B[33m"#x1B[39;49;00m#x1B[33mCookie:#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m)#x1B[90m#x1B[39;49;00m
>       #x1B[94massert#x1B[39;49;00m cookies_sent == expected#x1B[90m#x1B[39;49;00m
#x1B[1m#x1B[31mE       assert 'Cookie: foo=quoted_value' == 'Cookie: foo="quoted_value"'#x1B[0m
#x1B[1m#x1B[31mE         #x1B[0m
#x1B[1m#x1B[31mE         - Cookie: foo="quoted_value"#x1B[0m
#x1B[1m#x1B[31mE         ?             -            -#x1B[0m
#x1B[1m#x1B[31mE         + Cookie: foo=quoted_value#x1B[0m

cookies    = 'foo="quoted_value"'
cookies_sent = 'Cookie: foo=quoted_value'
expected   = 'Cookie: foo="quoted_value"'
jar        = <aiohttp.cookiejar.CookieJar object at 0x107860c10>
loop       = <_UnixSelectorEventLoop running=False closed=False debug=False>
quote_bool = True

#x1B[1m#x1B[31mtests/test_cookiejar.py#x1B[0m:407: AssertionError

To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard

@Dreamsorcerer
Copy link
Member Author

I'm giving up on this one. I think at some point we should probably drop http.cookies, as it seems to give too many issues. We should also lose the interpretation of quoted cookies altogether as this concept doesn't exist in either latest or oldest cookie spec and was never adopted by browsers.

@Dreamsorcerer Dreamsorcerer deleted the fix-quoted-cookie branch September 9, 2024 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Client] Inconsistent quoted cookie handling
4 participants