lockbox

password manager
Log | Files | Refs | README | LICENSE

commit 7edb88c7262d8589da71f414194b43b3baf9727a
parent 459f27802d604d717d051442001dc9869b3ae5c0
Author: Sean Enck <sean@ttypty.com>
Date:   Sun, 11 Aug 2024 10:54:41 -0400

piping and multiline really just mean interactive

Diffstat:
Minternal/app/core.go | 6+++---
Minternal/app/insert.go | 2+-
Minternal/app/insert_test.go | 29+++++++++++++++--------------
Minternal/app/rekey.go | 2+-
Minternal/app/rekey_test.go | 2+-
Minternal/platform/os.go | 4++--
6 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/internal/app/core.go b/internal/app/core.go @@ -96,7 +96,7 @@ type ( UserInputOptions interface { CommandOptions IsPipe() bool - Input(bool, bool) ([]byte, error) + Input(bool) ([]byte, error) } // DefaultCommand is the default CLI app type for actual execution @@ -179,8 +179,8 @@ func (a DefaultCommand) Password() (string, error) { } // Input will read user input -func (a *DefaultCommand) Input(pipe, multi bool) ([]byte, error) { - return platform.GetUserInputPassword(pipe, multi) +func (a *DefaultCommand) Input(interactive bool) ([]byte, error) { + return platform.GetUserInputPassword(interactive) } func subCommand(parent, name, args, desc string) string { diff --git a/internal/app/insert.go b/internal/app/insert.go @@ -43,7 +43,7 @@ func Insert(cmd UserInputOptions, mode InsertMode) error { } } } - password, err := cmd.Input(isPipe, mode == MultiLineInsert) + password, err := cmd.Input(!isPipe && mode != MultiLineInsert) if err != nil { return fmt.Errorf("invalid input: %w", err) } diff --git a/internal/app/insert_test.go b/internal/app/insert_test.go @@ -12,12 +12,12 @@ import ( type ( mockInsert struct { - command *mockCommand - noTOTP func() (bool, error) - input func(bool, bool) ([]byte, error) - pipe func() bool - token func() string - isMulti bool + command *mockCommand + noTOTP func() (bool, error) + input func() ([]byte, error) + pipe func() bool + token func() string + interactive bool } ) @@ -35,9 +35,9 @@ func (m *mockInsert) IsPipe() bool { return m.pipe() } -func (m *mockInsert) Input(pipe, multi bool) ([]byte, error) { - m.isMulti = multi - return m.input(pipe, multi) +func (m *mockInsert) Input(interactive bool) ([]byte, error) { + m.interactive = interactive + return m.input() } func (m *mockInsert) Args() []string { @@ -67,7 +67,7 @@ func TestInsertDo(t *testing.T) { } m.command.args = []string{"test/test2"} m.command.confirm = false - m.input = func(bool, bool) ([]byte, error) { + m.input = func() ([]byte, error) { return nil, errors.New("failure") } m.command.buf = bytes.Buffer{} @@ -81,7 +81,7 @@ func TestInsertDo(t *testing.T) { if err := app.Insert(m, app.SingleLineInsert); err == nil || err.Error() != "invalid input: failure" { t.Errorf("invalid error: %v", err) } - m.input = func(bool, bool) ([]byte, error) { + m.input = func() ([]byte, error) { return []byte("TEST"), nil } m.command.confirm = true @@ -119,22 +119,23 @@ func TestInsertDo(t *testing.T) { if m.command.buf.String() != "" { t.Error("invalid insert") } - m.isMulti = false + m.interactive = false m.command.confirm = true m.command.buf = bytes.Buffer{} m.command.args = []string{"test/test2/test1"} if err := app.Insert(m, app.SingleLineInsert); err != nil { t.Errorf("invalid error: %v", err) } - if m.command.buf.String() == "" || m.isMulti { + if m.command.buf.String() == "" || !m.interactive { t.Error("invalid insert") } + m.interactive = false m.command.buf = bytes.Buffer{} m.command.args = []string{"test/test2/test1"} if err := app.Insert(m, app.MultiLineInsert); err != nil { t.Errorf("invalid error: %v", err) } - if m.command.buf.String() == "" || !m.isMulti { + if m.command.buf.String() == "" || m.interactive { t.Error("invalid insert") } } diff --git a/internal/app/rekey.go b/internal/app/rekey.go @@ -19,7 +19,7 @@ func ReKey(cmd UserInputOptions) error { } var pass string if !vars.NoKey { - p, err := cmd.Input(piping, false) + p, err := cmd.Input(!piping) if err != nil { return err } diff --git a/internal/app/rekey_test.go b/internal/app/rekey_test.go @@ -32,7 +32,7 @@ func (m *mockKeyer) Args() []string { return m.args } -func (m *mockKeyer) Input(pipe, multi bool) ([]byte, error) { +func (m *mockKeyer) Input(bool) ([]byte, error) { return []byte(m.pass), nil } diff --git a/internal/platform/os.go b/internal/platform/os.go @@ -46,9 +46,9 @@ func termEcho(on bool) { } // GetUserInputPassword will read the user's input from stdin via multiple means. -func GetUserInputPassword(piping, multiLine bool) ([]byte, error) { +func GetUserInputPassword(interactive bool) ([]byte, error) { var password string - if !multiLine && !piping { + if interactive { input, err := confirmInputsMatch() if err != nil { return nil, err