Skip to content

fix(endpoints): fall back to last-used username on first connect - #5384

Merged
norman-abramovitz merged 1 commit into
cloudfoundry:developfrom
nabramovitz:fix/remember-username-global-fallback
May 27, 2026
Merged

fix(endpoints): fall back to last-used username on first connect#5384
norman-abramovitz merged 1 commit into
cloudfoundry:developfrom
nabramovitz:fix/remember-username-global-fallback

Conversation

@nabramovitz

Copy link
Copy Markdown
Contributor

Summary

Extends the existing per-endpoint username cache with a global last-used-username fallback. The per-endpoint cache (#5350) prefills the reconnect dialog after disconnect, but the FIRST connect to each newly-registered endpoint still starts blank — even when the operator just connected to a sibling endpoint with the same UAA account.

Real-world hit: an operator registers several CFs that share an identity provider (e.g. several Kevin tenants). First connect to each new endpoint required re-typing the same username every time.

What it does

  • Adds a global slot stratos.endpoint.username.__last written on every successful credentials connect alongside the existing per-endpoint key
  • New getRememberedUsername(guid) helper returns:
    1. Per-endpoint cache when present
    2. Global last-used fallback when per-endpoint is empty
    3. null otherwise
  • connect-endpoint.component swaps its direct localStorage read for the helper, so the fallback applies uniformly
  • forgetRememberedUsername deliberately does NOT clear the global slot — disconnecting one CF shouldn't blank the prefill for unrelated endpoints

Behavior

Scenario Per-endpoint slot Global slot Prefill
First connect ever empty empty nothing (user types)
Reconnect after disconnect populated populated per-endpoint value
First connect to new endpoint after using another empty populated global value (operator can overwrite)
Just disconnected, opening another endpoint's dialog empty populated (survived forget) global value

SSO / token forms have no username control, so the prefill is a no-op for those — same as before.

Defensive change to existing tests

Two pre-existing tests asserted localStorage.getItem(...).toBeNull() for missing keys. Some happy-dom variants return '' instead of null, so those tests broke alongside this PR. Updated to use the new helper (which treats '' and null equivalently) or assert against both forms.

Test plan

  • 9 specs in remembered-username.spec.ts (5 new for the fallback, 4 existing updated for happy-dom robustness)
  • Existing connect-endpoint.component.spec.ts unchanged + passes
  • Full make check gate ran clean (exit 0)

The per-endpoint username cache landed in c9e649a so a reconnect
after disconnect could prefill the dialog. But the cache is keyed by
endpoint guid, so the first connect to each newly-registered endpoint
starts blank — even when the operator just connected to a sibling
endpoint using the same account a moment ago. Friction for the common
"register N CFs that share UAA" workflow.

Add a global last-used slot (`stratos.endpoint.username.__last`)
written on every successful credentials connect alongside the
per-endpoint slot. The new `getRememberedUsername(guid)` helper
returns the per-endpoint value when present, otherwise the global,
otherwise null. forgetRememberedUsername stays per-endpoint —
disconnecting one CF shouldn't blank the prefill for unrelated ones.

connect-endpoint.component swaps its direct localStorage read for the
helper, so the fallback applies uniformly. Empty-string handling is
explicit (some happy-dom variants return '' for missing keys) — the
helper treats '' as "no value" instead of trusting the chain operator.

Spec coverage: per-endpoint hit, global fallback, latest-write wins,
forget preserves global, empty-state returns null. Updates the two
older tests that checked `localStorage.getItem(...) === null` directly
— they were relying on a behavior the current happy-dom doesn't
guarantee.

@norman-abramovitz norman-abramovitz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified that the username is remembered across connect/disconnect to simulate a reconnect command.

@norman-abramovitz
norman-abramovitz merged commit 7d93bc8 into cloudfoundry:develop May 27, 2026
12 checks passed
@nabramovitz
nabramovitz deleted the fix/remember-username-global-fallback branch June 17, 2026 08:11
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.

2 participants