forked from hashicorp/vault-plugin-secrets-azure
-
Notifications
You must be signed in to change notification settings - Fork 4
/
backend_test.go
97 lines (81 loc) · 2.35 KB
/
backend_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package azuresecrets
import (
"context"
"testing"
"time"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault-plugin-secrets-azure/api"
"github.com/hashicorp/vault/sdk/helper/logging"
"github.com/hashicorp/vault/sdk/logical"
)
const (
defaultLeaseTTLHr = 1 * time.Hour
maxLeaseTTLHr = 12 * time.Hour
defaultTestTTL = 300
defaultTestMaxTTL = 3600
)
var (
testClientID = "testClientId"
testClientSecret = "testClientSecret"
)
func getTestBackend(t *testing.T, initConfig bool) (*azureSecretBackend, logical.Storage) {
b := backend()
config := &logical.BackendConfig{
Logger: logging.NewVaultLogger(log.Trace),
System: &logical.StaticSystemView{
DefaultLeaseTTLVal: defaultLeaseTTLHr,
MaxLeaseTTLVal: maxLeaseTTLHr,
},
StorageView: &logical.InmemStorage{},
}
err := b.Setup(context.Background(), config)
if err != nil {
t.Fatalf("unable to create backend: %v", err)
}
b.settings = new(clientSettings)
mockProvider := newMockProvider()
b.getProvider = func(s *clientSettings, p api.Passwords) (api.AzureProvider, error) {
return mockProvider, nil
}
if initConfig {
cfg := map[string]interface{}{
"subscription_id": generateUUID(),
"tenant_id": generateUUID(),
"client_id": testClientID,
"client_secret": testClientSecret,
"environment": "AZURECHINACLOUD",
"ttl": defaultTestTTL,
"max_ttl": defaultTestMaxTTL,
}
testConfigCreate(t, b, config.StorageView, cfg)
}
return b, config.StorageView
}
func TestPeriodicFuncNilConfig(t *testing.T) {
b := backend()
config := &logical.BackendConfig{
Logger: logging.NewVaultLogger(log.Trace),
System: &logical.StaticSystemView{
DefaultLeaseTTLVal: defaultLeaseTTLHr,
MaxLeaseTTLVal: maxLeaseTTLHr,
},
StorageView: &logical.InmemStorage{},
}
err := b.Setup(context.Background(), config)
if err != nil {
t.Fatalf("unable to create backend: %v", err)
}
b.settings = new(clientSettings)
mockProvider := newMockProvider()
b.getProvider = func(s *clientSettings, p api.Passwords) (api.AzureProvider, error) {
return mockProvider, nil
}
err = b.periodicFunc(context.Background(), &logical.Request{
Storage: config.StorageView,
})
if err != nil {
t.Fatalf("periodicFunc error not nil, it should have been: %v", err)
}
}