1
0
Fork 0
mirror of https://github.com/external-secrets/external-secrets.git synced 2024-12-14 11:57:59 +00:00
external-secrets/pkg/provider/azure/keyvault/keyvault_test.go
Minho Ryang 99194e0237
feat: k8s provider can handle all types of secret, fix #2709 (#2792)
Signed-off-by: Minho Ryang <minho@comcom.ai>
2023-11-01 22:42:49 +01:00

1597 lines
78 KiB
Go

/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package keyvault
import (
"context"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"reflect"
"testing"
"github.com/Azure/azure-sdk-for-go/services/keyvault/2016-10-01/keyvault"
"github.com/Azure/go-autorest/autorest"
pointer "k8s.io/utils/ptr"
esv1beta1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1"
v1 "github.com/external-secrets/external-secrets/apis/meta/v1"
fake "github.com/external-secrets/external-secrets/pkg/provider/azure/keyvault/fake"
utils "github.com/external-secrets/external-secrets/pkg/utils"
)
type secretManagerTestCase struct {
mockClient *fake.AzureMockClient
secretName string
secretVersion string
serviceURL string
ref *esv1beta1.ExternalSecretDataRemoteRef
refFind *esv1beta1.ExternalSecretFind
apiErr error
setErr error
deleteErr error
pushRef esv1beta1.PushRemoteRef
secretOutput keyvault.SecretBundle
setSecretOutput keyvault.SecretBundle
keyOutput keyvault.KeyBundle
createKeyOutput keyvault.KeyBundle
certOutput keyvault.CertificateBundle
importOutput keyvault.CertificateBundle
listOutput keyvault.SecretListResultIterator
deleteKeyOutput keyvault.DeletedKeyBundle
deleteCertificateOutput keyvault.DeletedCertificateBundle
deleteSecretOutput keyvault.DeletedSecretBundle
expectError string
setValue []byte
expectedSecret string
// for testing secretmap
expectedData map[string][]byte
}
func makeValidSecretManagerTestCase() *secretManagerTestCase {
secretString := "Hello World!"
smtc := secretManagerTestCase{
mockClient: &fake.AzureMockClient{},
secretName: "MySecret",
secretVersion: "",
ref: makeValidRef(),
refFind: makeValidFind(),
secretOutput: keyvault.SecretBundle{Value: &secretString},
serviceURL: "",
apiErr: nil,
expectError: "",
expectedSecret: secretString,
expectedData: map[string][]byte{},
}
smtc.mockClient.WithValue(smtc.serviceURL, smtc.secretName, smtc.secretVersion, smtc.secretOutput, smtc.apiErr)
return &smtc
}
func makeValidSecretManagerTestCaseCustom(tweaks ...func(smtc *secretManagerTestCase)) *secretManagerTestCase {
smtc := makeValidSecretManagerTestCase()
for _, fn := range tweaks {
fn(smtc)
}
smtc.mockClient.WithValue(smtc.serviceURL, smtc.secretName, smtc.secretVersion, smtc.secretOutput, smtc.apiErr)
smtc.mockClient.WithKey(smtc.serviceURL, smtc.secretName, smtc.secretVersion, smtc.keyOutput, smtc.apiErr)
smtc.mockClient.WithCertificate(smtc.serviceURL, smtc.secretName, smtc.secretVersion, smtc.certOutput, smtc.apiErr)
smtc.mockClient.WithList(smtc.serviceURL, smtc.listOutput, smtc.apiErr)
smtc.mockClient.WithImportCertificate(smtc.importOutput, smtc.setErr)
smtc.mockClient.WithImportKey(smtc.createKeyOutput, smtc.setErr)
smtc.mockClient.WithSetSecret(smtc.setSecretOutput, smtc.setErr)
smtc.mockClient.WithDeleteCertificate(smtc.deleteCertificateOutput, smtc.deleteErr)
smtc.mockClient.WithDeleteKey(smtc.deleteKeyOutput, smtc.deleteErr)
smtc.mockClient.WithDeleteSecret(smtc.deleteSecretOutput, smtc.deleteErr)
return smtc
}
const (
jwkPubRSA = `{"kid":"ex","kty":"RSA","key_ops":["sign","verify","wrapKey","unwrapKey","encrypt","decrypt"],"n":"p2VQo8qCfWAZmdWBVaYuYb-a-tWWm78K6Sr9poCvNcmv8rUPSLACxitQWR8gZaSH1DklVkqz-Ed8Cdlf8lkDg4Ex5tkB64jRdC1Uvn4CDpOH6cp-N2s8hTFLqy9_YaDmyQS7HiqthOi9oVjil1VMeWfaAbClGtFt6UnKD0Vb_DvLoWYQSqlhgBArFJi966b4E1pOq5Ad02K8pHBDThlIIx7unibLehhDU6q3DCwNH_OOLx6bgNtmvGYJDd1cywpkLQ3YzNCUPWnfMBJRP3iQP_WI21uP6cvo0DqBPBM4wvVzHbCT0vnIflwkbgEWkq1FprqAitZlop9KjLqzjp9vyQ","e":"AQAB"}`
jwkPubEC = `{"kid":"https://example.vault.azure.net/keys/ec-p-521/e3d0e9c179b54988860c69c6ae172c65","kty":"EC","key_ops":["sign","verify"],"crv":"P-521","x":"AedOAtb7H7Oz1C_cPKI_R4CN_eai5nteY6KFW07FOoaqgQfVCSkQDK22fCOiMT_28c8LZYJRsiIFz_IIbQUW7bXj","y":"AOnchHnmBphIWXvanmMAmcCDkaED6ycW8GsAl9fQ43BMVZTqcTkJYn6vGnhn7MObizmkNSmgZYTwG-vZkIg03HHs"}`
jsonTestString = `{"Name": "External", "LastName": "Secret", "Address": { "Street": "Myroad st.", "CP": "J4K4T4" } }`
jsonSingleTestString = `{"Name": "External", "LastName": "Secret" }`
jsonTagTestString = `{"tagname":"tagvalue","tagname2":"tagvalue2"}`
keyName = "key/keyname"
certName = "cert/certname"
secretString = "changedvalue"
unexpectedError = "[%d] unexpected error: %s, expected: '%s'"
unexpectedSecretData = "[%d] unexpected secret data: expected %#v, got %#v"
errorNoTag = "tag something does not exist"
errNotManaged = "not managed by external-secrets"
errNoPermission = "No Permissions"
errAPI = "unexpected api error"
something = "something"
tagname = "tagname"
tagname2 = "tagname2"
tagvalue = "tagvalue"
tagvalue2 = "tagvalue2"
secretName = "example-1"
testsecret = "test-secret"
fakeURL = "noop"
foo = "foo"
bar = "bar"
errStore = "Azure.ValidateStore() error = %v, wantErr %v"
)
func getTagMap() map[string]*string {
tag1 := "tagname"
tag2 := "tagname2"
value1 := "tagvalue"
value2 := "tagvalue2"
tagMap := make(map[string]*string)
tagMap[tag1] = &value1
tagMap[tag2] = &value2
return tagMap
}
func newKVJWK(b []byte) *keyvault.JSONWebKey {
var key keyvault.JSONWebKey
err := json.Unmarshal(b, &key)
if err != nil {
panic(err)
}
return &key
}
type fakeRef struct {
key string
}
func (f fakeRef) GetRemoteKey() string {
return f.key
}
func (f fakeRef) GetProperty() string {
return ""
}
func TestAzureKeyVaultDeleteSecret(t *testing.T) {
unsupportedType := func(smtc *secretManagerTestCase) {
smtc.pushRef = fakeRef{
key: "yadayada/foo",
}
smtc.expectError = "secret type 'yadayada' is not supported"
}
secretSuccess := func(smtc *secretManagerTestCase) {
smtc.pushRef = fakeRef{
key: secretName,
}
smtc.secretOutput = keyvault.SecretBundle{
Tags: map[string]*string{
"managed-by": pointer.To("external-secrets"),
},
Value: pointer.To("foo"),
}
smtc.deleteSecretOutput = keyvault.DeletedSecretBundle{}
}
secretNotFound := func(smtc *secretManagerTestCase) {
smtc.pushRef = fakeRef{
key: secretName,
}
smtc.apiErr = autorest.DetailedError{StatusCode: 404, Method: "GET", Message: "Not Found"}
smtc.deleteErr = autorest.DetailedError{StatusCode: 404, Method: "DELETE", Message: "Not Found"}
}
secretNotManaged := func(smtc *secretManagerTestCase) {
smtc.pushRef = fakeRef{
key: secretName,
}
smtc.secretOutput = keyvault.SecretBundle{
Value: pointer.To("foo"),
}
smtc.expectError = errNotManaged
smtc.deleteErr = autorest.DetailedError{StatusCode: 500, Method: "DELETE", Message: "Shouldnt happen"}
}
secretUnexpectedError := func(smtc *secretManagerTestCase) {
smtc.pushRef = fakeRef{
key: secretName,
}
smtc.expectError = "boom"
smtc.apiErr = fmt.Errorf("boom")
}
secretNoDeletePermissions := func(smtc *secretManagerTestCase) {
smtc.pushRef = fakeRef{
key: secretName,
}
smtc.secretOutput = keyvault.SecretBundle{
Tags: map[string]*string{
"managed-by": pointer.To("external-secrets"),
},
Value: pointer.To("foo"),
}
smtc.expectError = errNoPermission
smtc.deleteErr = autorest.DetailedError{StatusCode: 403, Method: "DELETE", Message: errNoPermission}
}
secretNoGetPermissions := func(smtc *secretManagerTestCase) {
smtc.pushRef = fakeRef{
key: secretName,
}
smtc.expectError = errNoPermission
smtc.apiErr = autorest.DetailedError{StatusCode: 403, Method: "GET", Message: errNoPermission}
}
certificateSuccess := func(smtc *secretManagerTestCase) {
smtc.pushRef = fakeRef{
key: certName,
}
smtc.certOutput = keyvault.CertificateBundle{
Tags: map[string]*string{
"managed-by": pointer.To("external-secrets"),
},
}
smtc.deleteCertificateOutput = keyvault.DeletedCertificateBundle{}
}
certNotFound := func(smtc *secretManagerTestCase) {
smtc.pushRef = fakeRef{
key: certName,
}
smtc.apiErr = autorest.DetailedError{StatusCode: 404, Method: "GET", Message: "Certificate Not Found"}
smtc.deleteErr = autorest.DetailedError{StatusCode: 404, Method: "DELETE", Message: "Not Found"}
}
certNotManaged := func(smtc *secretManagerTestCase) {
smtc.pushRef = fakeRef{
key: certName,
}
smtc.certOutput = keyvault.CertificateBundle{}
smtc.expectError = errNotManaged
smtc.deleteErr = autorest.DetailedError{StatusCode: 500, Method: "DELETE", Message: "Shouldnt happen"}
}
certUnexpectedError := func(smtc *secretManagerTestCase) {
smtc.pushRef = fakeRef{
key: certName,
}
smtc.expectError = "crash"
smtc.apiErr = fmt.Errorf("crash")
}
certNoDeletePermissions := func(smtc *secretManagerTestCase) {
smtc.pushRef = fakeRef{
key: certName,
}
smtc.certOutput = keyvault.CertificateBundle{
Tags: map[string]*string{
"managed-by": pointer.To("external-secrets"),
},
}
smtc.expectError = "No certificate delete Permissions"
smtc.deleteErr = autorest.DetailedError{StatusCode: 403, Method: "DELETE", Message: "No certificate delete Permissions"}
}
certNoGetPermissions := func(smtc *secretManagerTestCase) {
smtc.pushRef = fakeRef{
key: certName,
}
smtc.expectError = "No certificate get Permissions"
smtc.apiErr = autorest.DetailedError{StatusCode: 403, Method: "GET", Message: "No certificate get Permissions"}
}
keySuccess := func(smtc *secretManagerTestCase) {
smtc.pushRef = fakeRef{
key: keyName,
}
smtc.keyOutput = keyvault.KeyBundle{
Tags: map[string]*string{
"managed-by": pointer.To("external-secrets"),
},
}
smtc.deleteKeyOutput = keyvault.DeletedKeyBundle{}
}
keyNotFound := func(smtc *secretManagerTestCase) {
smtc.pushRef = fakeRef{
key: keyName,
}
smtc.apiErr = autorest.DetailedError{StatusCode: 404, Method: "GET", Message: "Not Found"}
smtc.deleteErr = autorest.DetailedError{StatusCode: 404, Method: "DELETE", Message: "Not Found"}
}
keyNotManaged := func(smtc *secretManagerTestCase) {
smtc.pushRef = fakeRef{
key: keyName,
}
smtc.keyOutput = keyvault.KeyBundle{}
smtc.expectError = errNotManaged
smtc.deleteErr = autorest.DetailedError{StatusCode: 500, Method: "DELETE", Message: "Shouldnt happen"}
}
keyUnexpectedError := func(smtc *secretManagerTestCase) {
smtc.pushRef = fakeRef{
key: keyName,
}
smtc.expectError = "tls timeout"
smtc.apiErr = fmt.Errorf("tls timeout")
}
keyNoDeletePermissions := func(smtc *secretManagerTestCase) {
smtc.pushRef = fakeRef{
key: keyName,
}
smtc.keyOutput = keyvault.KeyBundle{
Tags: map[string]*string{
"managed-by": pointer.To("external-secrets"),
},
}
smtc.expectError = errNoPermission
smtc.deleteErr = autorest.DetailedError{StatusCode: 403, Method: "DELETE", Message: errNoPermission}
}
keyNoGetPermissions := func(smtc *secretManagerTestCase) {
smtc.pushRef = fakeRef{
key: keyName,
}
smtc.expectError = errNoPermission
smtc.apiErr = autorest.DetailedError{StatusCode: 403, Method: "GET", Message: errNoPermission}
}
successCases := []*secretManagerTestCase{
makeValidSecretManagerTestCaseCustom(unsupportedType),
makeValidSecretManagerTestCaseCustom(secretSuccess),
makeValidSecretManagerTestCaseCustom(secretNotFound),
makeValidSecretManagerTestCaseCustom(secretNotManaged),
makeValidSecretManagerTestCaseCustom(secretUnexpectedError),
makeValidSecretManagerTestCaseCustom(secretNoDeletePermissions),
makeValidSecretManagerTestCaseCustom(secretNoGetPermissions),
makeValidSecretManagerTestCaseCustom(certificateSuccess),
makeValidSecretManagerTestCaseCustom(certNotFound),
makeValidSecretManagerTestCaseCustom(certNotManaged),
makeValidSecretManagerTestCaseCustom(certUnexpectedError),
makeValidSecretManagerTestCaseCustom(certNoDeletePermissions),
makeValidSecretManagerTestCaseCustom(certNoGetPermissions),
makeValidSecretManagerTestCaseCustom(keySuccess),
makeValidSecretManagerTestCaseCustom(keyNotFound),
makeValidSecretManagerTestCaseCustom(keyNotManaged),
makeValidSecretManagerTestCaseCustom(keyUnexpectedError),
makeValidSecretManagerTestCaseCustom(keyNoDeletePermissions),
makeValidSecretManagerTestCaseCustom(keyNoGetPermissions),
}
sm := Azure{
provider: &esv1beta1.AzureKVProvider{VaultURL: pointer.To(fakeURL)},
}
for k, v := range successCases {
sm.baseClient = v.mockClient
err := sm.DeleteSecret(context.Background(), v.pushRef)
if !utils.ErrorContains(err, v.expectError) {
if err == nil {
t.Errorf("[%d] unexpected error: <nil>, expected: '%s'", k, v.expectError)
} else {
t.Errorf("[%d] unexpected error: '%s', expected: '%s'", k, err.Error(), v.expectError)
}
}
}
}
func TestAzureKeyVaultPushSecret(t *testing.T) {
p12Cert, _ := base64.StdEncoding.DecodeString("MIIQaQIBAzCCEC8GCSqGSIb3DQEHAaCCECAEghAcMIIQGDCCBk8GCSqGSIb3DQEHBqCCBkAwggY8AgEAMIIGNQYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQYwDgQIoJ3l+zBtWI8CAggAgIIGCBqkhjPsUaowPQrDumYb2OySFN7Jt91IbIeCt1W3Lk99ueJbZ4+xNUiOD+ZDLLJJI/EDtq+0b+TgWHjx92q/IEUj2woQV2rg1W8EW815MmstyD0YRnw7KvoEKBH+CsWiR/JcC/IVoiV1od0dWFfWGSBtWY5xLiaBWUX6xV8zcBVz1fkB+pHOofkStW2up6G2sQos1WwIptAvz6VpS16xLUmZ1whZZvPhqz1GPfexJSavBWEe7YcoxVd/q8LLGQmQCfV7zXwyUX3WnHATkesYPMSTDPuRWXMOrJRjy2zinQP5XweNY2DeZ2bRV6y3v8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/secret",
}
smtc.expectError = "secret type badtype not supported"
}
secretSuccess := func(smtc *secretManagerTestCase) {
smtc.setValue = []byte("secret")
smtc.pushRef = fakeRef{
key: secretName,
}
smtc.secretOutput = keyvault.SecretBundle{
Tags: map[string]*string{
"managed-by": pointer.To("external-secrets"),
},
Value: &goodSecret,
}
}
secretNoChange := func(smtc *secretManagerTestCase) {
smtc.setValue = []byte(goodSecret)
smtc.pushRef = fakeRef{
key: secretName,
}
smtc.secretOutput = keyvault.SecretBundle{
Tags: map[string]*string{
"managed-by": pointer.To("external-secrets"),
},
Value: &goodSecret,
}
}
secretWrongTags := func(smtc *secretManagerTestCase) {
smtc.setValue = []byte(goodSecret)
smtc.pushRef = fakeRef{
key: secretName,
}
smtc.secretOutput = keyvault.SecretBundle{
Tags: map[string]*string{
"managed-by": pointer.To("nope"),
},
Value: &goodSecret,
}
smtc.expectError = errNotManaged
}
secretNoTags := func(smtc *secretManagerTestCase) {
smtc.setValue = []byte(goodSecret)
smtc.pushRef = fakeRef{
key: secretName,
}
smtc.secretOutput = keyvault.SecretBundle{
Tags: map[string]*string{},
Value: &goodSecret,
}
smtc.expectError = errNotManaged
}
secretNotFound := func(smtc *secretManagerTestCase) {
smtc.setValue = []byte(goodSecret)
smtc.pushRef = fakeRef{
key: secretName,
}
smtc.apiErr = autorest.DetailedError{StatusCode: 404, Method: "GET", Message: "Not Found"}
}
failedGetSecret := func(smtc *secretManagerTestCase) {
smtc.setValue = []byte(goodSecret)
smtc.pushRef = fakeRef{
key: secretName,
}
smtc.apiErr = autorest.DetailedError{StatusCode: 403, Method: "GET", Message: "Forbidden"}
smtc.expectError = errAPI
}
failedNotParseableError := func(smtc *secretManagerTestCase) {
smtc.setValue = []byte(goodSecret)
smtc.pushRef = fakeRef{
key: secretName,
}
smtc.apiErr = fmt.Errorf("crash")
smtc.expectError = "crash"
}
failedSetSecret := func(smtc *secretManagerTestCase) {
smtc.setValue = []byte(goodSecret)
smtc.pushRef = fakeRef{
key: secretName,
}
smtc.apiErr = autorest.DetailedError{StatusCode: 404, Method: "GET", Message: "Not Found"}
smtc.setErr = autorest.DetailedError{StatusCode: 403, Method: "POST", Message: "Forbidden"}
smtc.expectError = "could not set secret example-1: #POST: Forbidden: StatusCode=403"
}
keySuccess := func(smtc *secretManagerTestCase) {
smtc.setValue = goodKey
smtc.pushRef = fakeRef{
key: keyName,
}
smtc.keyOutput = keyvault.KeyBundle{
Tags: map[string]*string{
"managed-by": pointer.To(managerLabel),
},
Key: &keyvault.JSONWebKey{},
}
}
symmetricKeySuccess := func(smtc *secretManagerTestCase) {
smtc.setValue = []byte("secret")
smtc.pushRef = fakeRef{
key: keyName,
}
smtc.keyOutput = keyvault.KeyBundle{
Tags: map[string]*string{
"managed-by": pointer.To(managerLabel),
},
Key: &keyvault.JSONWebKey{},
}
}
RSAKeySuccess := func(smtc *secretManagerTestCase) {
smtc.setValue, _ = base64.StdEncoding.DecodeString("LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlKS1FJQkFBS0NBZ0VBdmIxYjM2YlpyaFNFYm5YWGtRL1pjR3VLY05HMDBGa2U1SkVOaWU4UzFHTG1uK1N0CndmdittVFRUN2xyVkdpVkplV3ZhQnRkMUVLRll0aWdlVlhJQjA0MllzeHRmMlM5WkNzNlUxaFZDWFZQc3BobEUKOUVyOHNHa0Ewa1lKdmxWejR2eFA2NTNzNjFGYTBpclRvUGlJTFZwMU1jdGRxVnB0VnJFV1JadzQ2NEF4MzhNNgpCMjFvN2NaUmlZN3VGZTA4UEllbEd3VGc0cHJRdEg2VXVuK09BV3MrNFNDTU5xT2xDRkNzSDBLK0NZZUMyZmpXClplaURsbjBTUDdkZ3puMmJsbk9VQzZ0Z3VtQ3grdW1ISVdmV1hzUDVQR0hoWFBwYlpGbDA4ZktaelNqbytCOWkKVzVsbWhrRE1HM0dsU0JPMmEvcEtjck1uTFVWbE15OVdWLy9LUmw3ZWFtdmJ5dWFzSnZHbVJ4L3d1NXlpYVhwS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Flb016T2pwbE45a1JOREsxT2k4MUpZRitlKzdTYm9nbkJZMXZHCktoU2FlQ0dqWkFkMG1BbElaYmVtZlVmbk1PeHNaSStvTVFLQ0FRQmdETzBkTEt2Z3k0OFFwNzdzU3FkeGRRdTEKb2pqYm9rMGY4VVo5ZDJZWWl1WHMwb0k2WFQ4cmpESmJYUGZSUmFVUU1JYWRrL1VZOWxRdHZRRThHbW9aR2ozbgpXYTVXWGVkcUR3YUR4aHpmVnZQUzFMVm1VdkhsbllPWVBVT0JPc1ZUaU4yWXk1L0Y5WEpxMWRlVW0xVnVOZCs1ClVuK3d0YWVHVGR5K1pyQjF2RUFRT3M3R1REVFI2MjgwV1BPZ1JsenVRejhkYllYR29iajJrd3N1empCa0EvSjAKc2dkeEF0dExBWmIzQlVSQ2NmenkrdHJCd0Y3S1ZYek5EQnhmcit3MklRR0hINXR5NmNvcExTVDNXb2Y4WVRuTQpMdHBCVDNZTmgwTm5hS25HTlRGc3pZRldIRlJqSjRZU1BrcW85TkdWa0tiblZyOTllMDFjLys1VjBYY00KLS0tLS1FTkQgUlNBIFBSSVZBVEUgS0VZLS0tLS0K")
smtc.pushRef = fakeRef{
key: keyName,
}
smtc.keyOutput = keyvault.KeyBundle{
Tags: map[string]*string{
"managed-by": pointer.To(managerLabel),
},
Key: &keyvault.JSONWebKey{},
}
}
ECKeySuccess := func(smtc *secretManagerTestCase) {
smtc.setValue, _ = base64.StdEncoding.DecodeString("LS0tLS1CRUdJTiBFQyBQUklWQVRFIEtFWS0tLS0tCk1JR2tBZ0VCQkRBWTk0L0NYOGo4UDNBakZXUkZYR0pWMFNWT1ErU1ZpV01nd0VFdy9rV2ZXcHF1OGtidllVTnAKVTQyN1Fubk5NV3VnQndZRks0RUVBQ0toWkFOaUFBU1FyOXAvcytDWHpFY2RUZ2t0aVFhTkxuVzJnNmQ1QkF4cQpBQXNaQms2UW11WngrZTZMUUdra080Uit0SVVaZCtWTGJlV3pLeEl3dk9xSVA3bkp0QldtTjZ4N3JsMjJibnhNCm5QWVQyNy9wSXM1RTk1L2dPV2RhOGMyUStHQTd5RTQ9Ci0tLS0tRU5EIEVDIFBSSVZBVEUgS0VZLS0tLS0K")
smtc.pushRef = fakeRef{
key: keyName,
}
smtc.keyOutput = keyvault.KeyBundle{
Tags: map[string]*string{
"managed-by": pointer.To(managerLabel),
},
Key: &keyvault.JSONWebKey{},
}
}
invalidKey := func(smtc *secretManagerTestCase) {
smtc.setValue, _ = base64.StdEncoding.DecodeString("LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUZhekNDQTFPZ0F3SUJBZ0lVUHZKZ21wcTBKUWVRNkJuL0hmVTcvUDhRTFlFd0RRWUpLb1pJaHZjTkFRRUwKQlFBd1JURUxNQWtHQTFVRUJoTUNRVlV4RXpBUkJnTlZCQWdNQ2xOdmJXVXRVM1JoZEdVeElUQWZCZ05WQkFvTQpHRWx1ZEdWeWJtVjBJRmRwWkdkcGRITWdVSFI1SUV4MFpEQWVGdzB5TWpBMk1UY3lNREEwTWpSYUZ3MHlNekEyCk1UY3lNREEwTWpSYU1FVXhDekFKQmdOVkJBWVRBa0ZWTVJNd0VRWURWUVFJREFwVGIyMWxMVk4wWVhSbE1TRXcKSHdZRFZRUUtEQmhKYm5SbGNtNWxkQ0JYYVdSbmFYUnpJRkIwZVNCTWRHUXdnZ0lpTUEwR0NTcUdTSWIzRFFFQgpBUVVBQTRJQ0R3QXdnZ0lLQW9JQ0FRRGlEditEVENBL0xaZjZiNnlVYnliQUxlSUViOHh0aHd1dnRFZk5aZ1dOClN3ZWNMZXY0QXF1N3lSUWRidlQ1cnRKOGs3TnJ0TUE0RDNVN1BQamkwOXVpdjFnSGRockY0VlloTjhiRFllc1UKaEpxZXZSVFBVQ0hRek9xMmNhT3ViRnBUN3JxN3lsMVFTQTFlbkptMUQxNnc0UnlJcEtTLzhvVDNQaGtXM1YydwpkWmFjblZSV1RXZE5MTy9iVWdseDd1YzJMS0wwd2pIMzNSbkZiWUU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tDYVVSeU4vNTZXYk9OanhzRUhUbFhnClBBTEVYKzZVNDMzdktkYnNZdTJXZ2hXSmNwMytSZkI2MU90VmdvYTJYaThhL2pSbFpKVUJ1ZURESGEwVTE0L2EKaFRKcVdQWElROFlTY1BCbndsTzFyRjJkaEtMU0hiczZBd3d6VEVHUE5SUVpGRXF4YTJlb3VvV0NWUmxHTGVueQpMcWxnb1FSQ1pGRTdNNnBJazE5b0ZwV2tTSmNXYjFRMjJRWE03SFdKNjNtM2VBRjBUNThXcE45UzBsYXFNbnZCClZxNVpueUs1YVNDNjV3MGp1YzJteWM2K1RyUmNQSmM0UHJCY3VSZ0gvS1M1bkQvVFlKSStOSVBjU0NVZ2VKWFgKR003THNZanVuY1pCQmJkbFByRXJJN3pkYVNGdVJJbWYrSmh3T2p4OThSZjg3WkQ3d05pRmtzd1ZQYWZFQzFXQQoxc3ZMZDI0Nk0vR3I0RFVDK2Y2MUx4eFNKUkRWMDNySmdsZnY2cWlrL3hjaVlKU2lDdkZzR0hqYzBJaEtyTXBNCnFKRW03dWQxK3VTM3NHWTR6SkVUMUhleEJudjJ4RVlESjZhbGErV3FsNDdZTllSNm4yNlAvUWpNYjdSSGE1ZWMKUEhPMW5HaTY5L1U1dmVMRVlmZmtIV01qSTlKa1dhQzFiREcrMDl0clpSdXNUQWJCZHhqbWxzZ3o0UUFDeFd3PQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==")
smtc.pushRef = fakeRef{
key: keyName,
}
smtc.keyOutput = keyvault.KeyBundle{
Tags: map[string]*string{
"managed-by": pointer.To(managerLabel),
},
Key: &keyvault.JSONWebKey{},
}
smtc.expectError = "could not load private key keyname: key type CERTIFICATE is not supported"
}
noTags := func(smtc *secretManagerTestCase) {
smtc.setValue = goodKey
smtc.pushRef = fakeRef{
key: keyName,
}
smtc.keyOutput = keyvault.KeyBundle{
Tags: map[string]*string{},
Key: &keyvault.JSONWebKey{},
}
smtc.expectError = errNotManaged
}
wrongTags := func(smtc *secretManagerTestCase) {
smtc.setValue = goodKey
smtc.pushRef = fakeRef{
key: keyName,
}
smtc.keyOutput = keyvault.KeyBundle{
Tags: map[string]*string{
"managed-by": pointer.To("internal-secrets"),
},
Key: &keyvault.JSONWebKey{},
}
smtc.expectError = errNotManaged
}
errorGetKey := func(smtc *secretManagerTestCase) {
smtc.setValue = goodKey
smtc.pushRef = fakeRef{
key: keyName,
}
smtc.apiErr = autorest.DetailedError{StatusCode: 403, Method: "GET", Message: "Forbidden"}
smtc.expectError = errAPI
}
keyNotFound := func(smtc *secretManagerTestCase) {
smtc.setValue = goodKey
smtc.pushRef = fakeRef{
key: keyName,
}
smtc.apiErr = autorest.DetailedError{StatusCode: 404, Method: "GET", Message: "Not Found"}
smtc.expectError = ""
}
importKeyFailed := func(smtc *secretManagerTestCase) {
smtc.setValue = goodKey
smtc.pushRef = fakeRef{
key: keyName,
}
smtc.apiErr = autorest.DetailedError{StatusCode: 404, Method: "GET", Message: "Not Found"}
smtc.setErr = autorest.DetailedError{StatusCode: 403, Method: "POST", Message: "Forbidden"}
smtc.expectError = "could not import key keyname: #POST: Forbidden: StatusCode=403"
}
certP12Success := func(smtc *secretManagerTestCase) {
smtc.setValue = p12Cert
smtc.pushRef = fakeRef{
key: certName,
}
smtc.certOutput = keyvault.CertificateBundle{
X509Thumbprint: pointer.To("123"),
Tags: map[string]*string{
"managed-by": pointer.To("external-secrets"),
},
}
}
certPEMSuccess := func(smtc *secretManagerTestCase) {
pemCert, _ := base64.StdEncoding.DecodeString("LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUZwekNDQTQrZ0F3SUJBZ0lVTUhhVDZtZG8vd2Urbit0NFB2R0JZaUdDSXE0d0RRWUpLb1pJaHZjTkFRRUwKQlFBd1l6RUxNQWtHQTFVRUJoTUNRVlV4RXpBUkJnTlZCQWdNQ2xOdmJXVXRVM1JoZEdVeElUQWZCZ05WQkFvTQpHRWx1ZEdWeWJtVjBJRmRwWkdkcGRITWdVSF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Z3V6R0Zka0czRVh1K09oR2JVMC8rNzdWTW5aaTJJUVpuL2F3R1VhN1grTVAwQkR2alZZNWtWcE1aMWgKYzJDbERqZ3hOc0xHdGlrTzRjV2I1c1FSUjJHWU0zZE1rNTBWUWN0SjVScXNSczZwT0NYRFhFM1JlVlFqNGhOQgplV3ZhRFdRMktteU9haTU1ZGJEcmxKK251ODNPbUNwNTlSelA1azU4WmFEWG5sQzM4VXdUdDBxMUQ3K3pGMHRzCjFHOTMydUVCSFdZSHVPQT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=")
smtc.setValue = pemCert
smtc.pushRef = fakeRef{
key: certName,
}
smtc.certOutput = keyvault.CertificateBundle{
X509Thumbprint: pointer.To("123"),
Tags: map[string]*string{
"managed-by": pointer.To("external-secrets"),
},
}
}
certPEMWithGarbageSuccess := func(smtc *secretManagerTestCase) {
pemCert, _ := base64.StdEncoding.DecodeString("LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFb3dJQkFBS0NBUUVBNWNXTTdWYnd2dGtxWXVLd1lrVUhlSXRMQnd2eUd2ekhzODQwbDZpT00rZXZneEVXCmcydFAvb3NYeG1Rb1ZOdDJLUXRScEwweTh4K3JhWHhRRm5VTlJEc3pHSEkyWTdmWnVVRWd0M2FQQVhmUUlMNm0KazdJaWQ0VmZUdlpLTFhNbnB6dEduNVlaTVBxak0yU3k3ZWY5ZjJMNkxuamNwRkRNZFBqN25vd0pxcTdMb3kxcAo2aU1xeHNyRGY1RXloRHdGUVhiZHRQM0pPNmpjSDY4UUVsVkE0eVR5RHR4WXpxSS9mb0pIM2tGZStHSmJwS0FNCnlNQXRwVkphS2F6VGVnTCtWZnc1MFV2czFLT3A3L1ZxZXVCd2FpZDhtWkhYWDFRUE44RE9VUmJRbkhoVUp1Y3UKZlIyNVdlbHhqWUtOMGdGWFE1bHo5MXY1TmVlTnhQWkhRbkZ2NVFJREFRQUJBb0lCQUNQR2FuYlp2b280amR6d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cE9DWERYRTNSZVZRajRoTkIKZVd2YURXUTJLbXlPYWk1NWRiRHJsSitudTgzT21DcDU5UnpQNWs1OFphRFhubEMzOFV3VHQwcTFENyt6RjB0cwoxRzkzMnVFQkhXWUh1T0E9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K")
smtc.setValue = pemCert
smtc.pushRef = fakeRef{
key: certName,
}
smtc.certOutput = keyvault.CertificateBundle{
X509Thumbprint: pointer.To("123"),
Tags: map[string]*string{
"managed-by": pointer.To("external-secrets"),
},
}
}
certDERSuccess := func(smtc *secretManagerTestCase) {
derCert, _ := base64.StdEncoding.DecodeString("MIIFpzCCA4+gAwIBAgIUMHaT6mdo/we+n+t4PvGBYiGCIq4wDQYJKoZIhvcNAQELBQAwYzELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEcMBoGA1UEAwwTYW5vdGhlci1mb28tYmFyLmNvbTAeFw0yMjA2MDkxNzQ1MzZaFw0yMzA2MDkxNzQ1MzZaMGMxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxHDAaBgNVBAMME2Fub3RoZXItZm9vLWJhci5jb20wggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCZHO4o6JmyOZdfAt7DWjGkGw7D5UHSPGet2N86rpFYw+e8g/wRx0gd0sFOizPADGcrzfua9gvEp4VsWoaGncwQxjvs+gZ+Zd6REO4tK74TFf1ifbnj0Pq68CeBQiho1l3p3e0C/2zeI23bvVDve2mwUq9h68Q1ERgV1MKibGSSZjNCC7dDaPZjJk5b0YVTWqDEbzdDVxveUL5RqFg/DJA33Vq6TT3Ce9F0HpJ+ox+i+8qLfYNjdLRP6elKKMNgiXa51ovt921xREFvXEv/MKjY9a6Ji6wHE+46golV8Wjn+lLFDJTxzX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R2GYM3dMk50VQctJ5RqsRs6pOCXDXE3ReVQj4hNBeWvaDWQ2KmyOai55dbDrlJ+nu83OmCp59RzP5k58ZaDXnlC38UwTt0q1D7+zF0ts1G932uEBHWYHuOA=")
smtc.setValue = derCert
smtc.pushRef = fakeRef{
key: certName,
}
smtc.certOutput = keyvault.CertificateBundle{
X509Thumbprint: pointer.To("123"),
Tags: map[string]*string{
"managed-by": pointer.To("external-secrets"),
},
}
}
certImportCertificateError := func(smtc *secretManagerTestCase) {
smtc.setErr = errors.New("error")
smtc.setValue = p12Cert
smtc.pushRef = fakeRef{
key: certName,
}
smtc.certOutput = keyvault.CertificateBundle{
X509Thumbprint: pointer.To("123"),
Tags: map[string]*string{
"managed-by": pointer.To("external-secrets"),
},
}
smtc.expectError = "could not import certificate certname: error"
}
certFingerprintMatches := func(smtc *secretManagerTestCase) {
smtc.setErr = errors.New("error")
cert, _ := base64.StdEncoding.DecodeString("MIIFpzCCA4+gAwIBAgIUMHaT6mdo/we+n+t4PvGBYiGCIq4wDQYJKoZIhvcNAQELBQAwYzELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEcMBoGA1UEAwwTYW5vdGhlci1mb28tYmFyLmNvbTAeFw0yMjA2MDkxNzQ1MzZaFw0yMzA2MDkxNzQ1MzZaMGMxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxHDAaBgNVBAMME2Fub3RoZXItZm9vLWJhci5jb20wggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCZHO4o6JmyOZdfAt7DWjGkGw7D5UHSPGet2N86rpFYw+e8g/wRx0gd0sFOizPADGcrzfua9gvEp4VsWoaGncwQxjvs+gZ+Zd6REO4tK74TFf1ifbnj0Pq68CeBQiho1l3p3e0C/2zeI23bvVDve2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FXAAUjJ5OXabxbDrQ+OMejwc4HqqsxztJgD2aP2eK2/L5PWPug0E+1g8ABZfVboh/M3MHgbzPgaTqguzGFdkG3EXu+OhGbU0/+77VMnZi2IQZn/awGUa7X+MP0BDvjVY5kVpMZ1hc2ClDjgxNsLGtikO4cWb5sQRR2GYM3dMk50VQctJ5RqsRs6pOCXDXE3ReVQj4hNBeWvaDWQ2KmyOai55dbDrlJ+nu83OmCp59RzP5k58ZaDXnlC38UwTt0q1D7+zF0ts1G932uEBHWYHuOA=")
smtc.setValue = p12Cert
smtc.pushRef = fakeRef{
key: certName,
}
smtc.certOutput = keyvault.CertificateBundle{
Cer: &cert,
Tags: map[string]*string{
"managed-by": pointer.To("external-secrets"),
},
}
}
certNotManagedByES := func(smtc *secretManagerTestCase) {
smtc.setValue = p12Cert
smtc.pushRef = fakeRef{
key: certName,
}
smtc.certOutput = keyvault.CertificateBundle{
X509Thumbprint: pointer.To("123"),
Tags: map[string]*string{
"managed-by": pointer.To("foobar"),
},
}
smtc.expectError = "certificate certname: not managed by external-secrets"
}
certNoManagerTags := func(smtc *secretManagerTestCase) {
smtc.setValue = p12Cert
smtc.pushRef = fakeRef{
key: certName,
}
smtc.certOutput = keyvault.CertificateBundle{
X509Thumbprint: pointer.To("123"),
}
smtc.expectError = "certificate certname: not managed by external-secrets"
}
certNotACertificate := func(smtc *secretManagerTestCase) {
smtc.setValue = []byte("foobar")
smtc.pushRef = fakeRef{
key: certName,
}
smtc.certOutput = keyvault.CertificateBundle{
X509Thumbprint: pointer.To("123"),
}
smtc.expectError = "value from secret is not a valid certificate: could not parse certificate value as PKCS#12, DER or PEM"
}
certNoPermissions := func(smtc *secretManagerTestCase) {
smtc.apiErr = autorest.DetailedError{
StatusCode: 403,
Method: "GET",
Message: "Insufficient Permissions",
}
smtc.setValue = p12Cert
smtc.pushRef = fakeRef{
key: certName,
}
smtc.certOutput = keyvault.CertificateBundle{
X509Thumbprint: pointer.To("123"),
}
smtc.expectError = errAPI
}
successCases := []*secretManagerTestCase{
makeValidSecretManagerTestCaseCustom(certP12Success),
makeValidSecretManagerTestCaseCustom(certPEMSuccess),
makeValidSecretManagerTestCaseCustom(certPEMWithGarbageSuccess),
makeValidSecretManagerTestCaseCustom(certDERSuccess),
makeValidSecretManagerTestCaseCustom(certImportCertificateError),
makeValidSecretManagerTestCaseCustom(certFingerprintMatches),
makeValidSecretManagerTestCaseCustom(certNotManagedByES),
makeValidSecretManagerTestCaseCustom(certNoManagerTags),
makeValidSecretManagerTestCaseCustom(certNotACertificate),
makeValidSecretManagerTestCaseCustom(certNoPermissions),
makeValidSecretManagerTestCaseCustom(keySuccess),
makeValidSecretManagerTestCaseCustom(symmetricKeySuccess),
makeValidSecretManagerTestCaseCustom(RSAKeySuccess),
makeValidSecretManagerTestCaseCustom(ECKeySuccess),
makeValidSecretManagerTestCaseCustom(invalidKey),
makeValidSecretManagerTestCaseCustom(errorGetKey),
makeValidSecretManagerTestCaseCustom(keyNotFound),
makeValidSecretManagerTestCaseCustom(importKeyFailed),
makeValidSecretManagerTestCaseCustom(noTags),
makeValidSecretManagerTestCaseCustom(wrongTags),
makeValidSecretManagerTestCaseCustom(secretSuccess),
makeValidSecretManagerTestCaseCustom(secretNoChange),
makeValidSecretManagerTestCaseCustom(secretWrongTags),
makeValidSecretManagerTestCaseCustom(secretNoTags),
makeValidSecretManagerTestCaseCustom(secretNotFound),
makeValidSecretManagerTestCaseCustom(failedGetSecret),
makeValidSecretManagerTestCaseCustom(failedNotParseableError),
makeValidSecretManagerTestCaseCustom(failedSetSecret),
makeValidSecretManagerTestCaseCustom(typeNotSupported),
}
sm := Azure{
provider: &esv1beta1.AzureKVProvider{VaultURL: pointer.To(fakeURL)},
}
for k, v := range successCases {
sm.baseClient = v.mockClient
err := sm.PushSecret(context.Background(), v.setValue, "", nil, v.pushRef)
if !utils.ErrorContains(err, v.expectError) {
if err == nil {
t.Errorf("[%d] unexpected error: <nil>, expected: '%s'", k, v.expectError)
} else {
t.Errorf("[%d] unexpected error: %s, expected: '%s'", k, err.Error(), v.expectError)
}
}
}
}
// test the sm<->azurekv interface
// make sure correct values are passed and errors are handled accordingly.
func TestAzureKeyVaultSecretManagerGetSecret(t *testing.T) {
secretString := "changedvalue"
secretCertificate := "certificate_value"
tagMap := getTagMap()
// good case
setSecretString := func(smtc *secretManagerTestCase) {
smtc.expectedSecret = secretString
smtc.secretOutput = keyvault.SecretBundle{
Value: &secretString,
}
}
// good case
secretNotFound := func(smtc *secretManagerTestCase) {
smtc.expectedSecret = ""
smtc.apiErr = autorest.DetailedError{StatusCode: 404}
smtc.expectError = esv1beta1.NoSecretError{}.Error()
}
certNotFound := func(smtc *secretManagerTestCase) {
smtc.expectedSecret = ""
smtc.secretName = certName
smtc.apiErr = autorest.DetailedError{StatusCode: 404}
smtc.expectError = esv1beta1.NoSecretError{}.Error()
}
keyNotFound := func(smtc *secretManagerTestCase) {
smtc.expectedSecret = ""
smtc.secretName = keyName
smtc.apiErr = autorest.DetailedError{StatusCode: 404}
smtc.expectError = esv1beta1.NoSecretError{}.Error()
}
setSecretStringWithVersion := func(smtc *secretManagerTestCase) {
smtc.expectedSecret = secretString
smtc.secretOutput = keyvault.SecretBundle{
Value: &secretString,
}
smtc.ref.Version = "v1"
smtc.secretVersion = smtc.ref.Version
}
setSecretWithProperty := func(smtc *secretManagerTestCase) {
jsonString := jsonTestString
smtc.expectedSecret = "External"
smtc.secretOutput = keyvault.SecretBundle{
Value: &jsonString,
}
smtc.ref.Property = "Name"
}
badSecretWithProperty := func(smtc *secretManagerTestCase) {
jsonString := jsonTestString
smtc.expectedSecret = ""
smtc.secretOutput = keyvault.SecretBundle{
Value: &jsonString,
}
smtc.ref.Property = "Age"
smtc.expectError = fmt.Sprintf("property %s does not exist in key %s", smtc.ref.Property, smtc.ref.Key)
smtc.apiErr = errors.New(smtc.expectError)
}
// // good case: key set
setPubRSAKey := func(smtc *secretManagerTestCase) {
smtc.secretName = keyName
smtc.expectedSecret = jwkPubRSA
smtc.keyOutput = keyvault.KeyBundle{
Key: newKVJWK([]byte(jwkPubRSA)),
}
smtc.ref.Key = smtc.secretName
}
// // good case: key set
setPubECKey := func(smtc *secretManagerTestCase) {
smtc.secretName = keyName
smtc.expectedSecret = jwkPubEC
smtc.keyOutput = keyvault.KeyBundle{
Key: newKVJWK([]byte(jwkPubEC)),
}
smtc.ref.Key = smtc.secretName
}
// // good case: key set
setCertificate := func(smtc *secretManagerTestCase) {
byteArrString := []byte(secretCertificate)
smtc.secretName = certName
smtc.expectedSecret = secretCertificate
smtc.certOutput = keyvault.CertificateBundle{
Cer: &byteArrString,
}
smtc.ref.Key = smtc.secretName
}
badSecretType := func(smtc *secretManagerTestCase) {
smtc.secretName = "name"
smtc.expectedSecret = ""
smtc.expectError = fmt.Sprintf("unknown Azure Keyvault object Type for %s", smtc.secretName)
smtc.ref.Key = fmt.Sprintf("example/%s", smtc.secretName)
}
setSecretWithTag := func(smtc *secretManagerTestCase) {
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
smtc.ref.Property = tagname
smtc.secretOutput = keyvault.SecretBundle{
Value: &secretString, Tags: tagMap,
}
smtc.expectedSecret = tagvalue
}
badSecretWithTag := func(smtc *secretManagerTestCase) {
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
smtc.ref.Property = something
smtc.expectedSecret = ""
smtc.expectError = errorNoTag
smtc.apiErr = errors.New(smtc.expectError)
}
setSecretWithNoSpecificTag := func(smtc *secretManagerTestCase) {
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
smtc.secretOutput = keyvault.SecretBundle{
Value: &secretString, Tags: tagMap,
}
smtc.expectedSecret = jsonTagTestString
}
setSecretWithNoTags := func(smtc *secretManagerTestCase) {
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
smtc.secretOutput = keyvault.SecretBundle{}
smtc.expectedSecret = "{}"
}
setCertWithTag := func(smtc *secretManagerTestCase) {
byteArrString := []byte(secretCertificate)
smtc.secretName = certName
smtc.certOutput = keyvault.CertificateBundle{
Cer: &byteArrString, Tags: tagMap,
}
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
smtc.ref.Property = tagname
smtc.expectedSecret = tagvalue
smtc.ref.Key = smtc.secretName
}
badCertWithTag := func(smtc *secretManagerTestCase) {
byteArrString := []byte(secretCertificate)
smtc.secretName = certName
smtc.ref.Key = smtc.secretName
smtc.certOutput = keyvault.CertificateBundle{
Cer: &byteArrString,
}
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
smtc.ref.Property = something
smtc.expectedSecret = ""
smtc.expectError = errorNoTag
smtc.apiErr = errors.New(smtc.expectError)
}
setCertWithNoSpecificTag := func(smtc *secretManagerTestCase) {
byteArrString := []byte(secretCertificate)
smtc.secretName = certName
smtc.ref.Key = smtc.secretName
smtc.certOutput = keyvault.CertificateBundle{
Cer: &byteArrString, Tags: tagMap,
}
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
smtc.expectedSecret = jsonTagTestString
}
setCertWithNoTags := func(smtc *secretManagerTestCase) {
byteArrString := []byte(secretCertificate)
smtc.secretName = certName
smtc.ref.Key = smtc.secretName
smtc.certOutput = keyvault.CertificateBundle{
Cer: &byteArrString,
}
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
smtc.expectedSecret = "{}"
}
setKeyWithTag := func(smtc *secretManagerTestCase) {
smtc.secretName = keyName
smtc.keyOutput = keyvault.KeyBundle{
Key: newKVJWK([]byte(jwkPubRSA)), Tags: tagMap,
}
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
smtc.ref.Property = tagname
smtc.expectedSecret = tagvalue
smtc.ref.Key = smtc.secretName
}
badKeyWithTag := func(smtc *secretManagerTestCase) {
smtc.secretName = keyName
smtc.ref.Key = smtc.secretName
smtc.keyOutput = keyvault.KeyBundle{
Key: newKVJWK([]byte(jwkPubRSA)), Tags: tagMap,
}
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
smtc.ref.Property = something
smtc.expectedSecret = ""
smtc.expectError = errorNoTag
smtc.apiErr = errors.New(smtc.expectError)
}
setKeyWithNoSpecificTag := func(smtc *secretManagerTestCase) {
smtc.secretName = keyName
smtc.ref.Key = smtc.secretName
smtc.keyOutput = keyvault.KeyBundle{
Key: newKVJWK([]byte(jwkPubRSA)), Tags: tagMap,
}
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
smtc.expectedSecret = jsonTagTestString
}
setKeyWithNoTags := func(smtc *secretManagerTestCase) {
smtc.secretName = keyName
smtc.ref.Key = smtc.secretName
smtc.keyOutput = keyvault.KeyBundle{
Key: newKVJWK([]byte(jwkPubRSA)),
}
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
smtc.expectedSecret = "{}"
}
badPropertyTag := func(smtc *secretManagerTestCase) {
smtc.ref.Property = tagname
smtc.expectedSecret = ""
smtc.expectError = "property tagname does not exist in key test-secret"
smtc.apiErr = errors.New(smtc.expectError)
}
fetchSingleTag := func(smtc *secretManagerTestCase) {
jsonString := jsonTestString
smtc.expectedSecret = bar
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
secretTags := map[string]*string{}
tagValue := bar
secretTags[foo] = &tagValue
smtc.secretOutput = keyvault.SecretBundle{
Value: &jsonString,
Tags: secretTags,
}
smtc.ref.Property = foo
}
fetchJSONTag := func(smtc *secretManagerTestCase) {
jsonString := jsonTestString
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
secretTags := map[string]*string{}
tagValue := "{\"key\":\"value\"}"
secretTags[foo] = &tagValue
smtc.secretOutput = keyvault.SecretBundle{
Value: &jsonString,
Tags: secretTags,
}
smtc.ref.Property = foo
smtc.expectedSecret = tagValue
}
fetchDottedJSONTag := func(smtc *secretManagerTestCase) {
jsonString := jsonTestString
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
secretTags := map[string]*string{}
tagValue := "{\"key\":\"value\"}"
secretTags[foo] = &tagValue
smtc.secretOutput = keyvault.SecretBundle{
Value: &jsonString,
Tags: secretTags,
}
smtc.ref.Property = "foo.key"
smtc.expectedSecret = "value"
}
fetchNestedJSONTag := func(smtc *secretManagerTestCase) {
jsonString := jsonTestString
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
secretTags := map[string]*string{}
tagValue := "{\"key\":\"value\", \"nested\": {\"foo\":\"bar\"}}"
secretTags["foo"] = &tagValue
smtc.secretOutput = keyvault.SecretBundle{
Value: &jsonString,
Tags: secretTags,
}
smtc.ref.Property = "foo.nested"
smtc.expectedSecret = "{\"foo\":\"bar\"}"
}
fetchNestedDottedJSONTag := func(smtc *secretManagerTestCase) {
jsonString := jsonTestString
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
secretTags := map[string]*string{}
tagValue := "{\"key\":\"value\", \"nested\": {\"foo\":\"bar\"}}"
secretTags[foo] = &tagValue
smtc.secretOutput = keyvault.SecretBundle{
Value: &jsonString,
Tags: secretTags,
}
smtc.ref.Property = "foo.nested.foo"
smtc.expectedSecret = bar
}
fetchDottedKeyJSONTag := func(smtc *secretManagerTestCase) {
jsonString := jsonTestString
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
secretTags := map[string]*string{}
tagValue := "{\"foo.json\":\"bar\"}"
secretTags[foo] = &tagValue
smtc.secretOutput = keyvault.SecretBundle{
Value: &jsonString,
Tags: secretTags,
}
smtc.ref.Property = "foo.foo.json"
smtc.expectedSecret = bar
}
fetchDottedSecretJSONTag := func(smtc *secretManagerTestCase) {
jsonString := "{\"foo.json\":\"bar\"}"
smtc.secretOutput = keyvault.SecretBundle{
Value: &jsonString,
}
smtc.ref.Property = "foo.json"
smtc.expectedSecret = bar
}
successCases := []*secretManagerTestCase{
makeValidSecretManagerTestCase(),
makeValidSecretManagerTestCaseCustom(setSecretString),
makeValidSecretManagerTestCaseCustom(setSecretStringWithVersion),
makeValidSecretManagerTestCaseCustom(setSecretWithProperty),
makeValidSecretManagerTestCaseCustom(badSecretWithProperty),
makeValidSecretManagerTestCaseCustom(setPubRSAKey),
makeValidSecretManagerTestCaseCustom(setPubECKey),
makeValidSecretManagerTestCaseCustom(secretNotFound),
makeValidSecretManagerTestCaseCustom(certNotFound),
makeValidSecretManagerTestCaseCustom(keyNotFound),
makeValidSecretManagerTestCaseCustom(setCertificate),
makeValidSecretManagerTestCaseCustom(badSecretType),
makeValidSecretManagerTestCaseCustom(setSecretWithTag),
makeValidSecretManagerTestCaseCustom(badSecretWithTag),
makeValidSecretManagerTestCaseCustom(setSecretWithNoSpecificTag),
makeValidSecretManagerTestCaseCustom(setSecretWithNoTags),
makeValidSecretManagerTestCaseCustom(setCertWithTag),
makeValidSecretManagerTestCaseCustom(badCertWithTag),
makeValidSecretManagerTestCaseCustom(setCertWithNoSpecificTag),
makeValidSecretManagerTestCaseCustom(setCertWithNoTags),
makeValidSecretManagerTestCaseCustom(setKeyWithTag),
makeValidSecretManagerTestCaseCustom(badKeyWithTag),
makeValidSecretManagerTestCaseCustom(setKeyWithNoSpecificTag),
makeValidSecretManagerTestCaseCustom(setKeyWithNoTags),
makeValidSecretManagerTestCaseCustom(badPropertyTag),
makeValidSecretManagerTestCaseCustom(fetchSingleTag),
makeValidSecretManagerTestCaseCustom(fetchJSONTag),
makeValidSecretManagerTestCaseCustom(fetchDottedJSONTag),
makeValidSecretManagerTestCaseCustom(fetchNestedJSONTag),
makeValidSecretManagerTestCaseCustom(fetchNestedDottedJSONTag),
makeValidSecretManagerTestCaseCustom(fetchDottedKeyJSONTag),
makeValidSecretManagerTestCaseCustom(fetchDottedSecretJSONTag),
}
sm := Azure{
provider: &esv1beta1.AzureKVProvider{VaultURL: pointer.To(fakeURL)},
}
for k, v := range successCases {
sm.baseClient = v.mockClient
out, err := sm.GetSecret(context.Background(), *v.ref)
if !utils.ErrorContains(err, v.expectError) {
t.Errorf("[%d] unexpected error: %s, expected: '%s'", k, err.Error(), v.expectError)
}
if string(out) != v.expectedSecret {
t.Errorf("[%d] unexpected secret: expected %s, got %s", k, v.expectedSecret, string(out))
}
}
}
func TestAzureKeyVaultSecretManagerGetSecretMap(t *testing.T) {
secretString := "changedvalue"
secretCertificate := "certificate_value"
tagMap := getTagMap()
badSecretString := func(smtc *secretManagerTestCase) {
smtc.expectedSecret = secretString
smtc.secretOutput = keyvault.SecretBundle{
Value: &secretString,
}
smtc.expectError = "error unmarshalling json data: invalid character 'c' looking for beginning of value"
}
setSecretJSON := func(smtc *secretManagerTestCase) {
jsonString := jsonSingleTestString
smtc.secretOutput = keyvault.SecretBundle{
Value: &jsonString,
}
smtc.expectedData["Name"] = []byte("External")
smtc.expectedData["LastName"] = []byte("Secret")
}
setSecretJSONWithProperty := func(smtc *secretManagerTestCase) {
jsonString := jsonTestString
smtc.secretOutput = keyvault.SecretBundle{
Value: &jsonString,
}
smtc.ref.Property = "Address"
smtc.expectedData["Street"] = []byte("Myroad st.")
smtc.expectedData["CP"] = []byte("J4K4T4")
}
badSecretWithProperty := func(smtc *secretManagerTestCase) {
jsonString := jsonTestString
smtc.expectedSecret = ""
smtc.secretOutput = keyvault.SecretBundle{
Value: &jsonString,
}
smtc.ref.Property = "Age"
smtc.expectError = fmt.Sprintf("property %s does not exist in key %s", smtc.ref.Property, smtc.ref.Key)
smtc.apiErr = errors.New(smtc.expectError)
}
badPubRSAKey := func(smtc *secretManagerTestCase) {
smtc.secretName = keyName
smtc.expectedSecret = jwkPubRSA
smtc.keyOutput = keyvault.KeyBundle{
Key: newKVJWK([]byte(jwkPubRSA)),
}
smtc.ref.Key = smtc.secretName
smtc.expectError = "cannot get use dataFrom to get key secret"
}
badCertificate := func(smtc *secretManagerTestCase) {
byteArrString := []byte(secretCertificate)
smtc.secretName = certName
smtc.expectedSecret = secretCertificate
smtc.certOutput = keyvault.CertificateBundle{
Cer: &byteArrString,
}
smtc.ref.Key = smtc.secretName
smtc.expectError = "cannot get use dataFrom to get certificate secret"
}
badSecretType := func(smtc *secretManagerTestCase) {
smtc.secretName = "name"
smtc.expectedSecret = ""
smtc.expectError = fmt.Sprintf("unknown Azure Keyvault object Type for %s", smtc.secretName)
smtc.ref.Key = fmt.Sprintf("example/%s", smtc.secretName)
}
setSecretTags := func(smtc *secretManagerTestCase) {
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
smtc.secretOutput = keyvault.SecretBundle{
Tags: tagMap,
}
smtc.expectedData[testsecret+"_"+tagname] = []byte(tagvalue)
smtc.expectedData[testsecret+"_"+tagname2] = []byte(tagvalue2)
}
setSecretWithJSONTag := func(smtc *secretManagerTestCase) {
tagJSONMap := make(map[string]*string)
tagJSONData := `{"keyname":"keyvalue","x":"y"}`
tagJSONMap["json"] = &tagJSONData
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
smtc.secretOutput = keyvault.SecretBundle{
Value: &secretString, Tags: tagJSONMap,
}
smtc.expectedData[testsecret+"_json_keyname"] = []byte("keyvalue")
smtc.expectedData[testsecret+"_json_x"] = []byte("y")
}
setSecretWithNoTags := func(smtc *secretManagerTestCase) {
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
tagMapTestEmpty := make(map[string]*string)
smtc.secretOutput = keyvault.SecretBundle{
Tags: tagMapTestEmpty,
}
smtc.expectedSecret = ""
}
nestedJSONNoProperty := func(smtc *secretManagerTestCase) {
jsonString := jsonTestString
smtc.expectedSecret = ""
smtc.secretOutput = keyvault.SecretBundle{
Value: &jsonString,
}
smtc.ref.Property = ""
smtc.expectedData["Name"] = []byte("External")
smtc.expectedData["LastName"] = []byte("Secret")
smtc.expectedData["Address"] = []byte(`{ "Street": "Myroad st.", "CP": "J4K4T4" }`)
}
setNestedJSONTag := func(smtc *secretManagerTestCase) {
secretTags := map[string]*string{}
tagValue := `{"foo":"bar","nested.tag":{"foo":"bar"}}`
bug := "1137"
secretTags["dev"] = &tagValue
secretTags["bug"] = &bug
smtc.ref.MetadataPolicy = esv1beta1.ExternalSecretMetadataPolicyFetch
smtc.secretOutput = keyvault.SecretBundle{
Tags: secretTags,
}
smtc.ref.Property = "dev"
smtc.expectedData[testsecret+"_dev"] = []byte(tagValue)
}
successCases := []*secretManagerTestCase{
makeValidSecretManagerTestCaseCustom(badSecretString),
makeValidSecretManagerTestCaseCustom(setSecretJSON),
makeValidSecretManagerTestCaseCustom(setSecretJSONWithProperty),
makeValidSecretManagerTestCaseCustom(badSecretWithProperty),
makeValidSecretManagerTestCaseCustom(badPubRSAKey),
makeValidSecretManagerTestCaseCustom(badCertificate),
makeValidSecretManagerTestCaseCustom(badSecretType),
makeValidSecretManagerTestCaseCustom(setSecretTags),
makeValidSecretManagerTestCaseCustom(setSecretWithJSONTag),
makeValidSecretManagerTestCaseCustom(setSecretWithNoTags),
makeValidSecretManagerTestCaseCustom(nestedJSONNoProperty),
makeValidSecretManagerTestCaseCustom(setNestedJSONTag),
}
sm := Azure{
provider: &esv1beta1.AzureKVProvider{VaultURL: pointer.To(fakeURL)},
}
for k, v := range successCases {
sm.baseClient = v.mockClient
out, err := sm.GetSecretMap(context.Background(), *v.ref)
if !utils.ErrorContains(err, v.expectError) {
t.Errorf("[%d] unexpected error: %s, expected: '%s'", k, err.Error(), v.expectError)
}
if err == nil && !reflect.DeepEqual(out, v.expectedData) {
t.Errorf("[%d] unexpected secret data: expected %#v, got %#v", k, v.expectedData, out)
}
}
}
func TestAzureKeyVaultSecretManagerGetAllSecrets(t *testing.T) {
secretString := secretString
secretName := secretName
wrongName := "not-valid"
environment := "dev"
author := "seb"
enabled := true
getNextPage := func(ctx context.Context, list keyvault.SecretListResult) (result keyvault.SecretListResult, err error) {
return keyvault.SecretListResult{
Value: nil,
NextLink: nil,
}, nil
}
setOneSecretByName := func(smtc *secretManagerTestCase) {
enabledAtt := keyvault.SecretAttributes{
Enabled: &enabled,
}
secretItem := keyvault.SecretItem{
ID: &secretName,
Attributes: &enabledAtt,
}
secretList := make([]keyvault.SecretItem, 0)
secretList = append(secretList, secretItem)
list := keyvault.SecretListResult{
Value: &secretList,
}
resultPage := keyvault.NewSecretListResultPage(list, getNextPage)
smtc.listOutput = keyvault.NewSecretListResultIterator(resultPage)
smtc.expectedSecret = secretString
smtc.secretOutput = keyvault.SecretBundle{
Value: &secretString,
}
smtc.expectedData[secretName] = []byte(secretString)
}
setTwoSecretsByName := func(smtc *secretManagerTestCase) {
enabledAtt := keyvault.SecretAttributes{
Enabled: &enabled,
}
secretItemOne := keyvault.SecretItem{
ID: &secretName,
Attributes: &enabledAtt,
}
secretItemTwo := keyvault.SecretItem{
ID: &wrongName,
Attributes: &enabledAtt,
}
secretList := make([]keyvault.SecretItem, 1)
secretList = append(secretList, secretItemOne, secretItemTwo)
list := keyvault.SecretListResult{
Value: &secretList,
}
resultPage := keyvault.NewSecretListResultPage(list, getNextPage)
smtc.listOutput = keyvault.NewSecretListResultIterator(resultPage)
smtc.expectedSecret = secretString
smtc.secretOutput = keyvault.SecretBundle{
Value: &secretString,
}
smtc.expectedData[secretName] = []byte(secretString)
}
setOneSecretByTag := func(smtc *secretManagerTestCase) {
enabledAtt := keyvault.SecretAttributes{
Enabled: &enabled,
}
secretItem := keyvault.SecretItem{
ID: &secretName,
Attributes: &enabledAtt,
Tags: map[string]*string{"environment": &environment},
}
secretList := make([]keyvault.SecretItem, 0)
secretList = append(secretList, secretItem)
list := keyvault.SecretListResult{
Value: &secretList,
}
resultPage := keyvault.NewSecretListResultPage(list, getNextPage)
smtc.listOutput = keyvault.NewSecretListResultIterator(resultPage)
smtc.expectedSecret = secretString
smtc.secretOutput = keyvault.SecretBundle{
Value: &secretString,
}
smtc.refFind.Tags = map[string]string{"environment": environment}
smtc.expectedData[secretName] = []byte(secretString)
}
setTwoSecretsByTag := func(smtc *secretManagerTestCase) {
enabled := true
enabledAtt := keyvault.SecretAttributes{
Enabled: &enabled,
}
secretItem := keyvault.SecretItem{
ID: &secretName,
Attributes: &enabledAtt,
Tags: map[string]*string{"environment": &environment, "author": &author},
}
secretList := make([]keyvault.SecretItem, 0)
secretList = append(secretList, secretItem)
list := keyvault.SecretListResult{
Value: &secretList,
}
resultPage := keyvault.NewSecretListResultPage(list, getNextPage)
smtc.listOutput = keyvault.NewSecretListResultIterator(resultPage)
smtc.expectedSecret = secretString
smtc.secretOutput = keyvault.SecretBundle{
Value: &secretString,
}
smtc.refFind.Tags = map[string]string{"environment": environment, "author": author}
smtc.expectedData[secretName] = []byte(secretString)
}
successCases := []*secretManagerTestCase{
makeValidSecretManagerTestCaseCustom(setOneSecretByName),
makeValidSecretManagerTestCaseCustom(setTwoSecretsByName),
makeValidSecretManagerTestCaseCustom(setOneSecretByTag),
makeValidSecretManagerTestCaseCustom(setTwoSecretsByTag),
}
sm := Azure{
provider: &esv1beta1.AzureKVProvider{VaultURL: pointer.To(fakeURL)},
}
for k, v := range successCases {
sm.baseClient = v.mockClient
out, err := sm.GetAllSecrets(context.Background(), *v.refFind)
if !utils.ErrorContains(err, v.expectError) {
t.Errorf(unexpectedError, k, err.Error(), v.expectError)
}
if err == nil && !reflect.DeepEqual(out, v.expectedData) {
t.Errorf(unexpectedSecretData, k, v.expectedData, out)
}
}
}
func makeValidRef() *esv1beta1.ExternalSecretDataRemoteRef {
return &esv1beta1.ExternalSecretDataRemoteRef{
Key: "test-secret",
Version: "default",
Property: "",
}
}
func makeValidFind() *esv1beta1.ExternalSecretFind {
return &esv1beta1.ExternalSecretFind{
Name: &esv1beta1.FindName{
RegExp: "^example",
},
Tags: map[string]string{},
}
}
func TestValidateStore(t *testing.T) {
type args struct {
store *esv1beta1.SecretStore
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "storeIsNil",
wantErr: true,
},
{
name: "specIsNil",
wantErr: true,
args: args{
store: &esv1beta1.SecretStore{},
},
},
{
name: "providerIsNil",
wantErr: true,
args: args{
store: &esv1beta1.SecretStore{
Spec: esv1beta1.SecretStoreSpec{},
},
},
},
{
name: "azureKVIsNil",
wantErr: true,
args: args{
store: &esv1beta1.SecretStore{
Spec: esv1beta1.SecretStoreSpec{
Provider: &esv1beta1.SecretStoreProvider{},
},
},
},
},
{
name: "empty auth",
wantErr: false,
args: args{
store: &esv1beta1.SecretStore{
Spec: esv1beta1.SecretStoreSpec{
Provider: &esv1beta1.SecretStoreProvider{
AzureKV: &esv1beta1.AzureKVProvider{},
},
},
},
},
},
{
name: "empty client id",
wantErr: false,
args: args{
store: &esv1beta1.SecretStore{
Spec: esv1beta1.SecretStoreSpec{
Provider: &esv1beta1.SecretStoreProvider{
AzureKV: &esv1beta1.AzureKVProvider{
AuthSecretRef: &esv1beta1.AzureKVAuth{},
},
},
},
},
},
},
{
name: "invalid client id",
wantErr: true,
args: args{
store: &esv1beta1.SecretStore{
Spec: esv1beta1.SecretStoreSpec{
Provider: &esv1beta1.SecretStoreProvider{
AzureKV: &esv1beta1.AzureKVProvider{
AuthSecretRef: &esv1beta1.AzureKVAuth{
ClientID: &v1.SecretKeySelector{
Namespace: pointer.To("invalid"),
},
},
},
},
},
},
},
},
{
name: "invalid client secret",
wantErr: true,
args: args{
store: &esv1beta1.SecretStore{
Spec: esv1beta1.SecretStoreSpec{
Provider: &esv1beta1.SecretStoreProvider{
AzureKV: &esv1beta1.AzureKVProvider{
AuthSecretRef: &esv1beta1.AzureKVAuth{
ClientSecret: &v1.SecretKeySelector{
Namespace: pointer.To("invalid"),
},
},
},
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := &Azure{}
if tt.name == "storeIsNil" {
if err := a.ValidateStore(nil); (err != nil) != tt.wantErr {
t.Errorf(errStore, err, tt.wantErr)
}
} else if err := a.ValidateStore(tt.args.store); (err != nil) != tt.wantErr {
t.Errorf(errStore, err, tt.wantErr)
}
})
}
}