Skip to content

Commit

Permalink
enabler(backends): allow ssl string parameters in PostgreSQL URL (#575)…
Browse files Browse the repository at this point in the history
… (#576)

The underlying library asyncpg accepts string values in the ssl
parameter. The old code only accepted the values true and false, which
are converted to boolean.
  • Loading branch information
Exagone313 authored Nov 28, 2023
1 parent 2d05618 commit c2e4c5b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion databases/backends/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def _get_connection_kwargs(self) -> dict:
if max_size is not None:
kwargs["max_size"] = int(max_size)
if ssl is not None:
kwargs["ssl"] = {"true": True, "false": False}[ssl.lower()]
ssl = ssl.lower()
kwargs["ssl"] = {"true": True, "false": False}.get(ssl, ssl)

kwargs.update(self._options)

Expand Down
12 changes: 12 additions & 0 deletions tests/test_connection_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,24 @@ def test_postgres_ssl():
assert kwargs == {"ssl": True}


def test_postgres_ssl_verify_full():
backend = PostgresBackend("postgres://localhost/database?ssl=verify-full")
kwargs = backend._get_connection_kwargs()
assert kwargs == {"ssl": "verify-full"}


def test_postgres_explicit_ssl():
backend = PostgresBackend("postgres://localhost/database", ssl=True)
kwargs = backend._get_connection_kwargs()
assert kwargs == {"ssl": True}


def test_postgres_explicit_ssl_verify_full():
backend = PostgresBackend("postgres://localhost/database", ssl="verify-full")
kwargs = backend._get_connection_kwargs()
assert kwargs == {"ssl": "verify-full"}


def test_postgres_no_extra_options():
backend = PostgresBackend("postgres://localhost/database")
kwargs = backend._get_connection_kwargs()
Expand Down

0 comments on commit c2e4c5b

Please sign in to comment.