mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2026-09-03 20:52:57 -05:00
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:
@@ -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")},
|
||||
|
||||
Reference in New Issue
Block a user