lockbox

password manager
Log | Files | Refs | README | LICENSE

commit 12a345f8701ed2858cc7ed81c3629f4c6d29dbd2
parent 7ff89f89b65b245235eea35759ba5d4ee38716ed
Author: Sean Enck <sean@ttypty.com>
Date:   Sat, 15 Oct 2022 17:11:46 -0400

tests converted to go file

Diffstat:
Mtests/Makefile | 9+++++----
Mtests/expected.log | 5+++++
Atests/run.go | 114+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dtests/run.sh | 65-----------------------------------------------------------------
4 files changed, 124 insertions(+), 69 deletions(-)

diff --git a/tests/Makefile b/tests/Makefile @@ -1,6 +1,7 @@ -BUILD := -DATA := bin +DATA := bin +ACTUAL := $(DATA)/actual.log all: - ./run.sh $(BUILD) $(DATA) - diff -u $(DATA)/actual.log expected.log + mkdir -p $(DATA) + go run run.go 2>&1 | sed "s#$(PWD)/$(DATA)##g" | sed 's/^[0-9][0-9][0-9][0-9][0-9][0-9]$$/XXXXXX/g' > $(ACTUAL) + diff -u $(ACTUAL) expected.log diff --git a/tests/expected.log b/tests/expected.log @@ -3,8 +3,11 @@ unable to check for existing entry (path can NOT end with separator) +exit status 1 unable to check for existing entry (path can NOT be rooted) +exit status 1 unable to check for existing entry (unwilling to operate on path with empty segment) +exit status 1 key/a/one keys/k/one @@ -37,6 +40,8 @@ hash:b6c44d5d8a75071d8e8a39df231b0b98584d1d42982b5cf230e44f94d9c48e2983e78955a54 delete entry? (y/N) delete entry? (y/N) delete entry? (y/N) unable to remove entry (no entities given) +exit status 1 + keys/k/one2 keyx/d/e diff --git a/tests/run.go b/tests/run.go @@ -0,0 +1,114 @@ +// package main runs the tests +package main + +import ( + "bytes" + "fmt" + "os" + "os/exec" + "path/filepath" + "time" +) + +const ( + testDir = "bin" + testKey = "plaintextkey" + binary = "../bin/lb" +) + +func die(message string, err error) { + fmt.Fprintf(os.Stderr, "%s (%v)", message, err) + os.Exit(1) +} + +func runCommand(args []string, data []string) { + p := exec.Command(binary, args...) + var buf bytes.Buffer + for _, d := range data { + if _, err := buf.WriteString(fmt.Sprintf("%s\n", d)); err != nil { + die("failed to write stdin", err) + } + } + p.Stdout = os.Stdout + p.Stderr = os.Stderr + p.Stdin = &buf + if err := p.Run(); err != nil { + fmt.Println(err) + } +} + +func ls() { + runCommand([]string{"ls"}, nil) +} + +func rm(k string) { + runCommand([]string{"rm", k}, []string{"y"}) +} + +func show(k string) { + runCommand([]string{"show", k}, nil) +} + +func insert(k string, d []string) { + runCommand([]string{"insert", k}, d) +} + +func totpList() { + runCommand([]string{"totp", "-list"}, nil) +} + +func main() { + store := filepath.Join(testDir, fmt.Sprintf("%s.kdbx", time.Now().Format("20060102150405"))) + os.Setenv("LOCKBOX_STORE", store) + os.Setenv("LOCKBOX_KEY", testKey) + os.Setenv("LOCKBOX_TOTP", "totp") + os.Setenv("LOCKBOX_INTERACTIVE", "no") + os.Setenv("LOCKBOX_READONLY", "no") + os.Setenv("LOCKBOX_KEYMODE", "plaintext") + insert("keys/k/one2", []string{"test2"}) + for _, k := range []string{"keys/k/one", "key/a/one", "keys/k/one", "keys/k/one/", "/keys/k/one", "keys/aa/b//s///e"} { + insert(k, []string{"test"}) + } + insert("keys2/k/three", []string{"test3", "test4"}) + ls() + rm("keys/k/one") + fmt.Println() + ls() + runCommand([]string{"find", "e"}, nil) + show("keys/k/one2") + show("keys2/k/three") + for _, k := range []string{"test/k", "test/k/totp"} { + runCommand([]string{"insert", "-totp", k}, []string{"5ae472abqdekjqykoyxk7hvc2leklq5n"}) + } + totpList() + insert("test/k/totp", []string{"5ae472abqdekjqykoyxk7hvc2leklq5n"}) + totpList() + runCommand([]string{"totp", "test/k"}, nil) + runCommand([]string{"hash", store}, nil) + rm("keys2/k/three") + fmt.Println() + rm("test/k/totp") + fmt.Println() + rm("test/k/one") + fmt.Println() + fmt.Println() + runCommand([]string{"mv", "key/a/one", "keyx/d/e"}, nil) + ls() + rm("keyx/d/e") + fmt.Println() + ls() + insert("keys/k2/one2", []string{"test2"}) + insert("keys/k2/one", []string{"test"}) + insert("keys/k2/t1/one2", []string{"test2"}) + insert("keys/k2/t1/one", []string{"test"}) + insert("keys/k2/t2/one2", []string{"test2"}) + insert("keys/k2/t2/one", []string{"test"}) + fmt.Println() + ls() + rm("keys/k2/t1/*") + fmt.Println() + ls() + rm("keys/k2/*") + fmt.Println() + ls() +} diff --git a/tests/run.sh b/tests/run.sh @@ -1,65 +0,0 @@ -#!/bin/bash -BIN="$1" -TESTS="$2" - -export LOCKBOX_STORE="$TESTS/lb.kdbx" -export LOCKBOX_KEYMODE="plaintext" -export LOCKBOX_KEY="plaintextkey" -export LOCKBOX_TOTP="totp" -export LOCKBOX_INTERACTIVE="no" -export LOCKBOX_READONLY="no" - -rm -rf $TESTS -mkdir -p $TESTS - -_run() { - echo "test2" | "$BIN/lb" insert keys/k/one2 - echo "test" | "$BIN/lb" insert keys/k/one - echo "test" | "$BIN/lb" insert key/a/one - echo "test" | "$BIN/lb" insert keys/k/one - echo "test" | "$BIN/lb" insert keys/k/one/ - echo "test" | "$BIN/lb" insert /keys/k/one - echo "test" | "$BIN/lb" insert keys/aa/b//s///e - echo -e "test3\ntest4" | "$BIN/lb" insert keys2/k/three - "$BIN/lb" ls - yes 2>/dev/null | "$BIN/lb" rm keys/k/one - echo - "$BIN/lb" ls - "$BIN/lb" find e - "$BIN/lb" show keys/k/one2 - "$BIN/lb" show keys2/k/three - echo "5ae472abqdekjqykoyxk7hvc2leklq5n" | "$BIN/lb" insert -totp test/k - echo "5ae472abqdekjqykoyxk7hvc2leklq5n" | "$BIN/lb" insert -totp test/k/totp - "$BIN/lb" "totp" -list - echo "5ae472abqdekjqykoyxk7hvc2leklq5n" | "$BIN/lb" insert test/k/totp - "$BIN/lb" "totp" -list - "$BIN/lb" "totp" test/k | tr '[:digit:]' 'X' - "$BIN/lb" "hash" $LOCKBOX_STORE - yes 2>/dev/null | "$BIN/lb" rm keys2/k/three - echo - yes 2>/dev/null | "$BIN/lb" rm test/k/totp - echo - yes 2>/dev/null | "$BIN/lb" rm test/k/one - echo - "$BIN/lb" mv key/a/one keyx/d/e - "$BIN/lb" ls - yes 2>/dev/null | "$BIN/lb" rm keyx/d/e - echo - "$BIN/lb" ls - echo "test2" | "$BIN/lb" insert keys/k2/one2 - echo "test" | "$BIN/lb" insert keys/k2/one - echo "test2" | "$BIN/lb" insert keys/k2/t1/one2 - echo "test" | "$BIN/lb" insert keys/k2/t1/one - echo "test2" | "$BIN/lb" insert keys/k2/t2/one2 - echo "test" | "$BIN/lb" insert keys/k2/t2/one - echo - "$BIN/lb" ls - yes 2>/dev/null | "$BIN/lb" rm "keys/k2/t1/*" - echo - "$BIN/lb" ls - yes 2>/dev/null | "$BIN/lb" rm "keys/k2/*" - echo - "$BIN/lb" ls -} - -_run 2>&1 | sed "s#$LOCKBOX_STORE##g" > $TESTS/actual.log