mirror of
https://github.com/gopasspw/gopass.git
synced 2026-05-30 11:18:48 +02:00
Increase test coverage (#2461)
RELEASE_NOTES=n/a Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
This commit is contained in:
@@ -53,6 +53,7 @@ linters:
|
||||
- noctx
|
||||
- nolintlint
|
||||
- nosnakecase
|
||||
- paralleltest
|
||||
- revive
|
||||
- rowserrcheck
|
||||
- scopelint
|
||||
|
||||
@@ -97,6 +97,10 @@ fulltest: $(GOPASS_OUTPUT)
|
||||
$(GO) test -run '(Test|Example)' $(BUILDFLAGS) $(TESTFLAGS) -coverprofile=coverage.out -covermode=atomic $(pkg) || exit 1;\
|
||||
tail -n +2 coverage.out >> coverage-all.out;)
|
||||
@$(GO) tool cover -html=coverage-all.out -o coverage-all.html
|
||||
@which go-cover-treemap > /dev/null; if [ $$? -ne 0 ]; then \
|
||||
$(GO) install github.com/nikolaydubina/go-cover-treemap@latest; \
|
||||
fi
|
||||
@go-cover-treemap -coverprofile coverage-all.out > coverage-all.svg
|
||||
|
||||
test: $(GOPASS_OUTPUT)
|
||||
@echo ">> TEST, \"fast-mode\": race detector off"
|
||||
|
||||
@@ -46,10 +46,7 @@ func newMock(ctx context.Context, path string) (*Action, error) {
|
||||
}
|
||||
|
||||
func TestAction(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithInteractive(ctx, false)
|
||||
@@ -72,18 +69,16 @@ func TestAction(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
td := t.TempDir()
|
||||
cfg := config.NewNoWrites()
|
||||
sv := semver.Version{}
|
||||
|
||||
t.Run("init a new store", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("init a new store", func(t *testing.T) {
|
||||
_, err := New(cfg, sv)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("init an existing plain store", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("init an existing plain store", func(t *testing.T) {
|
||||
require.NoError(t, cfg.SetPath(filepath.Join(td, "store")))
|
||||
assert.NoError(t, os.MkdirAll(cfg.Path(), 0o700))
|
||||
assert.NoError(t, os.WriteFile(filepath.Join(cfg.Path(), plain.IDFile), []byte("foobar"), 0o600))
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/gopasspw/gopass/internal/out"
|
||||
"github.com/gopasspw/gopass/pkg/ctxutil"
|
||||
"github.com/gopasspw/gopass/tests/gptest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAliases(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
ctx = ctxutil.WithHidden(ctx, true)
|
||||
act, err := newMock(ctx, u.StoreDir(""))
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, act)
|
||||
ctx = act.cfg.WithConfig(ctx)
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
out.Stdout = buf
|
||||
stdout = buf
|
||||
defer func() {
|
||||
out.Stdout = os.Stdout
|
||||
stdout = os.Stdout
|
||||
}()
|
||||
|
||||
assert.NoError(t, act.AliasesPrint(gptest.CliCtx(ctx, t)))
|
||||
}
|
||||
@@ -14,9 +14,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAudit(t *testing.T) { //nolint:paralleltest
|
||||
func TestAudit(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -34,7 +33,7 @@ func TestAudit(t *testing.T) { //nolint:paralleltest
|
||||
stdout = os.Stdout
|
||||
}()
|
||||
|
||||
t.Run("expect audit complaints on very weak passwords", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("expect audit complaints on very weak passwords", func(t *testing.T) {
|
||||
sec := secrets.NewAKV()
|
||||
sec.SetPassword("123")
|
||||
assert.NoError(t, act.Store.Set(ctx, "bar", sec))
|
||||
@@ -44,13 +43,13 @@ func TestAudit(t *testing.T) { //nolint:paralleltest
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("test with filter and very passwords", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("test with filter and very passwords", func(t *testing.T) {
|
||||
c := gptest.CliCtx(ctx, t, "foo")
|
||||
assert.Error(t, act.Audit(c))
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("test empty store", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("test empty store", func(t *testing.T) {
|
||||
for _, v := range []string{"foo", "bar", "baz"} {
|
||||
assert.NoError(t, act.Store.Delete(ctx, v))
|
||||
}
|
||||
|
||||
@@ -15,9 +15,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestBinary(t *testing.T) { //nolint:paralleltest
|
||||
func TestBinary(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -40,9 +39,8 @@ func TestBinary(t *testing.T) { //nolint:paralleltest
|
||||
assert.Error(t, act.Sum(gptest.CliCtx(ctx, t)))
|
||||
}
|
||||
|
||||
func TestBinaryCat(t *testing.T) { //nolint:paralleltest
|
||||
func TestBinaryCat(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -64,16 +62,16 @@ func TestBinaryCat(t *testing.T) { //nolint:paralleltest
|
||||
infile := filepath.Join(u.Dir, "input.txt")
|
||||
writeBinfile(t, infile)
|
||||
|
||||
t.Run("populate store", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("populate store", func(t *testing.T) {
|
||||
assert.NoError(t, act.binaryCopy(ctx, gptest.CliCtx(ctx, t), infile, "bar", true))
|
||||
})
|
||||
|
||||
t.Run("binary cat bar", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("binary cat bar", func(t *testing.T) {
|
||||
assert.NoError(t, act.Cat(gptest.CliCtx(ctx, t, "bar")))
|
||||
})
|
||||
|
||||
stdinfile := filepath.Join(u.Dir, "stdin")
|
||||
t.Run("binary cat baz from stdin", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("binary cat baz from stdin", func(t *testing.T) {
|
||||
writeBinfile(t, stdinfile)
|
||||
|
||||
fd, err := os.Open(stdinfile)
|
||||
@@ -87,7 +85,7 @@ func TestBinaryCat(t *testing.T) { //nolint:paralleltest
|
||||
assert.NoError(t, act.Cat(gptest.CliCtx(ctx, t, "baz")))
|
||||
})
|
||||
|
||||
t.Run("compare output", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("compare output", func(t *testing.T) {
|
||||
buf, err := os.ReadFile(stdinfile)
|
||||
require.NoError(t, err)
|
||||
sec, err := act.binaryGet(ctx, "baz")
|
||||
@@ -96,9 +94,8 @@ func TestBinaryCat(t *testing.T) { //nolint:paralleltest
|
||||
})
|
||||
}
|
||||
|
||||
func TestBinaryCopy(t *testing.T) { //nolint:paralleltest
|
||||
func TestBinaryCopy(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -115,7 +112,7 @@ func TestBinaryCopy(t *testing.T) { //nolint:paralleltest
|
||||
require.NotNil(t, act)
|
||||
ctx = act.cfg.WithConfig(ctx)
|
||||
|
||||
t.Run("copy textfile", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("copy textfile", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
|
||||
infile := filepath.Join(u.Dir, "input.txt")
|
||||
@@ -125,43 +122,42 @@ func TestBinaryCopy(t *testing.T) { //nolint:paralleltest
|
||||
|
||||
infile := filepath.Join(u.Dir, "input.raw")
|
||||
outfile := filepath.Join(u.Dir, "output.raw")
|
||||
t.Run("copy binary file", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("copy binary file", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
|
||||
writeBinfile(t, infile)
|
||||
assert.NoError(t, act.binaryCopy(ctx, gptest.CliCtx(ctx, t), infile, "bar", true))
|
||||
})
|
||||
|
||||
t.Run("binary copy bar tempdir/bar", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("binary copy bar tempdir/bar", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.BinaryCopy(gptest.CliCtx(ctx, t, "bar", outfile)))
|
||||
})
|
||||
|
||||
t.Run("binary copy tempdir/bar tempdir/bar", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("binary copy tempdir/bar tempdir/bar", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
|
||||
assert.Error(t, act.BinaryCopy(gptest.CliCtx(ctx, t, outfile, outfile)))
|
||||
})
|
||||
|
||||
t.Run("binary copy bar bar", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("binary copy bar bar", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.Error(t, act.BinaryCopy(gptest.CliCtx(ctx, t, "bar", "bar")))
|
||||
})
|
||||
|
||||
t.Run("binary move tempdir/bar bar2", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("binary move tempdir/bar bar2", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.BinaryMove(gptest.CliCtx(ctx, t, outfile, "bar2")))
|
||||
})
|
||||
|
||||
t.Run("binary move bar2 tempdir/bar", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("binary move bar2 tempdir/bar", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.BinaryMove(gptest.CliCtx(ctx, t, "bar2", outfile)))
|
||||
})
|
||||
}
|
||||
|
||||
func TestBinarySum(t *testing.T) { //nolint:paralleltest
|
||||
func TestBinarySum(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -180,20 +176,19 @@ func TestBinarySum(t *testing.T) { //nolint:paralleltest
|
||||
|
||||
infile := filepath.Join(u.Dir, "input.raw")
|
||||
|
||||
t.Run("populate store", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("populate store", func(t *testing.T) {
|
||||
writeBinfile(t, infile)
|
||||
assert.NoError(t, act.binaryCopy(ctx, gptest.CliCtx(ctx, t), infile, "bar", true))
|
||||
})
|
||||
|
||||
t.Run("binary sum bar", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("binary sum bar", func(t *testing.T) {
|
||||
assert.NoError(t, act.Sum(gptest.CliCtx(ctx, t, "bar")))
|
||||
buf.Reset()
|
||||
})
|
||||
}
|
||||
|
||||
func TestBinaryGet(t *testing.T) { //nolint:paralleltest
|
||||
func TestBinaryGet(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
@@ -9,8 +9,6 @@ import (
|
||||
)
|
||||
|
||||
func TestParseArgs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
argIn []string
|
||||
@@ -69,8 +67,6 @@ func TestParseArgs(t *testing.T) {
|
||||
tc := tc
|
||||
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if tc.argOut == nil {
|
||||
tc.argOut = argList{}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/blang/semver/v4"
|
||||
@@ -39,9 +40,8 @@ func aGitRepo(ctx context.Context, t *testing.T, u *gptest.Unit, name string) st
|
||||
return gd
|
||||
}
|
||||
|
||||
func TestClone(t *testing.T) { //nolint:paralleltest
|
||||
func TestClone(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -63,27 +63,26 @@ func TestClone(t *testing.T) { //nolint:paralleltest
|
||||
stdout = os.Stdout
|
||||
}()
|
||||
|
||||
t.Run("no args", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("no args", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
c := gptest.CliCtx(ctx, t)
|
||||
assert.Error(t, act.Clone(c))
|
||||
})
|
||||
|
||||
t.Run("clone to initialized store", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("clone to initialized store", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.Error(t, act.clone(ctx, "/tmp/non-existing-repo.git", "", filepath.Join(u.Dir, "store")))
|
||||
})
|
||||
|
||||
t.Run("clone to mount", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("clone to mount", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
gd := aGitRepo(ctx, t, u, "other-repo")
|
||||
assert.NoError(t, act.clone(ctx, gd, "gd", filepath.Join(u.Dir, "mount")))
|
||||
})
|
||||
}
|
||||
|
||||
func TestCloneBackendIsStoredForMount(t *testing.T) { //nolint:paralleltest
|
||||
func TestCloneBackendIsStoredForMount(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
out.Stdout = buf
|
||||
@@ -118,9 +117,8 @@ func TestCloneBackendIsStoredForMount(t *testing.T) { //nolint:paralleltest
|
||||
require.Contains(t, act.cfg.Mounts(), "the-project")
|
||||
}
|
||||
|
||||
func TestCloneGetGitConfig(t *testing.T) { //nolint:paralleltest
|
||||
func TestCloneGetGitConfig(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
r1 := gptest.UnsetVars(termio.NameVars...)
|
||||
defer r1()
|
||||
@@ -141,3 +139,43 @@ func TestCloneGetGitConfig(t *testing.T) { //nolint:paralleltest
|
||||
assert.Equal(t, "0xDEADBEEF", name)
|
||||
assert.Equal(t, "0xDEADBEEF", email)
|
||||
}
|
||||
|
||||
func TestCloneCheckDecryptionKeys(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
out.Stdout = buf
|
||||
out.Stderr = buf
|
||||
stdout = buf
|
||||
defer func() {
|
||||
out.Stdout = os.Stdout
|
||||
out.Stderr = os.Stderr
|
||||
stdout = os.Stdout
|
||||
}()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
ctx = ctxutil.WithInteractive(ctx, false)
|
||||
|
||||
cfg := config.NewNoWrites()
|
||||
require.NoError(t, cfg.SetPath(u.StoreDir("")))
|
||||
|
||||
act, err := newAction(cfg, semver.Version{}, false)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, act)
|
||||
ctx = act.cfg.WithConfig(ctx)
|
||||
|
||||
c := gptest.CliCtx(ctx, t)
|
||||
require.NoError(t, act.IsInitialized(c))
|
||||
|
||||
repo := aGitRepo(ctx, t, u, "my-project")
|
||||
|
||||
if runtime.GOOS != "linux" {
|
||||
t.Skip("TODO: not working on non-linux builders, yet")
|
||||
}
|
||||
|
||||
c = gptest.CliCtxWithFlags(ctx, t, map[string]string{"check-keys": "true"}, repo, "the-project")
|
||||
assert.NoError(t, act.Clone(c))
|
||||
|
||||
require.Contains(t, act.cfg.Mounts(), "the-project")
|
||||
}
|
||||
|
||||
@@ -38,10 +38,7 @@ func testCommand(t *testing.T, cmd *cli.Command) {
|
||||
}
|
||||
|
||||
func TestCommands(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithInteractive(ctx, false)
|
||||
@@ -53,8 +50,6 @@ func TestCommands(t *testing.T) {
|
||||
for _, cmd := range act.GetCommands() {
|
||||
cmd := cmd
|
||||
t.Run(cmd.Name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCommand(t, cmd)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -15,11 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func TestBashEscape(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("bash escape", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
expected := `a\\<\\>\\|\\\\and\\ sometimes\\?\\*\\(\\)\\&\\;\\#`
|
||||
if escaped := bashEscape(`a<>|\and sometimes?*()&;#`); escaped != expected {
|
||||
t.Errorf("Expected %q, but got %q", expected, escaped)
|
||||
@@ -27,8 +23,6 @@ func TestBashEscape(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("bash escape single quote", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
expected := `good\\ ol\'\\ days`
|
||||
if escaped := bashEscape(`good ol' days`); escaped != expected {
|
||||
t.Errorf("Expected %q, but got %q", expected, escaped)
|
||||
@@ -36,8 +30,6 @@ func TestBashEscape(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("bash escape double quote", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
expected := `my\\ \\\"bad\\\"\\ password`
|
||||
if escaped := bashEscape(`my "bad" password`); escaped != expected {
|
||||
t.Errorf("Expected %q, but got %q", expected, escaped)
|
||||
@@ -45,9 +37,8 @@ func TestBashEscape(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestComplete(t *testing.T) { //nolint:paralleltest
|
||||
func TestComplete(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
out.Stdout = buf
|
||||
@@ -72,21 +63,21 @@ func TestComplete(t *testing.T) { //nolint:paralleltest
|
||||
},
|
||||
}
|
||||
|
||||
t.Run("complete foo", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("complete foo", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
|
||||
act.Complete(gptest.CliCtx(ctx, t))
|
||||
assert.Equal(t, "foo\n", buf.String())
|
||||
})
|
||||
|
||||
t.Run("bash completion", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("bash completion", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
|
||||
assert.NoError(t, act.CompletionBash(nil))
|
||||
assert.Contains(t, buf.String(), "action.test")
|
||||
})
|
||||
|
||||
t.Run("fish completion", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("fish completion", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
|
||||
assert.NoError(t, act.CompletionFish(app))
|
||||
@@ -94,7 +85,7 @@ func TestComplete(t *testing.T) { //nolint:paralleltest
|
||||
assert.Error(t, act.CompletionFish(nil))
|
||||
})
|
||||
|
||||
t.Run("zsh completion", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("zsh completion", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
|
||||
assert.NoError(t, act.CompletionZSH(app))
|
||||
@@ -102,7 +93,7 @@ func TestComplete(t *testing.T) { //nolint:paralleltest
|
||||
assert.Error(t, act.CompletionZSH(nil))
|
||||
})
|
||||
|
||||
t.Run("openbsdksh completion", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("openbsdksh completion", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
|
||||
assert.NoError(t, act.CompletionOpenBSDKsh(app))
|
||||
|
||||
@@ -14,9 +14,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestConfig(t *testing.T) { //nolint:paralleltest
|
||||
func TestConfig(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithInteractive(ctx, false)
|
||||
@@ -33,7 +32,7 @@ func TestConfig(t *testing.T) { //nolint:paralleltest
|
||||
stdout = os.Stdout
|
||||
}()
|
||||
|
||||
t.Run("display config", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("display config", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
|
||||
c := gptest.CliCtx(ctx, t)
|
||||
@@ -50,7 +49,7 @@ core.notifications = true
|
||||
assert.Equal(t, want, buf.String())
|
||||
})
|
||||
|
||||
t.Run("set valid config value", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("set valid config value", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
|
||||
assert.NoError(t, act.setConfigValue(ctx, "", "core.nopager", "true"))
|
||||
@@ -59,13 +58,13 @@ core.notifications = true
|
||||
assert.Equal(t, "true", strings.TrimSpace(buf.String()), "action.setConfigValue")
|
||||
})
|
||||
|
||||
t.Run("set invalid config value", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("set invalid config value", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
|
||||
assert.Error(t, act.setConfigValue(ctx, "", "foobar", "true"))
|
||||
})
|
||||
|
||||
t.Run("print single config value", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("print single config value", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
|
||||
act.printConfigValues(ctx, "", "core.nopager")
|
||||
@@ -74,7 +73,7 @@ core.notifications = true
|
||||
assert.Equal(t, want, strings.TrimSpace(buf.String()), "action.printConfigValues")
|
||||
})
|
||||
|
||||
t.Run("print all config values", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("print all config values", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
|
||||
act.printConfigValues(ctx, "")
|
||||
@@ -90,7 +89,7 @@ core.notifications = true
|
||||
assert.Equal(t, want, strings.TrimSpace(buf.String()), "action.printConfigValues")
|
||||
})
|
||||
|
||||
t.Run("show autoimport value", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("show autoimport value", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
|
||||
c := gptest.CliCtx(ctx, t, "core.autoimport")
|
||||
@@ -98,7 +97,7 @@ core.notifications = true
|
||||
assert.Equal(t, "true", strings.TrimSpace(buf.String()))
|
||||
})
|
||||
|
||||
t.Run("disable autoimport", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("disable autoimport", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
|
||||
c := gptest.CliCtx(ctx, t, "core.autoimport", "false")
|
||||
@@ -106,7 +105,7 @@ core.notifications = true
|
||||
assert.Equal(t, "false", strings.TrimSpace(buf.String()))
|
||||
})
|
||||
|
||||
t.Run("complete config items", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("complete config items", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
|
||||
act.ConfigComplete(gptest.CliCtx(ctx, t))
|
||||
@@ -122,7 +121,7 @@ mounts.path
|
||||
assert.Equal(t, want, buf.String())
|
||||
})
|
||||
|
||||
t.Run("set autoimport to invalid value", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("set autoimport to invalid value", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
|
||||
c := gptest.CliCtx(ctx, t, "autoimport", "false", "42")
|
||||
|
||||
@@ -8,8 +8,6 @@ import (
|
||||
)
|
||||
|
||||
func TestWithClip(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
if IsClip(ctx) {
|
||||
@@ -22,8 +20,6 @@ func TestWithClip(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithPasswordOnly(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
if IsPasswordOnly(ctx) {
|
||||
@@ -36,8 +32,6 @@ func TestWithPasswordOnly(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithPrintQR(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
assert.False(t, IsPrintQR(ctx))
|
||||
@@ -45,8 +39,6 @@ func TestWithPrintQR(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithRevision(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
assert.Equal(t, "", GetRevision(ctx))
|
||||
@@ -56,8 +48,6 @@ func TestWithRevision(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithKey(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
assert.Equal(t, "", GetKey(ctx))
|
||||
@@ -65,8 +55,6 @@ func TestWithKey(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithOnlyClip(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
assert.False(t, IsOnlyClip(ctx))
|
||||
@@ -74,8 +62,6 @@ func TestWithOnlyClip(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithAlsoClip(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
assert.False(t, IsAlsoClip(ctx))
|
||||
|
||||
@@ -75,7 +75,7 @@ func (s *Action) Convert(c *cli.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ok {
|
||||
if ctxutil.IsInteractive(ctx) && !ok {
|
||||
out.Notice(ctx, "Aborted")
|
||||
|
||||
return nil
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/gopasspw/gopass/internal/out"
|
||||
"github.com/gopasspw/gopass/pkg/ctxutil"
|
||||
"github.com/gopasspw/gopass/pkg/gopass/secrets"
|
||||
"github.com/gopasspw/gopass/tests/gptest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestConvert(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
ctx = ctxutil.WithTerminal(ctx, false)
|
||||
ctx = ctxutil.WithInteractive(ctx, false)
|
||||
ctx = ctxutil.WithPasswordCallback(ctx, func(s string, b bool) ([]byte, error) {
|
||||
return []byte("foo"), nil
|
||||
})
|
||||
ctx = ctxutil.WithPasswordPurgeCallback(ctx, func(s string) {})
|
||||
|
||||
act, err := newMock(ctx, u.StoreDir(""))
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, act)
|
||||
ctx = act.cfg.WithConfig(ctx)
|
||||
|
||||
color.NoColor = true
|
||||
buf := &bytes.Buffer{}
|
||||
out.Stdout = buf
|
||||
stdout = buf
|
||||
defer func() {
|
||||
stdout = os.Stdout
|
||||
out.Stdout = os.Stdout
|
||||
}()
|
||||
|
||||
// first add another entry in a subdir
|
||||
sec := secrets.NewAKV()
|
||||
sec.SetPassword("123")
|
||||
assert.NoError(t, sec.Set("bar", "zab"))
|
||||
assert.NoError(t, act.Store.Set(ctx, "bar/baz", sec))
|
||||
buf.Reset()
|
||||
|
||||
assert.NoError(t, act.Convert(gptest.CliCtxWithFlags(ctx, t, map[string]string{
|
||||
"move": "true",
|
||||
"storage": "fs",
|
||||
"crypto": "age",
|
||||
})))
|
||||
// TODO: validate converted store. t.Logf("Buffer: %s", buf.String()).
|
||||
}
|
||||
@@ -15,9 +15,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCopy(t *testing.T) { //nolint:paralleltest
|
||||
func TestCopy(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithInteractive(ctx, false)
|
||||
@@ -94,13 +93,12 @@ func TestCopy(t *testing.T) { //nolint:paralleltest
|
||||
buf.Reset()
|
||||
}
|
||||
|
||||
func TestCopyGpg(t *testing.T) { //nolint:paralleltest
|
||||
func TestCopyGpg(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode.")
|
||||
}
|
||||
|
||||
u := gptest.NewGUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithInteractive(ctx, false)
|
||||
|
||||
@@ -14,9 +14,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCreate(t *testing.T) { //nolint:paralleltest
|
||||
func TestCreate(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
aclip.Unsupported = true
|
||||
|
||||
|
||||
@@ -14,9 +14,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestDelete(t *testing.T) { //nolint:paralleltest
|
||||
func TestDelete(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
@@ -13,9 +13,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestEdit(t *testing.T) { //nolint:paralleltest
|
||||
func TestEdit(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -44,9 +43,8 @@ func TestEdit(t *testing.T) { //nolint:paralleltest
|
||||
buf.Reset()
|
||||
}
|
||||
|
||||
func TestEditUpdate(t *testing.T) { //nolint:paralleltest
|
||||
func TestEditUpdate(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
@@ -16,9 +16,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestEnvLeafHappyPath(t *testing.T) { //nolint:paralleltest
|
||||
func TestEnvLeafHappyPath(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -49,9 +48,8 @@ func TestEnvLeafHappyPath(t *testing.T) { //nolint:paralleltest
|
||||
assert.Contains(t, buf.String(), fmt.Sprintf("BAZ=%s\n", pw))
|
||||
}
|
||||
|
||||
func TestEnvLeafHappyPathKeepCase(t *testing.T) { //nolint:paralleltest
|
||||
func TestEnvLeafHappyPathKeepCase(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -85,9 +83,8 @@ func TestEnvLeafHappyPathKeepCase(t *testing.T) { //nolint:paralleltest
|
||||
assert.Contains(t, buf.String(), fmt.Sprintf("BaZ=%s\n", pw))
|
||||
}
|
||||
|
||||
func TestEnvSecretNotFound(t *testing.T) { //nolint:paralleltest
|
||||
func TestEnvSecretNotFound(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -102,9 +99,8 @@ func TestEnvSecretNotFound(t *testing.T) { //nolint:paralleltest
|
||||
"Secret non-existing not found")
|
||||
}
|
||||
|
||||
func TestEnvProgramNotFound(t *testing.T) { //nolint:paralleltest
|
||||
func TestEnvProgramNotFound(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -127,9 +123,8 @@ func TestEnvProgramNotFound(t *testing.T) { //nolint:paralleltest
|
||||
}
|
||||
|
||||
// Crash regression.
|
||||
func TestEnvProgramNotSpecified(t *testing.T) { //nolint:paralleltest
|
||||
func TestEnvProgramNotSpecified(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestError(t *testing.T) { //nolint:paralleltest
|
||||
func TestError(t *testing.T) {
|
||||
buf := &bytes.Buffer{}
|
||||
out.Stdout = buf
|
||||
defer func() {
|
||||
|
||||
@@ -19,9 +19,8 @@ import (
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func TestFind(t *testing.T) { //nolint:paralleltest
|
||||
func TestFind(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithTerminal(ctx, false)
|
||||
|
||||
@@ -17,9 +17,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestFsck(t *testing.T) { //nolint:paralleltest
|
||||
func TestFsck(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithTerminal(ctx, false)
|
||||
@@ -73,13 +72,12 @@ func TestFsck(t *testing.T) { //nolint:paralleltest
|
||||
buf.Reset()
|
||||
}
|
||||
|
||||
func TestFsckGpg(t *testing.T) { //nolint:paralleltest
|
||||
func TestFsckGpg(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode.")
|
||||
}
|
||||
|
||||
u := gptest.NewGUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithTerminal(ctx, false)
|
||||
|
||||
@@ -21,15 +21,12 @@ import (
|
||||
)
|
||||
|
||||
func TestRuleLookup(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
domain, _ := hasPwRuleForSecret(context.Background(), "foo/gopass.pw")
|
||||
assert.Equal(t, "", domain)
|
||||
}
|
||||
|
||||
func TestGenerate(t *testing.T) { //nolint:paralleltest
|
||||
func TestGenerate(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -52,13 +49,13 @@ func TestGenerate(t *testing.T) { //nolint:paralleltest
|
||||
color.NoColor = true
|
||||
|
||||
// generate
|
||||
t.Run("generate", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("generate", func(t *testing.T) {
|
||||
assert.Error(t, act.Generate(gptest.CliCtx(ctx, t)))
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
// generate foobar
|
||||
t.Run("generate foobar", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("generate foobar", func(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode.")
|
||||
}
|
||||
@@ -69,7 +66,7 @@ func TestGenerate(t *testing.T) { //nolint:paralleltest
|
||||
|
||||
// generate foobar
|
||||
// should succeed because of always yes
|
||||
t.Run("generate foobar again", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("generate foobar again", func(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode.")
|
||||
}
|
||||
@@ -79,7 +76,7 @@ func TestGenerate(t *testing.T) { //nolint:paralleltest
|
||||
})
|
||||
|
||||
// generate --edit foobar
|
||||
t.Run("generate --edit foobar", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("generate --edit foobar", func(t *testing.T) {
|
||||
if testing.Short() || runtime.GOOS == "windows" {
|
||||
t.Skip("skipping test in short mode.")
|
||||
}
|
||||
@@ -89,7 +86,7 @@ func TestGenerate(t *testing.T) { //nolint:paralleltest
|
||||
})
|
||||
|
||||
// generate --force foobar
|
||||
t.Run("generate --force foobar", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("generate --force foobar", func(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode.")
|
||||
}
|
||||
@@ -99,7 +96,7 @@ func TestGenerate(t *testing.T) { //nolint:paralleltest
|
||||
})
|
||||
|
||||
// generate --force foobar 32
|
||||
t.Run("generate --force foobar 32", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("generate --force foobar 32", func(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode.")
|
||||
}
|
||||
@@ -109,7 +106,7 @@ func TestGenerate(t *testing.T) { //nolint:paralleltest
|
||||
})
|
||||
|
||||
// generate --force --symbols foobar 32
|
||||
t.Run("generate --force --symbols foobar 32", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("generate --force --symbols foobar 32", func(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode.")
|
||||
}
|
||||
@@ -120,7 +117,7 @@ func TestGenerate(t *testing.T) { //nolint:paralleltest
|
||||
})
|
||||
|
||||
// generate --force --symbols=false foobar 32
|
||||
t.Run("generate --force --symbols=False foobar 32", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("generate --force --symbols=False foobar 32", func(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode.")
|
||||
}
|
||||
@@ -131,31 +128,31 @@ func TestGenerate(t *testing.T) { //nolint:paralleltest
|
||||
})
|
||||
|
||||
// generate --force --xkcd foobar 32
|
||||
t.Run("generate --force --xkcd foobar 32", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("generate --force --xkcd foobar 32", func(t *testing.T) {
|
||||
assert.NoError(t, act.Generate(gptest.CliCtxWithFlags(ctx, t, map[string]string{"force": "true", "xkcd": "true", "lang": "en"}, "foobar", "32")))
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
// generate --force --xkcd foobar baz 32
|
||||
t.Run("generate --force --xkcd foobar baz 32", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("generate --force --xkcd foobar baz 32", func(t *testing.T) {
|
||||
assert.NoError(t, act.Generate(gptest.CliCtxWithFlags(ctx, t, map[string]string{"force": "true", "xkcd": "true", "lang": "en"}, "foobar", "baz", "32")))
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
// generate --force --xkcd foobar baz
|
||||
t.Run("generate --force --xkcd foobar baz", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("generate --force --xkcd foobar baz", func(t *testing.T) {
|
||||
assert.NoError(t, act.Generate(gptest.CliCtxWithFlags(ctx, t, map[string]string{"force": "true", "xkcd": "true", "lang": "en"}, "foobar", "baz")))
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
// generate --force --xkcd --print foobar baz
|
||||
t.Run("generate --force --xkcd --print foobar baz", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("generate --force --xkcd --print foobar baz", func(t *testing.T) {
|
||||
assert.NoError(t, act.Generate(gptest.CliCtxWithFlags(ctx, t, map[string]string{"force": "true", "xkcd": "true", "print": "true", "lang": "en"}, "foobar", "baz")))
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
// generate --force foobar 24 w/ autoclip and output redirection
|
||||
t.Run("generate --force foobar 24", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("generate --force foobar 24", func(t *testing.T) {
|
||||
ov := act.cfg.Get("core.autoclip")
|
||||
defer func() {
|
||||
require.NoError(t, act.cfg.Set("", "core.autoclip", ov))
|
||||
@@ -168,7 +165,7 @@ func TestGenerate(t *testing.T) { //nolint:paralleltest
|
||||
})
|
||||
|
||||
// generate --force foobar 24 w/ autoclip and no output redirection
|
||||
t.Run("generate --force foobar 24", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("generate --force foobar 24", func(t *testing.T) {
|
||||
ov := act.cfg.Get("core.autoclip")
|
||||
defer func() {
|
||||
require.NoError(t, act.cfg.Set("", "core.autoclip", ov))
|
||||
@@ -181,7 +178,7 @@ func TestGenerate(t *testing.T) { //nolint:paralleltest
|
||||
})
|
||||
|
||||
// generate --force foobar w/ pw length set via env variable (42 chars)
|
||||
t.Run("generate --force foobar", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("generate --force foobar", func(t *testing.T) {
|
||||
t.Setenv("GOPASS_PW_DEFAULT_LENGTH", "42")
|
||||
|
||||
assert.NoError(t, act.Generate(gptest.CliCtxWithFlags(ctx, t, map[string]string{"force": "true", "print": "true", "symbols": "false"}, "foobar")))
|
||||
@@ -191,7 +188,7 @@ func TestGenerate(t *testing.T) { //nolint:paralleltest
|
||||
})
|
||||
|
||||
// generate --force foobar w/ pw length set via env variable to invalid value, fallback mechanism
|
||||
t.Run("generate --force foobar", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("generate --force foobar", func(t *testing.T) {
|
||||
t.Setenv("GOPASS_PW_DEFAULT_LENGTH", "0")
|
||||
|
||||
if testing.Short() {
|
||||
@@ -220,9 +217,7 @@ func passIsAlphaNum(t *testing.T, buf string, want bool) {
|
||||
}
|
||||
|
||||
func TestKeyAndLength(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
for _, tc := range []struct { //nolint:paralleltest
|
||||
for _, tc := range []struct {
|
||||
in []string
|
||||
key string
|
||||
length string
|
||||
@@ -251,8 +246,6 @@ func TestKeyAndLength(t *testing.T) {
|
||||
tc := tc
|
||||
|
||||
t.Run(fmt.Sprintf("%v", tc.in), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
app := cli.NewApp()
|
||||
fs := flag.NewFlagSet("default", flag.ContinueOnError)
|
||||
assert.NoError(t, fs.Parse(append([]string{"foobar"}, tc.in...)))
|
||||
@@ -266,9 +259,7 @@ func TestKeyAndLength(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExtractEmails(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
for _, tc := range []struct { //nolint:paralleltest
|
||||
for _, tc := range []struct {
|
||||
in []string
|
||||
out []string
|
||||
}{
|
||||
@@ -282,17 +273,13 @@ func TestExtractEmails(t *testing.T) {
|
||||
} {
|
||||
tc := tc
|
||||
t.Run(fmt.Sprintf("%v", tc.in), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert.Equal(t, tc.out, extractEmails(tc.in))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractDomains(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
for _, tc := range []struct { //nolint:paralleltest
|
||||
for _, tc := range []struct {
|
||||
in []string
|
||||
out []string
|
||||
}{
|
||||
@@ -306,17 +293,13 @@ func TestExtractDomains(t *testing.T) {
|
||||
} {
|
||||
tc := tc
|
||||
t.Run(fmt.Sprintf("%v", tc.in), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert.Equal(t, tc.out, extractDomains(tc.in))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUniq(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
for _, tc := range []struct { //nolint:paralleltest
|
||||
for _, tc := range []struct {
|
||||
in []string
|
||||
out []string
|
||||
}{
|
||||
@@ -330,17 +313,13 @@ func TestUniq(t *testing.T) {
|
||||
} {
|
||||
tc := tc
|
||||
t.Run(fmt.Sprintf("%v", tc.in), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert.Equal(t, tc.out, uniq(tc.in))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterPrefix(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
for _, tc := range []struct { //nolint:paralleltest
|
||||
for _, tc := range []struct {
|
||||
in []string
|
||||
prefix string
|
||||
out []string
|
||||
@@ -361,8 +340,6 @@ func TestFilterPrefix(t *testing.T) {
|
||||
} {
|
||||
tc := tc
|
||||
t.Run(fmt.Sprintf("%v", tc.in), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert.Equal(t, tc.out, filterPrefix(tc.in, tc.prefix))
|
||||
})
|
||||
}
|
||||
@@ -370,19 +347,19 @@ func TestFilterPrefix(t *testing.T) {
|
||||
|
||||
// NOTE: Do not use t.Parallel because environment variables are being used
|
||||
// which can leak into other tests that run in parallel.
|
||||
func TestDefaultLengthFromEnv(t *testing.T) { //nolint:paralleltest
|
||||
func TestDefaultLengthFromEnv(t *testing.T) {
|
||||
const pwLengthEnvName = "GOPASS_PW_DEFAULT_LENGTH"
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("use default value if no environment variable is set", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("use default value if no environment variable is set", func(t *testing.T) {
|
||||
actual, isCustom := defaultLengthFromEnv(ctx)
|
||||
expected := defaultLength
|
||||
assert.Equal(t, actual, expected)
|
||||
assert.False(t, isCustom)
|
||||
})
|
||||
|
||||
t.Run("interpretetion of various inputs for environment variable", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("interpretetion of various inputs for environment variable", func(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
in string
|
||||
expected int
|
||||
|
||||
@@ -14,9 +14,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGrep(t *testing.T) { //nolint:paralleltest
|
||||
func TestGrep(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -33,12 +32,12 @@ func TestGrep(t *testing.T) { //nolint:paralleltest
|
||||
}()
|
||||
|
||||
c := gptest.CliCtx(ctx, t, "foo")
|
||||
t.Run("empty store", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("empty store", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.Grep(c))
|
||||
})
|
||||
|
||||
t.Run("add some secret", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("add some secret", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
sec := secrets.NewAKV()
|
||||
sec.SetPassword("foobar")
|
||||
@@ -47,12 +46,12 @@ func TestGrep(t *testing.T) { //nolint:paralleltest
|
||||
assert.NoError(t, act.Store.Set(ctx, "foo", sec))
|
||||
})
|
||||
|
||||
t.Run("should find existing", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("should find existing", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.Grep(c))
|
||||
})
|
||||
|
||||
t.Run("RE2", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("RE2", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
c := gptest.CliCtxWithFlags(ctx, t, map[string]string{"regexp": "true"}, "f..bar")
|
||||
assert.NoError(t, act.Grep(c))
|
||||
|
||||
@@ -17,9 +17,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestHistory(t *testing.T) { //nolint:paralleltest
|
||||
func TestHistory(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
r1 := gptest.UnsetVars(termio.NameVars...)
|
||||
r2 := gptest.UnsetVars(termio.EmailVars...)
|
||||
@@ -41,7 +40,7 @@ func TestHistory(t *testing.T) { //nolint:paralleltest
|
||||
require.NotNil(t, act)
|
||||
ctx = act.cfg.WithConfig(ctx)
|
||||
|
||||
t.Run("can initialize", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("can initialize", func(t *testing.T) {
|
||||
require.NoError(t, act.IsInitialized(gptest.CliCtx(ctx, t)))
|
||||
})
|
||||
|
||||
@@ -51,23 +50,23 @@ func TestHistory(t *testing.T) { //nolint:paralleltest
|
||||
out.Stdout = os.Stdout
|
||||
}()
|
||||
|
||||
t.Run("init git", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("init git", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
require.NoError(t, act.rcsInit(ctx, "", "foo bar", "foo.bar@example.org"))
|
||||
t.Logf("init git: %s", buf.String())
|
||||
})
|
||||
|
||||
t.Run("insert bar", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("insert bar", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.Insert(gptest.CliCtx(ctx, t, "bar")))
|
||||
})
|
||||
|
||||
t.Run("history bar", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("history bar", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.History(gptest.CliCtx(ctx, t, "bar")))
|
||||
})
|
||||
|
||||
t.Run("history --password bar", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("history --password bar", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.History(gptest.CliCtxWithFlags(ctx, t, map[string]string{"password": "true"}, "bar")))
|
||||
})
|
||||
|
||||
@@ -17,9 +17,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestInit(t *testing.T) { //nolint:paralleltest
|
||||
func TestInit(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -62,7 +61,7 @@ func TestInit(t *testing.T) { //nolint:paralleltest
|
||||
buf.Reset()
|
||||
}
|
||||
|
||||
func TestInitParseContext(t *testing.T) { //nolint:paralleltest
|
||||
func TestInitParseContext(t *testing.T) {
|
||||
buf := &bytes.Buffer{}
|
||||
out.Stdout = buf
|
||||
out.Stderr = buf
|
||||
@@ -101,8 +100,6 @@ func TestInitParseContext(t *testing.T) { //nolint:paralleltest
|
||||
tc := tc
|
||||
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
c := gptest.CliCtxWithFlags(context.Background(), t, tc.flags)
|
||||
assert.NoError(t, tc.check(initParseContext(c.Context, c)), tc.name)
|
||||
buf.Reset()
|
||||
|
||||
@@ -14,9 +14,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestInsert(t *testing.T) { //nolint:paralleltest
|
||||
func TestInsert(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -36,17 +35,17 @@ func TestInsert(t *testing.T) { //nolint:paralleltest
|
||||
out.Stdout = os.Stdout
|
||||
}()
|
||||
|
||||
t.Run("insert bar", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("insert bar", func(t *testing.T) {
|
||||
assert.NoError(t, act.Insert(gptest.CliCtx(ctx, t, "bar")))
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("insert bar baz", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("insert bar baz", func(t *testing.T) {
|
||||
assert.NoError(t, act.Insert(gptest.CliCtx(ctx, t, "bar", "baz")))
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("insert baz via stdin w/o newline", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("insert baz via stdin w/o newline", func(t *testing.T) {
|
||||
assert.NoError(t, act.insertStdin(ctx, "baz", []byte("foobar"), false))
|
||||
buf.Reset()
|
||||
|
||||
@@ -55,7 +54,7 @@ func TestInsert(t *testing.T) { //nolint:paralleltest
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("insert baz via stdin w/ newline", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("insert baz via stdin w/ newline", func(t *testing.T) {
|
||||
assert.NoError(t, act.insertStdin(ctx, "baz", []byte("foobar\n"), false))
|
||||
buf.Reset()
|
||||
|
||||
@@ -64,7 +63,7 @@ func TestInsert(t *testing.T) { //nolint:paralleltest
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("insert baz via stdin w/ yaml", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("insert baz via stdin w/ yaml", func(t *testing.T) {
|
||||
assert.NoError(t, act.insertStdin(ctx, "baz", []byte("foobar\n---\nuser: name\nother: meh"), false))
|
||||
buf.Reset()
|
||||
|
||||
@@ -73,7 +72,7 @@ func TestInsert(t *testing.T) { //nolint:paralleltest
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("insert baz via stdin w/ k-v", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("insert baz via stdin w/ k-v", func(t *testing.T) {
|
||||
in := "foobar\ninvalid key-value\nOther: meh\nUser: name\nbody text\n"
|
||||
assert.NoError(t, act.insertStdin(ctx, "baz", []byte(in), false))
|
||||
buf.Reset()
|
||||
@@ -83,7 +82,7 @@ func TestInsert(t *testing.T) { //nolint:paralleltest
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("insert zab#key", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("insert zab#key", func(t *testing.T) {
|
||||
ctx = ctxutil.WithInteractive(ctx, false)
|
||||
require.NoError(t, act.cfg.Set("", "core.showsafecontent", "true"))
|
||||
assert.NoError(t, act.insertYAML(ctx, "zabkey", "key", []byte("foobar"), nil))
|
||||
@@ -92,19 +91,19 @@ func TestInsert(t *testing.T) { //nolint:paralleltest
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("insert --multiline bar baz", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("insert --multiline bar baz", func(t *testing.T) {
|
||||
assert.NoError(t, act.Insert(gptest.CliCtxWithFlags(ctx, t, map[string]string{"multiline": "true"}, "bar", "baz")))
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("insert key:value", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("insert key:value", func(t *testing.T) {
|
||||
assert.NoError(t, act.Insert(gptest.CliCtxWithFlags(ctx, t, nil, "keyvaltest", "baz:val")))
|
||||
assert.NoError(t, act.show(ctx, gptest.CliCtx(ctx, t), "keyvaltest", false))
|
||||
assert.Contains(t, buf.String(), "baz: val")
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("insert baz via stdin w/ yaml and input parsing and safecontent", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("insert baz via stdin w/ yaml and input parsing and safecontent", func(t *testing.T) {
|
||||
assert.NoError(t, act.insertStdin(ctx, "baz", []byte("foobar\n---\nuser: name\nother: 0123"), false))
|
||||
buf.Reset()
|
||||
|
||||
@@ -113,7 +112,7 @@ func TestInsert(t *testing.T) { //nolint:paralleltest
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("insert baz via stdin w/ yaml", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("insert baz via stdin w/ yaml", func(t *testing.T) {
|
||||
require.NoError(t, act.cfg.Set("", "core.showsafecontent", "false"))
|
||||
assert.NoError(t, act.insertStdin(ctx, "baz", []byte("foobar\n---\nuser: name\nother: 0123"), false))
|
||||
buf.Reset()
|
||||
@@ -124,9 +123,8 @@ func TestInsert(t *testing.T) { //nolint:paralleltest
|
||||
})
|
||||
}
|
||||
|
||||
func TestInsertStdin(t *testing.T) { //nolint:paralleltest
|
||||
func TestInsertStdin(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/gopasspw/gopass/internal/out"
|
||||
"github.com/gopasspw/gopass/pkg/ctxutil"
|
||||
"github.com/gopasspw/gopass/pkg/gopass/secrets"
|
||||
"github.com/gopasspw/gopass/tests/gptest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestLink(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
ctx = ctxutil.WithTerminal(ctx, false)
|
||||
ctx = ctxutil.WithInteractive(ctx, false)
|
||||
|
||||
act, err := newMock(ctx, u.StoreDir(""))
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, act)
|
||||
ctx = act.cfg.WithConfig(ctx)
|
||||
|
||||
color.NoColor = true
|
||||
buf := &bytes.Buffer{}
|
||||
out.Stdout = buf
|
||||
stdout = buf
|
||||
defer func() {
|
||||
stdout = os.Stdout
|
||||
out.Stdout = os.Stdout
|
||||
}()
|
||||
|
||||
// first add another entry in a subdir
|
||||
sec := secrets.NewAKV()
|
||||
sec.SetPassword("123")
|
||||
assert.NoError(t, sec.Set("bar", "zab"))
|
||||
assert.NoError(t, act.Store.Set(ctx, "bar/baz", sec))
|
||||
buf.Reset()
|
||||
|
||||
assert.NoError(t, act.Link(gptest.CliCtx(ctx, t, "bar/baz", "other/linkdest")))
|
||||
|
||||
// original secret should be equal to the linkdest
|
||||
oSec, err := act.Store.Get(ctx, "bar/baz")
|
||||
require.NoError(t, err)
|
||||
|
||||
lSec, err := act.Store.Get(ctx, "other/linkdest")
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, oSec.Bytes(), lSec.Bytes())
|
||||
|
||||
// update the original, linkdest should still be the same
|
||||
oSec.SetPassword("456")
|
||||
assert.NoError(t, act.Store.Set(ctx, "bar/baz", sec))
|
||||
buf.Reset()
|
||||
|
||||
oSec, err = act.Store.Get(ctx, "bar/baz")
|
||||
require.NoError(t, err)
|
||||
|
||||
lSec, err = act.Store.Get(ctx, "other/linkdest")
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, oSec.Bytes(), lSec.Bytes())
|
||||
}
|
||||
@@ -17,9 +17,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestList(t *testing.T) { //nolint:paralleltest
|
||||
func TestList(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -117,9 +116,8 @@ foo2/bar2
|
||||
buf.Reset()
|
||||
}
|
||||
|
||||
func TestListLimit(t *testing.T) { //nolint:paralleltest
|
||||
func TestListLimit(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -152,7 +150,7 @@ func TestListLimit(t *testing.T) { //nolint:paralleltest
|
||||
assert.Equal(t, want, buf.String())
|
||||
buf.Reset()
|
||||
|
||||
t.Run("folders-limit-0", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("folders-limit-0", func(t *testing.T) {
|
||||
assert.NoError(t, act.List(gptest.CliCtxWithFlags(ctx, t, map[string]string{"folders": "true", "limit": "0"})))
|
||||
want = `foo/
|
||||
foo2/
|
||||
@@ -161,7 +159,7 @@ foo2/
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("folders-limit-1", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("folders-limit-1", func(t *testing.T) {
|
||||
assert.NoError(t, act.List(gptest.CliCtxWithFlags(ctx, t, map[string]string{"folders": "true", "limit": "1"})))
|
||||
want = `foo/
|
||||
foo/zen/
|
||||
@@ -171,7 +169,7 @@ foo2/
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("folders-limit--1", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("folders-limit--1", func(t *testing.T) {
|
||||
assert.NoError(t, act.List(gptest.CliCtxWithFlags(ctx, t, map[string]string{"folders": "true", "limit": "-1"})))
|
||||
want = `foo/
|
||||
foo/zen/
|
||||
@@ -182,7 +180,7 @@ foo2/
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("flat-limit--1", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("flat-limit--1", func(t *testing.T) {
|
||||
assert.NoError(t, act.List(gptest.CliCtxWithFlags(ctx, t, map[string]string{"flat": "true", "limit": "-1"})))
|
||||
want = `foo
|
||||
foo/bar
|
||||
@@ -193,7 +191,7 @@ foo2/bar2
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("folders-limit-0", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("folders-limit-0", func(t *testing.T) {
|
||||
assert.NoError(t, act.List(gptest.CliCtxWithFlags(ctx, t, map[string]string{"flat": "true", "limit": "0"})))
|
||||
want = `foo
|
||||
foo2/
|
||||
@@ -202,7 +200,7 @@ foo2/
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("folders-limit-2", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("folders-limit-2", func(t *testing.T) {
|
||||
assert.NoError(t, act.List(gptest.CliCtxWithFlags(ctx, t, map[string]string{"flat": "true", "limit": "2"})))
|
||||
want = `foo
|
||||
foo/bar
|
||||
@@ -215,7 +213,7 @@ foo2/bar2
|
||||
})
|
||||
}
|
||||
|
||||
func TestRedirectPager(t *testing.T) { //nolint:paralleltest
|
||||
func TestRedirectPager(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
var buf *bytes.Buffer
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/gopasspw/gopass/internal/out"
|
||||
"github.com/gopasspw/gopass/pkg/ctxutil"
|
||||
"github.com/gopasspw/gopass/pkg/gopass"
|
||||
"github.com/gopasspw/gopass/pkg/gopass/secrets"
|
||||
"github.com/gopasspw/gopass/tests/gptest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestMerge(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
ctx = ctxutil.WithTerminal(ctx, false)
|
||||
ctx = ctxutil.WithInteractive(ctx, false)
|
||||
|
||||
act, err := newMock(ctx, u.StoreDir(""))
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, act)
|
||||
ctx = act.cfg.WithConfig(ctx)
|
||||
|
||||
color.NoColor = true
|
||||
buf := &bytes.Buffer{}
|
||||
out.Stdout = buf
|
||||
stdout = buf
|
||||
defer func() {
|
||||
stdout = os.Stdout
|
||||
out.Stdout = os.Stdout
|
||||
}()
|
||||
|
||||
// first add two entries
|
||||
var sec gopass.Secret
|
||||
sec = secrets.NewAKV()
|
||||
sec.SetPassword("123")
|
||||
assert.NoError(t, sec.Set("bar", "zab"))
|
||||
assert.NoError(t, act.Store.Set(ctx, "bar/baz", sec))
|
||||
buf.Reset()
|
||||
|
||||
sec = secrets.NewAKV()
|
||||
sec.SetPassword("456")
|
||||
assert.NoError(t, sec.Set("bar", "baz"))
|
||||
assert.NoError(t, act.Store.Set(ctx, "bar/zab", sec))
|
||||
buf.Reset()
|
||||
|
||||
assert.NoError(t, act.Merge(gptest.CliCtxWithFlags(ctx, t, map[string]string{"force": "true"}, "bar/baz", "bar/zab")))
|
||||
|
||||
sec, err = act.Store.Get(ctx, "bar/baz")
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "\n# Secret: bar/baz\n123\nbar: zab\n\n# Secret: bar/zab\n456\nbar: baz\n", string(sec.Bytes()))
|
||||
}
|
||||
@@ -14,9 +14,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestMounts(t *testing.T) { //nolint:paralleltest
|
||||
func TestMounts(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -36,33 +35,33 @@ func TestMounts(t *testing.T) { //nolint:paralleltest
|
||||
stdout = os.Stdout
|
||||
}()
|
||||
|
||||
t.Run("print mounts", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("print mounts", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.MountsPrint(gptest.CliCtx(ctx, t)))
|
||||
})
|
||||
|
||||
t.Run("complete mounts", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("complete mounts", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
act.MountsComplete(gptest.CliCtx(ctx, t))
|
||||
assert.Equal(t, buf.String(), "")
|
||||
})
|
||||
|
||||
t.Run("remove no non-existing mount", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("remove no non-existing mount", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.Error(t, act.MountRemove(gptest.CliCtx(ctx, t)))
|
||||
})
|
||||
|
||||
t.Run("remove non-existing mount", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("remove non-existing mount", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.MountRemove(gptest.CliCtx(ctx, t, "foo")))
|
||||
})
|
||||
|
||||
t.Run("add non-existing mount", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("add non-existing mount", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.Error(t, act.MountAdd(gptest.CliCtx(ctx, t, "foo", filepath.Join(u.Dir, "mount1"))))
|
||||
})
|
||||
|
||||
t.Run("add some mounts", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("add some mounts", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, u.InitStore("mount1"))
|
||||
assert.NoError(t, u.InitStore("mount2"))
|
||||
@@ -70,7 +69,7 @@ func TestMounts(t *testing.T) { //nolint:paralleltest
|
||||
assert.NoError(t, act.Store.AddMount(ctx, "mount2", u.StoreDir("mount2")))
|
||||
})
|
||||
|
||||
t.Run("print mounts", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("print mounts", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.MountsPrint(gptest.CliCtx(ctx, t)))
|
||||
})
|
||||
|
||||
@@ -13,9 +13,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestMove(t *testing.T) { //nolint:paralleltest
|
||||
func TestMove(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
@@ -16,9 +16,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestOTP(t *testing.T) { //nolint:paralleltest
|
||||
func TestOTP(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -35,12 +34,12 @@ func TestOTP(t *testing.T) { //nolint:paralleltest
|
||||
out.Stdout = os.Stdout
|
||||
}()
|
||||
|
||||
t.Run("display non-otp secret", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("display non-otp secret", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.Error(t, act.OTP(gptest.CliCtx(ctx, t, "foo")))
|
||||
})
|
||||
|
||||
t.Run("create and display valid OTP", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("create and display valid OTP", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
sec := secrets.NewAKV()
|
||||
sec.SetPassword("foo")
|
||||
@@ -51,12 +50,12 @@ func TestOTP(t *testing.T) { //nolint:paralleltest
|
||||
assert.NoError(t, act.OTP(gptest.CliCtx(ctx, t, "bar")))
|
||||
})
|
||||
|
||||
t.Run("copy to clipboard", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("copy to clipboard", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.otp(ctx, "bar", "", true, false, false))
|
||||
})
|
||||
|
||||
t.Run("write QR file", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("write QR file", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
fn := filepath.Join(u.Dir, "qr.png")
|
||||
assert.NoError(t, act.OTP(gptest.CliCtxWithFlags(ctx, t, map[string]string{"qr": fn}, "bar")))
|
||||
|
||||
@@ -16,9 +16,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestProcess(t *testing.T) { //nolint:paralleltest
|
||||
func TestProcess(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
@@ -35,10 +35,9 @@ func testCommand(t *testing.T, cmd *cli.Command) {
|
||||
}
|
||||
|
||||
func TestCommands(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
// necessary for setting up the env
|
||||
u := gptest.NewGUnitTester(t)
|
||||
assert.NotNil(t, u)
|
||||
|
||||
for _, cmd := range GetCommands() {
|
||||
testCommand(t, cmd)
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
package pwgen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/gopasspw/gopass/internal/action/exit"
|
||||
"github.com/gopasspw/gopass/internal/out"
|
||||
"github.com/gopasspw/gopass/pkg/pwgen"
|
||||
"github.com/gopasspw/gopass/pkg/pwgen/xkcdgen"
|
||||
"github.com/urfave/cli/v2"
|
||||
@@ -52,18 +52,22 @@ func xkcdGen(c *cli.Context, num int) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(s)
|
||||
out.Print(c.Context, s)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func pwGen(c *cli.Context, pwLen, pwNum int) error {
|
||||
ctx := c.Context
|
||||
|
||||
perLine := numPerLine(pwLen)
|
||||
if c.Bool("one-per-line") {
|
||||
perLine = 1
|
||||
}
|
||||
|
||||
charset := pwgen.CharAlphaNum
|
||||
|
||||
switch {
|
||||
case c.Bool("no-numerals") && c.Bool("no-capitalize"):
|
||||
charset = pwgen.Lower
|
||||
@@ -72,18 +76,22 @@ func pwGen(c *cli.Context, pwLen, pwNum int) error {
|
||||
case c.Bool("no-capitalize"):
|
||||
charset = pwgen.Digits + pwgen.Lower
|
||||
}
|
||||
|
||||
if c.Bool("ambiguous") {
|
||||
charset = pwgen.Prune(charset, pwgen.Ambiq)
|
||||
}
|
||||
|
||||
if c.Bool("symbols") {
|
||||
charset += pwgen.Syms
|
||||
}
|
||||
|
||||
for i := 0; i < pwNum; i++ {
|
||||
for j := 0; j < perLine; j++ {
|
||||
fmt.Print(pwgen.GeneratePasswordCharset(pwLen, charset))
|
||||
fmt.Print(" ")
|
||||
ctx := out.WithNewline(ctx, false)
|
||||
out.Print(ctx, pwgen.GeneratePasswordCharset(pwLen, charset))
|
||||
out.Print(ctx, " ")
|
||||
}
|
||||
fmt.Println()
|
||||
out.Print(ctx, "")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package pwgen
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/gopasspw/gopass/internal/out"
|
||||
"github.com/gopasspw/gopass/pkg/ctxutil"
|
||||
"github.com/gopasspw/gopass/tests/gptest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPwgen(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
assert.NotNil(t, u)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
out.Stdout = buf
|
||||
defer func() {
|
||||
out.Stdout = os.Stdout
|
||||
}()
|
||||
|
||||
assert.NoError(t, Pwgen(gptest.CliCtxWithFlags(ctx, t, map[string]string{"one-per-line": "true"}, "24", "1")))
|
||||
assert.True(t, len(buf.Bytes()) >= 24, string(buf.Bytes()))
|
||||
}
|
||||
@@ -13,9 +13,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGit(t *testing.T) { //nolint:paralleltest
|
||||
func TestGit(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
@@ -15,9 +15,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestRecipients(t *testing.T) { //nolint:paralleltest
|
||||
func TestRecipients(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -39,7 +38,7 @@ func TestRecipients(t *testing.T) { //nolint:paralleltest
|
||||
stdout = os.Stdout
|
||||
}()
|
||||
|
||||
t.Run("print recipients tree", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("print recipients tree", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.RecipientsPrint(gptest.CliCtx(ctx, t)))
|
||||
|
||||
@@ -51,46 +50,45 @@ func TestRecipients(t *testing.T) { //nolint:paralleltest
|
||||
assert.Contains(t, buf.String(), want)
|
||||
})
|
||||
|
||||
t.Run("complete recipients", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("complete recipients", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
act.RecipientsComplete(gptest.CliCtx(ctx, t))
|
||||
want := "0xDEADBEEF\n"
|
||||
assert.Equal(t, want, buf.String())
|
||||
})
|
||||
|
||||
t.Run("add recipients w/o args", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("add recipients w/o args", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.Error(t, act.RecipientsAdd(gptest.CliCtx(ctx, t)))
|
||||
})
|
||||
|
||||
t.Run("remove recipients w/o args", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("remove recipients w/o args", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.Error(t, act.RecipientsRemove(gptest.CliCtx(ctx, t)))
|
||||
})
|
||||
|
||||
t.Run("add recipient 0xFEEDBEEF", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("add recipient 0xFEEDBEEF", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.RecipientsAdd(gptest.CliCtx(ctx, t, "0xFEEDBEEF")))
|
||||
})
|
||||
|
||||
t.Run("add recipient 0xBEEFFEED", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("add recipient 0xBEEFFEED", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.RecipientsAdd(gptest.CliCtx(ctx, t, "0xBEEFFEED")))
|
||||
})
|
||||
|
||||
t.Run("remove recipient 0xDEADBEEF", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("remove recipient 0xDEADBEEF", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.RecipientsRemove(gptest.CliCtx(ctx, t, "0xDEADBEEF")))
|
||||
})
|
||||
}
|
||||
|
||||
func TestRecipientsGpg(t *testing.T) { //nolint:paralleltest
|
||||
func TestRecipientsGpg(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode.")
|
||||
}
|
||||
|
||||
u := gptest.NewGUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -113,7 +111,7 @@ func TestRecipientsGpg(t *testing.T) { //nolint:paralleltest
|
||||
stdout = os.Stdout
|
||||
}()
|
||||
|
||||
t.Run("print recipients tree", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("print recipients tree", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.RecipientsPrint(gptest.CliCtx(ctx, t)))
|
||||
|
||||
@@ -125,44 +123,44 @@ func TestRecipientsGpg(t *testing.T) { //nolint:paralleltest
|
||||
assert.Contains(t, buf.String(), want)
|
||||
})
|
||||
|
||||
t.Run("complete recipients", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("complete recipients", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
act.RecipientsComplete(gptest.CliCtx(ctx, t))
|
||||
want := "0x82EBD945BE73F104\n"
|
||||
assert.Equal(t, want, buf.String())
|
||||
})
|
||||
|
||||
t.Run("add recipients w/o args", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("add recipients w/o args", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.Error(t, act.RecipientsAdd(gptest.CliCtx(ctx, t)))
|
||||
})
|
||||
|
||||
t.Run("remove recipients w/o args", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("remove recipients w/o args", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.Error(t, act.RecipientsRemove(gptest.CliCtx(ctx, t)))
|
||||
})
|
||||
|
||||
t.Run("add recipient 0xFEEDBEEF", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("add recipient 0xFEEDBEEF", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.RecipientsAdd(gptest.CliCtx(ctx, t, "0xFEEDBEEF")))
|
||||
})
|
||||
|
||||
t.Run("add recipient 0xBEEFFEED", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("add recipient 0xBEEFFEED", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.RecipientsAdd(gptest.CliCtx(ctx, t, "0xBEEFFEED")))
|
||||
})
|
||||
|
||||
t.Run("remove recipient 0x82EBD945BE73F104", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("remove recipient 0x82EBD945BE73F104", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.RecipientsRemove(gptest.CliCtx(ctx, t, "0x82EBD945BE73F104")))
|
||||
})
|
||||
|
||||
t.Run("add recipient 0xFEEDFEED", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("add recipient 0xFEEDFEED", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.RecipientsAdd(gptest.CliCtxWithFlags(ctx, t, map[string]string{"force": "true"}, "0xFEEDFEED")))
|
||||
})
|
||||
|
||||
t.Run("remove recipient 0xFEEDFEED", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("remove recipient 0xFEEDFEED", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.Error(t, act.RecipientsRemove(gptest.CliCtx(ctx, t, "0xFEEDFEED")))
|
||||
assert.NoError(t, act.RecipientsRemove(gptest.CliCtxWithFlags(ctx, t, map[string]string{"force": "true"}, "0xFEEDFEED")))
|
||||
|
||||
@@ -153,6 +153,15 @@ func (s *Action) initGenerateIdentity(ctx context.Context, crypto backend.Crypto
|
||||
passphrase = sv
|
||||
}
|
||||
|
||||
// support fully automated setup (e.g. for tests)
|
||||
if !ctxutil.IsInteractive(ctx) && ctxutil.HasPasswordCallback(ctx) {
|
||||
pw, err := ctxutil.GetPasswordCallback(ctx)("", true)
|
||||
if err == nil {
|
||||
passphrase = string(pw)
|
||||
}
|
||||
pwGenerated = false
|
||||
}
|
||||
|
||||
if crypto.Name() == "gpgcli" {
|
||||
// Note: This issue shouldn't matter much past Linux Kernel 5.6,
|
||||
// eventually we might want to remove this notice. Only applies to
|
||||
@@ -167,7 +176,7 @@ func (s *Action) initGenerateIdentity(ctx context.Context, crypto backend.Crypto
|
||||
return fmt.Errorf("failed to create new private key: %w", err)
|
||||
}
|
||||
|
||||
out.OKf(ctx, "Key pair generated")
|
||||
out.OKf(ctx, "Key pair for %s generated", crypto.Name())
|
||||
|
||||
if pwGenerated {
|
||||
out.Printf(ctx, color.MagentaString("Passphrase: ")+passphrase)
|
||||
@@ -194,7 +203,7 @@ func (s *Action) initGenerateIdentity(ctx context.Context, crypto backend.Crypto
|
||||
if err := s.initExportPublicKey(ctx, crypto, kl[0]); err != nil {
|
||||
return err
|
||||
}
|
||||
out.OKf(ctx, "Key pair validated")
|
||||
out.OKf(ctx, "Key pair %s validated", kl[0])
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/gopasspw/gopass/internal/backend"
|
||||
"github.com/gopasspw/gopass/internal/backend/crypto/plain"
|
||||
"github.com/gopasspw/gopass/internal/out"
|
||||
"github.com/gopasspw/gopass/pkg/ctxutil"
|
||||
"github.com/gopasspw/gopass/tests/gptest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSetupAgeGitFS(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
ctx = ctxutil.WithInteractive(ctx, false)
|
||||
ctx = backend.WithCryptoBackend(ctx, backend.Age)
|
||||
ctx = backend.WithStorageBackend(ctx, backend.GitFS)
|
||||
ctx = ctxutil.WithPasswordCallback(ctx, func(_ string, _ bool) ([]byte, error) {
|
||||
return []byte("foobar"), nil
|
||||
})
|
||||
ctx = ctxutil.WithPasswordPurgeCallback(ctx, func(s string) {})
|
||||
|
||||
t.Skip("TODO: fix setup test")
|
||||
|
||||
act, err := newMock(ctx, u.StoreDir(""))
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, act)
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
out.Stdout = buf
|
||||
out.Stderr = buf
|
||||
defer func() {
|
||||
out.Stdout = os.Stdout
|
||||
out.Stderr = os.Stderr
|
||||
}()
|
||||
|
||||
// remove existing config and store, we want to start fresh
|
||||
assert.NoError(t, os.RemoveAll(u.StoreDir("")))
|
||||
assert.NoError(t, os.Remove(u.GPConfig()))
|
||||
|
||||
c := gptest.CliCtxWithFlags(ctx, t, map[string]string{"storage": "gitfs", "crypto": "age"})
|
||||
assert.Error(t, act.IsInitialized(c))
|
||||
assert.NoError(t, act.Setup(c))
|
||||
assert.Contains(t, buf.String(), "Welcome to gopass")
|
||||
|
||||
crypto := act.Store.Crypto(ctx, "")
|
||||
require.NotNil(t, crypto)
|
||||
assert.Equal(t, "age", crypto.Name())
|
||||
assert.True(t, act.initHasUseablePrivateKeys(ctx, crypto))
|
||||
assert.Error(t, act.initGenerateIdentity(ctx, crypto, "foo bar", "foo.bar@example.org"))
|
||||
buf.Reset()
|
||||
|
||||
act.printRecipients(ctx, "")
|
||||
assert.Contains(t, buf.String(), "0xDEADBEEF")
|
||||
buf.Reset()
|
||||
}
|
||||
|
||||
func TestSetupPlainFS(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
ctx = ctxutil.WithInteractive(ctx, false)
|
||||
ctx = backend.WithCryptoBackend(ctx, backend.Plain)
|
||||
ctx = backend.WithStorageBackend(ctx, backend.FS)
|
||||
|
||||
act, err := newMock(ctx, u.StoreDir(""))
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, act)
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
out.Stdout = buf
|
||||
out.Stderr = buf
|
||||
defer func() {
|
||||
out.Stdout = os.Stdout
|
||||
out.Stderr = os.Stderr
|
||||
}()
|
||||
|
||||
c := gptest.CliCtx(ctx, t, "foo.bar@example.org")
|
||||
assert.NoError(t, act.IsInitialized(c))
|
||||
buf.Reset()
|
||||
|
||||
t.Skip("TODO: fix these tests")
|
||||
|
||||
assert.Error(t, act.Init(c))
|
||||
assert.Contains(t, buf.String(), "already initialized")
|
||||
buf.Reset()
|
||||
|
||||
// this will abort because the store is already initialized
|
||||
assert.NoError(t, act.Setup(c))
|
||||
assert.Contains(t, buf.String(), "already initialized")
|
||||
buf.Reset()
|
||||
|
||||
crypto := act.Store.Crypto(ctx, "")
|
||||
require.NotNil(t, crypto)
|
||||
assert.Equal(t, "plain", crypto.Name())
|
||||
assert.True(t, act.initHasUseablePrivateKeys(ctx, crypto))
|
||||
assert.Error(t, act.initGenerateIdentity(ctx, crypto, "foo bar", "foo.bar@example.org"))
|
||||
buf.Reset()
|
||||
|
||||
act.printRecipients(ctx, "")
|
||||
assert.Contains(t, buf.String(), "0xDEADBEEF")
|
||||
buf.Reset()
|
||||
|
||||
// un-initialize the store
|
||||
assert.NoError(t, os.Remove(filepath.Join(u.StoreDir(""), plain.IDFile)))
|
||||
assert.Error(t, act.IsInitialized(c))
|
||||
buf.Reset()
|
||||
|
||||
// remove existing config and store
|
||||
assert.NoError(t, os.RemoveAll(u.StoreDir("")))
|
||||
assert.NoError(t, os.Remove(u.GPConfig()))
|
||||
|
||||
// re-initialize the store, i.e. test that a fresh setup with plain and fs works
|
||||
assert.NoError(t, act.Setup(c))
|
||||
assert.Contains(t, buf.String(), "Welcome to gopass")
|
||||
buf.Reset()
|
||||
}
|
||||
@@ -17,9 +17,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestShowMulti(t *testing.T) { //nolint:paralleltest
|
||||
func TestShowMulti(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -47,21 +46,21 @@ func TestShowMulti(t *testing.T) { //nolint:paralleltest
|
||||
assert.NoError(t, act.Store.Set(ctx, "bar/baz", sec))
|
||||
buf.Reset()
|
||||
|
||||
t.Run("show foo", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("show foo", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
c := gptest.CliCtx(ctx, t, "foo")
|
||||
assert.NoError(t, act.Show(c))
|
||||
assert.Contains(t, buf.String(), "secret")
|
||||
})
|
||||
|
||||
t.Run("show --sync foo", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("show --sync foo", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
c := gptest.CliCtxWithFlags(ctx, t, map[string]string{"sync": "true"}, "foo")
|
||||
assert.NoError(t, act.Show(c))
|
||||
assert.Contains(t, buf.String(), "secret")
|
||||
})
|
||||
|
||||
t.Run("show dir", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("show dir", func(t *testing.T) {
|
||||
c := gptest.CliCtx(ctx, t, "bar")
|
||||
assert.NoError(t, act.Show(c))
|
||||
assert.Equal(t, "bar/\n└── baz\n\n", buf.String())
|
||||
@@ -70,7 +69,7 @@ func TestShowMulti(t *testing.T) { //nolint:paralleltest
|
||||
|
||||
require.NoError(t, act.cfg.Set("", "core.showsafecontent", "true"))
|
||||
|
||||
t.Run("show twoliner with safecontent enabled", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("show twoliner with safecontent enabled", func(t *testing.T) {
|
||||
c := gptest.CliCtx(ctx, t, "bar/baz")
|
||||
|
||||
assert.NoError(t, act.Show(c))
|
||||
@@ -80,21 +79,21 @@ func TestShowMulti(t *testing.T) { //nolint:paralleltest
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("show foo with safecontent enabled, should error out", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("show foo with safecontent enabled, should error out", func(t *testing.T) {
|
||||
c := gptest.CliCtx(ctx, t, "foo")
|
||||
assert.NoError(t, act.Show(c))
|
||||
assert.NotContains(t, buf.String(), "secret")
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("show foo with safecontent enabled, with the force flag", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("show foo with safecontent enabled, with the force flag", func(t *testing.T) {
|
||||
c := gptest.CliCtxWithFlags(ctx, t, map[string]string{"unsafe": "true"}, "foo")
|
||||
assert.NoError(t, act.Show(c))
|
||||
assert.Contains(t, buf.String(), "secret")
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("show twoliner with safecontent enabled, but with the clip flag, which should copy just the secret", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("show twoliner with safecontent enabled, but with the clip flag, which should copy just the secret", func(t *testing.T) {
|
||||
c := gptest.CliCtxWithFlags(ctx, t, map[string]string{"clip": "true"}, "bar/baz")
|
||||
|
||||
assert.NoError(t, act.Show(c))
|
||||
@@ -102,7 +101,7 @@ func TestShowMulti(t *testing.T) { //nolint:paralleltest
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("show entry with unsafe keys", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("show entry with unsafe keys", func(t *testing.T) {
|
||||
sec := secrets.NewAKV()
|
||||
sec.SetPassword("123")
|
||||
assert.NoError(t, sec.Set("bar", "zab"))
|
||||
@@ -120,7 +119,7 @@ func TestShowMulti(t *testing.T) { //nolint:paralleltest
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("show twoliner with safecontent enabled", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("show twoliner with safecontent enabled", func(t *testing.T) {
|
||||
c := gptest.CliCtx(ctx, t, "bar/baz")
|
||||
|
||||
assert.NoError(t, act.Show(c))
|
||||
@@ -130,7 +129,7 @@ func TestShowMulti(t *testing.T) { //nolint:paralleltest
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("show twoliner with safecontent enabled", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("show twoliner with safecontent enabled", func(t *testing.T) {
|
||||
c := gptest.CliCtx(ctx, t, "bar/baz")
|
||||
|
||||
assert.NoError(t, act.Show(c))
|
||||
@@ -143,7 +142,7 @@ func TestShowMulti(t *testing.T) { //nolint:paralleltest
|
||||
|
||||
require.NoError(t, act.cfg.Set("", "core.showsafecontent", "false"))
|
||||
|
||||
t.Run("show key ", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("show key ", func(t *testing.T) {
|
||||
c := gptest.CliCtx(ctx, t, "bar/baz", "bar")
|
||||
|
||||
assert.NoError(t, act.Show(c))
|
||||
@@ -151,14 +150,14 @@ func TestShowMulti(t *testing.T) { //nolint:paralleltest
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("show nonexisting key", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("show nonexisting key", func(t *testing.T) {
|
||||
c := gptest.CliCtx(ctx, t, "bar/baz", "nonexisting")
|
||||
|
||||
assert.Error(t, act.Show(c))
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("show keys with mixed case", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("show keys with mixed case", func(t *testing.T) {
|
||||
assert.NoError(t, act.insertStdin(ctx, "baz2", []byte("foobar\nOther: meh\nuser: name\nbody text"), false))
|
||||
buf.Reset()
|
||||
|
||||
@@ -168,7 +167,7 @@ func TestShowMulti(t *testing.T) { //nolint:paralleltest
|
||||
buf.Reset()
|
||||
})
|
||||
|
||||
t.Run("show value with format strings", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("show value with format strings", func(t *testing.T) {
|
||||
pw := "some-chars-are-odd-%s-%p-%q"
|
||||
|
||||
assert.NoError(t, act.insertStdin(ctx, "printf", []byte(pw), false))
|
||||
@@ -182,7 +181,7 @@ func TestShowMulti(t *testing.T) { //nolint:paralleltest
|
||||
})
|
||||
}
|
||||
|
||||
func TestShowAutoClip(t *testing.T) { //nolint:paralleltest
|
||||
func TestShowAutoClip(t *testing.T) {
|
||||
// make sure we consistently get the unsupported error message
|
||||
ov := clipboard.Unsupported
|
||||
defer func() {
|
||||
@@ -191,7 +190,6 @@ func TestShowAutoClip(t *testing.T) { //nolint:paralleltest
|
||||
clipboard.Unsupported = true
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -223,7 +221,7 @@ func TestShowAutoClip(t *testing.T) { //nolint:paralleltest
|
||||
// -> w/o terminal
|
||||
// -> Print password
|
||||
// for use in scripts
|
||||
t.Run("gopass show foo", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("gopass show foo", func(t *testing.T) {
|
||||
// terminal=false
|
||||
ctx = ctxutil.WithTerminal(ctx, false)
|
||||
// initialize context with config values, also detects if we're running in a terminal
|
||||
@@ -239,7 +237,7 @@ func TestShowAutoClip(t *testing.T) { //nolint:paralleltest
|
||||
|
||||
// gopass show -c foo
|
||||
// -> Copy to clipboard
|
||||
t.Run("gopass show -c foo", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("gopass show -c foo", func(t *testing.T) {
|
||||
c := gptest.CliCtxWithFlags(ctx, t, map[string]string{"clip": "true"}, "foo")
|
||||
assert.NoError(t, act.Show(c))
|
||||
assert.Contains(t, stderrBuf.String(), "WARNING")
|
||||
@@ -250,7 +248,7 @@ func TestShowAutoClip(t *testing.T) { //nolint:paralleltest
|
||||
|
||||
// gopass show -C foo
|
||||
// -> Copy to clipboard AND print
|
||||
t.Run("gopass show -C foo", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("gopass show -C foo", func(t *testing.T) {
|
||||
c := gptest.CliCtxWithFlags(ctx, t, map[string]string{"alsoclip": "true"}, "foo")
|
||||
assert.NoError(t, act.Show(c))
|
||||
assert.Contains(t, stderrBuf.String(), "WARNING")
|
||||
@@ -262,7 +260,7 @@ func TestShowAutoClip(t *testing.T) { //nolint:paralleltest
|
||||
|
||||
// gopass show -f foo
|
||||
// -> ONLY print
|
||||
t.Run("gopass show -f foo", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("gopass show -f foo", func(t *testing.T) {
|
||||
c := gptest.CliCtxWithFlags(ctx, t, map[string]string{"unsafe": "true"}, "foo")
|
||||
assert.NoError(t, act.Show(c))
|
||||
assert.NotContains(t, stderrBuf.String(), "WARNING")
|
||||
@@ -274,7 +272,7 @@ func TestShowAutoClip(t *testing.T) { //nolint:paralleltest
|
||||
|
||||
// gopass show foo
|
||||
// -> Copy to clipboard
|
||||
t.Run("gopass show foo", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("gopass show foo", func(t *testing.T) {
|
||||
c := gptest.CliCtx(ctx, t, "foo")
|
||||
assert.NoError(t, act.Show(c))
|
||||
assert.NotContains(t, stderrBuf.String(), "WARNING")
|
||||
@@ -285,7 +283,7 @@ func TestShowAutoClip(t *testing.T) { //nolint:paralleltest
|
||||
|
||||
// gopass show -c foo
|
||||
// -> Copy to clipboard
|
||||
t.Run("gopass show -c foo", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("gopass show -c foo", func(t *testing.T) {
|
||||
c := gptest.CliCtxWithFlags(ctx, t, map[string]string{"clip": "true"}, "foo")
|
||||
assert.NoError(t, act.Show(c))
|
||||
assert.Contains(t, stderrBuf.String(), "WARNING")
|
||||
@@ -296,7 +294,7 @@ func TestShowAutoClip(t *testing.T) { //nolint:paralleltest
|
||||
|
||||
// gopass show -C foo
|
||||
// -> Copy to clipboard AND print
|
||||
t.Run("gopass show -C foo", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("gopass show -C foo", func(t *testing.T) {
|
||||
c := gptest.CliCtxWithFlags(ctx, t, map[string]string{"alsoclip": "true"}, "foo")
|
||||
assert.NoError(t, act.Show(c))
|
||||
assert.Contains(t, stderrBuf.String(), "WARNING")
|
||||
@@ -308,7 +306,7 @@ func TestShowAutoClip(t *testing.T) { //nolint:paralleltest
|
||||
|
||||
// gopass show -f foo
|
||||
// -> ONLY Print
|
||||
t.Run("gopass show -f foo", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("gopass show -f foo", func(t *testing.T) {
|
||||
c := gptest.CliCtxWithFlags(ctx, t, map[string]string{"unsafe": "true"}, "foo")
|
||||
assert.NoError(t, act.Show(c))
|
||||
assert.NotContains(t, stderrBuf.String(), "WARNING")
|
||||
@@ -319,9 +317,8 @@ func TestShowAutoClip(t *testing.T) { //nolint:paralleltest
|
||||
})
|
||||
}
|
||||
|
||||
func TestShowHandleRevision(t *testing.T) { //nolint:paralleltest
|
||||
func TestShowHandleRevision(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -349,9 +346,8 @@ func TestShowHandleRevision(t *testing.T) { //nolint:paralleltest
|
||||
})
|
||||
}
|
||||
|
||||
func TestShowHandleError(t *testing.T) { //nolint:paralleltest
|
||||
func TestShowHandleError(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -376,9 +372,8 @@ func TestShowHandleError(t *testing.T) { //nolint:paralleltest
|
||||
buf.Reset()
|
||||
}
|
||||
|
||||
func TestShowPrintQR(t *testing.T) { //nolint:paralleltest
|
||||
func TestShowPrintQR(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -403,9 +398,8 @@ func TestShowPrintQR(t *testing.T) { //nolint:paralleltest
|
||||
buf.Reset()
|
||||
}
|
||||
|
||||
func TestShowHasAliasDomain(t *testing.T) { //nolint:paralleltest
|
||||
func TestShowHasAliasDomain(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
@@ -13,9 +13,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSync(t *testing.T) { //nolint:paralleltest
|
||||
func TestSync(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
out.Stdout = buf
|
||||
@@ -32,12 +31,12 @@ func TestSync(t *testing.T) { //nolint:paralleltest
|
||||
require.NotNil(t, act)
|
||||
ctx = act.cfg.WithConfig(ctx)
|
||||
|
||||
t.Run("default", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("default", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.Sync(gptest.CliCtx(ctx, t)))
|
||||
})
|
||||
|
||||
t.Run("sync --store=root", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("sync --store=root", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.Sync(gptest.CliCtxWithFlags(ctx, t, map[string]string{"store": "root"})))
|
||||
})
|
||||
|
||||
@@ -16,9 +16,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestTemplates(t *testing.T) { //nolint:paralleltest
|
||||
func TestTemplates(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -38,13 +37,13 @@ func TestTemplates(t *testing.T) { //nolint:paralleltest
|
||||
out.Stdout = os.Stdout
|
||||
}()
|
||||
|
||||
t.Run("display empty template tree", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("display empty template tree", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.TemplatesPrint(gptest.CliCtx(ctx, t, "foo")))
|
||||
assert.Equal(t, "gopass\n\n", buf.String())
|
||||
})
|
||||
|
||||
t.Run("add template", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("add template", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.Store.SetTemplate(ctx, "foo", []byte("foobar")))
|
||||
assert.NoError(t, act.TemplatesPrint(gptest.CliCtx(ctx, t, "foo")))
|
||||
@@ -55,24 +54,24 @@ func TestTemplates(t *testing.T) { //nolint:paralleltest
|
||||
assert.Contains(t, buf.String(), want)
|
||||
})
|
||||
|
||||
t.Run("complete templates", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("complete templates", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
act.TemplatesComplete(gptest.CliCtx(ctx, t, "foo"))
|
||||
assert.Equal(t, "foo\n", buf.String())
|
||||
})
|
||||
|
||||
t.Run("print template", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("print template", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.TemplatePrint(gptest.CliCtx(ctx, t, "foo")))
|
||||
assert.Equal(t, "foobar\n", buf.String())
|
||||
})
|
||||
|
||||
t.Run("edit template", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("edit template", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.Error(t, act.TemplateEdit(gptest.CliCtx(ctx, t, "foo")))
|
||||
})
|
||||
|
||||
t.Run("remove template", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("remove template", func(t *testing.T) {
|
||||
defer buf.Reset()
|
||||
assert.NoError(t, act.TemplateRemove(gptest.CliCtx(ctx, t, "foo")))
|
||||
})
|
||||
|
||||
@@ -14,9 +14,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestUnclip(t *testing.T) { //nolint:paralleltest
|
||||
func TestUnclip(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
out.Stdout = buf
|
||||
|
||||
@@ -49,12 +49,9 @@ const testUpdateJSON = `{
|
||||
}`
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
updater.UpdateMoveAfterQuit = false
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
@@ -17,10 +17,7 @@ import (
|
||||
)
|
||||
|
||||
func TestVersion(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
@@ -35,17 +35,22 @@ func New(ctx context.Context) (*Age, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rc, err := cache.NewOnDisk("age-identity-recipients", 30*time.Hour)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Age{
|
||||
a := &Age{
|
||||
ghCache: ghc,
|
||||
recpCache: rc,
|
||||
identity: filepath.Join(appdir.UserConfig(), "age", "identities"),
|
||||
askPass: newAskPass(ctx),
|
||||
}, nil
|
||||
}
|
||||
|
||||
debug.Log("age initialized (ghc: %s, recipients: %s, identity: %s)", a.ghCache.String(), a.recpCache.String(), a.identity)
|
||||
|
||||
return a, nil
|
||||
}
|
||||
|
||||
// Initialized returns nil.
|
||||
|
||||
@@ -81,6 +81,7 @@ func (a *Age) encryptFile(ctx context.Context, filename string, plaintext []byte
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
buf, err := a.encrypt(plaintext, id)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -207,11 +207,11 @@ func (a *Age) saveIdentities(ctx context.Context, ids []string, newFile bool) er
|
||||
if err := os.MkdirAll(filepath.Dir(a.identity), 0o700); err != nil {
|
||||
debug.Log("failed to create directory for the keyring at %s: %s", a.identity, err)
|
||||
|
||||
return err
|
||||
return fmt.Errorf("failed to create directory for %s: %w", a.identity, err)
|
||||
}
|
||||
|
||||
if err := a.encryptFile(ctx, a.identity, []byte(strings.Join(ids, "\n")), newFile); err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to write encrypted identity to %s: %w", a.identity, err)
|
||||
}
|
||||
|
||||
debug.Log("saved %d identities to %s", len(ids), a.identity)
|
||||
|
||||
@@ -15,13 +15,14 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestEncryptDecrypt(t *testing.T) { //nolint:paralleltest
|
||||
func TestEncryptDecrypt(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode.")
|
||||
}
|
||||
|
||||
// necessary for setting up the env
|
||||
u := gptest.NewGUnitTester(t)
|
||||
defer u.Remove()
|
||||
assert.NotNil(t, u)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithTerminal(ctx, false)
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGpgOpts(t *testing.T) { //nolint:paralleltest
|
||||
func TestGpgOpts(t *testing.T) {
|
||||
for _, vn := range []string{"GOPASS_GPG_OPTS", "PASSWORD_STORE_GPG_OPTS"} {
|
||||
for in, out := range map[string][]string{
|
||||
"": nil,
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestDetectCrypto(t *testing.T) { //nolint:paralleltest
|
||||
for _, tc := range []struct { //nolint:paralleltest
|
||||
func TestDetectCrypto(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
file string
|
||||
}{
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGitConfig(t *testing.T) { //nolint:paralleltest
|
||||
func TestGitConfig(t *testing.T) {
|
||||
gitdir := filepath.Join(t.TempDir(), "git")
|
||||
require.NoError(t, os.Mkdir(gitdir, 0o755))
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGit(t *testing.T) { //nolint:paralleltest
|
||||
func TestGit(t *testing.T) {
|
||||
td := t.TempDir()
|
||||
|
||||
gitdir := filepath.Join(td, "git")
|
||||
@@ -30,7 +30,7 @@ func TestGit(t *testing.T) { //nolint:paralleltest
|
||||
out.Stdout = os.Stdout
|
||||
}()
|
||||
|
||||
t.Run("init new repo", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("init new repo", func(t *testing.T) {
|
||||
git, err := Init(ctx, gitdir, "Dead Beef", "dead.beef@example.org")
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, git)
|
||||
@@ -50,7 +50,7 @@ func TestGit(t *testing.T) { //nolint:paralleltest
|
||||
assert.Error(t, git.Pull(ctx, "origin", "master"))
|
||||
})
|
||||
|
||||
t.Run("open existing repo", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("open existing repo", func(t *testing.T) {
|
||||
git, err := New(gitdir)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, git)
|
||||
@@ -60,7 +60,7 @@ func TestGit(t *testing.T) { //nolint:paralleltest
|
||||
assert.Error(t, git.RemoveRemote(ctx, "foo"))
|
||||
})
|
||||
|
||||
t.Run("clone existing repo", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("clone existing repo", func(t *testing.T) {
|
||||
git, err := Clone(ctx, gitdir, gitdir2, "", "")
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, git)
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDetectStorage(t *testing.T) { //nolint:paralleltest
|
||||
func TestDetectStorage(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
td := t.TempDir()
|
||||
|
||||
Vendored
+5
@@ -47,6 +47,11 @@ func (o *OnDisk) ensureDir() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// String return the identity of this cache instance.
|
||||
func (o *OnDisk) String() string {
|
||||
return fmt.Sprintf("OnDiskCache(name: %s, ttl: %d, dir: %s)", o.name, o.ttl, o.dir)
|
||||
}
|
||||
|
||||
// Get fetches an entry from the cache.
|
||||
func (o *OnDisk) Get(key string) ([]string, error) {
|
||||
key = fsutil.CleanFilename(key)
|
||||
|
||||
Vendored
+5
@@ -1,6 +1,7 @@
|
||||
package ghssh
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-github/github"
|
||||
@@ -27,3 +28,7 @@ func New() (*Cache, error) {
|
||||
Timeout: 30 * time.Second,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *Cache) String() string {
|
||||
return fmt.Sprintf("Github SSH key cache (OnDisk: %s)", c.disk.String())
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ func newWithOptions(noWrites bool) *Config {
|
||||
// if there is no per-user gitconfig we try to migrate
|
||||
// an existing config. But we will leave it around for
|
||||
// gopass fsck to (optionaly) clean it up.
|
||||
if nm := os.Getenv("GOPASS_CONFIG_NO_MIGRATE"); !gitconfig.HasGlobalConfig() && nm == "" {
|
||||
if nm := os.Getenv("GOPASS_CONFIG_NO_MIGRATE"); !HasGlobalConfig() && nm == "" {
|
||||
if err := migrateConfigs(); err != nil {
|
||||
debug.Log("failed to migrate: %s", err)
|
||||
}
|
||||
@@ -92,6 +92,11 @@ func newWithOptions(noWrites bool) *Config {
|
||||
return c
|
||||
}
|
||||
|
||||
// HasGlobalConfig returns true if there is an existing global config.
|
||||
func HasGlobalConfig() bool {
|
||||
return newGitconfig().HasGlobalConfig()
|
||||
}
|
||||
|
||||
// IsSet returns true if the key is set in the root config.
|
||||
func (c *Config) IsSet(key string) bool {
|
||||
return c.root.IsSet(key)
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestConfig(t *testing.T) { //nolint:paralleltest
|
||||
func TestConfig(t *testing.T) {
|
||||
td := t.TempDir()
|
||||
t.Setenv("GOPASS_HOMEDIR", td)
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewConfig(t *testing.T) { //nolint:paralleltest
|
||||
func TestNewConfig(t *testing.T) {
|
||||
assert.NoError(t, os.Setenv("GOPASS_CONFIG", filepath.Join(os.TempDir(), ".gopass.yml")))
|
||||
|
||||
cfg := legacy.New()
|
||||
@@ -30,7 +30,7 @@ func TestNewConfig(t *testing.T) { //nolint:paralleltest
|
||||
assert.Contains(t, cs, `SafeContent:false, Mounts:map[string]string{"bar":"", "foo":""},`)
|
||||
}
|
||||
|
||||
func TestSetConfigValue(t *testing.T) { //nolint:paralleltest
|
||||
func TestSetConfigValue(t *testing.T) {
|
||||
assert.NoError(t, os.Setenv("GOPASS_CONFIG", filepath.Join(os.TempDir(), ".gopass.yml")))
|
||||
|
||||
cfg := legacy.New()
|
||||
|
||||
@@ -376,7 +376,7 @@ mounts:
|
||||
safecontent: false
|
||||
version: 1.4.0`
|
||||
|
||||
func TestLoad(t *testing.T) { //nolint:paralleltest
|
||||
func TestLoad(t *testing.T) {
|
||||
td := os.TempDir()
|
||||
gcfg := filepath.Join(td, ".gopass.yml")
|
||||
_ = os.Remove(gcfg)
|
||||
@@ -389,7 +389,7 @@ func TestLoad(t *testing.T) { //nolint:paralleltest
|
||||
assert.True(t, cfg.SafeContent)
|
||||
}
|
||||
|
||||
func TestLoadError(t *testing.T) { //nolint:paralleltest
|
||||
func TestLoadError(t *testing.T) {
|
||||
gcfg := filepath.Join(os.TempDir(), ".gopass-err.yml")
|
||||
assert.NoError(t, os.Setenv("GOPASS_CONFIG", gcfg))
|
||||
|
||||
@@ -413,7 +413,7 @@ func TestLoadError(t *testing.T) { //nolint:paralleltest
|
||||
assert.NoError(t, cfg.Save())
|
||||
}
|
||||
|
||||
func TestDecodeError(t *testing.T) { //nolint:paralleltest
|
||||
func TestDecodeError(t *testing.T) {
|
||||
gcfg := filepath.Join(os.TempDir(), ".gopass-err2.yml")
|
||||
assert.NoError(t, os.Setenv("GOPASS_CONFIG", gcfg))
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPwStoreDirNoEnv(t *testing.T) { //nolint:paralleltest
|
||||
func TestPwStoreDirNoEnv(t *testing.T) {
|
||||
if runtime.GOOS != "windows" {
|
||||
t.Setenv("GOPASS_HOMEDIR", "/tmp")
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestPwStoreDir(t *testing.T) { //nolint:paralleltest
|
||||
func TestPwStoreDir(t *testing.T) {
|
||||
gph := filepath.Join(os.TempDir(), "home")
|
||||
require.NoError(t, os.Setenv("GOPASS_HOMEDIR", gph))
|
||||
|
||||
@@ -39,7 +39,7 @@ func TestPwStoreDir(t *testing.T) { //nolint:paralleltest
|
||||
assert.NoError(t, os.Unsetenv("XDG_DATA_HOME"))
|
||||
}
|
||||
|
||||
func TestConfigLocation(t *testing.T) { //nolint:paralleltest
|
||||
func TestConfigLocation(t *testing.T) {
|
||||
evs := map[string]struct {
|
||||
ev string
|
||||
loc string
|
||||
@@ -60,7 +60,7 @@ func TestConfigLocation(t *testing.T) { //nolint:paralleltest
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigLocations(t *testing.T) { //nolint:paralleltest
|
||||
func TestConfigLocations(t *testing.T) {
|
||||
gpcfg := filepath.Join(os.TempDir(), "config", ".gopass.yml")
|
||||
xdghome := filepath.Join(os.TempDir(), "xdg")
|
||||
gphome := filepath.Join(os.TempDir(), "home")
|
||||
|
||||
@@ -29,10 +29,6 @@ const (
|
||||
|
||||
// AskForPrivateKey prompts the user to select from a list of private keys.
|
||||
func AskForPrivateKey(ctx context.Context, crypto backend.Crypto, prompt string) (string, error) {
|
||||
if !ctxutil.IsInteractive(ctx) {
|
||||
return "", fmt.Errorf("can not select private key without terminal")
|
||||
}
|
||||
|
||||
if crypto == nil {
|
||||
return "", fmt.Errorf("can not select private key without valid crypto backend")
|
||||
}
|
||||
@@ -43,7 +39,7 @@ func AskForPrivateKey(ctx context.Context, crypto backend.Crypto, prompt string)
|
||||
}
|
||||
|
||||
if len(kl) < 1 {
|
||||
return "", fmt.Errorf("no useable private keys found. make sure you have valid private keys with sufficient trust")
|
||||
return "", fmt.Errorf("no useable private keys found for %s. make sure you have valid private keys with sufficient trust", crypto.Name())
|
||||
}
|
||||
|
||||
// shortcut: If there is only one key, use it
|
||||
@@ -53,7 +49,7 @@ func AskForPrivateKey(ctx context.Context, crypto backend.Crypto, prompt string)
|
||||
|
||||
fmtStr := "[%" + strconv.Itoa((len(kl)/10)+1) + "d] %s - %s\n"
|
||||
for i := 0; i < maxTries; i++ {
|
||||
if !ctxutil.IsTerminal(ctx) {
|
||||
if !ctxutil.IsTerminal(ctx) || !ctxutil.IsInteractive(ctx) {
|
||||
return kl[0], nil
|
||||
}
|
||||
// check for context cancelation
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAskForPrivateKey(t *testing.T) { //nolint:paralleltest
|
||||
func TestAskForPrivateKey(t *testing.T) {
|
||||
buf := &bytes.Buffer{}
|
||||
Stdout = buf
|
||||
defer func() {
|
||||
@@ -29,9 +29,10 @@ func TestAskForPrivateKey(t *testing.T) { //nolint:paralleltest
|
||||
buf.Reset()
|
||||
}
|
||||
|
||||
func TestAskForGitConfigUser(t *testing.T) { //nolint:paralleltest
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
func TestAskForGitConfigUser(t *testing.T) {
|
||||
// necessary for setting up the env
|
||||
u := gptest.NewGUnitTester(t)
|
||||
assert.NotNil(t, u)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithTerminal(ctx, true)
|
||||
@@ -47,7 +48,7 @@ func (f fakeMountPointer) MountPoints() []string {
|
||||
return f
|
||||
}
|
||||
|
||||
func TestAskForStore(t *testing.T) { //nolint:paralleltest
|
||||
func TestAskForStore(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
// test non-interactive
|
||||
|
||||
@@ -17,9 +17,10 @@ import (
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func TestEditor(t *testing.T) { //nolint:paralleltest
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
func TestEditor(t *testing.T) {
|
||||
// necessary for setting up the env
|
||||
u := gptest.NewGUnitTester(t)
|
||||
assert.NotNil(t, u)
|
||||
|
||||
ctx := context.Background()
|
||||
touch, err := exec.LookPath("touch")
|
||||
@@ -33,7 +34,7 @@ func TestEditor(t *testing.T) { //nolint:paralleltest
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetEditor(t *testing.T) { //nolint:paralleltest
|
||||
func TestGetEditor(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
|
||||
// --editor=fooed
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestEdit(t *testing.T) { //nolint:paralleltest
|
||||
func TestEdit(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
ctx = ctxutil.WithTerminal(ctx, false)
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
func TestEditor(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
assert.NotNil(t, u)
|
||||
|
||||
ctx := context.Background()
|
||||
touch, err := exec.LookPath("rundll32")
|
||||
|
||||
@@ -11,13 +11,13 @@ import (
|
||||
)
|
||||
|
||||
// to test cmd.exec correctly we use the same functionality as go itself see exec_test.go.
|
||||
func TestDarwinNotify(t *testing.T) { //nolint:paralleltest
|
||||
func TestDarwinNotify(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
t.Setenv("GOPASS_NO_NOTIFY", "true")
|
||||
assert.NoError(t, Notify(ctx, "foo", "bar"))
|
||||
}
|
||||
|
||||
func TestLegacyNotification(t *testing.T) { //nolint:paralleltest
|
||||
func TestLegacyNotification(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
// override execCommand with mock
|
||||
execCommand = mockExecCommand
|
||||
@@ -29,7 +29,7 @@ func TestLegacyNotification(t *testing.T) { //nolint:paralleltest
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestLegacyTerminalNotifierNotification(t *testing.T) { //nolint:paralleltest
|
||||
func TestLegacyTerminalNotifierNotification(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
// override execCommand with mock
|
||||
execCommand = mockExecCommand
|
||||
@@ -42,7 +42,7 @@ func TestLegacyTerminalNotifierNotification(t *testing.T) { //nolint:paralleltes
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestNoExecutableFound(t *testing.T) { //nolint:paralleltest
|
||||
func TestNoExecutableFound(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
// override execCommand with mock
|
||||
execCommand = mockExecCommand
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNotify(t *testing.T) { //nolint:paralleltest
|
||||
func TestNotify(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
t.Setenv("GOPASS_NO_NOTIFY", "true")
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPrint(t *testing.T) { //nolint:paralleltest
|
||||
func TestPrint(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
buf := &bytes.Buffer{}
|
||||
Stdout = buf
|
||||
|
||||
@@ -37,7 +37,7 @@ func (s *Store) Convert(ctx context.Context, cryptoBe backend.CryptoBackend, sto
|
||||
// create temp path
|
||||
tmpPath := s.path + "-autoconvert"
|
||||
if err := os.MkdirAll(tmpPath, 0o700); err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to create temporary conversion directory %s: %w", tmpPath, err)
|
||||
}
|
||||
|
||||
debug.Log("create temporary store path for conversion: %s", tmpPath)
|
||||
@@ -45,14 +45,14 @@ func (s *Store) Convert(ctx context.Context, cryptoBe backend.CryptoBackend, sto
|
||||
// init new store at temp path
|
||||
st, err := backend.InitStorage(ctx, storageBe, tmpPath)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to initialize new stroage backend %s: %w", storageBe.String(), err)
|
||||
}
|
||||
|
||||
debug.Log("initialized storage %s at %s", st, tmpPath)
|
||||
|
||||
crypto, err := backend.NewCrypto(ctx, cryptoBe)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to initialize new crypto backend %s: %w", cryptoBe.String(), err)
|
||||
}
|
||||
|
||||
debug.Log("initialized Crypto %s", crypto)
|
||||
@@ -67,17 +67,17 @@ func (s *Store) Convert(ctx context.Context, cryptoBe backend.CryptoBackend, sto
|
||||
// init new store
|
||||
key, err := cui.AskForPrivateKey(ctx, crypto, "Please select a private key")
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to ask for the private key for %v: %w", crypto, err)
|
||||
}
|
||||
|
||||
if err := tmpStore.Init(ctx, tmpPath, key); err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to init new store at %s: %w", tmpPath, err)
|
||||
}
|
||||
|
||||
// copy everything from old to temp, including all revisions
|
||||
entries, err := s.List(ctx, "")
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to list entries of the old store: %w", err)
|
||||
}
|
||||
|
||||
out.Printf(ctx, "Converting store ...")
|
||||
@@ -95,7 +95,7 @@ func (s *Store) Convert(ctx context.Context, cryptoBe backend.CryptoBackend, sto
|
||||
debug.Log("converting %s", e)
|
||||
revs, err := s.ListRevisions(ctx, e)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to list revision of %s: %w", e, err)
|
||||
}
|
||||
sort.Sort(sort.Reverse(backend.Revisions(revs)))
|
||||
|
||||
@@ -103,7 +103,7 @@ func (s *Store) Convert(ctx context.Context, cryptoBe backend.CryptoBackend, sto
|
||||
debug.Log("converting %s@%s", e, r.Hash)
|
||||
sec, err := s.GetRevision(ctx, e, r.Hash)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to convert revision %s of %s: %w", r.Hash, e, err)
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("%s\n%s\nCommitted as: %s\nDate: %s\nAuthor: %s <%s>",
|
||||
@@ -117,7 +117,7 @@ func (s *Store) Convert(ctx context.Context, cryptoBe backend.CryptoBackend, sto
|
||||
ctx := ctxutil.WithCommitMessage(ctx, msg)
|
||||
ctx = ctxutil.WithCommitTimestamp(ctx, r.Date)
|
||||
if err := tmpStore.Set(ctx, e, sec); err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to write converted revision %s of %s to the new store: %w", r.Hash, e, err)
|
||||
}
|
||||
}
|
||||
bar.Inc()
|
||||
@@ -128,6 +128,8 @@ func (s *Store) Convert(ctx context.Context, cryptoBe backend.CryptoBackend, sto
|
||||
_ = q.Close(ctx)
|
||||
|
||||
if !move {
|
||||
debug.Log("conversion done. no move requested. keeping both.")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -141,9 +143,13 @@ func (s *Store) Convert(ctx context.Context, cryptoBe backend.CryptoBackend, sto
|
||||
|
||||
// rename old to backup
|
||||
if err := os.Rename(s.path, bDir); err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to rename old store from %s to backup at %s: %w", s.path, bDir, err)
|
||||
}
|
||||
|
||||
// rename temp to old
|
||||
return os.Rename(tmpPath, s.path)
|
||||
if err := os.Rename(tmpPath, s.path); err != nil {
|
||||
return fmt.Errorf("failed to rename temp store %s to old %s: %w", tmpPath, s.path, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func TestList(t *testing.T) {
|
||||
out.Stdout = os.Stdout
|
||||
}()
|
||||
|
||||
for _, tc := range []struct { //nolint:paralleltest
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
prep func(s *Store) error
|
||||
out []string
|
||||
|
||||
@@ -26,7 +26,7 @@ func TestCopy(t *testing.T) {
|
||||
out.Stdout = os.Stdout
|
||||
}()
|
||||
|
||||
for _, tc := range []struct { //nolint:paralleltest
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
tf func(s *Store) func(t *testing.T)
|
||||
}{
|
||||
@@ -110,7 +110,7 @@ func TestMove(t *testing.T) {
|
||||
out.Stdout = os.Stdout
|
||||
}()
|
||||
|
||||
for _, tc := range []struct { //nolint:paralleltest
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
tf func(s *Store) func(t *testing.T)
|
||||
}{
|
||||
@@ -195,7 +195,7 @@ func TestDelete(t *testing.T) {
|
||||
out.Stdout = os.Stdout
|
||||
}()
|
||||
|
||||
for _, tc := range []struct { //nolint:paralleltest
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
tf func(s *Store) func(t *testing.T)
|
||||
}{
|
||||
@@ -262,7 +262,7 @@ func TestPrune(t *testing.T) {
|
||||
out.Stdout = os.Stdout
|
||||
}()
|
||||
|
||||
for _, tc := range []struct { //nolint:paralleltest
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
tf func(s *Store) func(t *testing.T)
|
||||
}{
|
||||
|
||||
@@ -16,7 +16,7 @@ func (r *Store) Convert(ctx context.Context, name string, cryptoBe backend.Crypt
|
||||
return fmt.Errorf("mount not found: %w", err)
|
||||
}
|
||||
|
||||
debug.Log("converting %s to crypto: %s, rcs: %s, storage: %s", name, cryptoBe, storageBe)
|
||||
debug.Log("converting %s to crypto: %s, storage: %s", name, cryptoBe, storageBe)
|
||||
|
||||
if err := sub.Convert(ctx, cryptoBe, storageBe, move); err != nil {
|
||||
return fmt.Errorf("failed to convert %q: %w", name, err)
|
||||
|
||||
@@ -12,10 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func TestCrypto(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
@@ -11,10 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func TestFsck(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
@@ -13,10 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func TestInit(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
@@ -13,10 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
@@ -11,10 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func TestMount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
@@ -12,8 +12,6 @@ import (
|
||||
)
|
||||
|
||||
func TestMoveShadow(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
u.Entries = []string{
|
||||
"old/www/foo",
|
||||
@@ -22,8 +20,6 @@ func TestMoveShadow(t *testing.T) {
|
||||
|
||||
require.NoError(t, u.InitStore(""))
|
||||
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
ctx = ctxutil.WithHidden(ctx, true)
|
||||
@@ -52,8 +48,6 @@ func TestMoveShadow(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMove(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
u.Entries = []string{
|
||||
"foo/bar",
|
||||
@@ -62,8 +56,6 @@ func TestMove(t *testing.T) {
|
||||
}
|
||||
require.NoError(t, u.InitStore(""))
|
||||
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
ctx = ctxutil.WithHidden(ctx, true)
|
||||
@@ -151,8 +143,6 @@ func TestMove(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUnixMvSemantics(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
u.Entries = []string{
|
||||
"a/f1",
|
||||
@@ -161,8 +151,6 @@ func TestUnixMvSemantics(t *testing.T) {
|
||||
}
|
||||
require.NoError(t, u.InitStore(""))
|
||||
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
ctx = ctxutil.WithHidden(ctx, true)
|
||||
@@ -192,8 +180,6 @@ func TestUnixMvSemantics(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRegression2079(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
u.Entries = []string{
|
||||
"comm/test",
|
||||
@@ -202,8 +188,6 @@ func TestRegression2079(t *testing.T) {
|
||||
}
|
||||
require.NoError(t, u.InitStore(""))
|
||||
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
ctx = ctxutil.WithHidden(ctx, true)
|
||||
@@ -233,8 +217,6 @@ func TestRegression2079(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCopy(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
u.Entries = []string{
|
||||
"foo/bar",
|
||||
@@ -243,8 +225,6 @@ func TestCopy(t *testing.T) {
|
||||
}
|
||||
require.NoError(t, u.InitStore(""))
|
||||
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
ctx = ctxutil.WithHidden(ctx, true)
|
||||
@@ -254,7 +234,7 @@ func TestCopy(t *testing.T) {
|
||||
assert.NoError(t, rs.Delete(ctx, "foo"))
|
||||
|
||||
// Initial state:
|
||||
t.Run("initial state", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("initial state", func(t *testing.T) {
|
||||
entries, err := rs.List(ctx, tree.INF)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []string{
|
||||
@@ -270,7 +250,7 @@ func TestCopy(t *testing.T) {
|
||||
assert.Error(t, rs.Copy(ctx, "foo", "misc/zab"))
|
||||
|
||||
// -> copy foo/ misc => OK
|
||||
t.Run("copy foo misc", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("copy foo misc", func(t *testing.T) {
|
||||
assert.NoError(t, rs.Copy(ctx, "foo", "misc"))
|
||||
entries, err := rs.List(ctx, tree.INF)
|
||||
require.NoError(t, err)
|
||||
@@ -284,7 +264,7 @@ func TestCopy(t *testing.T) {
|
||||
})
|
||||
|
||||
// -> copy misc/foo/ bar/ => OK
|
||||
t.Run("copy misc/foo/ bar/", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("copy misc/foo/ bar/", func(t *testing.T) {
|
||||
assert.NoError(t, rs.Copy(ctx, "misc/foo/", "bar/"))
|
||||
entries, err := rs.List(ctx, tree.INF)
|
||||
require.NoError(t, err)
|
||||
@@ -300,7 +280,7 @@ func TestCopy(t *testing.T) {
|
||||
})
|
||||
|
||||
// -> copy misc/zab bar/foo/zab => OK
|
||||
t.Run("copy misc/zab bar/foo/zab", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("copy misc/zab bar/foo/zab", func(t *testing.T) {
|
||||
assert.NoError(t, rs.Copy(ctx, "misc/zab", "bar/foo/zab"))
|
||||
entries, err := rs.List(ctx, tree.INF)
|
||||
require.NoError(t, err)
|
||||
@@ -318,14 +298,11 @@ func TestCopy(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMoveSelf(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
u.Entries = []string{
|
||||
"foo/bar/example",
|
||||
}
|
||||
require.NoError(t, u.InitStore(""))
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
@@ -335,7 +312,7 @@ func TestMoveSelf(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Initial state:
|
||||
t.Run("initial state", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("initial state", func(t *testing.T) {
|
||||
entries, err := rs.List(ctx, tree.INF)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []string{
|
||||
@@ -345,7 +322,7 @@ func TestMoveSelf(t *testing.T) {
|
||||
})
|
||||
|
||||
// -> move foo/bar/example foo/bar -> no op
|
||||
t.Run("move self", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("move self", func(t *testing.T) {
|
||||
assert.Error(t, rs.Move(ctx, "foo/bar/example", "foo/bar"))
|
||||
entries, err := rs.List(ctx, tree.INF)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -12,10 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func TestRCS(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
@@ -11,10 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
@@ -12,10 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func TestRecipients(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
@@ -17,12 +17,9 @@ import (
|
||||
)
|
||||
|
||||
func TestSimpleList(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
rs, err := createRootStore(ctx, u)
|
||||
require.NoError(t, err)
|
||||
@@ -33,13 +30,10 @@ func TestSimpleList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListMulti(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = backend.WithCryptoBackend(ctx, backend.Plain)
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
// root store
|
||||
rs, err := createRootStore(ctx, u)
|
||||
@@ -79,13 +73,10 @@ func TestListMulti(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListNested(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = backend.WithCryptoBackend(ctx, backend.Plain)
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
// root store
|
||||
rs, err := createRootStore(ctx, u)
|
||||
|
||||
@@ -12,10 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func TestTemplate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
@@ -12,10 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func TestSet(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
//nolint:wrapcheck
|
||||
func TestIsUpdateable(t *testing.T) { //nolint:paralleltest
|
||||
func TestIsUpdateable(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
oldExec := executable
|
||||
|
||||
|
||||
+1
-2
@@ -100,9 +100,8 @@ var commandsWithError = set.Map([]string{
|
||||
".unclip",
|
||||
})
|
||||
|
||||
func TestGetCommands(t *testing.T) { //nolint:paralleltest
|
||||
func TestGetCommands(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
defer u.Remove()
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
color.NoColor = true
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUserHome(t *testing.T) { //nolint:paralleltest
|
||||
func TestUserHome(t *testing.T) {
|
||||
td := t.TempDir()
|
||||
t.Setenv("GOPASS_HOMEDIR", td)
|
||||
|
||||
|
||||
@@ -12,69 +12,69 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestUserConfig(t *testing.T) { //nolint:paralleltest
|
||||
func TestUserConfig(t *testing.T) {
|
||||
ov := gptest.UnsetVars("GOPASS_HOMEDIR", "XDG_CONFIG_HOME", "HOME")
|
||||
defer ov()
|
||||
|
||||
t.Run("gopass homedir", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("gopass homedir", func(t *testing.T) {
|
||||
require.NoError(t, os.Setenv("GOPASS_HOMEDIR", "/foo/bar"))
|
||||
assert.Equal(t, "/foo/bar/.config/gopass", UserConfig())
|
||||
require.NoError(t, os.Unsetenv("GOPASS_HOMEDIR"))
|
||||
})
|
||||
|
||||
t.Run("xdg_config_home", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("xdg_config_home", func(t *testing.T) {
|
||||
require.NoError(t, os.Setenv("XDG_CONFIG_HOME", "/foo/baz/myconfig"))
|
||||
assert.Equal(t, "/foo/baz/myconfig/gopass", UserConfig())
|
||||
require.NoError(t, os.Unsetenv("XDG_CONFIG_HOME"))
|
||||
})
|
||||
|
||||
t.Run("default", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("default", func(t *testing.T) {
|
||||
require.NoError(t, os.Setenv("HOME", "/home/gopass"))
|
||||
assert.Equal(t, "/home/gopass/.config/gopass", UserConfig())
|
||||
require.NoError(t, os.Unsetenv("HOME"))
|
||||
})
|
||||
}
|
||||
|
||||
func TestUserCache(t *testing.T) { //nolint:paralleltest
|
||||
func TestUserCache(t *testing.T) {
|
||||
ov := gptest.UnsetVars("GOPASS_HOMEDIR", "XDG_CACHE_HOME", "HOME")
|
||||
defer ov()
|
||||
|
||||
t.Run("gopass homedir", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("gopass homedir", func(t *testing.T) {
|
||||
require.NoError(t, os.Setenv("GOPASS_HOMEDIR", "/foo/bar"))
|
||||
assert.Equal(t, "/foo/bar/.cache/gopass", UserCache())
|
||||
require.NoError(t, os.Unsetenv("GOPASS_HOMEDIR"))
|
||||
})
|
||||
|
||||
t.Run("xdg_cache_home", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("xdg_cache_home", func(t *testing.T) {
|
||||
require.NoError(t, os.Setenv("XDG_CACHE_HOME", "/foo/baz/mycache"))
|
||||
assert.Equal(t, "/foo/baz/mycache/gopass", UserCache())
|
||||
require.NoError(t, os.Unsetenv("XDG_CACHE_HOME"))
|
||||
})
|
||||
|
||||
t.Run("default", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("default", func(t *testing.T) {
|
||||
require.NoError(t, os.Setenv("HOME", "/home/gopass"))
|
||||
assert.Equal(t, "/home/gopass/.cache/gopass", UserCache())
|
||||
require.NoError(t, os.Unsetenv("HOME"))
|
||||
})
|
||||
}
|
||||
|
||||
func TestUserData(t *testing.T) { //nolint:paralleltest
|
||||
func TestUserData(t *testing.T) {
|
||||
ov := gptest.UnsetVars("GOPASS_HOMEDIR", "XDG_DATA_HOME", "HOME")
|
||||
defer ov()
|
||||
|
||||
t.Run("gopass homedir", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("gopass homedir", func(t *testing.T) {
|
||||
require.NoError(t, os.Setenv("GOPASS_HOMEDIR", "/foo/bar"))
|
||||
assert.Equal(t, "/foo/bar/.local/share/gopass", UserData())
|
||||
require.NoError(t, os.Unsetenv("GOPASS_HOMEDIR"))
|
||||
})
|
||||
|
||||
t.Run("xdg_data_home", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("xdg_data_home", func(t *testing.T) {
|
||||
require.NoError(t, os.Setenv("XDG_DATA_HOME", "/foo/baz/mydata"))
|
||||
assert.Equal(t, "/foo/baz/mydata/gopass", UserData())
|
||||
require.NoError(t, os.Unsetenv("XDG_DATA_HOME"))
|
||||
})
|
||||
|
||||
t.Run("default", func(t *testing.T) { //nolint:paralleltest
|
||||
t.Run("default", func(t *testing.T) {
|
||||
require.NoError(t, os.Setenv("HOME", "/home/gopass"))
|
||||
assert.Equal(t, "/home/gopass/.local/share/gopass", UserData())
|
||||
require.NoError(t, os.Unsetenv("HOME"))
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNotExistingClipboardCopyCommand(t *testing.T) { //nolint:paralleltest
|
||||
func TestNotExistingClipboardCopyCommand(t *testing.T) {
|
||||
t.Setenv("GOPASS_NO_NOTIFY", "true")
|
||||
t.Setenv("GOPASS_CLIPBOARD_COPY_CMD", "not_existing_command")
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestNotExistingClipboardCopyCommand(t *testing.T) { //nolint:paralleltest
|
||||
assert.Contains(t, maybeErr.Error(), "\"not_existing_command\": executable file not found")
|
||||
}
|
||||
|
||||
func TestUnsupportedCopyToClipboard(t *testing.T) { //nolint:paralleltest
|
||||
func TestUnsupportedCopyToClipboard(t *testing.T) {
|
||||
t.Setenv("GOPASS_NO_NOTIFY", "true")
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@@ -43,7 +43,7 @@ func TestUnsupportedCopyToClipboard(t *testing.T) { //nolint:paralleltest
|
||||
assert.Contains(t, buf.String(), "WARNING")
|
||||
}
|
||||
|
||||
func TestClearClipboard(t *testing.T) { //nolint:paralleltest
|
||||
func TestClearClipboard(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
assert.NoError(t, clear(ctx, "foo", []byte("bar"), 0))
|
||||
cancel()
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNotExistingClipboardClearCommand(t *testing.T) { //nolint:paralleltest
|
||||
func TestNotExistingClipboardClearCommand(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
|
||||
|
||||
@@ -52,6 +52,8 @@ func initDebug() bool {
|
||||
func initDebugLogger() {
|
||||
debugfile := os.Getenv("GOPASS_DEBUG_LOG")
|
||||
if debugfile == "" {
|
||||
opts.logger = log.New(os.Stderr, "", log.Ldate|log.Lmicroseconds)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
package debug
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func BenchmarkLogging(b *testing.B) {
|
||||
@@ -24,3 +30,101 @@ func BenchmarkNoLogging(b *testing.B) {
|
||||
Log("string")
|
||||
}
|
||||
}
|
||||
|
||||
// can not import out.Secret.
|
||||
type testSecret string
|
||||
|
||||
func (t testSecret) SafeStr() string {
|
||||
return "(elided)"
|
||||
}
|
||||
|
||||
type testShort string
|
||||
|
||||
func (t testShort) Str() string {
|
||||
return "shorter"
|
||||
}
|
||||
|
||||
func TestDebug(t *testing.T) {
|
||||
td := t.TempDir()
|
||||
t.Cleanup(func() {
|
||||
initDebug()
|
||||
})
|
||||
|
||||
fn := filepath.Join(td, "gopass.log")
|
||||
t.Setenv("GOPASS_DEBUG_LOG", fn)
|
||||
|
||||
// it's been already initialized, need to re-init
|
||||
assert.True(t, initDebug())
|
||||
|
||||
Log("foo")
|
||||
Log("%s", testSecret("secret"))
|
||||
Log("%s", testShort("toolong"))
|
||||
|
||||
buf, err := ioutil.ReadFile(fn)
|
||||
require.NoError(t, err)
|
||||
|
||||
logStr := string(buf)
|
||||
assert.Contains(t, logStr, "foo")
|
||||
assert.NotContains(t, logStr, "secret")
|
||||
assert.NotContains(t, logStr, "toolong")
|
||||
assert.Contains(t, logStr, "shorter")
|
||||
}
|
||||
|
||||
func TestDebugSecret(t *testing.T) {
|
||||
td := t.TempDir()
|
||||
t.Cleanup(func() {
|
||||
initDebug()
|
||||
})
|
||||
|
||||
fn := filepath.Join(td, "gopass.log")
|
||||
t.Setenv("GOPASS_DEBUG_LOG", fn)
|
||||
t.Setenv("GOPASS_DEBUG_LOG_SECRETS", "true")
|
||||
|
||||
// it's been already initialized, need to re-init
|
||||
assert.True(t, initDebug())
|
||||
|
||||
assert.True(t, logSecrets)
|
||||
|
||||
Log("foo")
|
||||
Log("%s", testSecret("secret"))
|
||||
|
||||
buf, err := ioutil.ReadFile(fn)
|
||||
require.NoError(t, err)
|
||||
|
||||
logStr := string(buf)
|
||||
assert.Contains(t, logStr, "foo")
|
||||
assert.Contains(t, logStr, "secret")
|
||||
}
|
||||
|
||||
func TestDebugFilter(t *testing.T) {
|
||||
td := t.TempDir()
|
||||
t.Cleanup(func() {
|
||||
initDebug()
|
||||
})
|
||||
|
||||
fn := filepath.Join(td, "gopass.log")
|
||||
t.Setenv("GOPASS_DEBUG_LOG", fn)
|
||||
t.Setenv("GOPASS_DEBUG_FUNCS", "TestDebugFilter")
|
||||
t.Setenv("GOPASS_DEBUG_FILES", "debug_test.go")
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
Stderr = buf
|
||||
defer func() {
|
||||
Stderr = os.Stderr
|
||||
}()
|
||||
|
||||
// it's been already initialized, need to re-init
|
||||
assert.True(t, initDebug())
|
||||
|
||||
Log("foo")
|
||||
Log("%s", testSecret("secret"))
|
||||
|
||||
fbuf, err := ioutil.ReadFile(fn)
|
||||
require.NoError(t, err)
|
||||
|
||||
logStr := string(fbuf)
|
||||
assert.Contains(t, logStr, "foo")
|
||||
|
||||
stderrStr := buf.String()
|
||||
assert.Contains(t, stderrStr, "TestDebugFilter")
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func TestCleanFilename(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCleanPath(t *testing.T) { //nolint:paralleltest
|
||||
func TestCleanPath(t *testing.T) {
|
||||
tempdir := t.TempDir()
|
||||
|
||||
m := map[string]string{
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUmask(t *testing.T) { //nolint:paralleltest
|
||||
func TestUmask(t *testing.T) {
|
||||
for _, vn := range []string{"GOPASS_UMASK", "PASSWORD_STORE_UMASK"} {
|
||||
for in, out := range map[string]int{
|
||||
"002": 0o2,
|
||||
|
||||
@@ -71,7 +71,7 @@ func (c *Config) Set(key, value string) error {
|
||||
|
||||
// already present at the same value, no need to rewrite the config
|
||||
if v, found := c.vars[key]; found && v == value {
|
||||
debug.Log("key %q with value %q already present. No re-writing.", key, value)
|
||||
debug.Log("key %q with value %q already present. Not re-writing.", key, value)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -157,6 +157,10 @@ func TestUnsetSection(t *testing.T) {
|
||||
bar = baz
|
||||
`, c.raw.String())
|
||||
|
||||
// should not exist
|
||||
assert.NoError(t, c.Unset("foo.bla"))
|
||||
|
||||
// TODO: support remvoing sections
|
||||
t.Skip("removing sections is not supported, yet")
|
||||
|
||||
assert.NoError(t, c.Unset("foo.bar"))
|
||||
@@ -185,6 +189,8 @@ func TestNewFromMap(t *testing.T) {
|
||||
|
||||
assert.True(t, cfg.IsSet("core.foo"))
|
||||
assert.False(t, cfg.IsSet("core.bar"))
|
||||
assert.NoError(t, cfg.Unset("core.foo"))
|
||||
assert.True(t, cfg.IsSet("core.foo"))
|
||||
}
|
||||
|
||||
func TestLoadConfig(t *testing.T) {
|
||||
@@ -205,7 +211,7 @@ func TestLoadConfig(t *testing.T) {
|
||||
assert.Equal(t, "false", cfg.vars["core.bar"])
|
||||
}
|
||||
|
||||
func TestLoadFromEnv(t *testing.T) { //nolint:paralleltest
|
||||
func TestLoadFromEnv(t *testing.T) {
|
||||
tc := map[string]string{
|
||||
"core.foo": "bar",
|
||||
"core.pager": "false",
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user