From e2fe26fb300b9ed769ea793370d4a07eaa68f0ad Mon Sep 17 00:00:00 2001 From: sudobangbang Date: Fri, 7 Jun 2024 16:04:31 -0700 Subject: [PATCH 1/4] use quote_plus instead of quote `asyncpg` doesn't work well for all US-ASCII characters, we need to use `quote_plus` instead https://github.com/MagicStack/asyncpg/pull/1159 --- stac_fastapi/pgstac/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stac_fastapi/pgstac/config.py b/stac_fastapi/pgstac/config.py index 9c825006..2c3b7783 100644 --- a/stac_fastapi/pgstac/config.py +++ b/stac_fastapi/pgstac/config.py @@ -1,7 +1,7 @@ """Postgres API configuration.""" from typing import List, Type -from urllib.parse import quote +from urllib.parse import quote_plus as quote from pydantic import BaseModel from pydantic_settings import SettingsConfigDict From e457fd948752778a5f05f7b0603ea90d2e1f9eba Mon Sep 17 00:00:00 2001 From: ranchodeluxe Date: Wed, 26 Jun 2024 17:02:01 -0700 Subject: [PATCH 2/4] make it fail --- stac_fastapi/pgstac/config.py | 3 ++- tests/conftest.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/stac_fastapi/pgstac/config.py b/stac_fastapi/pgstac/config.py index 2c3b7783..48f050d9 100644 --- a/stac_fastapi/pgstac/config.py +++ b/stac_fastapi/pgstac/config.py @@ -1,7 +1,8 @@ """Postgres API configuration.""" from typing import List, Type -from urllib.parse import quote_plus as quote +from urllib.parse import quote + from pydantic import BaseModel from pydantic_settings import SettingsConfigDict diff --git a/tests/conftest.py b/tests/conftest.py index b3f569dd..18bcfb83 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -53,7 +53,7 @@ def database(postgresql_proc): port=postgresql_proc.port, dbname="pgstactestdb", version=postgresql_proc.version, - password="secret", + password="a2Vw:yk=)CdSis[fek]tW=/o", ) as jan: connection = ( f"postgresql://{jan.user}:{jan.password}@{jan.host}:{jan.port}/{jan.dbname}" From 485d2f0f518317a0fbc22ed846114018328f647a Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Thu, 27 Jun 2024 08:49:48 +0200 Subject: [PATCH 3/4] fix test --- stac_fastapi/pgstac/config.py | 3 +-- tests/conftest.py | 8 +++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/stac_fastapi/pgstac/config.py b/stac_fastapi/pgstac/config.py index 48f050d9..2c3b7783 100644 --- a/stac_fastapi/pgstac/config.py +++ b/stac_fastapi/pgstac/config.py @@ -1,8 +1,7 @@ """Postgres API configuration.""" from typing import List, Type -from urllib.parse import quote - +from urllib.parse import quote_plus as quote from pydantic import BaseModel from pydantic_settings import SettingsConfigDict diff --git a/tests/conftest.py b/tests/conftest.py index 18bcfb83..edb916b5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,6 +4,7 @@ import os import time from typing import Callable, Dict +from urllib.parse import quote_plus as quote from urllib.parse import urljoin import asyncpg @@ -55,9 +56,7 @@ def database(postgresql_proc): version=postgresql_proc.version, password="a2Vw:yk=)CdSis[fek]tW=/o", ) as jan: - connection = ( - f"postgresql://{jan.user}:{jan.password}@{jan.host}:{jan.port}/{jan.dbname}" - ) + connection = f"postgresql://{jan.user}:{quote(jan.password)}@{jan.host}:{jan.port}/{jan.dbname}" with PgstacDB(dsn=connection) as db: migrator = Migrate(db) version = migrator.run_migration() @@ -68,7 +67,7 @@ def database(postgresql_proc): @pytest.fixture(autouse=True) async def pgstac(database): - connection = f"postgresql://{database.user}:{database.password}@{database.host}:{database.port}/{database.dbname}" + connection = f"postgresql://{database.user}:{quote(database.password)}@{database.host}:{database.port}/{database.dbname}" yield conn = await asyncpg.connect(dsn=connection) await conn.execute( @@ -99,7 +98,6 @@ async def pgstac(database): ) def api_client(request, database): hydrate, prefix, response_model = request.param - api_settings = Settings( postgres_user=database.user, postgres_pass=database.password, From a085a57270d6fe628bda8822f9b5154c7b274352 Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Thu, 27 Jun 2024 09:09:40 +0200 Subject: [PATCH 4/4] one more quote --- tests/api/test_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/api/test_api.py b/tests/api/test_api.py index 3546867d..5b2d577a 100644 --- a/tests/api/test_api.py +++ b/tests/api/test_api.py @@ -712,7 +712,7 @@ async def test_no_extension( hydrate, validation, load_test_data, database, pgstac ) -> None: """test PgSTAC with no extension.""" - connection = f"postgresql://{database.user}:{database.password}@{database.host}:{database.port}/{database.dbname}" + connection = f"postgresql://{database.user}:{quote_plus(database.password)}@{database.host}:{database.port}/{database.dbname}" with PgstacDB(dsn=connection) as db: loader = Loader(db=db) loader.load_collections(os.path.join(DATA_DIR, "test_collection.json"))