Skip to content

Commit 4498c4f

Browse files
authored
Merge pull request lightspeed-core#1761 from tisnik/lcore-623-gss-encmode-config-type
LCORE-623: proper gss_encmode config type in PostgreSQL configuration
2 parents 1ece752 + b6305dd commit 4498c4f

4 files changed

Lines changed: 52 additions & 2 deletions

File tree

docs/openapi.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16325,6 +16325,11 @@
1632516325
},
1632616326
"gss_encmode": {
1632716327
"type": "string",
16328+
"enum": [
16329+
"disable",
16330+
"prefer",
16331+
"require"
16332+
],
1632816333
"title": "GSS encmode",
1632916334
"description": "This option determines whether or with what priority a secure GSS TCP/IP connection will be negotiated with the server.",
1633016335
"default": "prefer"

src/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
# See: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-SSLMODE
161161
POSTGRES_DEFAULT_SSL_MODE: Final[Literal["prefer"]] = "prefer"
162162
# See: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-GSSENCMODE
163-
POSTGRES_DEFAULT_GSS_ENCMODE: Final[str] = "prefer"
163+
POSTGRES_DEFAULT_GSS_ENCMODE: Final[Literal["prefer"]] = "prefer"
164164

165165
# cache constants
166166
CACHE_TYPE_MEMORY: Final[str] = "memory"

src/models/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ class PostgreSQLDatabaseConfiguration(ConfigurationBase):
236236
description="SSL mode",
237237
)
238238

239-
gss_encmode: str = Field(
239+
gss_encmode: Literal["disable", "prefer", "require"] = Field(
240240
constants.POSTGRES_DEFAULT_GSS_ENCMODE,
241241
title="GSS encmode",
242242
description="This option determines whether or with what priority a secure GSS "

tests/unit/models/config/test_postgresql_database_configuration.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,48 @@ def test_postgresql_database_configuration_improper_ssl_mode(
264264
password="password",
265265
ssl_mode=ssl_mode,
266266
) # pyright: ignore[reportCallIssue]
267+
268+
269+
def test_postgresql_database_configuration_gss_encmode(subtests: SubTests) -> None:
270+
"""Test the PostgreSQLDatabaseConfiguration model."""
271+
gss_encmodes = ("disable", "prefer", "require")
272+
273+
for gss_encmode in gss_encmodes:
274+
with subtests.test(msg=f"GSS encmode {gss_encmode}"):
275+
# pylint: disable=no-member
276+
c = PostgreSQLDatabaseConfiguration(
277+
db="db",
278+
user="user",
279+
password="password",
280+
gss_encmode=gss_encmode,
281+
) # pyright: ignore[reportCallIssue]
282+
283+
# most attributes are set to default values
284+
assert c is not None
285+
assert c.host == "localhost"
286+
assert c.port == 5432
287+
assert c.db == "db"
288+
assert c.user == "user"
289+
assert c.password.get_secret_value() == "password"
290+
assert c.ssl_mode == POSTGRES_DEFAULT_SSL_MODE
291+
assert c.gss_encmode == gss_encmode
292+
assert c.namespace == "public"
293+
assert c.ca_cert_path is None
294+
295+
296+
def test_postgresql_database_configuration_improper_gss_encmode(
297+
subtests: SubTests,
298+
) -> None:
299+
"""Test the PostgreSQLDatabaseConfiguration model."""
300+
gss_encmodes = ("foo", "bar", "baz", "")
301+
302+
for gss_encmode in gss_encmodes:
303+
with subtests.test(msg=f"GSS encmode {gss_encmode}"):
304+
with pytest.raises(ValueError, match="Input should be 'disable'"):
305+
# pylint: disable=no-member
306+
PostgreSQLDatabaseConfiguration(
307+
db="db",
308+
user="user",
309+
password="password",
310+
gss_encmode=gss_encmode,
311+
) # pyright: ignore[reportCallIssue]

0 commit comments

Comments
 (0)