-
Notifications
You must be signed in to change notification settings - Fork 0
/
path_credentials_test.go
82 lines (73 loc) · 2.21 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package secretsengine
import (
"context"
"os"
"testing"
"time"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/sdk/helper/logging"
"github.com/hashicorp/vault/sdk/logical"
)
const (
testPrometheusUser = "1"
testLokiUser = "2"
testTempoUser = "3"
testAlertmanagerUser = "4"
testGraphiteUser = "5"
testPrometheusURL = "http://prometheus"
testLokiURL = "http://loki"
testTempoURL = "http://tempo"
testAlertmanagerURL = "http://alertmanager"
testGraphiteURL = "http://graphite"
)
// newAcceptanceTestEnv creates a test environment for credentials.
func newAcceptanceTestEnv() (*testEnv, error) {
ctx := context.Background()
maxLease, _ := time.ParseDuration("60s")
defaultLease, _ := time.ParseDuration("30s")
conf := &logical.BackendConfig{
System: &logical.StaticSystemView{
DefaultLeaseTTLVal: defaultLease,
MaxLeaseTTLVal: maxLease,
},
Logger: logging.NewVaultLogger(log.Debug),
}
b, err := Factory(ctx, conf)
if err != nil {
return nil, err
}
return &testEnv{
Organisation: os.Getenv(envVarGrafanaCloudOrganisation),
Key: os.Getenv(envVarGrafanaCloudAPIKey),
URL: os.Getenv(envVarGrafanaCloudURL),
PrometheusUser: testPrometheusUser,
PrometheusURL: testPrometheusURL,
LokiUser: testLokiUser,
LokiURL: testLokiURL,
TempoUser: testTempoUser,
TempoURL: testTempoURL,
AlertmanagerUser: testAlertmanagerUser,
AlertmanagerURL: testAlertmanagerURL,
GraphiteUser: testGraphiteUser,
GraphiteURL: testGraphiteURL,
Backend: b,
Context: ctx,
Storage: &logical.InmemStorage{},
}, nil
}
// TestAcceptanceAPIKey tests a series of steps to make
// sure the role and token creation work correctly.
func TestAcceptanceAPIKey(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 api key role", acceptanceTestEnv.AddAPIKeyRole)
t.Run("read api key cred", acceptanceTestEnv.ReadAPIKey)
t.Run("read api key cred", acceptanceTestEnv.ReadAPIKey)
t.Run("cleanup api keys", acceptanceTestEnv.CleanupAPIKeys)
}