-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpath_creds_test.go
More file actions
109 lines (88 loc) · 2.56 KB
/
path_creds_test.go
File metadata and controls
109 lines (88 loc) · 2.56 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package cognito
import (
"context"
"github.com/hashicorp/vault/sdk/logical"
"testing"
"time"
)
func TestClientCredentialsGrantRead(t *testing.T) {
b, s := getTestBackend(t, true)
t.Run("Client credentials grant role", func(t *testing.T) {
name := generateUUID()
testRole := map[string]interface{}{
"app_client_id": "my id",
"app_client_secret": "my secret",
"cognito_pool_domain": "my url",
}
testRoleCreate(t, b, s, name, testRole)
resp, err := b.HandleRequest(context.Background(), &logical.Request{
Operation: logical.ReadOperation,
Path: "creds/" + name,
Storage: s,
})
assertErrorIsNil(t, err)
if resp.IsError() {
t.Fatalf("expected no response error, actual:%#v", resp.Error())
}
exp := map[string]interface{}{
"access_token": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"expires_in": 3600,
"token_type": "Bearer",
}
equal(t, exp, resp.Data)
})
}
func TestUserRead(t *testing.T) {
b, s := getTestBackend(t, true)
// verify basic cred issuance
t.Run("User Role", func(t *testing.T) {
name := generateUUID()
testRole := map[string]interface{}{
"credential_type": "user",
}
testRoleCreate(t, b, s, name, testRole)
resp, err := b.HandleRequest(context.Background(), &logical.Request{
Operation: logical.ReadOperation,
Path: "creds/" + name,
Storage: s,
})
assertErrorIsNil(t, err)
if resp.IsError() {
t.Fatalf("expected no response error, actual:%#v", resp.Error())
}
exp := map[string]interface{}{
"username": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"password": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
}
equal(t, exp, resp.Data)
})
// verify role TTLs are reflected in secret
t.Run("TTLs", func(t *testing.T) {
name := generateUUID()
testRole := map[string]interface{}{
"credential_type": "user",
}
testRoleCreate(t, b, s, name, testRole)
resp, err := b.HandleRequest(context.Background(), &logical.Request{
Operation: logical.ReadOperation,
Path: "creds/" + name,
Storage: s,
})
assertErrorIsNil(t, err)
equal(t, 0*time.Second, resp.Secret.TTL)
equal(t, 0*time.Second, resp.Secret.MaxTTL)
roleUpdate := map[string]interface{}{
"ttl": 20,
"max_ttl": 30,
}
testRoleCreate(t, b, s, name, roleUpdate)
resp, err = b.HandleRequest(context.Background(), &logical.Request{
Operation: logical.ReadOperation,
Path: "creds/" + name,
Storage: s,
})
assertErrorIsNil(t, err)
equal(t, 20*time.Second, resp.Secret.TTL)
equal(t, 30*time.Second, resp.Secret.MaxTTL)
})
}