check / check (push) Waiting to run
`secret vault import` took only a vault without a long-term key, and `secret init` and `secret vault create` give every vault one, so it always failed. A mnemonic enters through those two commands, so the command goes, with its tests and its README entry. The help and the note of `secret generate mnemonic` named `secret import`, which imports a file as a secret; they now name `secret init` and `secret vault create`. `secret vault import` now prints the help of `secret vault` and exits 0, as cobra does for any subcommand of `secret vault` it does not know. Judgement call: TestWorkflowMismatch in internal/vault, which replayed the import step by step, is deleted. Model: opus-5-5
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
//nolint:testpackage // white-box test of unexported internals
|
|
package cli
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/awnumar/memguard"
|
|
"github.com/spf13/afero"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// TestInvalidMnemonicError checks that every command that takes a mnemonic
|
|
// returns errInvalidMnemonicPhrase for one that is not valid BIP39.
|
|
func TestInvalidMnemonicError(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
command string
|
|
run func(c *Instance) error
|
|
}{
|
|
{"secret init", func(c *Instance) error { return c.Init(c.cmd) }},
|
|
{"secret vault create work", func(c *Instance) error {
|
|
return c.CreateVault(c.cmd, "work")
|
|
}},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.command, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
instance, _ := newTestInstance(afero.NewMemMapFs())
|
|
instance.Mnemonic = memguard.NewBufferFromBytes([]byte("not a mnemonic"))
|
|
t.Cleanup(instance.Mnemonic.Destroy)
|
|
|
|
require.ErrorIs(t, tt.run(instance), errInvalidMnemonicPhrase)
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestGenerateSecretErrors checks that `secret generate secret` gives one
|
|
// error for a length below 1 and one for a type it cannot generate.
|
|
func TestGenerateSecretErrors(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
instance, cmd := newTestInstance(afero.NewMemMapFs())
|
|
|
|
err := instance.GenerateSecret(cmd, "x", 0, "base58", false)
|
|
require.ErrorIs(t, err, errLengthTooSmall)
|
|
|
|
_, err = generateRandomString(0, "ab")
|
|
require.ErrorIs(t, err, errLengthTooSmall)
|
|
|
|
err = instance.GenerateSecret(cmd, "x", defaultSecretLength, "mnemonic", false)
|
|
require.ErrorIs(t, err, errUnsupportedSecretType)
|
|
|
|
err = instance.GenerateSecret(cmd, "x", defaultSecretLength, "hex", false)
|
|
require.ErrorIs(t, err, errUnsupportedSecretType)
|
|
}
|