Merge pull request #3163 from michael-genson/fix/url-encode-postgres-passwords

fix: URL-Encode Postgres Password
This commit is contained in:
boc-the-git 2024-02-13 08:50:43 +11:00 committed by GitHub
commit fe3bd95c85
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -1,5 +1,6 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from pathlib import Path from pathlib import Path
from urllib import parse as urlparse
from pydantic import BaseModel, PostgresDsn from pydantic import BaseModel, PostgresDsn
from pydantic_settings import BaseSettings, SettingsConfigDict from pydantic_settings import BaseSettings, SettingsConfigDict
@ -48,7 +49,7 @@ class PostgresProvider(AbstractDBProvider, BaseSettings):
PostgresDsn.build( PostgresDsn.build(
scheme="postgresql", scheme="postgresql",
username=self.POSTGRES_USER, username=self.POSTGRES_USER,
password=self.POSTGRES_PASSWORD, password=urlparse.quote_plus(self.POSTGRES_PASSWORD),
host=host, host=host,
path=f"{self.POSTGRES_DB or ''}", path=f"{self.POSTGRES_DB or ''}",
) )

View File

@ -38,6 +38,15 @@ def test_pg_connection_args(monkeypatch):
assert app_settings.DB_URL == "postgresql://mealie:mealie@postgres:5432/mealie" assert app_settings.DB_URL == "postgresql://mealie:mealie@postgres:5432/mealie"
def test_pg_connection_url_encode_password(monkeypatch):
monkeypatch.setenv("DB_ENGINE", "postgres")
monkeypatch.setenv("POSTGRES_SERVER", "postgres")
monkeypatch.setenv("POSTGRES_PASSWORD", "please,url#encode/this?password")
get_app_settings.cache_clear()
app_settings = get_app_settings()
assert app_settings.DB_URL == "postgresql://mealie:please%2Curl%23encode%2Fthis%3Fpassword@postgres:5432/mealie"
@dataclass(slots=True) @dataclass(slots=True)
class SMTPValidationCase: class SMTPValidationCase:
host: str host: str