Skip to content

Commit

Permalink
test @ in password (#60)
Browse files Browse the repository at this point in the history
Changes:

- test with @ in password
- update services to have all an @ in the pw
- fix pw typo in docs
  • Loading branch information
devkral authored Nov 21, 2024
1 parent 1810b67 commit c631cab
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 18 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion docs/connections-and-transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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\
"""
25 changes: 20 additions & 5 deletions tests/test_database_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit c631cab

Please sign in to comment.