Skip to content

Reject empty or null Username on non-shared server import - #10320

Open
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:fix/10309-username-validation
Open

Reject empty or null Username on non-shared server import#10320
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:fix/10309-username-validation

Conversation

@dpage

@dpage dpage commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary

validate_json_data() only checked that the Username key was present
on a non-shared server entry in servers.json, not that it held anything
useful. {"Username": ""} and {"Username": null} both imported
cleanly and left behind a server that couldn't sensibly connect: libpq
treats an empty user as "unset" and substitutes the OS account running
pgAdmin, so the resulting authentication failure has no obvious link
back to the servers.json that caused it. The server dialog already
rejects an empty username ("Username must be specified."); import was
more permissive than the UI it's meant to mirror.

This checks the value rather than just the key, matching the truthiness
check already used for the shared-server Username/SharedUsername
pair a few lines above.

Fixes #10309.

Test plan

  • Added two scenarios to test_validate_json_data.py covering an empty
    and a null Username on a non-shared server (both now rejected).
  • python regression/runtests.py --pkg utils.tests.test_validate_json_data
    passes (14/14).

Summary by CodeRabbit

  • Bug Fixes

    • Improved server validation to reject non-shared server configurations with missing, empty, or null usernames.
    • Ensured a clear validation error is displayed for invalid username values.
  • Tests

    • Added coverage for empty and null username validation scenarios.

…in-org#10309)

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.
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 35035039-a033-492b-a4ab-a88deb87c3d8

📥 Commits

Reviewing files that changed from the base of the PR and between 0ebefaf and d8f33d4.

📒 Files selected for processing (2)
  • web/pgadmin/utils/__init__.py
  • web/pgadmin/utils/tests/test_validate_json_data.py

Included review availability: Your plan provides up to 8 included reviews per hour; 0 remain after this review.


Walkthrough

Non-shared server validation now rejects empty or null Username values. Tests cover both cases and verify that the server entry remains unchanged.

Changes

Server import username validation

Layer / File(s) Summary
Validate non-shared Username values
web/pgadmin/utils/__init__.py, web/pgadmin/utils/tests/test_validate_json_data.py
validate_json_data checks the Username value instead of only checking key presence. Tests verify rejection of empty and null usernames without removing the server entry.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to d8f33

This localized validation change rejects unusable empty or null usernames during non-shared server import, preventing misleading connection failures; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: kijonghan

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: rejecting empty or null usernames during non-shared server import.
Linked Issues check ✅ Passed The change directly addresses issue #10309 and preserves the Service exception while adding regression tests for empty and null usernames.
Out of Scope Changes check ✅ Passed The changes are limited to non-shared username validation and related regression tests, with no unrelated scope identified.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

servers.json import accepts an empty or null Username

1 participant