-
Notifications
You must be signed in to change notification settings - Fork 1
fix: handle init credential backend switches #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,6 +120,43 @@ func TestInteractiveInitUsesPromptedBackendForStoreAndConfig(t *testing.T) { | |
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. File-level note: internal/cmd/initcmd/init_test.go The new regression coverage does not prove the preserved interactive same-backend guard. Reply inline to this comment. |
||
| } | ||
|
|
||
| func TestInteractiveInitBackendChangeReplacesDestinationCredential(t *testing.T) { | ||
| harness := newInitHarness(t) | ||
| cfg := config.Default() | ||
| cfg.Keyring.Backend = "file" | ||
| if err := config.Save(harness.scope, cfg); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| key := "default/" + credentials.OAuthTokenKey | ||
| harness.store.values[key] = "stale-destination-credential" | ||
| harness.interactive = true | ||
| harness.prompt = func(setup *Setup) error { | ||
| setup.ClientID = "client-id" | ||
| setup.Backend = "keychain" | ||
| return nil | ||
| } | ||
| if err := harness.execute("--no-verify"); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if harness.store.values[key] == "stale-destination-credential" || harness.store.setCalls != 1 { | ||
| t.Fatalf("credential = %q, set calls = %d", harness.store.values[key], harness.store.setCalls) | ||
| } | ||
| } | ||
|
|
||
| func TestNonInteractiveInitBackendChangeStillRequiresOverwrite(t *testing.T) { | ||
| harness := newInitHarness(t) | ||
| cfg := config.Default() | ||
| cfg.Keyring.Backend = "file" | ||
| if err := config.Save(harness.scope, cfg); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| harness.store.values["default/"+credentials.OAuthTokenKey] = "old-secret" | ||
| err := harness.execute("--backend", "keychain", "--non-interactive", "--client-id", "client-id", "--no-verify") | ||
| if !errors.Is(err, credstore.ErrExists) { | ||
| t.Fatalf("error = %v", err) | ||
| } | ||
| } | ||
|
|
||
| func TestNonInteractiveInitNamesMissingClientID(t *testing.T) { | ||
| harness := newInitHarness(t) | ||
| called := false | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the documented overwrite contract: README currently directs users to use
sptfy init --overwriteto replace an older credential, but interactive backend switches now replace an existing destination credential implicitly. Update that user-facing guidance to distinguish ordinary replacement from an intentional interactive backend change, so the durable behavior is discoverable.Reply inline to this comment.