Skip to content

Commit 13aed2f

Browse files
authored
Merge pull request #393 from ZlatyChlapec/aiohttp-ssl-context-support
ext.aiohttp: Add option for SSL
2 parents 96bd689 + 6a254cc commit 13aed2f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

gino/ext/aiohttp.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class Gino(_Gino):
8282
* ``pool_min_size`` - the initial number of connections of the db pool.
8383
* ``pool_max_size`` - the maximum number of connections in the db pool.
8484
* ``echo`` - enable SQLAlchemy echo mode.
85+
* ``ssl`` - SSL context passed to ``asyncpg.connect``, default is ``None``.
8586
8687
If the ``db`` is set as an aiohttp middleware, then a lazy connection is
8788
available at ``request['connection']``. By default, a database connection
@@ -129,6 +130,7 @@ async def before_server_start(app_):
129130
echo=config.setdefault('echo', False),
130131
min_size=config.setdefault('pool_min_size', 5),
131132
max_size=config.setdefault('pool_max_size', 10),
133+
ssl=config.setdefault("ssl"),
132134
loop=app_.loop,
133135
)
134136

tests/test_aiohttp.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ async def test_client_dsn():
8585
await _test_client(dict(dsn=PG_URL))
8686

8787

88+
@pytest.fixture
89+
@async_generator
90+
async def test_client_ssl():
91+
import ssl
92+
93+
ctx = ssl.create_default_context()
94+
ctx.check_hostname = False
95+
ctx.verify_mode = ssl.CERT_NONE
96+
97+
await _test_client(dict(dsn=PG_URL, ssl=ctx))
98+
99+
88100
async def _test_index_returns_200(test_client):
89101
response = await test_client.get('/')
90102
assert response.status == 200
@@ -122,3 +134,7 @@ async def test(test_client):
122134

123135
async def test_dsn(test_client_dsn):
124136
await _test(test_client_dsn)
137+
138+
139+
async def test_ssl(test_client_ssl):
140+
await _test(test_client_ssl)

0 commit comments

Comments
 (0)