|
1 | 1 | import locale
|
2 | 2 | import os
|
| 3 | +import pathlib |
3 | 4 | import subprocess
|
4 | 5 | import typing as t
|
5 | 6 |
|
@@ -84,6 +85,30 @@ def test_locale(connection: psycopg.Connection):
|
84 | 85 | assert locale.normalize(lc_ctype) == "en_US.UTF-8"
|
85 | 86 |
|
86 | 87 |
|
| 88 | +def test_environment_variables(): |
| 89 | + """Test that only expected 'PG*' variables are set.""" |
| 90 | + |
| 91 | + pg_environ = {k: v for k, v in os.environ.items() if k.startswith("PG")} |
| 92 | + |
| 93 | + # In case of Windows, there might be a mix of forward and backward slashes |
| 94 | + # as separators. So let's compare paths semantically instead. |
| 95 | + pg_servicefile = pathlib.Path(pg_environ.pop("PGSERVICEFILE", "")) |
| 96 | + pg_servicefile_exp = pathlib.Path(os.environ["RUNNER_TEMP"], "pgdata", "pg_service.conf") |
| 97 | + assert pg_servicefile.resolve() == pg_servicefile_exp.resolve() |
| 98 | + |
| 99 | + if os.name == "nt": |
| 100 | + pg_environ_exp = { |
| 101 | + "PGBIN": "", |
| 102 | + "PGDATA": "", |
| 103 | + "PGPASSWORD": "", |
| 104 | + "PGROOT": "", |
| 105 | + "PGUSER": "", |
| 106 | + } |
| 107 | + else: |
| 108 | + pg_environ_exp = {} |
| 109 | + assert pg_environ == pg_environ_exp |
| 110 | + |
| 111 | + |
87 | 112 | def test_user_permissions(connection: psycopg.Connection):
|
88 | 113 | """Test that a user has super/createdb permissions."""
|
89 | 114 |
|
@@ -201,6 +226,19 @@ def test_client_applications(
|
201 | 226 | subprocess.check_call(["dropuser", username])
|
202 | 227 |
|
203 | 228 |
|
| 229 | +def test_libpq_applications(service_name: str, monkeypatch: pytest.MonkeyPatch): |
| 230 | + """Test that libpq-using applications can be used.""" |
| 231 | + |
| 232 | + # Request connection parameters from the connection service file prepared |
| 233 | + # by our action. |
| 234 | + monkeypatch.setenv("PGSERVICE", service_name) |
| 235 | + |
| 236 | + with psycopg.connect() as connection: |
| 237 | + assert connection \ |
| 238 | + .execute("SELECT usename FROM pg_user WHERE usename = CURRENT_USER") \ |
| 239 | + .fetchone() |
| 240 | + |
| 241 | + |
204 | 242 | def test_auth_wrong_username(connection_factory: ConnectionFactory, connection_uri: str):
|
205 | 243 | """Test that wrong username is rejected!"""
|
206 | 244 |
|
|
0 commit comments