diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index 4bf0706..c818249 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -23,7 +23,7 @@ jobs: image: mariadb:11 env: MYSQL_USER: username - MYSQL_PASSWORD: passwsss*1348394# + MYSQL_PASSWORD: passwsss*1348394#@ MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: testsuite ports: @@ -34,7 +34,7 @@ jobs: image: postgres:16 env: POSTGRES_USER: username - POSTGRES_PASSWORD: passwsss*1348394# + POSTGRES_PASSWORD: passwsss*1348394#@ POSTGRES_DB: testsuite ports: - 5432:5432 @@ -43,13 +43,13 @@ jobs: mssql: image: mcr.microsoft.com/mssql/server:2022-CU13-ubuntu-22.04 env: - MSSQL_SA_PASSWORD: Mssql123mssql- + MSSQL_SA_PASSWORD: Mssql123mssql-@ ACCEPT_EULA: "Y" MSSQL_PID: Developer ports: - 1433:1433 options: >- - --health-cmd "/opt/mssql-tools/bin/sqlcmd -U sa -P Mssql123mssql- -Q 'select 1' -b -o /dev/null" + --health-cmd "/opt/mssql-tools/bin/sqlcmd -U sa -P 'Mssql123mssql-@' -Q 'select 1' -b -o /dev/null" --health-interval 60s --health-timeout 30s --health-start-period 20s diff --git a/docker-compose.yml b/docker-compose.yml index b5731eb..2aed1d1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: image: postgres:16 environment: POSTGRES_USER: username - POSTGRES_PASSWORD: passwsss*1348394# + POSTGRES_PASSWORD: passwsss*1348394#@ POSTGRES_DB: testsuite ports: - "127.0.0.1:5432:5432" @@ -15,7 +15,7 @@ services: image: mariadb:11 environment: MYSQL_USER: username - MYSQL_PASSWORD: passwsss*1348394# + MYSQL_PASSWORD: passwsss*1348394#@ MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: testsuite ports: @@ -26,7 +26,7 @@ services: restart: always image: mcr.microsoft.com/mssql/server:2022-latest environment: - MSSQL_SA_PASSWORD: Mssql123mssql- + MSSQL_SA_PASSWORD: Mssql123mssql-@ ACCEPT_EULA: "Y" MSSQL_PID: Developer ports: diff --git a/docs/connections-and-transactions.md b/docs/connections-and-transactions.md index 1b6bb24..dde4122 100644 --- a/docs/connections-and-transactions.md +++ b/docs/connections-and-transactions.md @@ -233,7 +233,7 @@ Let us now use an example using `MSSQL` which usually requires more options to b * Type: `mssql` * Database name: `master` * User: `sa` -* Password: `Mssql123mssql` +* Password: `Mssql123mssql-` * Port: `1433` * Host: `localhost` diff --git a/pyproject.toml b/pyproject.toml index ca10b5b..b275fc3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -211,9 +211,9 @@ extra-dependencies = [ [tool.hatch.envs.hatch-test.env-vars] TEST_DATABASE_URLS = """ sqlite+aiosqlite:///testsuite.sqlite3,\ -mysql+aiomysql://username:passwsss*1348394#@localhost:3306/testsuite,\ -mysql+asyncmy://username:passwsss*1348394#@localhost:3306/testsuite,\ -postgresql+psycopg://username:passwsss*1348394#@localhost:5432/testsuite,\ -postgresql+asyncpg://username:passwsss*1348394#@localhost:5432/testsuite,\ -mssql+aioodbc://sa:Mssql123mssql-@localhost:1433/master?driver=ODBC+Driver+18+for+SQL+Server&TrustServerCertificate=yes&Encrypt=Optional\ +mysql+aiomysql://username:passwsss*1348394#%40@localhost:3306/testsuite,\ +mysql+asyncmy://username:passwsss*1348394#%40@localhost:3306/testsuite,\ +postgresql+psycopg://username:passwsss*1348394#%40@localhost:5432/testsuite,\ +postgresql+asyncpg://username:passwsss*1348394#%40@localhost:5432/testsuite,\ +mssql+aioodbc://sa:Mssql123mssql-%40@localhost:1433/master?driver=ODBC+Driver+18+for+SQL+Server&TrustServerCertificate=yes&Encrypt=Optional\ """ diff --git a/tests/test_database_url.py b/tests/test_database_url.py index 724e200..2ce2c6d 100644 --- a/tests/test_database_url.py +++ b/tests/test_database_url.py @@ -41,16 +41,31 @@ def test_database_url_properties(): def test_database_url_escape(): - u = DatabaseURL(f"postgresql://username:{quote('[password')}@localhost/mydatabase") + u = DatabaseURL(f"postgresql://username:{quote('[@password')}@localhost/mydatabase") assert u.username == "username" - assert u.password == "[password" - assert u.userinfo == f"username:{quote('[password')}".encode() + assert u.password == "[@password" + assert u.userinfo == f"username:{quote('[@password')}".encode() u2 = DatabaseURL(u) - assert u2.password == "[password" + assert u2.password == "[@password" u3 = DatabaseURL(str(u)) - assert u3.password == "[password" + assert u3.password == "[@password" + + +def test_password_with_escape_update(): + u = DatabaseURL("postgresql://@localhost/mydatabase") + u = u.replace(username="foo", password=r"@[]{5}") + assert u.username == "foo" + assert u.password == r"@[]{5}" + assert u.userinfo == f"foo:{quote(r'@[]{5}')}".encode() + assert str(u).count("@") == 1 + + u2 = DatabaseURL(u) + assert u2.password == r"@[]{5}" + + u3 = DatabaseURL(str(u)) + assert u3.password == r"@[]{5}" def test_database_url_constructor():