(self)
| 66 | assert cookie.has_nonstandard_attr('HttpOnly') is not None |
| 67 | |
| 68 | def test_complex_cookies(self) -> None: |
| 69 | cookies_jar = CookieJar() |
| 70 | |
| 71 | url = get_httpbin_url( |
| 72 | '/response-headers', |
| 73 | query={ |
| 74 | 'set-cookie': [ |
| 75 | 'basic=1; Path=/; HttpOnly; SameSite=Lax', |
| 76 | 'withpath=2; Path=/html; SameSite=None', |
| 77 | 'strict=3; Path=/; SameSite=Strict', |
| 78 | 'secure=4; Path=/; HttpOnly; Secure; SameSite=Strict', |
| 79 | 'short=5; Path=/;', |
| 80 | 'domain=6; Path=/; Domain=.127.0.0.1;', |
| 81 | ] |
| 82 | }, |
| 83 | ) |
| 84 | |
| 85 | impit.get(url, cookie_jar=cookies_jar, follow_redirects=True) |
| 86 | |
| 87 | assert len(cookies_jar) == 6 |
| 88 | for cookie in cookies_jar: |
| 89 | if cookie.name == 'basic': |
| 90 | assert cookie.value == '1' |
| 91 | assert cookie.secure is False |
| 92 | assert cookie.has_nonstandard_attr('HttpOnly') is True |
| 93 | assert cookie.get_nonstandard_attr('SameSite') == 'Lax' |
| 94 | elif cookie.name == 'withpath': |
| 95 | assert cookie.value == '2' |
| 96 | assert cookie.secure is False |
| 97 | assert cookie.get_nonstandard_attr('SameSite') == 'None' |
| 98 | assert cookie.has_nonstandard_attr('HttpOnly') is False |
| 99 | assert cookie.path == '/html' |
| 100 | elif cookie.name == 'strict': |
| 101 | assert cookie.value == '3' |
| 102 | assert cookie.secure is False |
| 103 | assert cookie.has_nonstandard_attr('HttpOnly') is False |
| 104 | assert cookie.get_nonstandard_attr('SameSite') == 'Strict' |
| 105 | elif cookie.name == 'secure': |
| 106 | assert cookie.value == '4' |
| 107 | assert cookie.secure is True |
| 108 | assert cookie.has_nonstandard_attr('HttpOnly') is True |
| 109 | assert cookie.get_nonstandard_attr('SameSite') == 'Strict' |
| 110 | elif cookie.name == 'short': |
| 111 | assert cookie.value == '5' |
| 112 | assert cookie.secure is False |
| 113 | assert cookie.has_nonstandard_attr('SameSite') is False |
| 114 | elif cookie.name == 'domain': |
| 115 | assert cookie.value == '6' |
| 116 | assert cookie.secure is False |
| 117 | # Crate cookies, ignores the starting dot in the domain |
| 118 | # but it's ok - https://www.rfc-editor.org/rfc/rfc6265#section-4.1.2.3 |
| 119 | assert cookie.domain == '127.0.0.1' |
| 120 | |
| 121 | def test_cookie_jar_works(self) -> None: |
| 122 | cookies = Cookies({'preset-cookie': '123'}) |
nothing calls this directly
no test coverage detected