-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbackend_test.go
130 lines (114 loc) · 4.39 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package openldap
import (
"context"
"errors"
"time"
"github.com/go-ldap/ldif"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault-plugin-secrets-openldap/client"
"github.com/hashicorp/vault/sdk/helper/logging"
"github.com/hashicorp/vault/sdk/logical"
"github.com/hashicorp/vault/sdk/queue"
)
var (
defaultLeaseTTLVal = time.Hour * 12
maxLeaseTTLVal = time.Hour * 24
testPasswordPolicy1 = "test_policy_1"
testPasswordPolicy2 = "test_policy_2"
testPasswordFromPolicy1 = "TestPolicy1Password"
testPasswordFromPolicy2 = "TestPolicy2Password"
)
func getBackend(throwsErr bool) (*backend, logical.Storage) {
config := &logical.BackendConfig{
Logger: logging.NewVaultLogger(log.Debug),
System: &logical.StaticSystemView{
DefaultLeaseTTLVal: defaultLeaseTTLVal,
MaxLeaseTTLVal: maxLeaseTTLVal,
PasswordPolicies: map[string]logical.PasswordGenerator{
testPasswordPolicy1: func() (string, error) {
return testPasswordFromPolicy1, nil
},
testPasswordPolicy2: func() (string, error) {
return testPasswordFromPolicy2, nil
},
},
},
StorageView: &logical.InmemStorage{},
}
b := Backend(&fakeLdapClient{throwErrs: throwsErr})
b.Setup(context.Background(), config)
b.credRotationQueue = queue.New()
// Create a context with a cancel method for processing any WAL entries and
// populating the queue
initCtx := context.Background()
ictx, cancel := context.WithCancel(initCtx)
b.cancelQueue = cancel
// Load queue and kickoff new periodic ticker
b.initQueue(ictx, &logical.InitializationRequest{
Storage: config.StorageView,
}, nil)
return b, config.StorageView
}
var _ ldapClient = (*fakeLdapClient)(nil)
type fakeLdapClient struct {
throwErrs bool
}
func (f *fakeLdapClient) UpdateUserPassword(_ *client.Config, _ string, _ string) error {
var err error
if f.throwErrs {
err = errors.New("forced error")
}
return err
}
func (f *fakeLdapClient) UpdateDNPassword(_ *client.Config, _ string, _ string) error {
var err error
if f.throwErrs {
err = errors.New("forced error")
}
return err
}
func (f *fakeLdapClient) Execute(_ *client.Config, _ []*ldif.Entry, _ bool) error {
var err error
if f.throwErrs {
err = errors.New("forced error")
}
return err
}
const validCertificate = `
-----BEGIN CERTIFICATE-----
MIIF7zCCA9egAwIBAgIJAOY2qjn64Qq5MA0GCSqGSIb3DQEBCwUAMIGNMQswCQYD
VQQGEwJVUzEQMA4GA1UECAwHTm93aGVyZTERMA8GA1UEBwwIVGltYnVrdHUxEjAQ
BgNVBAoMCVRlc3QgRmFrZTENMAsGA1UECwwETm9uZTEPMA0GA1UEAwwGTm9ib2R5
MSUwIwYJKoZIhvcNAQkBFhZkb25vdHRydXN0QG5vd2hlcmUuY29tMB4XDTE4MDQw
MzIwNDQwOFoXDTE5MDQwMzIwNDQwOFowgY0xCzAJBgNVBAYTAlVTMRAwDgYDVQQI
DAdOb3doZXJlMREwDwYDVQQHDAhUaW1idWt0dTESMBAGA1UECgwJVGVzdCBGYWtl
MQ0wCwYDVQQLDAROb25lMQ8wDQYDVQQDDAZOb2JvZHkxJTAjBgkqhkiG9w0BCQEW
FmRvbm90dHJ1c3RAbm93aGVyZS5jb20wggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAw
ggIKAoICAQDzQPGErqjaoFcuUV6QFpSMU6w8wO8F0othik+rrlKERmrGonUGsoum
WqR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