Skip to content

Commit

Permalink
chore: fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
avallete committed Sep 10, 2024
1 parent 1fd8913 commit 173f861
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 177 deletions.
11 changes: 3 additions & 8 deletions internal/logout/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func Run(ctx context.Context, stdout *os.File, fsys afero.Fs) error {
if shouldLogout, err := utils.NewConsole().PromptYesNo(ctx, "Do you want to log out? This will remove the access token and all supabase credentials from your system.", false); err != nil {
if shouldLogout, err := utils.NewConsole().PromptYesNo(ctx, "Do you want to log out? This will remove the access token from your system.", false); err != nil {
return err
} else if !shouldLogout {
return errors.New(context.Canceled)
Expand All @@ -25,13 +25,8 @@ func Run(ctx context.Context, stdout *os.File, fsys afero.Fs) error {
return err
}

// Delete all possibles stored projects credentials
if err := credentials.DeleteAll(); err != nil {
// If the credentials are not supported, we can ignore the error
if err != credentials.ErrNotSupported {
return err
}
}
// Delete all possible stored project credentials
_ = credentials.DeleteAll()

fmt.Fprintln(stdout, "Access token deleted successfully. You are now logged out.")
return nil
Expand Down
10 changes: 4 additions & 6 deletions internal/logout/logout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,19 @@ func TestLogoutCommand(t *testing.T) {
require.NoError(t, credentials.Set(utils.AccessTokenKey, token))
require.NoError(t, credentials.Set("project1", "password1"))
require.NoError(t, credentials.Set("project2", "password2"))
t.Cleanup(fstest.MockStdin(t, "y"))
// Run test
err := Run(context.Background(), os.Stdout, afero.NewMemMapFs())
// Check error
assert.NoError(t, err)
// Check that access token has been removed
saved, err := credentials.Get(utils.AccessTokenKey)
assert.NoError(t, err)
saved, _ := credentials.Get(utils.AccessTokenKey)
assert.Empty(t, saved)
// check that project 1 has been removed
saved, err = credentials.Get("project1")
assert.NoError(t, err)
saved, _ = credentials.Get("project1")
assert.Empty(t, saved)
// check that project 2 has been removed
saved, err = credentials.Get("project2")
assert.NoError(t, err)
saved, _ = credentials.Get("project2")
assert.Empty(t, saved)
})

Expand Down
1 change: 0 additions & 1 deletion internal/utils/credentials/keyring/keyring_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func (k macOSXKeychain) DeleteAll(service string) error {
return err
}
}

}

func init() {
Expand Down
162 changes: 0 additions & 162 deletions internal/utils/credentials/keyring/keyring_test.go
Original file line number Diff line number Diff line change
@@ -1,169 +1,7 @@
package keyring

import (
"runtime"
"strings"
"testing"
)

const (
service = "test-service"
user = "test-user"
password = "test-password"
)

// TestSet tests setting a user and password in the keyring.
func TestSet(t *testing.T) {
err := Set(service, user, password)
if err != nil {
t.Errorf("Should not fail, got: %s", err)
}
}

func TestSetTooLong(t *testing.T) {
extraLongPassword := "ba" + strings.Repeat("na", 5000)
err := Set(service, user, extraLongPassword)

if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
// should fail on those platforms
if err != ErrSetDataTooBig {
t.Errorf("Should have failed, got: %s", err)
}
}
}

// TestGetMultiline tests getting a multi-line password from the keyring
func TestGetMultiLine(t *testing.T) {
multilinePassword := `this password
has multiple
lines and will be
encoded by some keyring implementiations
like osx`
err := Set(service, user, multilinePassword)
if err != nil {
t.Errorf("Should not fail, got: %s", err)
}

pw, err := Get(service, user)
if err != nil {
t.Errorf("Should not fail, got: %s", err)
}

if multilinePassword != pw {
t.Errorf("Expected password %s, got %s", multilinePassword, pw)
}
}

// TestGetMultiline tests getting a multi-line password from the keyring
func TestGetUmlaut(t *testing.T) {
umlautPassword := "at least on OSX üöäÜÖÄß will be encoded"
err := Set(service, user, umlautPassword)
if err != nil {
t.Errorf("Should not fail, got: %s", err)
}

pw, err := Get(service, user)
if err != nil {
t.Errorf("Should not fail, got: %s", err)
}

if umlautPassword != pw {
t.Errorf("Expected password %s, got %s", umlautPassword, pw)
}
}

// TestGetSingleLineHex tests getting a single line hex string password from the keyring.
func TestGetSingleLineHex(t *testing.T) {
hexPassword := "abcdef123abcdef123"
err := Set(service, user, hexPassword)
if err != nil {
t.Errorf("Should not fail, got: %s", err)
}

pw, err := Get(service, user)
if err != nil {
t.Errorf("Should not fail, got: %s", err)
}

if hexPassword != pw {
t.Errorf("Expected password %s, got %s", hexPassword, pw)
}
}

// TestGet tests getting a password from the keyring.
func TestGet(t *testing.T) {
err := Set(service, user, password)
if err != nil {
t.Errorf("Should not fail, got: %s", err)
}

pw, err := Get(service, user)
if err != nil {
t.Errorf("Should not fail, got: %s", err)
}

if password != pw {
t.Errorf("Expected password %s, got %s", password, pw)
}
}

// TestGetNonExisting tests getting a secret not in the keyring.
func TestGetNonExisting(t *testing.T) {
_, err := Get(service, user+"fake")
if err != ErrNotFound {
t.Errorf("Expected error ErrNotFound, got %s", err)
}
}

// TestDelete tests deleting a secret from the keyring.
func TestDelete(t *testing.T) {
err := Delete(service, user)
if err != nil {
t.Errorf("Should not fail, got: %s", err)
}
}

// TestDeleteNonExisting tests deleting a secret not in the keyring.
func TestDeleteNonExisting(t *testing.T) {
err := Delete(service, user+"fake")
if err != ErrNotFound {
t.Errorf("Expected error ErrNotFound, got %s", err)
}
}

// TestDeleteAll tests deleting all secrets for a given service.
func TestDeleteAll(t *testing.T) {
// Set up multiple secrets for the same service
err := Set(service, user, password)
if err != nil {
t.Errorf("Should not fail, got: %s", err)
}

err = Set(service, user+"2", password+"2")
if err != nil {
t.Errorf("Should not fail, got: %s", err)
}

// Delete all secrets for the service
err = DeleteAll(service)
if err != nil {
t.Errorf("Should not fail, got: %s", err)
}

// Verify that all secrets for the service are deleted
_, err = Get(service, user)
if err != ErrNotFound {
t.Errorf("Expected error ErrNotFound, got %s", err)
}

_, err = Get(service, user+"2")
if err != ErrNotFound {
t.Errorf("Expected error ErrNotFound, got %s", err)
}

// Verify that DeleteAll on an empty service doesn't cause an error
err = DeleteAll(service)
if err != nil {
t.Errorf("Should not fail on empty service, got: %s", err)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ func (s *SecretService) CreateItem(collection dbus.BusObject, label string, attr
// handlePrompt checks if a prompt should be handles and handles it by
// triggering the prompt and waiting for the Secret service daemon to display
// the prompt to the user.
//
//nolint:all
func (s *SecretService) handlePrompt(prompt dbus.ObjectPath) (bool, dbus.Variant, error) {
if prompt != dbus.ObjectPath("/") {
err := s.AddMatchSignal(dbus.WithMatchObjectPath(prompt),
Expand Down

0 comments on commit 173f861

Please sign in to comment.