lockbox

password manager
Log | Files | Refs | README | LICENSE

commit 64dca2e6795efd486955df6b692fef980d715789
parent 257b6c5124e139ce377d7cce6598bb3ba995208c
Author: Sean Enck <sean@ttypty.com>
Date:   Mon, 27 Mar 2023 19:31:37 -0400

because totp does not have find (and will not) it makes less sense to also have find, use grep

Diffstat:
Mcmd/main.go | 4++--
Ainternal/app/list.go | 27+++++++++++++++++++++++++++
Ainternal/app/list_test.go | 46++++++++++++++++++++++++++++++++++++++++++++++
Dinternal/app/listfind.go | 35-----------------------------------
Dinternal/app/listfind_test.go | 61-------------------------------------------------------------
Minternal/cli/core.go | 3+--
Minternal/cli/core_test.go | 4++--
Mtests/run.sh | 2+-
8 files changed, 79 insertions(+), 103 deletions(-)

diff --git a/cmd/main.go b/cmd/main.go @@ -70,8 +70,8 @@ func run() error { if p.Confirm("proceed with rekey") { return p.Transaction().ReKey() } - case cli.ListCommand, cli.FindCommand: - return app.ListFind(p, command == cli.FindCommand) + case cli.ListCommand: + return app.List(p) case cli.MoveCommand: return app.Move(p) case cli.InsertCommand: diff --git a/internal/app/list.go b/internal/app/list.go @@ -0,0 +1,27 @@ +package app + +import ( + "errors" + "fmt" + + "github.com/enckse/lockbox/internal/backend" +) + +// List will list/find entries +func List(cmd CommandOptions) error { + args := cmd.Args() + opts := backend.QueryOptions{} + opts.Mode = backend.ListMode + if len(args) != 0 { + return errors.New("list does not support any arguments") + } + e, err := cmd.Transaction().QueryCallback(opts) + if err != nil { + return err + } + w := cmd.Writer() + for _, f := range e { + fmt.Fprintf(w, "%s\n", f.Path) + } + return nil +} diff --git a/internal/app/list_test.go b/internal/app/list_test.go @@ -0,0 +1,46 @@ +package app_test + +import ( + "os" + "testing" + + "github.com/enckse/lockbox/internal/app" + "github.com/enckse/lockbox/internal/backend" +) + +func fullSetup(t *testing.T, keep bool) *backend.Transaction { + if !keep { + os.Remove("test.kdbx") + } + os.Setenv("LOCKBOX_READONLY", "no") + os.Setenv("LOCKBOX_STORE", "test.kdbx") + os.Setenv("LOCKBOX_KEY", "test") + os.Setenv("LOCKBOX_KEYFILE", "") + os.Setenv("LOCKBOX_KEYMODE", "plaintext") + os.Setenv("LOCKBOX_TOTP", "totp") + os.Setenv("LOCKBOX_HOOKDIR", "") + os.Setenv("LOCKBOX_SET_MODTIME", "") + tr, err := backend.NewTransaction() + if err != nil { + t.Errorf("failed: %v", err) + } + return tr +} + +func setup(t *testing.T) *backend.Transaction { + return fullSetup(t, false) +} + +func TestList(t *testing.T) { + m := newMockCommand(t) + if err := app.List(m); err != nil { + t.Errorf("invalid error: %v", err) + } + if m.buf.String() == "" { + t.Error("nothing listed") + } + m.args = []string{"test"} + if err := app.List(m); err.Error() != "list does not support any arguments" { + t.Errorf("invalid error: %v", err) + } +} diff --git a/internal/app/listfind.go b/internal/app/listfind.go @@ -1,35 +0,0 @@ -package app - -import ( - "errors" - "fmt" - - "github.com/enckse/lockbox/internal/backend" -) - -// ListFind will list/find entries -func ListFind(cmd CommandOptions, isFind bool) error { - args := cmd.Args() - opts := backend.QueryOptions{} - opts.Mode = backend.ListMode - if isFind { - opts.Mode = backend.FindMode - if len(args) < 1 { - return errors.New("find requires search term") - } - opts.Criteria = args[0] - } else { - if len(args) != 0 { - return errors.New("list does not support any arguments") - } - } - e, err := cmd.Transaction().QueryCallback(opts) - if err != nil { - return err - } - w := cmd.Writer() - for _, f := range e { - fmt.Fprintf(w, "%s\n", f.Path) - } - return nil -} diff --git a/internal/app/listfind_test.go b/internal/app/listfind_test.go @@ -1,61 +0,0 @@ -package app_test - -import ( - "os" - "strings" - "testing" - - "github.com/enckse/lockbox/internal/app" - "github.com/enckse/lockbox/internal/backend" -) - -func fullSetup(t *testing.T, keep bool) *backend.Transaction { - if !keep { - os.Remove("test.kdbx") - } - os.Setenv("LOCKBOX_READONLY", "no") - os.Setenv("LOCKBOX_STORE", "test.kdbx") - os.Setenv("LOCKBOX_KEY", "test") - os.Setenv("LOCKBOX_KEYFILE", "") - os.Setenv("LOCKBOX_KEYMODE", "plaintext") - os.Setenv("LOCKBOX_TOTP", "totp") - os.Setenv("LOCKBOX_HOOKDIR", "") - os.Setenv("LOCKBOX_SET_MODTIME", "") - tr, err := backend.NewTransaction() - if err != nil { - t.Errorf("failed: %v", err) - } - return tr -} - -func setup(t *testing.T) *backend.Transaction { - return fullSetup(t, false) -} - -func TestList(t *testing.T) { - m := newMockCommand(t) - if err := app.ListFind(m, false); err != nil { - t.Errorf("invalid error: %v", err) - } - if m.buf.String() == "" { - t.Error("nothing listed") - } - m.args = []string{"test"} - if err := app.ListFind(m, false); err.Error() != "list does not support any arguments" { - t.Errorf("invalid error: %v", err) - } -} - -func TestFind(t *testing.T) { - m := newMockCommand(t) - if err := app.ListFind(m, true); err.Error() != "find requires search term" { - t.Errorf("invalid error: %v", err) - } - m.args = []string{"test1"} - if err := app.ListFind(m, true); err != nil { - t.Errorf("invalid error: %v", err) - } - if m.buf.String() == "" || strings.Contains(m.buf.String(), "test3") { - t.Error("wrong find") - } -} diff --git a/internal/cli/core.go b/internal/cli/core.go @@ -146,7 +146,7 @@ func BashCompletions(defaults bool) ([]string, error) { MoveCommand: MoveCommand, DoList: fmt.Sprintf("%s %s", name, ListCommand), DoTOTPList: fmt.Sprintf("%s %s %s", name, TOTPCommand, TOTPListCommand), - Options: []string{EnvCommand, FindCommand, HelpCommand, ListCommand, ShowCommand, VersionCommand, StatsCommand}, + Options: []string{EnvCommand, HelpCommand, ListCommand, ShowCommand, VersionCommand, StatsCommand}, } isReadOnly := false isClip := true @@ -207,7 +207,6 @@ func Usage(verbose bool) ([]string, error) { results = append(results, subCommand(BashCommand, BashDefaultsCommand, "", "generate default bash completion")) results = append(results, command(ClipCommand, "entry", "copy the entry's value into the clipboard")) results = append(results, command(EnvCommand, "", "display environment variable information")) - results = append(results, command(FindCommand, "criteria", "perform a text search over the entry keys")) results = append(results, command(HelpCommand, "", "show this usage information")) results = append(results, subCommand(HelpCommand, HelpAdvancedCommand, "", "display verbose help information")) results = append(results, command(InsertCommand, "entry", "insert a new entry into the store")) diff --git a/internal/cli/core_test.go b/internal/cli/core_test.go @@ -10,11 +10,11 @@ import ( func TestUsage(t *testing.T) { u, _ := cli.Usage(false) - if len(u) != 22 { + if len(u) != 21 { t.Errorf("invalid usage, out of date? %d", len(u)) } u, _ = cli.Usage(true) - if len(u) != 81 { + if len(u) != 80 { t.Errorf("invalid verbose usage, out of date? %d", len(u)) } for _, usage := range u { diff --git a/tests/run.sh b/tests/run.sh @@ -26,7 +26,7 @@ _execute() { echo y |${LB_BINARY} rm keys/k/one echo ${LB_BINARY} ls - ${LB_BINARY} find e + ${LB_BINARY} ls | grep e ${LB_BINARY} show keys/k/one2 ${LB_BINARY} show keys2/k/three ${LB_BINARY} stats keys2/k/three