Skip to content

Commit

Permalink
Fix #536: ssl_context not used (#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
akiuni committed Jul 23, 2021
1 parent 72c1573 commit 9b45993
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/536.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use ssl_context passsed to Docker constructor for creating underlying connection to docker engine.
5 changes: 3 additions & 2 deletions aiodocker/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ def __init__(
WIN_PRE_LEN = len(WIN_PRE)
if _rx_tcp_schemes.search(docker_host):
if os.environ.get("DOCKER_TLS_VERIFY", "0") == "1":
ssl_context = self._docker_machine_ssl_context()
docker_host = _rx_tcp_schemes.sub("https://", docker_host)
if ssl_context is None:
ssl_context = self._docker_machine_ssl_context()
docker_host = _rx_tcp_schemes.sub("https://", docker_host)
else:
ssl_context = None
connector = aiohttp.TCPConnector(ssl=ssl_context)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io
import os
import pathlib
import ssl
import sys
import tarfile
import time
Expand Down Expand Up @@ -70,6 +71,17 @@ async def test_ssl_context(monkeypatch):
docker = Docker()
assert docker.connector._ssl
await docker.close()
with pytest.raises(TypeError):
docker = Docker(ssl_context="bad ssl context")
ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS)
ssl_ctx.set_ciphers(ssl._RESTRICTED_SERVER_CIPHERS)
ssl_ctx.load_verify_locations(cafile=str(cert_dir / "ca.pem"))
ssl_ctx.load_cert_chain(
certfile=str(cert_dir / "cert.pem"), keyfile=str(cert_dir / "key.pem")
)
docker = Docker(ssl_context=ssl_ctx)
assert docker.connector._ssl
await docker.close()


@pytest.mark.skipif(
Expand Down

0 comments on commit 9b45993

Please sign in to comment.