Compare commits
1
Commits
4aae5925af
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31803b4474 |
@@ -100,9 +100,7 @@ m/83696968'/<app>'/<n>'
|
|||||||
to one tool. Each key type's number is spelled the way BIP-85 spells its own
|
to one tool. Each key type's number is spelled the way BIP-85 spells its own
|
||||||
RSA application (`828365` is the ASCII codes of `R`, `S`, `A` written out):
|
RSA application (`828365` is the ASCII codes of `R`, `S`, `A` written out):
|
||||||
SSH is `838372` (`S` `S` `H`), age is `657169` (`A` `G` `E`).
|
SSH is `838372` (`S` `S` `H`), age is `657169` (`A` `G` `E`).
|
||||||
- `n` is the key index, a decimal number: flag `--index` / `-n`, default `0`. A
|
- `n` is the key index: flag `--index` / `-n`, default `0`.
|
||||||
leading zero is still decimal (`-n 010` is index 10); a base prefix, an
|
|
||||||
underscore or a sign (`0x10`, `1_0`, `+1`) is refused.
|
|
||||||
|
|
||||||
## Giving it the mnemonic
|
## Giving it the mnemonic
|
||||||
|
|
||||||
@@ -119,17 +117,14 @@ order; the first one found wins:
|
|||||||
4. A prompt on the terminal with echo turned off.
|
4. A prompt on the terminal with echo turned off.
|
||||||
|
|
||||||
If none of these is available and standard input is not a terminal, the tool
|
If none of these is available and standard input is not a terminal, the tool
|
||||||
refuses and exits with status 1. A mnemonic that is empty, does not have 12, 15,
|
refuses and exits with status 1. A mnemonic that fails the BIP-39 checksum is
|
||||||
18, 21 or 24 words, has a word that is not on the BIP-39 word list, or fails the
|
refused with a message saying so. Keys are derived from the mnemonic's words
|
||||||
BIP-39 checksum is refused with a message saying which. A word that is not on
|
joined by single spaces, whatever whitespace is around or between them, so one
|
||||||
the list is named by its position, never printed. Keys are derived from the
|
word per line, tabs or extra spaces give the same keys.
|
||||||
mnemonic's words joined by single spaces, whatever whitespace is around or
|
|
||||||
between them, so one word per line, tabs or extra spaces give the same keys.
|
|
||||||
|
|
||||||
`KEYFUNC_MNEMONIC` and `KEYFUNC_MNEMONIC_COMMAND` are removed from the
|
`KEYFUNC_MNEMONIC` and `KEYFUNC_MNEMONIC_COMMAND` are removed from the
|
||||||
environment before the mnemonic command, the system `ssh` (`keyfunc ssh to`) and
|
environment before the system `ssh` (`keyfunc ssh to`) and `sftp`
|
||||||
`sftp` (`keyfunc ssh install`) are started, so the mnemonic is never handed on
|
(`keyfunc ssh install`) are started, so the mnemonic is never handed on to them.
|
||||||
to them.
|
|
||||||
|
|
||||||
Every command takes `--index` / `-n` and `--mnemonic-command`, and has `--help`.
|
Every command takes `--index` / `-n` and `--mnemonic-command`, and has `--help`.
|
||||||
`keyfunc --version` prints the version. `make build` stamps it; a binary
|
`keyfunc --version` prints the version. `make build` stamps it; a binary
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package cli_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -107,56 +106,6 @@ func TestAnIndexWithNoHardenedChildIsRefused(t *testing.T) {
|
|||||||
require.Empty(t, out)
|
require.Empty(t, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAnIndexWithALeadingZeroIsDecimal(t *testing.T) {
|
|
||||||
t.Setenv(mnemonic.Variable, example())
|
|
||||||
|
|
||||||
line := run(t, "ssh", "pub", "-n", "010")
|
|
||||||
require.Equal(t, run(t, "ssh", "pub", "-n", "10"), line)
|
|
||||||
require.True(t,
|
|
||||||
strings.HasSuffix(strings.TrimSpace(line), " keyfunc/ssh/10"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// The mnemonic command in these runs fails, so a refusal naming the
|
|
||||||
// flag shows that the number was refused before the mnemonic was
|
|
||||||
// looked for.
|
|
||||||
func TestAnIndexThatIsNotDecimalDigitsIsRefused(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
for _, index := range []string{"0x10", "1_0", "+1", "-1", ""} {
|
|
||||||
t.Run(index, func(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
out, err := execute(t,
|
|
||||||
"ssh", "pub", "-n", index, "--mnemonic-command", "exit 1",
|
|
||||||
)
|
|
||||||
require.ErrorIs(t, err, strconv.ErrSyntax)
|
|
||||||
require.ErrorContains(t, err, "--index")
|
|
||||||
require.Empty(t, out)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Neither a command group nor --version reads the index, so these
|
|
||||||
// show that it is refused while the flags are parsed.
|
|
||||||
func TestAnIndexNotInDecimalIsRefusedBeforeAnyCommandRuns(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
for _, args := range [][]string{
|
|
||||||
{"ssh", "-n", "0x10"},
|
|
||||||
{"-n", "0x10", "--version"},
|
|
||||||
} {
|
|
||||||
t.Run(strings.Join(args, " "), func(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
out, err := execute(t, args...)
|
|
||||||
require.ErrorIs(t, err, strconv.ErrSyntax)
|
|
||||||
require.ErrorContains(t, err, "--index")
|
|
||||||
require.Empty(t, out)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTheMnemonicCommandIsUsed(t *testing.T) {
|
func TestTheMnemonicCommandIsUsed(t *testing.T) {
|
||||||
t.Setenv(mnemonic.Variable, "")
|
t.Setenv(mnemonic.Variable, "")
|
||||||
|
|
||||||
@@ -189,22 +138,6 @@ func TestALengthTheToolDoesNotOfferIsRefused(t *testing.T) {
|
|||||||
require.Empty(t, out)
|
require.Empty(t, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTheWordCountIsDecimal(t *testing.T) {
|
|
||||||
t.Setenv(mnemonic.Variable, example())
|
|
||||||
|
|
||||||
words := strings.Fields(run(t, "mnemonic", "--words", "012"))
|
|
||||||
require.Len(t, words, twelve)
|
|
||||||
|
|
||||||
// As for the index, the failing mnemonic command shows that the
|
|
||||||
// number was refused first.
|
|
||||||
out, err := execute(t,
|
|
||||||
"mnemonic", "--words", "0x18", "--mnemonic-command", "exit 1",
|
|
||||||
)
|
|
||||||
require.ErrorIs(t, err, strconv.ErrSyntax)
|
|
||||||
require.ErrorContains(t, err, "--words")
|
|
||||||
require.Empty(t, out)
|
|
||||||
}
|
|
||||||
|
|
||||||
// run executes the tool with the given arguments and returns what it
|
// run executes the tool with the given arguments and returns what it
|
||||||
// wrote to standard output.
|
// wrote to standard output.
|
||||||
func run(t *testing.T, args ...string) string {
|
func run(t *testing.T, args ...string) string {
|
||||||
|
|||||||
@@ -31,9 +31,8 @@ func Command() *cobra.Command {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
words := options.Decimal(childmnemonic.DefaultWords)
|
cmd.Flags().Uint32(
|
||||||
cmd.Flags().Var(
|
"words", childmnemonic.DefaultWords,
|
||||||
&words, "words",
|
|
||||||
"how long the child mnemonic is: 12, 18 or 24 words",
|
"how long the child mnemonic is: 12, 18 or 24 words",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ package options
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"sneak.berlin/go/keyfunc/internal/mnemonic"
|
"sneak.berlin/go/keyfunc/internal/mnemonic"
|
||||||
@@ -17,8 +16,8 @@ func Add(cmd *cobra.Command) {
|
|||||||
"mnemonic-command", "",
|
"mnemonic-command", "",
|
||||||
"shell command whose output is the mnemonic",
|
"shell command whose output is the mnemonic",
|
||||||
)
|
)
|
||||||
cmd.PersistentFlags().VarP(
|
cmd.PersistentFlags().Uint32P(
|
||||||
new(Decimal), "index", "n",
|
"index", "n", 0,
|
||||||
"which key to derive",
|
"which key to derive",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -42,33 +41,3 @@ func Mnemonic(cmd *cobra.Command) (string, error) {
|
|||||||
|
|
||||||
return mnemonic.Read(cmd.Context(), command)
|
return mnemonic.Read(cmd.Context(), command)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decimal is a flag value for a number written in decimal digits only.
|
|
||||||
// The flag library's own uint32 flags read 010 as octal 8 and also
|
|
||||||
// take 0x10 or 1_0.
|
|
||||||
type Decimal uint32
|
|
||||||
|
|
||||||
// String returns the number in decimal digits.
|
|
||||||
func (d *Decimal) String() string {
|
|
||||||
return strconv.FormatUint(uint64(*d), 10)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set reads text as a decimal number that fits in 32 bits: a leading
|
|
||||||
// zero is still decimal, and a base prefix, an underscore or a sign is
|
|
||||||
// refused.
|
|
||||||
func (d *Decimal) Set(text string) error {
|
|
||||||
number, err := strconv.ParseUint(text, 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
*d = Decimal(number)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Type is what --help shows as the flag's type, and what GetUint32
|
|
||||||
// checks before it reads the value back.
|
|
||||||
func (d *Decimal) Type() string {
|
|
||||||
return "uint32"
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"sneak.berlin/go/keyfunc/internal/cli/signals"
|
"sneak.berlin/go/keyfunc/internal/cli/signals"
|
||||||
"sneak.berlin/go/keyfunc/internal/mnemonic"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Where the key goes on the host and what the file it arrives in is
|
// Where the key goes on the host and what the file it arrives in is
|
||||||
@@ -221,7 +220,7 @@ func session(
|
|||||||
|
|
||||||
//nolint:gosec // the options are the user's own, meant for sftp
|
//nolint:gosec // the options are the user's own, meant for sftp
|
||||||
command := exec.CommandContext(cmd.Context(), "sftp", argv...)
|
command := exec.CommandContext(cmd.Context(), "sftp", argv...)
|
||||||
command.Env = mnemonic.ChildEnv()
|
command.Env = childEnv()
|
||||||
command.Stdin = strings.NewReader(strings.Join(batch, "\n") + "\n")
|
command.Stdin = strings.NewReader(strings.Join(batch, "\n") + "\n")
|
||||||
command.Stdout = &said
|
command.Stdout = &said
|
||||||
command.Stderr = &said
|
command.Stderr = &said
|
||||||
|
|||||||
@@ -3,10 +3,13 @@ package ssh
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"sneak.berlin/go/keyfunc/internal/cli/options"
|
"sneak.berlin/go/keyfunc/internal/cli/options"
|
||||||
"sneak.berlin/go/keyfunc/internal/derive"
|
"sneak.berlin/go/keyfunc/internal/derive"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/mnemonic"
|
||||||
"sneak.berlin/go/keyfunc/internal/sshkey"
|
"sneak.berlin/go/keyfunc/internal/sshkey"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -84,6 +87,26 @@ func write(cmd *cobra.Command, text string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// childEnv is the tool's environment with the mnemonic variables taken
|
||||||
|
// out, for the ssh and sftp children it starts. "ssh to" exists so the
|
||||||
|
// private key never leaves the tool; the mnemonic, from either variable,
|
||||||
|
// must not leave it either.
|
||||||
|
func childEnv() []string {
|
||||||
|
environ := os.Environ()
|
||||||
|
kept := make([]string, 0, len(environ))
|
||||||
|
|
||||||
|
for _, entry := range environ {
|
||||||
|
name, _, _ := strings.Cut(entry, "=")
|
||||||
|
if name == mnemonic.Variable || name == mnemonic.CommandVariable {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
kept = append(kept, entry)
|
||||||
|
}
|
||||||
|
|
||||||
|
return kept
|
||||||
|
}
|
||||||
|
|
||||||
// addComment gives a command its comment flag.
|
// addComment gives a command its comment flag.
|
||||||
func addComment(cmd *cobra.Command) {
|
func addComment(cmd *cobra.Command) {
|
||||||
cmd.Flags().String(
|
cmd.Flags().String(
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"sneak.berlin/go/keyfunc/internal/cli/signals"
|
"sneak.berlin/go/keyfunc/internal/cli/signals"
|
||||||
"sneak.berlin/go/keyfunc/internal/mnemonic"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// StatusError says the tool should end with the status ssh ended with.
|
// StatusError says the tool should end with the status ssh ended with.
|
||||||
@@ -80,7 +79,7 @@ func to() *cobra.Command {
|
|||||||
func connect(ctx context.Context, argv []string) error {
|
func connect(ctx context.Context, argv []string) error {
|
||||||
//nolint:gosec // the arguments are the user's own, meant for ssh
|
//nolint:gosec // the arguments are the user's own, meant for ssh
|
||||||
command := exec.CommandContext(ctx, "ssh", argv...)
|
command := exec.CommandContext(ctx, "ssh", argv...)
|
||||||
command.Env = mnemonic.ChildEnv()
|
command.Env = childEnv()
|
||||||
command.Stdin = os.Stdin
|
command.Stdin = os.Stdin
|
||||||
command.Stdout = os.Stdout
|
command.Stdout = os.Stdout
|
||||||
command.Stderr = os.Stderr
|
command.Stderr = os.Stderr
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"slices"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
@@ -30,28 +29,6 @@ var ErrMissing = errors.New(
|
|||||||
"no mnemonic given and standard input is not a terminal",
|
"no mnemonic given and standard input is not a terminal",
|
||||||
)
|
)
|
||||||
|
|
||||||
// The lengths a BIP-39 mnemonic may have.
|
|
||||||
const (
|
|
||||||
twelve = 12
|
|
||||||
fifteen = 15
|
|
||||||
eighteen = 18
|
|
||||||
twentyOne = 21
|
|
||||||
twentyFour = 24
|
|
||||||
)
|
|
||||||
|
|
||||||
// ErrEmpty is returned for a mnemonic with no words in it, such as the
|
|
||||||
// output of a mnemonic command that printed nothing.
|
|
||||||
var ErrEmpty = errors.New("the mnemonic is empty")
|
|
||||||
|
|
||||||
// ErrWordCount is returned for a mnemonic with a number of words that
|
|
||||||
// BIP-39 does not allow.
|
|
||||||
var ErrWordCount = errors.New("a mnemonic has 12, 15, 18, 21 or 24 words")
|
|
||||||
|
|
||||||
// ErrUnknownWord is returned for a mnemonic with a word that is not on
|
|
||||||
// the BIP-39 English word list. The error gives the word's position,
|
|
||||||
// never the word, so the mnemonic stays out of the message.
|
|
||||||
var ErrUnknownWord = errors.New("not on the BIP-39 word list")
|
|
||||||
|
|
||||||
// ErrChecksum is returned for a mnemonic that fails the BIP-39
|
// ErrChecksum is returned for a mnemonic that fails the BIP-39
|
||||||
// checksum.
|
// checksum.
|
||||||
var ErrChecksum = errors.New("the mnemonic fails its BIP-39 checksum")
|
var ErrChecksum = errors.New("the mnemonic fails its BIP-39 checksum")
|
||||||
@@ -86,7 +63,6 @@ func Read(ctx context.Context, command string) (string, error) {
|
|||||||
func run(ctx context.Context, command string) (string, error) {
|
func run(ctx context.Context, command string) (string, error) {
|
||||||
//nolint:gosec // running the user's own command is the point
|
//nolint:gosec // running the user's own command is the point
|
||||||
shell := exec.CommandContext(ctx, "sh", "-c", command)
|
shell := exec.CommandContext(ctx, "sh", "-c", command)
|
||||||
shell.Env = ChildEnv()
|
|
||||||
|
|
||||||
var complaint bytes.Buffer
|
var complaint bytes.Buffer
|
||||||
|
|
||||||
@@ -107,25 +83,6 @@ func run(ctx context.Context, command string) (string, error) {
|
|||||||
return string(out), nil
|
return string(out), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChildEnv is the tool's environment with the mnemonic variables taken
|
|
||||||
// out, for the programs the tool starts: the mnemonic command, ssh and
|
|
||||||
// sftp. The mnemonic, from either variable, never leaves the tool.
|
|
||||||
func ChildEnv() []string {
|
|
||||||
environ := os.Environ()
|
|
||||||
kept := make([]string, 0, len(environ))
|
|
||||||
|
|
||||||
for _, entry := range environ {
|
|
||||||
name, _, _ := strings.Cut(entry, "=")
|
|
||||||
if name == Variable || name == CommandVariable {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
kept = append(kept, entry)
|
|
||||||
}
|
|
||||||
|
|
||||||
return kept
|
|
||||||
}
|
|
||||||
|
|
||||||
// ask prompts on the terminal with echo turned off.
|
// ask prompts on the terminal with echo turned off.
|
||||||
func ask() (string, error) {
|
func ask() (string, error) {
|
||||||
fd := int(os.Stdin.Fd())
|
fd := int(os.Stdin.Fd())
|
||||||
@@ -149,34 +106,13 @@ func ask() (string, error) {
|
|||||||
|
|
||||||
// checked joins the words with single spaces, whatever whitespace
|
// checked joins the words with single spaces, whatever whitespace
|
||||||
// separated them, since the seed is computed over the string itself,
|
// separated them, since the seed is computed over the string itself,
|
||||||
// and refuses a mnemonic that is not a valid BIP-39 mnemonic, with an
|
// and refuses a mnemonic that does not pass the BIP-39 checksum.
|
||||||
// error that says what is wrong with it.
|
func checked(words string) (string, error) {
|
||||||
func checked(text string) (string, error) {
|
words = strings.Join(strings.Fields(words), " ")
|
||||||
words := strings.Fields(text)
|
|
||||||
|
|
||||||
switch len(words) {
|
if !bip39.IsMnemonicValid(words) {
|
||||||
case 0:
|
|
||||||
return "", ErrEmpty
|
|
||||||
case twelve, fifteen, eighteen, twentyOne, twentyFour:
|
|
||||||
default:
|
|
||||||
return "", fmt.Errorf("%w, not %d", ErrWordCount, len(words))
|
|
||||||
}
|
|
||||||
|
|
||||||
wordList := bip39.English()
|
|
||||||
|
|
||||||
for i, word := range words {
|
|
||||||
if !slices.Contains(wordList, word) {
|
|
||||||
return "", fmt.Errorf(
|
|
||||||
"word %d of the mnemonic is %w", i+1, ErrUnknownWord,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
joined := strings.Join(words, " ")
|
|
||||||
|
|
||||||
if !bip39.IsMnemonicValid(joined) {
|
|
||||||
return "", ErrChecksum
|
return "", ErrChecksum
|
||||||
}
|
}
|
||||||
|
|
||||||
return joined, nil
|
return words, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package mnemonic_test
|
package mnemonic_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -63,31 +61,6 @@ func TestTheMnemonicInTheEnvironmentComesLast(t *testing.T) {
|
|||||||
require.Equal(t, fromVariable, words)
|
require.Equal(t, fromVariable, words)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTheMnemonicIsNotHandedToTheCommand(t *testing.T) {
|
|
||||||
const marker = "KEYFUNC_TEST_MARKER"
|
|
||||||
|
|
||||||
t.Setenv(mnemonic.CommandVariable, prints(fromCommandVariable))
|
|
||||||
t.Setenv(mnemonic.Variable, fromVariable)
|
|
||||||
t.Setenv(marker, "reaches the command")
|
|
||||||
|
|
||||||
path := filepath.Join(t.TempDir(), "environment")
|
|
||||||
|
|
||||||
words, err := mnemonic.Read(
|
|
||||||
t.Context(), "env > '"+path+"'; "+prints(example()),
|
|
||||||
)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, example(), words)
|
|
||||||
|
|
||||||
//nolint:gosec // the path is a temporary file of the test's own
|
|
||||||
content, err := os.ReadFile(path)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
environment := string(content)
|
|
||||||
require.NotContains(t, environment, mnemonic.Variable+"=")
|
|
||||||
require.NotContains(t, environment, mnemonic.CommandVariable+"=")
|
|
||||||
require.Contains(t, environment, marker+"=")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAFailingCommandSaysWhatWentWrong(t *testing.T) {
|
func TestAFailingCommandSaysWhatWentWrong(t *testing.T) {
|
||||||
t.Setenv(mnemonic.CommandVariable, "")
|
t.Setenv(mnemonic.CommandVariable, "")
|
||||||
t.Setenv(mnemonic.Variable, "")
|
t.Setenv(mnemonic.Variable, "")
|
||||||
@@ -105,38 +78,6 @@ func TestABadChecksumIsRefused(t *testing.T) {
|
|||||||
require.ErrorIs(t, err, mnemonic.ErrChecksum)
|
require.ErrorIs(t, err, mnemonic.ErrChecksum)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestACommandThatPrintsNothingGivesAnEmptyMnemonic(t *testing.T) {
|
|
||||||
t.Setenv(mnemonic.CommandVariable, "")
|
|
||||||
t.Setenv(mnemonic.Variable, "")
|
|
||||||
|
|
||||||
_, err := mnemonic.Read(t.Context(), "true")
|
|
||||||
require.ErrorIs(t, err, mnemonic.ErrEmpty)
|
|
||||||
require.NotContains(t, err.Error(), "checksum")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAWrongWordCountIsRefused(t *testing.T) {
|
|
||||||
t.Setenv(mnemonic.CommandVariable, "")
|
|
||||||
t.Setenv(mnemonic.Variable, strings.Repeat("abandon ", 3))
|
|
||||||
|
|
||||||
_, err := mnemonic.Read(t.Context(), "")
|
|
||||||
require.ErrorIs(t, err, mnemonic.ErrWordCount)
|
|
||||||
require.ErrorContains(t, err, "not 3")
|
|
||||||
require.NotContains(t, err.Error(), "checksum")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAWordNotOnTheListIsNamedByPositionOnly(t *testing.T) {
|
|
||||||
const typo = "abuot"
|
|
||||||
|
|
||||||
t.Setenv(mnemonic.CommandVariable, "")
|
|
||||||
t.Setenv(mnemonic.Variable, strings.Repeat("abandon ", 11)+typo)
|
|
||||||
|
|
||||||
_, err := mnemonic.Read(t.Context(), "")
|
|
||||||
require.ErrorIs(t, err, mnemonic.ErrUnknownWord)
|
|
||||||
require.ErrorContains(t, err, "word 12 ")
|
|
||||||
require.NotContains(t, err.Error(), typo)
|
|
||||||
require.NotContains(t, err.Error(), "checksum")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNothingToReadAndNobodyToAsk(t *testing.T) {
|
func TestNothingToReadAndNobodyToAsk(t *testing.T) {
|
||||||
t.Setenv(mnemonic.CommandVariable, "")
|
t.Setenv(mnemonic.CommandVariable, "")
|
||||||
t.Setenv(mnemonic.Variable, "")
|
t.Setenv(mnemonic.Variable, "")
|
||||||
|
|||||||
Reference in New Issue
Block a user