forked from gopasspw/gopass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
link_test.go
70 lines (55 loc) · 1.66 KB
/
link_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
61
62
63
64
65
66
67
68
69
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", oSec))
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())
}