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/pytest_localserver | |
parent | bbd3eacdd0520f608b6290efdd0050d7e55ad40d (diff) | |
download | ydb-637f8bbf610e99859dfbdbde49d99e9c60a7acf7.tar.gz |
Intermediate changes
commit_hash:20c3eb2f2d78b5f654ec928c071692413a1bd96d
Diffstat (limited to 'contrib/python/pytest-localserver/py3/pytest_localserver')
-rw-r--r-- | contrib/python/pytest-localserver/py3/pytest_localserver/_version.py | 4 | ||||
-rw-r--r-- | contrib/python/pytest-localserver/py3/pytest_localserver/cert.crt | 32 | ||||
-rw-r--r-- | contrib/python/pytest-localserver/py3/pytest_localserver/http.py | 12 | ||||
-rw-r--r-- | contrib/python/pytest-localserver/py3/pytest_localserver/https.py | 25 | ||||
-rw-r--r-- | contrib/python/pytest-localserver/py3/pytest_localserver/plugin.py | 4 | ||||
-rw-r--r-- | contrib/python/pytest-localserver/py3/pytest_localserver/server.key (renamed from contrib/python/pytest-localserver/py3/pytest_localserver/server.pem) | 32 | ||||
-rw-r--r-- | contrib/python/pytest-localserver/py3/pytest_localserver/smtp.py | 12 |
7 files changed, 67 insertions, 54 deletions
diff --git a/contrib/python/pytest-localserver/py3/pytest_localserver/_version.py b/contrib/python/pytest-localserver/py3/pytest_localserver/_version.py index 044524b166..372502bdbf 100644 --- a/contrib/python/pytest-localserver/py3/pytest_localserver/_version.py +++ b/contrib/python/pytest-localserver/py3/pytest_localserver/_version.py @@ -12,5 +12,5 @@ __version__: str __version_tuple__: VERSION_TUPLE version_tuple: VERSION_TUPLE -__version__ = version = '0.8.1' -__version_tuple__ = version_tuple = (0, 8, 1) +__version__ = version = '0.9.0.post0' +__version_tuple__ = version_tuple = (0, 9, 0) diff --git a/contrib/python/pytest-localserver/py3/pytest_localserver/cert.crt b/contrib/python/pytest-localserver/py3/pytest_localserver/cert.crt new file mode 100644 index 0000000000..94f804c513 --- /dev/null +++ b/contrib/python/pytest-localserver/py3/pytest_localserver/cert.crt @@ -0,0 +1,32 @@ +-----BEGIN CERTIFICATE----- +MIIFjzCCA3egAwIBAgIUPaO7CEh5PBQ5WVK10+B+NgkyBv0wDQYJKoZIhvcNAQEL +BQAwSTESMBAGA1UEAwwJMTI3LjAuMC4xMRswGQYDVQQKDBJweXRlc3QtbG9jYWxz +ZXJ2ZXIxFjAUBgNVBAsMDVRlc3RpbmcgRGVwdC4wHhcNMjQwMjIwMTQzNTIxWhcN +MzQwMjE3MTQzNTIxWjBJMRIwEAYDVQQDDAkxMjcuMC4wLjExGzAZBgNVBAoMEnB5 +dGVzdC1sb2NhbHNlcnZlcjEWMBQGA1UECwwNVGVzdGluZyBEZXB0LjCCAiIwDQYJ +KoZIhvcNAQEBBQADggIPADCCAgoCggIBALfVGVEMw3p4alDNlqq2CTv9zmH3w+g8 +1GkUWhS65YZ1/k+Ue/h8zKbtmbPaWPHUOq60qEghQqpLW+HF3nMwWmF45RNU9V9B +zl6+BMibUYXSsxJJpBIU9U5fec1caYXX8mr1hZNz+tvaez+z4inXNIoGoOx1FuuS ++lJrtzIKTFhy5i1ijmNFr3fQVufhw2P5oDd3EZd3hsst+dEGlEDRXlLMG/3cy04r +2SeBDBCGMEkL8v9pwc87l3NAhIGEz01NIIAfjObRKVOITEoOEF0TFJt2MCOcneTz +aE0UtSpjUkCbjJWW/APe81jiGR/+BbO5B4kiHMryQTgD50PwFnN0eugr3GeemZKV +Lv8/StpB3dVk9zyzAQPLD0yt0DlRT3lvTuxRWzQszS9aGL6vA0Akd+JDvu3BzRs/ +ueLLL8qD5Rh/ubSL+fK8kUqrvmsc59m+aw82z6A50l9/7LLi+/2mYiaPae6WA6Cs +avNzggKfHcamgqYYUOr+n6GqT30/3Z0UebB3t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/python/pytest-localserver/py3/pytest_localserver/http.py b/contrib/python/pytest-localserver/py3/pytest_localserver/http.py index 0899597f5e..a4c3bef223 100644 --- a/contrib/python/pytest-localserver/py3/pytest_localserver/http.py +++ b/contrib/python/pytest-localserver/py3/pytest_localserver/http.py @@ -15,7 +15,6 @@ from werkzeug.wrappers import Response class WSGIServer(threading.Thread): - """ HTTP server running a WSGI application in its own thread. """ @@ -61,7 +60,6 @@ def _encode_chunk(chunk, charset): class ContentServer(WSGIServer): - """ Small test server which can be taught which content (i.e. string) to serve with which response code. Try the following snippet for testing API calls:: @@ -89,12 +87,18 @@ class ContentServer(WSGIServer): self.compress = None self.requests = [] self.chunked = Chunked.NO + self.store_request_data = False def __call__(self, environ, start_response): """ This is the WSGI application. """ request = Request(environ) + + if self.store_request_data: + # need to invoke this method to cache the data + request.get_data(cache=True) + self.requests.append(request) if ( request.content_type == "application/x-www-form-urlencoded" @@ -129,7 +133,7 @@ class ContentServer(WSGIServer): return response(environ, start_response) - def serve_content(self, content, code=200, headers=None, chunked=Chunked.NO): + def serve_content(self, content, code=200, headers=None, chunked=Chunked.NO, store_request_data=True): """ Serves string content (with specified HTTP error code) as response to all subsequent request. @@ -138,6 +142,7 @@ class ContentServer(WSGIServer): :param code: HTTP status code :param headers: HTTP headers to be returned :param chunked: whether to apply chunked transfer encoding to the content + :param store_request_data: whether to store data sent as request payload. """ if not isinstance(content, (str, bytes, list, tuple)): # If content is an iterable which is not known to be a string, @@ -153,6 +158,7 @@ class ContentServer(WSGIServer): self.content = content self.code = code self.chunked = chunked + self.store_request_data = store_request_data if headers: self.headers = Headers(headers) diff --git a/contrib/python/pytest-localserver/py3/pytest_localserver/https.py b/contrib/python/pytest-localserver/py3/pytest_localserver/https.py index 856e222ac5..7339211497 100644 --- a/contrib/python/pytest-localserver/py3/pytest_localserver/https.py +++ b/contrib/python/pytest-localserver/py3/pytest_localserver/https.py @@ -6,12 +6,13 @@ import os.path from pytest_localserver.http import ContentServer -#: default server certificate -DEFAULT_CERTIFICATE = os.path.join(os.getcwd(), "server.pem") +# default key and certificate +_ROOT = os.getcwd() +DEFAULT_KEY = os.path.join(_ROOT, "server.key") +DEFAULT_CERTIFICATE = os.path.join(_ROOT, "cert.crt") class SecureContentServer(ContentServer): - """ Small test server which works just like :class:`http.Server` over HTTP:: @@ -111,13 +112,27 @@ class SecureContentServer(ContentServer): .. _pyOpenSSH: https://launchpad.net/pyopenssl """ - def __init__(self, host="localhost", port=0, key=DEFAULT_CERTIFICATE, cert=DEFAULT_CERTIFICATE): + def __init__(self, host="localhost", port=0, key=DEFAULT_KEY, cert=DEFAULT_CERTIFICATE): """ :param key: location of file containing the server private key. :param cert: location of file containing server certificate. """ - super().__init__(host, port, ssl_context=(key, cert)) + super().__init__(host, port, ssl_context=(cert, key)) + self._cert = cert + + @property + def certificate(self): + """ + Returns the path to the server's SSL/TLS certificate file. + Clients can use this path to access and verify the server's identity by + incorporating the certificate. + + .. note:: + Do not rely on having a stable filesystem path for the returned + certificate path across different versions or test runs. + """ + return self._cert if __name__ == "__main__": # pragma: no cover diff --git a/contrib/python/pytest-localserver/py3/pytest_localserver/plugin.py b/contrib/python/pytest-localserver/py3/pytest_localserver/plugin.py index 1e6ad2f172..501245eccd 100644 --- a/contrib/python/pytest-localserver/py3/pytest_localserver/plugin.py +++ b/contrib/python/pytest-localserver/py3/pytest_localserver/plugin.py @@ -64,8 +64,10 @@ def httpsserver(request): """ from pytest_localserver import https try: + with open(https.DEFAULT_KEY, 'wb') as f: + f.write(pkgutil.get_data('pytest_localserver', 'server.key')) with open(https.DEFAULT_CERTIFICATE, 'wb') as f: - f.write(pkgutil.get_data('pytest_localserver', 'server.pem')) + f.write(pkgutil.get_data('pytest_localserver', 'cert.crt')) server = https.SecureContentServer() server.start() request.addfinalizer(server.stop) diff --git a/contrib/python/pytest-localserver/py3/pytest_localserver/server.pem b/contrib/python/pytest-localserver/py3/pytest_localserver/server.key index 4f7f1ed322..31a498ede0 100644 --- a/contrib/python/pytest-localserver/py3/pytest_localserver/server.pem +++ b/contrib/python/pytest-localserver/py3/pytest_localserver/server.key @@ -50,35 +50,3 @@ lIqpHR4fwrBr4SLStzvBo9UK1YYQ94FyKd7xou3uXLLTlY3G8rD6jjKJE2Gg8Ga/ gGzbRCZWH6AOk1iO/CmOPH6AdFn5axXTx+uAML1Lr2VQ+azrYZCtIhKmW/kuQPQg apeiobcSY1vsX7eM8mQkM8TxrDLyNjtl -----END PRIVATE KEY----- ------BEGIN CERTIFICATE----- -MIIFiTCCA3GgAwIBAgIUUpWEFJm0PzrYTkhLe05yIBhBMuowDQYJKoZIhvcNAQEL -BQAwSTESMBAGA1UEAwwJMTI3LjAuMC4xMRswGQYDVQQKDBJweXRlc3QtbG9jYWxz -ZXJ2ZXIxFjAUBgNVBAsMDVRlc3RpbmcgRGVwdC4wHhcNMjEwOTE0MDU1NzAxWhcN -MzEwOTEyMDU1NzAxWjBJMRIwEAYDVQQDDAkxMjcuMC4wLjExGzAZBgNVBAoMEnB5 -dGVzdC1sb2NhbHNlcnZlcjEWMBQGA1UECwwNVGVzdGluZyBEZXB0LjCCAiIwDQYJ -KoZIhvcNAQEBBQADggIPADCCAgoCggIBALfVGVEMw3p4alDNlqq2CTv9zmH3w+g8 -1GkUWhS65YZ1/k+Ue/h8zKbtmbPaWPHUOq60qEghQqpLW+HF3nMwWmF45RNU9V9B -zl6+BMibUYXSsxJJpBIU9U5fec1caYXX8mr1hZNz+tvaez+z4inXNIoGoOx1FuuS -+lJrtzIKTFhy5i1ijmNFr3fQVufhw2P5oDd3EZd3hsst+dEGlEDRXlLMG/3cy04r -2SeBDBCGMEkL8v9pwc87l3NAhIGEz01NIIAfjObRKVOITEoOEF0TFJt2MCOcneTz -aE0UtSpjUkCbjJWW/APe81jiGR/+BbO5B4kiHMryQTgD50PwFnN0eugr3GeemZKV -Lv8/StpB3dVk9zyzAQPLD0yt0DlRT3lvTuxRWzQszS9aGL6vA0Akd+JDvu3BzRs/ -ueLLL8qD5Rh/ub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hjJLgi2AQsqeA6nDrCLtr2pWdqDWoUfxY8r -r5rc71nFLay/H2CbOYELI+20VFMp8GF3kOZbkRA= ------END CERTIFICATE----- diff --git a/contrib/python/pytest-localserver/py3/pytest_localserver/smtp.py b/contrib/python/pytest-localserver/py3/pytest_localserver/smtp.py index 82dbc394b9..0b285eb10a 100644 --- a/contrib/python/pytest-localserver/py3/pytest_localserver/smtp.py +++ b/contrib/python/pytest-localserver/py3/pytest_localserver/smtp.py @@ -31,7 +31,6 @@ class Handler: class Server(aiosmtpd.controller.Controller): - """ Small SMTP test server. @@ -96,16 +95,7 @@ class Server(aiosmtpd.controller.Controller): @property def accepting(self): - try: - return self.server.is_serving() - except AttributeError: - # asyncio.base_events.Server.is_serving() only exists in Python 3.6 - # and up. For Python 3.5, asyncio.base_events.BaseEventLoop.is_running() - # is a close approximation; it should mostly return the same value - # except for brief periods when the server is starting up or shutting - # down. Once we drop support for Python 3.5, this branch becomes - # unnecessary. - return self.loop.is_running() + return self.server.is_serving() # for aiosmtpd <1.4 if not hasattr(aiosmtpd.controller.Controller, "_trigger_server"): |