-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathkeychain_test.go
58 lines (46 loc) · 1.24 KB
/
keychain_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
// +build darwin,cgo
package store_test
import (
"testing"
"github.com/99designs/keyring"
"github.com/joemiller/vault-token-helper/pkg/store"
"github.com/stretchr/testify/assert"
)
func TestKeychainStore(t *testing.T) {
st, err := store.New(keyring.Config{
ServiceName: "test",
KeychainTrustApplication: true,
AllowedBackends: []keyring.BackendType{keyring.KeychainBackend},
})
assert.Nil(t, err)
assert.NotNil(t, st)
// should be empty
tokens, err := st.List()
assert.Nil(t, err)
assert.Empty(t, tokens)
// Get of a missing item should not return an error
_, err = st.Get("https://localhost:8200")
assert.Nil(t, err)
// Store a token
token1 := store.Token{
VaultAddr: "https://localhost:8200",
Token: "token-foo",
}
err = st.Store(token1)
assert.Nil(t, err)
// GetAll tokens
tokens, err = st.List()
assert.Nil(t, err)
assert.NotEmpty(t, tokens)
// Get a token by addr. Mixed case addr should be normalized for a successful lookup
v1, err := st.Get("httpS://LOCALhost:8200/")
assert.Nil(t, err)
assert.Equal(t, token1, v1)
// Erase
err = st.Erase("https://localhost:8200")
assert.Nil(t, err)
// empty token store
tokens, err = st.List()
assert.Nil(t, err)
assert.Empty(t, tokens)
}