Skip to content

Commit

Permalink
Fix warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanaasagi committed Oct 6, 2021
1 parent e1774fd commit 6dbdf64
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 16 deletions.
4 changes: 3 additions & 1 deletion aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,9 +876,11 @@ def _make_ssl_context(verified: bool) -> SSLContext:
if verified:
return ssl.create_default_context()
else:
sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
sslcontext = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
sslcontext.options |= ssl.OP_NO_SSLv2
sslcontext.options |= ssl.OP_NO_SSLv3
sslcontext.check_hostname = False
sslcontext.verify_mode = ssl.CERT_NONE
try:
sslcontext.options |= ssl.OP_NO_COMPRESSION
except AttributeError as attr_err:
Expand Down
6 changes: 4 additions & 2 deletions aiohttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,10 @@ def get_app(self) -> Application:
raise RuntimeError("Did you forget to define get_application()?")

def setUp(self) -> None:
if PY_38:
self.loop = asyncio.get_event_loop()
try:
self.loop = asyncio.get_running_loop()
except RuntimeError:
self.loop = asyncio.get_event_loop_policy().get_event_loop()

self.loop.run_until_complete(self.setUpAsync())

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def tls_certificate(tls_certificate_authority: Any) -> Any:

@pytest.fixture
def ssl_ctx(tls_certificate: Any) -> ssl.SSLContext:
ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
tls_certificate.configure_cert(ssl_ctx)
return ssl_ctx

Expand Down
2 changes: 1 addition & 1 deletion tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -2348,7 +2348,7 @@ def create(url: URL, srv: Any):
cert = tls_certificate_authority.issue_cert(
url.host, "localhost", "127.0.0.1"
)
ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
cert.configure_cert(ssl_ctx)
kwargs["ssl"] = ssl_ctx
return aiohttp_server(app, **kwargs)
Expand Down
14 changes: 9 additions & 5 deletions tests/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ async def go(app):

def create_mocked_conn(conn_closing_result: Optional[Any] = None, **kwargs: Any):
assert "loop" not in kwargs
loop = asyncio.get_event_loop()
try:
loop = asyncio.get_running_loop()
except RuntimeError:
loop = asyncio.get_event_loop_policy().get_event_loop()

proto = mock.Mock(**kwargs)
proto.closed = loop.create_future()
proto.closed.set_result(conn_closing_result)
Expand Down Expand Up @@ -1267,7 +1271,7 @@ async def test___get_ssl_context1(loop: Any) -> None:


async def test___get_ssl_context2(loop: Any) -> None:
ctx = ssl.SSLContext()
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
conn = aiohttp.TCPConnector()
req = mock.Mock()
req.is_ssl.return_value = True
Expand All @@ -1276,7 +1280,7 @@ async def test___get_ssl_context2(loop: Any) -> None:


async def test___get_ssl_context3(loop: Any) -> None:
ctx = ssl.SSLContext()
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
conn = aiohttp.TCPConnector(ssl=ctx)
req = mock.Mock()
req.is_ssl.return_value = True
Expand All @@ -1285,7 +1289,7 @@ async def test___get_ssl_context3(loop: Any) -> None:


async def test___get_ssl_context4(loop: Any) -> None:
ctx = ssl.SSLContext()
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
conn = aiohttp.TCPConnector(ssl=ctx)
req = mock.Mock()
req.is_ssl.return_value = True
Expand All @@ -1294,7 +1298,7 @@ async def test___get_ssl_context4(loop: Any) -> None:


async def test___get_ssl_context5(loop: Any) -> None:
ctx = ssl.SSLContext()
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
conn = aiohttp.TCPConnector(ssl=ctx)
req = mock.Mock()
req.is_ssl.return_value = True
Expand Down
6 changes: 3 additions & 3 deletions tests/test_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ async def test_on_startup_hook(self) -> None:
self.assertTrue(self.on_startup_called)

def test_default_loop(self) -> None:
self.assertIs(self.loop, asyncio.get_event_loop())
self.assertIs(self.loop, asyncio.get_event_loop_policy().get_event_loop())


def test_default_loop(loop: Any) -> None:
assert asyncio.get_event_loop() is loop
assert asyncio.get_event_loop_policy().get_event_loop() is loop


@pytest.mark.xfail(not PY_38, reason="ThreadedChildWatcher is only available in 3.8+")
Expand All @@ -53,7 +53,7 @@ def test_setup_loop_non_main_thread() -> None:
def target() -> None:
try:
with loop_context() as loop:
assert asyncio.get_event_loop() is loop
assert asyncio.get_event_loop_policy().get_event_loop() is loop
loop.run_until_complete(test_subprocess_co(loop))
except Exception as exc:
nonlocal child_exc
Expand Down
6 changes: 3 additions & 3 deletions tests/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def test__create_ssl_context_without_certs_and_ciphers(
worker,
tls_certificate_pem_path,
) -> None:
worker.cfg.ssl_version = ssl.PROTOCOL_SSLv23
worker.cfg.ssl_version = ssl.PROTOCOL_TLS_CLIENT
worker.cfg.cert_reqs = ssl.CERT_OPTIONAL
worker.cfg.certfile = tls_certificate_pem_path
worker.cfg.keyfile = tls_certificate_pem_path
Expand All @@ -264,7 +264,7 @@ def test__create_ssl_context_with_ciphers(
worker,
tls_certificate_pem_path,
) -> None:
worker.cfg.ssl_version = ssl.PROTOCOL_SSLv23
worker.cfg.ssl_version = ssl.PROTOCOL_TLS_CLIENT
worker.cfg.cert_reqs = ssl.CERT_OPTIONAL
worker.cfg.certfile = tls_certificate_pem_path
worker.cfg.keyfile = tls_certificate_pem_path
Expand All @@ -279,7 +279,7 @@ def test__create_ssl_context_with_ca_certs(
tls_ca_certificate_pem_path,
tls_certificate_pem_path,
) -> None:
worker.cfg.ssl_version = ssl.PROTOCOL_SSLv23
worker.cfg.ssl_version = ssl.PROTOCOL_TLS_CLIENT
worker.cfg.cert_reqs = ssl.CERT_OPTIONAL
worker.cfg.certfile = tls_certificate_pem_path
worker.cfg.keyfile = tls_certificate_pem_path
Expand Down

0 comments on commit 6dbdf64

Please sign in to comment.