diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2025-02-02 10:11:17 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2025-02-02 10:21:23 +0300 |
commit | 637f8bbf610e99859dfbdbde49d99e9c60a7acf7 (patch) | |
tree | 3e685433e89f53a34ca2a4635c29865598d12b4f /contrib/python/pytest-localserver/py3/tests | |
parent | bbd3eacdd0520f608b6290efdd0050d7e55ad40d (diff) | |
download | ydb-637f8bbf610e99859dfbdbde49d99e9c60a7acf7.tar.gz |
Intermediate changes
commit_hash:20c3eb2f2d78b5f654ec928c071692413a1bd96d
Diffstat (limited to 'contrib/python/pytest-localserver/py3/tests')
-rw-r--r-- | contrib/python/pytest-localserver/py3/tests/test_http.py | 36 | ||||
-rw-r--r-- | contrib/python/pytest-localserver/py3/tests/test_https.py | 14 |
2 files changed, 46 insertions, 4 deletions
diff --git a/contrib/python/pytest-localserver/py3/tests/test_http.py b/contrib/python/pytest-localserver/py3/tests/test_http.py index 64859ffd25..904e6aea5e 100644 --- a/contrib/python/pytest-localserver/py3/tests/test_http.py +++ b/contrib/python/pytest-localserver/py3/tests/test_http.py @@ -5,6 +5,7 @@ import textwrap import pytest import requests +from werkzeug.exceptions import ClientDisconnected from pytest_localserver import http from pytest_localserver import plugin @@ -90,6 +91,29 @@ def test_HEAD_request(httpserver): # assert resp.status_code == 200 +def test_POST_request_no_store_data(httpserver): + headers = {"Content-type": "text/plain"} + httpserver.serve_content("TEST!", store_request_data=False) + requests.post(httpserver.url, data=b"testdata", headers=headers) + + request = httpserver.requests[-1] + request.input_stream.close() + + with pytest.raises(ClientDisconnected): + request.data + + +def test_POST_request_store_data(httpserver): + headers = {"Content-type": "text/plain"} + httpserver.serve_content("TEST!", store_request_data=True) + requests.post(httpserver.url, data=b"testdata", headers=headers) + + request = httpserver.requests[-1] + request.input_stream.close() + + assert httpserver.requests[-1].data == b"testdata" + + @pytest.mark.parametrize("chunked_flag", [http.Chunked.YES, http.Chunked.AUTO, http.Chunked.NO]) def test_chunked_attribute_without_header(httpserver, chunked_flag): """ @@ -224,7 +248,7 @@ def _compare_chunks(expected, actual): __tracebackhide__ = True if expected != actual: message = [_format_chunk(expected) + " != " + _format_chunk(actual)] - if type(expected) == type(actual): + if type(expected) is type(actual): for i, (e, a) in enumerate(itertools.zip_longest(expected, actual, fillvalue="<end>")): if e != a: message += [ @@ -274,19 +298,23 @@ def test_GET_request_chunked_no_content_length(httpserver, chunked_flag): def test_httpserver_init_failure_no_stderr_during_cleanup(tmp_path): """ Test that, when the server encounters an error during __init__, its cleanup - does not raise an AttributeError in its __del__ method, which would emit a + does not raise an AttributeError in its __del__ method, which would emit a warning onto stderr. """ script_path = tmp_path.joinpath("script.py") - script_path.write_text(textwrap.dedent(""" + script_path.write_text( + textwrap.dedent( + """ from pytest_localserver import http from unittest.mock import patch with patch("pytest_localserver.http.make_server", side_effect=RuntimeError("init failure")): server = http.ContentServer() - """)) + """ + ) + ) result = subprocess.run([sys.executable, str(script_path)], stderr=subprocess.PIPE) diff --git a/contrib/python/pytest-localserver/py3/tests/test_https.py b/contrib/python/pytest-localserver/py3/tests/test_https.py index 4c676d1753..d66450b5bb 100644 --- a/contrib/python/pytest-localserver/py3/tests/test_https.py +++ b/contrib/python/pytest-localserver/py3/tests/test_https.py @@ -1,3 +1,4 @@ +import pytest import requests from pytest_localserver import https @@ -41,3 +42,16 @@ def test_HEAD_request(httpsserver): resp = requests.head(httpsserver.url, verify=False) assert resp.status_code == 200 assert resp.headers["Content-type"] == "text/plain" + + +def test_client_does_not_trust_self_signed_certificate(httpsserver): + httpsserver.serve_content("TEST!", headers={"Content-type": "text/plain"}) + with pytest.raises(requests.exceptions.SSLError, match="CERTIFICATE_VERIFY_FAILED"): + requests.get(httpsserver.url, verify=True) + + +def test_add_server_certificate_to_client_trust_chain(httpsserver): + httpsserver.serve_content("TEST!", headers={"Content-type": "text/plain"}) + resp = requests.get(httpsserver.url, verify=httpsserver.certificate) + assert resp.status_code == 200 + assert resp.headers["Content-type"] == "text/plain" |