Cookies that include a port flag set to 443 aren't stored if they came from an https location without the 443 port in the URI
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- python
- Ambito
- networking
Direzione di ricerca
Inizia con il riproduttore in tests/test_cookies.py ed esegui i test dei cookie parametrizzati per confermare il fallimento per https://localhost con port=443. Traccia il modo in cui la Session trasferisce i cookie della risposta nel proprio cookie jar, quindi fai passare il caso che fallisce senza introdurre regressioni nelle altre combinazioni di URL e porta.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
When performing a request to an https location that doesn't include a port explicitly (for example: https://localhost) and that location returns a cookie that includes a port flag set to 443, that cookie isn't stored into the cookie jar. However, this kind of cookie is stored into the cookie jar, when the port is set explicitly in the https location (for example: https://localhost:443).
Expected Result
A cookie that includes a port flag set to 443 should be stored into the cookie jar when the request is performed to an https location that doesn't include a port.
Reproduction Steps
I hope you don't mind that I've moved the Actual Result below this section. I did it because I've written a test-suite to reproduce the issue and the result of running that test-suite has been pasted in the Actual Result section.
import http
import pytest
import requests
from io import BytesIO
from urllib3.response import HTTPHeaderDict, HTTPResponse
class OriginalResponseShim:
def __init__(self, headers):
self.msg = headers
def isclosed(self):
return True
def close(self):
return
def make_http_response(
method,
url,
status=requests.codes.ok,
headers=None
):
http_headers = HTTPHeaderDict()
if headers is not None:
http_headers.extend(headers)
def _make_http_response(adapter, request, *args, **kwargs):
http_response = HTTPResponse(
status=status,
reason=http.client.responses.get(status, None),
body=BytesIO(b''),
headers=http_headers,
original_response=OriginalResponseShim(http_headers),
preload_content=False,
)
return adapter.build_response(request, http_response)
return _make_http_response
class TestCookies:
@pytest.mark.parametrize('url', [
'http://localhost',
'http://localhost:80',
'http://localhost:8080',
'https://localhost',
'https://localhost:443',
'https://localhost:8080',
])
def test_cookie_without_port(self, mocker, url):
mocker.patch(
'requests.adapters.HTTPAdapter.send',
new=make_http_response(
'GET',
url,
headers={
'set-cookie': 'cookie=value',
},
)
)
session = requests.Session()
resp = session.request('GET', url)
assert resp.status_code == requests.codes.ok
assert 'set-cookie' in resp.headers
assert 'cookie' in session.cookies
cookie = next(iter(session.cookies))
assert cookie.name == 'cookie'
assert cookie.value == 'value'
assert cookie.port is None
@pytest.mark.parametrize('url, port', [
('http://localhost', 80),
('http://localhost:80', 80),
('http://localhost:443', 443),
('http://localhost:8080', 8080),
('https://localhost', 443),
('https://localhost:80', 80),
('https://localhost:443', 443),
('https://localhost:8080', 8080),
])
def test_cookie_with_port(self, mocker, url, port):
mocker.patch(
'requests.adapters.HTTPAdapter.send',
new=make_http_response(
'GET',
url,
headers={
'set-cookie': f'cookie=value; port={port}',
},
)
)
session = requests.Session()
resp = session.request('GET', url)
assert resp.status_code == requests.codes.ok
assert 'set-cookie' in resp.headers
assert 'cookie' in session.cookies
cookie = next(iter(session.cookies))
assert cookie.name == 'cookie'
assert cookie.value == 'value'
assert cookie.port == f'{port}'
Actual Result
platform darwin -- Python 3.10.2, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /Users/fran/code/requests, configfile: pytest.ini
plugins: httpbin-1.0.0, mock-2.0.0, cov-3.0.0
collected 14 items
tests/test_cookies.py ..........F... [100%]
======================================== FAILURES ========================================
________________ TestCookies.test_cookie_with_port[https://localhost-443] ________________
self = <tests.test_cookies.TestCookies object at 0x10e309ff0>
mocker = <pytest_mock.plugin.MockFixture object at 0x10e30a290>, url = 'https://localhost'
port = 443
@pytest.mark.parametrize('url, port', [
('http://localhost', 80),
('http://localhost:80', 80),
('http://localhost:443', 443),
('http://localhost:8080', 8080),
('https://localhost', 443),
('https://localhost:80', 80),
('https://localhost:443', 443),
('https://localhost:8080', 8080),
])
def test_cookie_with_port(self, mocker, url, port):
mocker.patch(
'requests.adapters.HTTPAdapter.send',
new=make_http_response(
'GET',
url,
headers={
'set-cookie': f'cookie=value; port={port}',
},
)
)
session = requests.Session()
resp = session.request('GET', url)
assert resp.status_code == requests.codes.ok
assert 'set-cookie' in resp.headers
> assert 'cookie' in session.cookies
E AssertionError: assert 'cookie' in <RequestsCookieJar[]>
E + where <RequestsCookieJar[]> = <requests.sessions.Session object at 0x10e309b10>.cookies
tests/test_cookies.py:105: AssertionError
System Information
$ python -m requests.help
{
"chardet": {
"version": null
},
"charset_normalizer": {
"version": "2.0.12"
},
"cryptography": {
"version": ""
},
"idna": {
"version": "3.3"
},
"implementation": {
"name": "CPython",
"version": "3.10.2"
},
"platform": {
"release": "21.4.0",
"system": "Darwin"
},
"pyOpenSSL": {
"openssl_version": "",
"version": null
},
"requests": {
"version": "2.27.1"
},
"system_ssl": {
"version": "101010ef"
},
"urllib3": {
"version": "1.26.9"
},
"using_charset_normalizer": true,
"using_pyopenssl": false
}
- Lingua principale
- Python
- Stelle
- 54.7k
- Fork
- 10.8k
- Merge medio
- 18m
- PR unite (30g)
- 1
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di psf/requests
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
-
`iter_lines(decode_unicode=True, delimiter=<str>)` raises `TypeError` when `Response.encoding` is `None`Forse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
-
get_encoding_from_headers treats any content type containing 'text' as text/* (ISO-8859-1)Forse già presa @suyashgitt l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Invalid `params` type (e.g. int) raises misleading "TypeError: Cannot mix str and non-str arguments"Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Tutte le issue di psf/requests
Issue simili
-
add entry to blockAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
StevenBlack/hosts#3299 ·
-
`garak --report` overwrites the input report when its name has no ".report"Forse già presa @0z5a l’ha presa oggi. Apertaneeds-triage
Difficoltà 2/5 Mezza giornata Idoneità per principianti 72/100
I maintainer di solito rispondono entro 2 giorni
-
plot_graph crashes when a mesh node has no m2m edgeForse già presa @tygvi l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
mllam/neural-lam#883 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
future-agi/future-agi#4092 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
transcript analytics: a text whose only protected spans the prose pass redacts is withheld wholeAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
WingedGuardian/GENesis-AGI#4641 ·
I maintainer di solito rispondono entro 1 giorno