Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions cli/config/credentials/native_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ func NewNativeStore(file store, helperSuffix string) Store {

// Erase removes the given credentials from the native store.
func (c *nativeStore) Erase(serverAddress string) error {
if err := client.Erase(c.programFunc, serverAddress); err != nil {
return err
helperErr := client.Erase(c.programFunc, serverAddress)
// Drop the plaintext copy even when the helper fails. Logout tries
// several server-address spellings, and a clean erase of another
// spelling used to hide this failure while leaving the auth entry.
fileErr := c.fileStore.Erase(serverAddress)
if helperErr != nil {
return helperErr
}

// Fallback to plain text store to remove email
return c.fileStore.Erase(serverAddress)
return fileErr
}

// Get retrieves credentials for a specific server from the native store.
Expand Down
17 changes: 17 additions & 0 deletions cli/config/credentials/native_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,20 @@ func TestNativeStoreEraseInvalidAddress(t *testing.T) {
err := s.Erase(invalidServerAddress)
assert.ErrorContains(t, err, "program failed")
}

func TestNativeStoreEraseDropsPlaintextWhenHelperFails(t *testing.T) {
f := &fakeStore{configs: map[string]types.AuthConfig{
invalidServerAddress: {
Username: "other",
Password: "secret",
},
}}

s := &nativeStore{
programFunc: mockCommandFn,
fileStore: NewFileStore(f),
}
err := s.Erase(invalidServerAddress)
assert.ErrorContains(t, err, "program failed")
assert.Check(t, is.Len(f.GetAuthConfigs(), 0))
}
Loading