fix: quote username in user_mappings test helper for dotted local roles

The setUp helper in user_mappings/tests/utils.py interpolated
server['username'] directly into the CREATE USER MAPPING DDL, so a
local PostgreSQL role containing a dot (e.g. 'ashesh.vashi') was
parsed by PG as a schema-qualified identifier and rejected with
'syntax error at or near "."'. This blocked every test whose setUp
created a user mapping (UserMappingGetSQLTestCase, etc.).

Wrap the FOR target with Driver.qtIdent() so the identifier is
double-quoted when it contains special characters. Mirrors the
approach used by the resql framework's _normalize_owner() / <OWNER>
substitution introduced in d112dc3b9 - that fix covered SQL
expectation comparison; this fix covers test setUp DDL generation,
which the resql logic does not reach.

The OPTIONS user/password are left as raw '%s' since they are SQL
string literals (single-quoted), where dots are syntactically safe.

Verified: 33/33 user_mappings tests pass; zero 'syntax error at or
near "."' occurrences in the targeted run.
This commit is contained in:
Ashesh Vashi
2026-05-01 22:54:09 +05:30
parent 044355c5e0
commit 504775de80
@@ -13,6 +13,7 @@ import sys
import traceback
import json
from pgadmin.utils.driver.psycopg3 import Driver
from regression.python_test_utils.test_utils import get_db_connection,\
set_isolation_level
@@ -61,8 +62,12 @@ def create_user_mapping(server, db_name, fsrv_name):
old_isolation_level = connection.isolation_level
set_isolation_level(connection, 0)
pg_cursor = connection.cursor()
# Quote the username as an SQL identifier so usernames containing
# special characters (e.g. dots like 'ashesh.vashi') do not parse
# as schema-qualified names.
quoted_username = Driver.qtIdent(None, server['username'])
query = "CREATE USER MAPPING FOR %s SERVER %s OPTIONS" \
" (user '%s', password '%s')" % (server['username'],
" (user '%s', password '%s')" % (quoted_username,
fsrv_name,
server['username'],
server['db_password']