forked from gopasspw/gopass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
audit_test.go
60 lines (51 loc) · 1.44 KB
/
audit_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package action
import (
"bytes"
"context"
"os"
"testing"
"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 TestAudit(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
}()
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))
assert.NoError(t, act.Store.Set(ctx, "baz", sec))
assert.Error(t, act.Audit(gptest.CliCtx(ctx, t)))
buf.Reset()
})
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) {
for _, v := range []string{"foo", "bar", "baz"} {
assert.NoError(t, act.Store.Delete(ctx, v))
}
assert.NoError(t, act.Audit(gptest.CliCtx(ctx, t)))
assert.Contains(t, "No secrets found", buf.String())
buf.Reset()
})
}