-
Notifications
You must be signed in to change notification settings - Fork 6
/
path_credentials_test.go
61 lines (51 loc) · 1.25 KB
/
path_credentials_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
package btc
import (
"context"
"testing"
"github.com/hashicorp/vault/logical"
)
func TestCredentials(t *testing.T) {
b, storage := getTestBackend(t)
name := "test"
network := "testnet"
_, err := newWallet(t, b, storage, name, network)
if err != nil {
t.Fatal(err)
}
t.Run("Create auth token for wallet", func(t *testing.T) {
t.Parallel()
resp, err := newAuthToken(t, b, storage, name)
if err != nil {
t.Fatal(err)
}
if resp == nil {
t.Fatal("No response received")
}
})
t.Run("Create auth token for bad wallet should fail", func(t *testing.T) {
t.Parallel()
name := "badwallet"
exp := "Failed to create credentials for '" + name + "': wallet does not exist"
_, err := newAuthToken(t, b, storage, name)
if err == nil {
t.Fatal("Should have failed before")
}
if err.Error() != exp {
t.Fatalf("Want: %v, got: %v", exp, err)
}
})
}
func newAuthToken(t *testing.T, b logical.Backend, store logical.Storage, name string) (*logical.Response, error) {
resp, err := b.HandleRequest(context.Background(), &logical.Request{
Path: "creds/" + name,
Storage: store,
Operation: logical.ReadOperation,
})
if err != nil {
return nil, err
}
if resp.IsError() {
return nil, resp.Error()
}
return resp, nil
}