fix: reject empty or null Username on non-shared server import (#10309) (#10320)

validate_json_data() only checked that the Username key was present on
a non-shared server, not that it held anything useful, so an empty or
null value imported cleanly and left behind a server that libpq would
silently authenticate as the OS account running pgAdmin rather than
reject outright. Check the value, matching the truthiness check already
used for shared servers and the "Username must be specified" rule
enforced by the server dialog.
This commit is contained in:
Dave Page
2026-08-21 18:35:35 +05:30
committed by GitHub
parent c0fa2a18d8
commit 1f02466324
2 changed files with 19 additions and 3 deletions
+5 -3
View File
@@ -649,9 +649,11 @@ def validate_json_data(data, is_admin):
"found for server '%s'" % server
)
else:
errmsg = check_attrib("Username")
if errmsg:
return errmsg
if not obj.get("Username"):
return gettext(
"'Username' attribute not found for server '%s'" %
server
)
errmsg = check_attrib("MaintenanceDB")
if errmsg:
@@ -47,6 +47,20 @@ class TestValidateJsonData(BaseTestGenerator):
expected_error="'Username' attribute not found",
expected_servers=["1"]
)),
('A non-shared server with an empty username is rejected',
dict(
servers={"1": server(Username="")},
is_admin=True,
expected_error="'Username' attribute not found",
expected_servers=["1"]
)),
('A non-shared server with a null username is rejected',
dict(
servers={"1": server(Username=None)},
is_admin=True,
expected_error="'Username' attribute not found",
expected_servers=["1"]
)),
('A shared server with only a shared username is valid',
dict(
servers={"1": server(Shared=True, SharedUsername="postgres")},