internal/cli drops its copies of vault.ErrSecretNotFound, ErrVaultNotFound, ErrVersionNotFound and ErrSecretExists and of the secret package's keychain and Secure Enclave errors, and its second error for an unknown unlocker type, an invalid mnemonic, a length below 1, an unsupported secret type and an oversized secret. vault.ErrNilValueBuffer becomes secret.ErrNilValueBuffer. Every error of secret.ReadPassphrase wraps ErrPassphraseNotRead. ResolveGPGKeyFingerprint returns ErrGPGKeyNotFound for a key the keyring lacks. storeInKeychain returns errNilDataBuffer. bip85's ErrPasswordTooShort and ErrEncodedTooShort go with their unreachable checks, as does the macOS check in macOS-only code. Tests that matched these errors' text use errors.Is. Model: opus-5-5
This commit was merged in pull request #114.
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package cli_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.eeqj.de/sneak/secret/internal/cli"
|
||||
"git.eeqj.de/sneak/secret/internal/vault"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// TestMissingSecretOrVaultErrors checks that a command that finds no such
|
||||
// secret or vault returns the vault package's error for it, as `secret get`
|
||||
// does, and leaves the vaults unchanged. "default" is the current vault, and
|
||||
// both vaults hold the secret "x".
|
||||
func TestMissingSecretOrVaultErrors(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
before := snapshotStateDir(t, newTwoVaultFs(t))
|
||||
|
||||
tests := []struct {
|
||||
command string
|
||||
want error
|
||||
run func(c *cli.Instance) error
|
||||
}{
|
||||
{
|
||||
"rm --force nosuch", vault.ErrSecretNotFound,
|
||||
func(c *cli.Instance) error {
|
||||
return c.RemoveSecret(&cobra.Command{}, "nosuch", true)
|
||||
},
|
||||
},
|
||||
{
|
||||
"version rm --force nosuch", vault.ErrSecretNotFound,
|
||||
func(c *cli.Instance) error {
|
||||
return c.RemoveVersion(&cobra.Command{}, "nosuch", "20260101.001", true)
|
||||
},
|
||||
},
|
||||
{
|
||||
"mv --force work:nosuch default", vault.ErrSecretNotFound,
|
||||
func(c *cli.Instance) error {
|
||||
return c.MoveSecret(&cobra.Command{}, "work:nosuch", "default", true)
|
||||
},
|
||||
},
|
||||
{
|
||||
"decrypt nosuch", vault.ErrSecretNotFound,
|
||||
func(c *cli.Instance) error { return c.Decrypt("nosuch", "", "") },
|
||||
},
|
||||
{
|
||||
"vault rm --force nosuch", vault.ErrVaultNotFound,
|
||||
func(c *cli.Instance) error {
|
||||
return c.RemoveVault(&cobra.Command{}, "nosuch", true)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.command, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
requireRejectedAndUnchanged(t, before, tt.want, tt.run)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user