404 Commits

Author SHA1 Message Date
flysee 13d892bdbe Additional should_bypass_proxies function test cases 2024-03-18 22:33:17 +08:00
Ian Stapleton Cordasco a94e9b5308 Add local TLS server
This also adds certificates for testing purposes and files to make it
easy to generate/regenerate them.

This also replaces an existing test of how we utilize our pool manager
such that we don't connect to badssl.com

Finally, this adds additional context parameters for our pool manager to
account for mTLS certificates used by clients to authenticate to a
server.
2024-03-14 06:06:22 -05:00
Ian Stapleton Cordasco c0813a2d91 Use TLS settings in selecting connection pool
Previously, if someone made a request with `verify=False` then made a
request where they expected verification to be enabled to the same host,
they would potentially reuse a connection where TLS had not been
verified.

This fixes that issue.
2024-03-06 11:28:13 -06:00
Ian Stapleton Cordasco b8be93a721 Merge pull request #6589 from bruceadams/super_len_str_utf-8
Enhance `super_len` to count encoded bytes for str
2024-02-22 18:53:25 -06:00
Ian Stapleton Cordasco 3587a5f869 Merge pull request #6644 from sigmavirus24/bug/6643
Trim excess leading path separators
2024-02-22 18:49:42 -06:00
Ian Stapleton Cordasco 60389df6d6 Trim excess leading path separators
A URL with excess leading / (path-separator)s would cause urllib3 to
attempt to reparse the request-uri as a full URI with a host and port.
This bypasses that logic in ConnectionPool.urlopen by replacing these
leading /s with just a single /.

Closes #6643
2024-02-22 18:36:44 -06:00
Thomas Dehghani 3ff3ff21dd Fix #6628 - JSONDecodeError are not deserializable
requests.exceptions.JSONDecodeError are not deserializable: calling
`pickle.dumps` followed by `pickle.loads` will trigger an error.

This is particularly a problem in a process pool, as an attempt to
decode json on an invalid json document will result in the entire
process pool crashing.

This is due to the MRO of the `requests.exceptions.JSONDecodeError`
class: the `__reduce__` method called when pickling an instance is not
the one from the JSON library parent: two out of three args expected
for instantiation will be dropped, and the instance can't be
deserialised.

By specifying in the class which parent `__reduce__` method should be
called, the bug is fixed as all args are carried over in the resulting
pickled bytes.
2024-01-31 17:13:53 +01:00
Ata Tuzuner ec84f2c539 Fixes to test 2023-11-29 12:27:18 -05:00
Ata Tuzuner 889910c77a Added tests for status code 425 definitions. 2023-11-29 12:24:15 -05:00
Bruce Adams f6707042d8 Unit test for string containing multi-byte UTF-8
There are two tests here. One demonstrating existing, correct
behavior for `data=bytes`, and another, failing, test for the case
where `data=string` and the string contains multi-byte UTF-8.
2023-11-27 17:27:43 -05:00
sumedhrao7 a8e9c1b436 added assert statements into tests/test_requests/test_header_validation in regards to the issue #6551 2023-10-18 07:40:50 +05:30
Nate Prewitt 005571d118 Remove pytest-mock requirement (#6505) 2023-08-13 16:08:21 -07:00
Nate Prewitt 8112fcc7be Pre commit update (#6498) 2023-08-12 12:03:10 -07:00
Nate Prewitt 6e5b15d542 Fix linting issues 2023-05-22 09:36:22 -06:00
Nate Prewitt 74ea7cf7a6 Merge pull request from GHSA-j8r2-6x86-q33q 2023-05-22 09:08:57 -06:00
Seth Michael Larson 7f694b79e1 Allow str/bytes subclasses to be used as header parts 2023-03-03 14:39:02 -06:00
Quentin Pradet 15585909c3 Support missing SNIMissingWarning in tests (#6336) 2023-01-21 01:44:33 -07:00
Nate Prewitt e36f34597c Add valdation for header name (#6154) 2022-06-08 12:03:56 -06:00
Olivier Gayot 3af2f456d8 Fix output of test_lowlevel tests in case of timeout (#6136)
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-06-08 10:02:42 -06:00
Nate Prewitt 210095fd08 Tolerate bad registry entries in Windows proxy settings (#6149) 2022-06-01 11:36:26 -06:00
Mickaël Schoentgen cb233a101d Fix several ResourceWarnings in test_requests.py (#4766) 2022-05-10 19:04:17 -06:00
Nate Prewitt 2a6f290bc0 Add automatic code formatting to Requests (#6095) 2022-04-29 13:16:58 -06:00
Nate Prewitt 2d5517682b Fix inconsistent exception for JSONDecode error (#6097)
When calling .json() it was possible to raise a
requests.exceptions.JSONDecodeError or ValueError
depending on whether the encoding is set.
2022-03-28 12:51:27 -06:00
Nate Prewitt 8bce583b95 Farewell, sweet Concorde!
Formally removing any remaining vestiges of Python 2 from Requests.
We'll also leave behind Python 3.6 while we're at it.
2022-03-25 10:50:33 -06:00
Nate Prewitt 79c4a017fe Fix environment CA Bundle resolution 2022-02-25 11:25:20 -07:00
Nate Prewitt 95f4567336 Wrap urllib3's SSLError as requests' SSLError (#6057) 2022-02-05 11:56:05 -07:00
chyzzqo2 fa1b0a367a Initialize JsonDecodeError before initializing IOError (#6036)
That way we get the formated error message

Co-authored-by: Peter <cHYzZQo@netflix.com>
2022-01-13 08:42:49 -07:00
Nate Prewitt 38f3f8ecb9 Fix auth parsing for proxies
Co-authored-by: adamp01 <@adamp01>
2022-01-04 08:27:23 -07:00
Ian Stapleton Cordasco 28d537dde3 Merge pull request #5917 from nateprewitt/proxy_scheme_unknown_fix
Move from urlparse to parse_url for prepending schemes
2021-12-29 07:31:40 -06:00
Nate Prewitt ef59aa0227 Move from urlparse to parse_url for prepending schemes 2021-12-28 21:12:00 -07:00
Álvaro Mondéjar 658c10e84a Raise InvalidURL if hosts starts with '.' as was reported at #5367. 2021-12-28 14:24:24 -07:00
Nate Prewitt 7556ea4213 Merge pull request #5391 from hodbn/fix-5274
Send only one Host header in chunked request
2021-11-29 07:58:31 -08:00
David Hotham 2d2447e210 Catch AttributeError in utils.super_len (#5239)
* Catch AttributeError in utils.super_len

This allows it to handle files obtained via `Tarfile.extractfile()`.
2021-11-28 12:04:49 -08:00
Michał Górny 55da533a87 Defer the trustme import until inside the fixture
Move the trustme import from global scope into the nosan_server fixture
in order to make it possible to deselect the test via command-line
when trustme is not available.
2021-11-27 18:47:56 +01:00
Nate Prewitt 99b3b49241 Refactor rebuild_proxies to allow proxy resolution (#5924)
without stripping Proxy-Authorization header
2021-11-24 13:21:01 -06:00
Nate Prewitt 4ab2550d66 Add test for default chunked Host header 2021-09-02 01:53:34 -07:00
hodbn 6fbfca90b6 Send only one Host header in chunked request
Closes #5274
2021-09-02 00:53:08 -07:00
Nate Prewitt 10968357a1 Appropriately handle urllib3's InvalidHeader exception (#5914) 2021-08-26 20:11:30 -05:00
Ben Li-Sauerwine 2d30aeb7c6 Add a test which verifies that ChunkedEncodingError is emitted if an invalid Transfer-Encoding: chunked response is returned. (#5906) 2021-08-24 19:00:17 -07:00
Thomas Lam d8829f9f24 Fix extract_zipped_paths infinite loop when provided invalid unc path (#5851) 2021-08-02 19:40:34 -05:00
Michał Górny b227e3cb82 Fix creating non-listening sockets in tests on some platforms (#5890)
Fix the listen() invocation for the test server not to pass a backlog
value of zero.  The value of zero means no backlog which effectively
means that the socket can not accept any connections.  This does not
matter for the majority of platforms since the value is only advisory
and the platform tends to go with a bigger backlog anyway.  However,
a few platforms (e.g. alpha or riscv Linux) do take the value literally,
and therefore the tests fail since they are unable to connect to
the server.
2021-07-28 11:23:08 -05:00
Steve Berdy db575eeedc Fix inconsistent exception type in response.json() method (#5856) 2021-07-26 08:56:44 -07:00
Quentin Pradet e253eba5ed Stop abusing pytest-httpbin to test commonName support
pytest-httpbin<1.0 ships with a server certificate with a commonName but
no subjectAltName. urllib3 2.0 will stop supporting those in the future,
so we want to upgrade pytest-httpbin.

Unfortunately, `test_https_warnings` was relying on this broken
certificate. With this change, we use `trustme` to create a broken
certificate specifically for this test, so that we can upgrade
pytest-httpbin and make sure that other tests relying on httpbin TLS
support will continue to work with urllib3 2.0.
2021-07-12 09:44:43 -05:00
tallalnparis4ev 05a1a21593 Throw value error when serializing JSON object with NaN value (#5810)
* disallow nan values in json serialize

* test nan value in json post

* added exception for invalid json in request

* use invalid json exception

* invalid json test
2021-05-06 13:18:58 -05:00
Mateus Dubiela Oliveira 60ea7f0c2d #5677: Rebuild proxies on Session#send 2020-12-08 18:37:18 +01:00
Nate Prewitt 320a10d142 Remove Pipfile/Pipfile.lock 2020-11-11 10:29:13 -08:00
Miro Hrončok 427e8eb1e7 Fix test_conflicting_post_params to work on pytest 5 (#5305)
The non-contextmanager form of pytest.raises was removed in pytest 5.
http://doc.pytest.org/en/latest/deprecations.html#raises-warns-with-a-string-as-the-second-argument

It was used here to support Python < 2.7, but that is no longer needed.
https://github.com/psf/requests/pull/1503#issuecomment-22333666

Fixes https://github.com/psf/requests/issues/5304
2020-05-08 21:58:03 -07:00
Nate Prewitt fd13816d01 Revert "Fix for response with UTF-8 BOM #4976"
This reverts commit 19cff44ec1.
This reverts commit 9e27326d68.
This reverts commit f507a3ef12.
2020-02-18 18:56:39 -06:00
Nate Prewitt b15056d1d3 Revert "#4965 fix: Accessing response.content twice removes forgets read error."
This reverts commit bd10047244.

This reverts commit d91fe00983.
2020-02-18 18:56:39 -06:00
johnthagen 9b95b4e7b4 Add PyPy3 to Travis test suite (#5193) 2020-01-21 11:00:51 -06:00