Skip to content

fix(connections): verify before saving, keep stored password, + tests - #91

Merged
oesukam merged 3 commits into
mainfrom
fix/connect-verify-before-save
Aug 4, 2026
Merged

fix(connections): verify before saving, keep stored password, + tests#91
oesukam merged 3 commits into
mainfrom
fix/connect-verify-before-save

Conversation

@oesukam

@oesukam oesukam commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Two related fixes surfaced while debugging repeated 'Authentication failed' reports.

1. Connect verifies before saving

Per request: Connect should confirm the connection works, then save — not save first. onSaveAndConnect now calls test_connection (with the form's own credentials) up front and only saves + opens a session on success. A failed connect no longer leaves a broken saved connection behind.

2. Saving no longer wipes the stored password (data-loss bug)

save_connection did if let Some(pw) = input.password — but the form blanks the password when editing (secrets are never read back into the UI), so input.password is Some(""). That overwrote the keychain with an empty password, breaking the next connect. Now it only writes a secret when a non-empty value is supplied (same for SSH password/passphrase).

Verified

  • cargo check/clippy clean; frontend typecheck + lint (0 errors).

oesukam added 2 commits August 4, 2026 18:28
Two related fixes for the connect flow:

- Connect now VERIFIES the connection first (via test_connection with the
  form's own credentials) and only saves + opens a session once it
  actually connects. Previously it saved first, so a failed connect left
  a broken saved connection behind.

- save_connection no longer overwrites a stored secret with an empty
  value. Editing a connection re-opens the form with the password blanked
  (secrets are never read back into the UI), so an empty field means
  'keep the stored one'. Writing the empty string wiped the real keychain
  password and broke the next connect — a silent data-loss bug. Now we
  only (over)write when a non-empty value is supplied.
Add coverage for the connection bugs hit this session:
- Extract parsePostgresUri/buildPostgresUri to their own module and unit
  test them (the real managed-Postgres URL, hyphen/underscore passwords,
  percent-decoding, ssl modes, parse↔build round-trip).
- Rust integration tests (real Postgres container): connect succeeds with
  the correct password, FAILS with a wrong one, 'prefer' falls back to
  plaintext on a no-TLS server, and a parameterised query runs end-to-end
  (guards the unnamed-statement/pooler fix).
@oesukam oesukam changed the title fix(connections): verify before saving; never wipe stored password fix(connections): verify before saving, keep stored password, + tests Aug 4, 2026
…ilure

- test_connection falls back to the stored keychain password (DB + SSH)
  when the form field is empty and the input has an id — so re-testing an
  edited connection (password blanked for security) uses the saved secret
  instead of failing with a spurious auth error.
- onSaveAndConnect: on a post-save connect failure for a BRAND-NEW
  connection, roll back the save so a dead entry isn't left in the rail;
  surface the real 'Connect failed' message (not a mislabeled 'Save
  failed').
- SSH tests: add wrong-password-rejected and tunnel-to-dead-target tests,
  and pre-trust the container host key (mirrors the UI's TOFU prompt→trust
  flow) so container-based tunnel tests are deterministic.
@oesukam
oesukam merged commit 7484f16 into main Aug 4, 2026
0 of 6 checks passed
@oesukam
oesukam deleted the fix/connect-verify-before-save branch August 4, 2026 21:24
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.

1 participant