connect/auth: honor --org before the zero-orgs shortcut#182
Open
jetm wants to merge 1 commit into
Open
Conversation
`avocado connect auth login --org <id>` silently dropped the requested org whenever the auth server returned no organizations. pick_org tested `orgs.is_empty()` first and returned None, so the code exchange minted an unscoped token and the CLI reported a successful login for an org it never scoped to, leaving a bogus "all orgs" profile behind with no error. Resolve an explicit hint before the empty-list shortcut so a hint that matches nothing, including an empty list, fails loudly. The no-hint zero-orgs path still returns None unchanged. Signed-off-by: Javier Tia <javier@peridio.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
avocado connect auth login --org <id>can report a successful login while silently ignoring the org the user asked for.When the auth server's org list for the login code comes back empty,
pick_orghits itsorgs.is_empty()shortcut and returnsOrgPick::Nonebefore it ever looks at the--orghint. The code exchange then runs with noorganization_id, minting an unscoped token, and the CLI printsLogged in … / Created new profile. The user ends up with an "all orgs" profile scoped to nothing, for an org they explicitly named, with no error to signal it.This is a real footgun: a
--profile X --org <id>login "succeeds", butavocado connect auth status --profile Xthen reportsToken scope: unscoped (all orgs), and every subsequent org-scoped call fails confusingly. It cost meaningful debugging time chasing a token-scope problem that was actually a silent no-op at login.Fix
Resolve an explicit
--orghint before the zero-orgs shortcut. A hint that matches nothing, including against an empty list, now fails loudly:Everything else is unchanged: the no-hint zero-orgs path still returns
OrgPick::None(server falls back to its default scoping), and single-org auto-select, multi-org JSON default, and multi-org human prompt all behave exactly as before.Test
Added
pick_org_explicit_hint_with_no_orgs_errors_not_droppedas a regression guard (written failing first, against the old behavior). Fullpick_orgsuite green;cargo fmt --all -- --checkandcargo clippy --all-targets --all-features -- -D warningsclean.Validation
Built and run against
connect.peridio.com:auth login --org <non-member-org> --profile X→Logged in / Created new profile;auth status --profile X→Token scope: unscoped (all orgs).Error: organization '<id>' not found. Available: none; the browser shows "CLI Login Failed"; no profile is written.auth login --org <member-org>scopes the token correctly andprojects list --org <member-org>returns the org's projects.