-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathacceptance_test.go
75 lines (64 loc) · 1.88 KB
/
acceptance_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
71
72
73
74
75
package tencentcloud
import (
"context"
"os"
"testing"
"time"
"github.com/hashicorp/vault/sdk/logical"
)
const (
envVarRunAccTests = "VAULT_ACC"
envVarSecretId = "TENCENTCLOUD_SECRET_ID"
envVarSecretKey = "TENCENTCLOUD_SECRET_KEY"
envVarRoleARN = "TENCENTCLOUD_ROLE_ARN"
)
var runAcceptanceTests = os.Getenv(envVarRunAccTests) == "1"
func TestAcceptanceDynamicPolicyBasedCreds(t *testing.T) {
if !runAcceptanceTests {
t.SkipNow()
}
acceptanceTestEnv, err := newAcceptanceTestEnv()
if err != nil {
t.Fatal(err)
}
t.Run("add config", acceptanceTestEnv.AddConfig)
t.Run("add policy-based role", acceptanceTestEnv.AddPolicyBasedRole)
t.Run("read policy-based creds", acceptanceTestEnv.ReadPolicyBasedCreds)
t.Run("renew policy-based creds", acceptanceTestEnv.RenewPolicyBasedCreds)
t.Run("revoke policy-based creds", acceptanceTestEnv.RevokePolicyBasedCreds)
}
func TestAcceptanceDynamicRoleBasedCreds(t *testing.T) {
if !runAcceptanceTests {
t.SkipNow()
}
acceptanceTestEnv, err := newAcceptanceTestEnv()
if err != nil {
t.Fatal(err)
}
t.Run("add config", acceptanceTestEnv.AddConfig)
t.Run("add arn-based role", acceptanceTestEnv.AddARNBasedRole)
t.Run("read arn-based creds", acceptanceTestEnv.ReadARNBasedCreds)
t.Run("renew arn-based creds", acceptanceTestEnv.RenewARNBasedCreds)
t.Run("revoke arn-based creds", acceptanceTestEnv.RevokeARNBasedCreds)
}
func newAcceptanceTestEnv() (*testEnv, error) {
ctx := context.Background()
conf := &logical.BackendConfig{
System: &logical.StaticSystemView{
DefaultLeaseTTLVal: time.Hour,
MaxLeaseTTLVal: time.Hour,
},
}
b, err := Factory(ctx, conf)
if err != nil {
return nil, err
}
return &testEnv{
SecretId: os.Getenv(envVarSecretId),
SecretKey: os.Getenv(envVarSecretKey),
RoleARN: os.Getenv(envVarRoleARN),
Backend: b,
Context: ctx,
Storage: &logical.InmemStorage{},
}, nil
}