|
|
@@ -1064,17 +1064,15 @@ func TestSecretsManagerGetAllSecrets(t *testing.T) {
|
|
|
}
|
|
|
// Test cases
|
|
|
testCases := []struct {
|
|
|
- name string
|
|
|
- ref esv1beta1.ExternalSecretFind
|
|
|
-
|
|
|
- secretName string
|
|
|
- secretVersion string
|
|
|
- secretValue string
|
|
|
- fetchError error
|
|
|
- listSecretsFn func(ctx context.Context, input *awssm.ListSecretsInput, opts ...request.Option) (*awssm.ListSecretsOutput, error)
|
|
|
-
|
|
|
- expectedData map[string][]byte
|
|
|
- expectedError string
|
|
|
+ name string
|
|
|
+ ref esv1beta1.ExternalSecretFind
|
|
|
+ secretName string
|
|
|
+ secretVersion string
|
|
|
+ secretValue string
|
|
|
+ batchGetSecretValueWithContextFn func(aws.Context, *awssm.BatchGetSecretValueInput, ...request.Option) (*awssm.BatchGetSecretValueOutput, error)
|
|
|
+ listSecretsFn func(ctx context.Context, input *awssm.ListSecretsInput, opts ...request.Option) (*awssm.ListSecretsOutput, error)
|
|
|
+ expectedData map[string][]byte
|
|
|
+ expectedError string
|
|
|
}{
|
|
|
{
|
|
|
name: "Matching secrets found",
|
|
|
@@ -1087,14 +1085,16 @@ func TestSecretsManagerGetAllSecrets(t *testing.T) {
|
|
|
secretName: secretName,
|
|
|
secretVersion: secretVersion,
|
|
|
secretValue: secretValue,
|
|
|
- listSecretsFn: func(ctx context.Context, input *awssm.ListSecretsInput, opts ...request.Option) (*awssm.ListSecretsOutput, error) {
|
|
|
+ batchGetSecretValueWithContextFn: func(_ aws.Context, input *awssm.BatchGetSecretValueInput, _ ...request.Option) (*awssm.BatchGetSecretValueOutput, error) {
|
|
|
assert.Len(t, input.Filters, 1)
|
|
|
assert.Equal(t, "name", *input.Filters[0].Key)
|
|
|
assert.Equal(t, secretPath, *input.Filters[0].Values[0])
|
|
|
- return &awssm.ListSecretsOutput{
|
|
|
- SecretList: []*awssm.SecretListEntry{
|
|
|
+ return &awssm.BatchGetSecretValueOutput{
|
|
|
+ SecretValues: []*awssm.SecretValueEntry{
|
|
|
{
|
|
|
- Name: ptr.To(secretName),
|
|
|
+ Name: ptr.To(secretName),
|
|
|
+ VersionStages: []*string{ptr.To(secretVersion)},
|
|
|
+ SecretBinary: []byte(secretValue),
|
|
|
},
|
|
|
},
|
|
|
}, nil
|
|
|
@@ -1115,15 +1115,14 @@ func TestSecretsManagerGetAllSecrets(t *testing.T) {
|
|
|
secretName: secretName,
|
|
|
secretVersion: secretVersion,
|
|
|
secretValue: secretValue,
|
|
|
- fetchError: errBoom,
|
|
|
- listSecretsFn: func(ctx context.Context, input *awssm.ListSecretsInput, opts ...request.Option) (*awssm.ListSecretsOutput, error) {
|
|
|
- return &awssm.ListSecretsOutput{
|
|
|
- SecretList: []*awssm.SecretListEntry{
|
|
|
+ batchGetSecretValueWithContextFn: func(aws.Context, *awssm.BatchGetSecretValueInput, ...request.Option) (*awssm.BatchGetSecretValueOutput, error) {
|
|
|
+ return &awssm.BatchGetSecretValueOutput{
|
|
|
+ SecretValues: []*awssm.SecretValueEntry{
|
|
|
{
|
|
|
Name: ptr.To(secretName),
|
|
|
},
|
|
|
},
|
|
|
- }, nil
|
|
|
+ }, errBoom
|
|
|
},
|
|
|
expectedData: nil,
|
|
|
expectedError: errBoom.Error(),
|
|
|
@@ -1157,6 +1156,15 @@ func TestSecretsManagerGetAllSecrets(t *testing.T) {
|
|
|
},
|
|
|
}, nil
|
|
|
},
|
|
|
+ batchGetSecretValueWithContextFn: func(aws.Context, *awssm.BatchGetSecretValueInput, ...request.Option) (*awssm.BatchGetSecretValueOutput, error) {
|
|
|
+ return &awssm.BatchGetSecretValueOutput{
|
|
|
+ SecretValues: []*awssm.SecretValueEntry{
|
|
|
+ {
|
|
|
+ Name: ptr.To("other-secret"),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }, nil
|
|
|
+ },
|
|
|
expectedData: make(map[string][]byte),
|
|
|
expectedError: "",
|
|
|
},
|
|
|
@@ -1179,16 +1187,18 @@ func TestSecretsManagerGetAllSecrets(t *testing.T) {
|
|
|
secretName: secretName,
|
|
|
secretVersion: secretVersion,
|
|
|
secretValue: secretValue,
|
|
|
- listSecretsFn: func(ctx context.Context, input *awssm.ListSecretsInput, opts ...request.Option) (*awssm.ListSecretsOutput, error) {
|
|
|
+ batchGetSecretValueWithContextFn: func(_ aws.Context, input *awssm.BatchGetSecretValueInput, _ ...request.Option) (*awssm.BatchGetSecretValueOutput, error) {
|
|
|
assert.Len(t, input.Filters, 2)
|
|
|
assert.Equal(t, "tag-key", *input.Filters[0].Key)
|
|
|
assert.Equal(t, "foo", *input.Filters[0].Values[0])
|
|
|
assert.Equal(t, "tag-value", *input.Filters[1].Key)
|
|
|
assert.Equal(t, "bar", *input.Filters[1].Values[0])
|
|
|
- return &awssm.ListSecretsOutput{
|
|
|
- SecretList: []*awssm.SecretListEntry{
|
|
|
+ return &awssm.BatchGetSecretValueOutput{
|
|
|
+ SecretValues: []*awssm.SecretValueEntry{
|
|
|
{
|
|
|
- Name: ptr.To(secretName),
|
|
|
+ Name: ptr.To(secretName),
|
|
|
+ VersionStages: []*string{ptr.To(secretVersion)},
|
|
|
+ SecretBinary: []byte(secretValue),
|
|
|
},
|
|
|
},
|
|
|
}, nil
|
|
|
@@ -1206,15 +1216,16 @@ func TestSecretsManagerGetAllSecrets(t *testing.T) {
|
|
|
secretName: secretName,
|
|
|
secretVersion: secretVersion,
|
|
|
secretValue: secretValue,
|
|
|
- fetchError: errBoom,
|
|
|
- listSecretsFn: func(ctx context.Context, input *awssm.ListSecretsInput, opts ...request.Option) (*awssm.ListSecretsOutput, error) {
|
|
|
- return &awssm.ListSecretsOutput{
|
|
|
- SecretList: []*awssm.SecretListEntry{
|
|
|
+ batchGetSecretValueWithContextFn: func(aws.Context, *awssm.BatchGetSecretValueInput, ...request.Option) (*awssm.BatchGetSecretValueOutput, error) {
|
|
|
+ return &awssm.BatchGetSecretValueOutput{
|
|
|
+ SecretValues: []*awssm.SecretValueEntry{
|
|
|
{
|
|
|
- Name: ptr.To(secretName),
|
|
|
+ Name: ptr.To(secretName),
|
|
|
+ VersionStages: []*string{ptr.To(secretVersion)},
|
|
|
+ SecretBinary: []byte(secretValue),
|
|
|
},
|
|
|
},
|
|
|
- }, nil
|
|
|
+ }, errBoom
|
|
|
},
|
|
|
expectedData: nil,
|
|
|
expectedError: errBoom.Error(),
|
|
|
@@ -1224,7 +1235,7 @@ func TestSecretsManagerGetAllSecrets(t *testing.T) {
|
|
|
ref: esv1beta1.ExternalSecretFind{
|
|
|
Tags: secretTags,
|
|
|
},
|
|
|
- listSecretsFn: func(ctx context.Context, input *awssm.ListSecretsInput, opts ...request.Option) (*awssm.ListSecretsOutput, error) {
|
|
|
+ batchGetSecretValueWithContextFn: func(aws.Context, *awssm.BatchGetSecretValueInput, ...request.Option) (*awssm.BatchGetSecretValueOutput, error) {
|
|
|
return nil, errBoom
|
|
|
},
|
|
|
expectedData: nil,
|
|
|
@@ -1235,15 +1246,8 @@ func TestSecretsManagerGetAllSecrets(t *testing.T) {
|
|
|
for _, tc := range testCases {
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
fc := fakesm.NewClient()
|
|
|
+ fc.BatchGetSecretValueWithContextFn = tc.batchGetSecretValueWithContextFn
|
|
|
fc.ListSecretsFn = tc.listSecretsFn
|
|
|
- fc.WithValue(&awssm.GetSecretValueInput{
|
|
|
- SecretId: ptr.To(tc.secretName),
|
|
|
- VersionStage: ptr.To(tc.secretVersion),
|
|
|
- }, &awssm.GetSecretValueOutput{
|
|
|
- Name: ptr.To(tc.secretName),
|
|
|
- VersionStages: []*string{ptr.To(tc.secretVersion)},
|
|
|
- SecretBinary: []byte(tc.secretValue),
|
|
|
- }, tc.fetchError)
|
|
|
sm := SecretsManager{
|
|
|
client: fc,
|
|
|
cache: make(map[string]*awssm.GetSecretValueOutput),
|