From 173f86198c263c1b4df523eedf8fcf6ec5342d96 Mon Sep 17 00:00:00 2001 From: avallete Date: Tue, 10 Sep 2024 17:48:42 +0200 Subject: [PATCH] chore: fix lint --- internal/logout/logout.go | 11 +- internal/logout/logout_test.go | 10 +- .../credentials/keyring/keyring_darwin.go | 1 - .../utils/credentials/keyring/keyring_test.go | 162 ------------------ .../keyring/secret_service/secret_service.go | 2 + 5 files changed, 9 insertions(+), 177 deletions(-) diff --git a/internal/logout/logout.go b/internal/logout/logout.go index 5d631de7f..48560aea3 100644 --- a/internal/logout/logout.go +++ b/internal/logout/logout.go @@ -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) @@ -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 diff --git a/internal/logout/logout_test.go b/internal/logout/logout_test.go index 34ee73858..07a4b72a5 100644 --- a/internal/logout/logout_test.go +++ b/internal/logout/logout_test.go @@ -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) }) diff --git a/internal/utils/credentials/keyring/keyring_darwin.go b/internal/utils/credentials/keyring/keyring_darwin.go index 8e402432e..28625215a 100644 --- a/internal/utils/credentials/keyring/keyring_darwin.go +++ b/internal/utils/credentials/keyring/keyring_darwin.go @@ -128,7 +128,6 @@ func (k macOSXKeychain) DeleteAll(service string) error { return err } } - } func init() { diff --git a/internal/utils/credentials/keyring/keyring_test.go b/internal/utils/credentials/keyring/keyring_test.go index f1a8af36b..d98433199 100644 --- a/internal/utils/credentials/keyring/keyring_test.go +++ b/internal/utils/credentials/keyring/keyring_test.go @@ -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) - } -} diff --git a/internal/utils/credentials/keyring/secret_service/secret_service.go b/internal/utils/credentials/keyring/secret_service/secret_service.go index 4acce61ba..ea6791436 100644 --- a/internal/utils/credentials/keyring/secret_service/secret_service.go +++ b/internal/utils/credentials/keyring/secret_service/secret_service.go @@ -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),