|
|
@@ -1685,7 +1685,21 @@ func TestDeleteSecret(t *testing.T) {
|
|
|
want want
|
|
|
value []byte
|
|
|
}{
|
|
|
- "DeleteSecretNoOp": {
|
|
|
+ "DeleteSecretNoOpKV1": {
|
|
|
+ reason: "No secret is because it does not exist",
|
|
|
+ args: args{
|
|
|
+ store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV1).Spec.Provider.Vault,
|
|
|
+ vLogical: &fake.Logical{
|
|
|
+ ReadWithDataWithContextFn: fake.NewReadWithContextFn(nil, nil),
|
|
|
+ WriteWithContextFn: fake.ExpectWriteWithContextNoCall(),
|
|
|
+ DeleteWithContextFn: fake.ExpectDeleteWithContextNoCall(),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ want: want{
|
|
|
+ err: nil,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "DeleteSecretNoOpKV2": {
|
|
|
reason: "No secret is because it does not exist",
|
|
|
args: args{
|
|
|
store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV2).Spec.Provider.Vault,
|
|
|
@@ -1699,7 +1713,21 @@ func TestDeleteSecret(t *testing.T) {
|
|
|
err: nil,
|
|
|
},
|
|
|
},
|
|
|
- "DeleteSecretFailIfError": {
|
|
|
+ "DeleteSecretFailIfErrorKV1": {
|
|
|
+ reason: "No secret is because it does not exist",
|
|
|
+ args: args{
|
|
|
+ store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV1).Spec.Provider.Vault,
|
|
|
+ vLogical: &fake.Logical{
|
|
|
+ ReadWithDataWithContextFn: fake.NewReadWithContextFn(nil, fmt.Errorf("failed to read")),
|
|
|
+ WriteWithContextFn: fake.ExpectWriteWithContextNoCall(),
|
|
|
+ DeleteWithContextFn: fake.ExpectDeleteWithContextNoCall(),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ want: want{
|
|
|
+ err: fmt.Errorf("failed to read"),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "DeleteSecretFailIfErrorKV2": {
|
|
|
reason: "No secret is because it does not exist",
|
|
|
args: args{
|
|
|
store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV2).Spec.Provider.Vault,
|
|
|
@@ -1713,7 +1741,26 @@ func TestDeleteSecret(t *testing.T) {
|
|
|
err: fmt.Errorf("failed to read"),
|
|
|
},
|
|
|
},
|
|
|
- "DeleteSecretNotManaged": {
|
|
|
+ "DeleteSecretNotManagedKV1": {
|
|
|
+ reason: "No secret is because it does not exist",
|
|
|
+ args: args{
|
|
|
+ store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV1).Spec.Provider.Vault,
|
|
|
+ vLogical: &fake.Logical{
|
|
|
+ ReadWithDataWithContextFn: fake.NewReadWithContextFn(map[string]interface{}{
|
|
|
+ "fake-key": "fake-value",
|
|
|
+ "custom_metadata": map[string]interface{}{
|
|
|
+ "managed-by": "another-secret-tool",
|
|
|
+ },
|
|
|
+ }, nil),
|
|
|
+ WriteWithContextFn: fake.ExpectWriteWithContextNoCall(),
|
|
|
+ DeleteWithContextFn: fake.NewDeleteWithContextFn(nil, nil),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ want: want{
|
|
|
+ err: nil,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "DeleteSecretNotManagedKV2": {
|
|
|
reason: "No secret is because it does not exist",
|
|
|
args: args{
|
|
|
store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV2).Spec.Provider.Vault,
|
|
|
@@ -1734,7 +1781,26 @@ func TestDeleteSecret(t *testing.T) {
|
|
|
err: nil,
|
|
|
},
|
|
|
},
|
|
|
- "DeleteSecretSuccess": {
|
|
|
+ "DeleteSecretSuccessKV1": {
|
|
|
+ reason: "No secret is because it does not exist",
|
|
|
+ args: args{
|
|
|
+ store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV1).Spec.Provider.Vault,
|
|
|
+ vLogical: &fake.Logical{
|
|
|
+ ReadWithDataWithContextFn: fake.NewReadWithContextFn(map[string]interface{}{
|
|
|
+ "fake-key": "fake-value",
|
|
|
+ "custom_metadata": map[string]interface{}{
|
|
|
+ "managed-by": "external-secrets",
|
|
|
+ },
|
|
|
+ }, nil),
|
|
|
+ WriteWithContextFn: fake.ExpectWriteWithContextNoCall(),
|
|
|
+ DeleteWithContextFn: fake.NewDeleteWithContextFn(nil, nil),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ want: want{
|
|
|
+ err: nil,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "DeleteSecretSuccessKV2": {
|
|
|
reason: "No secret is because it does not exist",
|
|
|
args: args{
|
|
|
store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV2).Spec.Provider.Vault,
|
|
|
@@ -1755,7 +1821,26 @@ func TestDeleteSecret(t *testing.T) {
|
|
|
err: nil,
|
|
|
},
|
|
|
},
|
|
|
- "DeleteSecretError": {
|
|
|
+ "DeleteSecretErrorKV1": {
|
|
|
+ reason: "No secret is because it does not exist",
|
|
|
+ args: args{
|
|
|
+ store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV1).Spec.Provider.Vault,
|
|
|
+ vLogical: &fake.Logical{
|
|
|
+ ReadWithDataWithContextFn: fake.NewReadWithContextFn(map[string]interface{}{
|
|
|
+ "fake-key": "fake-value",
|
|
|
+ "custom_metadata": map[string]interface{}{
|
|
|
+ "managed-by": "external-secrets",
|
|
|
+ },
|
|
|
+ }, nil),
|
|
|
+ WriteWithContextFn: fake.ExpectWriteWithContextNoCall(),
|
|
|
+ DeleteWithContextFn: fake.NewDeleteWithContextFn(nil, fmt.Errorf("failed to delete")),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ want: want{
|
|
|
+ err: fmt.Errorf("failed to delete"),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "DeleteSecretErrorKV2": {
|
|
|
reason: "No secret is because it does not exist",
|
|
|
args: args{
|
|
|
store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV2).Spec.Provider.Vault,
|
|
|
@@ -1776,7 +1861,32 @@ func TestDeleteSecret(t *testing.T) {
|
|
|
err: fmt.Errorf("failed to delete"),
|
|
|
},
|
|
|
},
|
|
|
- "DeleteSecretUpdateProperty": {
|
|
|
+ "DeleteSecretUpdatePropertyKV1": {
|
|
|
+ reason: "Secret should only be updated if Property is set",
|
|
|
+ ref: &testingfake.PushSecretData{RemoteKey: "secret", Property: "fake-key"},
|
|
|
+ args: args{
|
|
|
+ store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV1).Spec.Provider.Vault,
|
|
|
+ vLogical: &fake.Logical{
|
|
|
+ ReadWithDataWithContextFn: fake.NewReadWithContextFn(map[string]interface{}{
|
|
|
+ "fake-key": "fake-value",
|
|
|
+ "foo": "bar",
|
|
|
+ "custom_metadata": map[string]interface{}{
|
|
|
+ "managed-by": "external-secrets",
|
|
|
+ },
|
|
|
+ }, nil),
|
|
|
+ WriteWithContextFn: fake.ExpectWriteWithContextValue(map[string]interface{}{
|
|
|
+ "foo": "bar",
|
|
|
+ "custom_metadata": map[string]interface{}{
|
|
|
+ "managed-by": "external-secrets",
|
|
|
+ }}),
|
|
|
+ DeleteWithContextFn: fake.ExpectDeleteWithContextNoCall(),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ want: want{
|
|
|
+ err: nil,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "DeleteSecretUpdatePropertyKV2": {
|
|
|
reason: "Secret should only be updated if Property is set",
|
|
|
ref: &testingfake.PushSecretData{RemoteKey: "secret", Property: "fake-key"},
|
|
|
args: args{
|
|
|
@@ -1799,7 +1909,27 @@ func TestDeleteSecret(t *testing.T) {
|
|
|
err: nil,
|
|
|
},
|
|
|
},
|
|
|
- "DeleteSecretIfNoOtherProperties": {
|
|
|
+ "DeleteSecretIfNoOtherPropertiesKV1": {
|
|
|
+ reason: "Secret should only be deleted if no other properties are set",
|
|
|
+ ref: &testingfake.PushSecretData{RemoteKey: "secret", Property: "foo"},
|
|
|
+ args: args{
|
|
|
+ store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV1).Spec.Provider.Vault,
|
|
|
+ vLogical: &fake.Logical{
|
|
|
+ ReadWithDataWithContextFn: fake.NewReadWithContextFn(map[string]interface{}{
|
|
|
+ "foo": "bar",
|
|
|
+ "custom_metadata": map[string]interface{}{
|
|
|
+ "managed-by": "external-secrets",
|
|
|
+ },
|
|
|
+ }, nil),
|
|
|
+ WriteWithContextFn: fake.ExpectWriteWithContextNoCall(),
|
|
|
+ DeleteWithContextFn: fake.NewDeleteWithContextFn(nil, nil),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ want: want{
|
|
|
+ err: nil,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "DeleteSecretIfNoOtherPropertiesKV2": {
|
|
|
reason: "Secret should only be deleted if no other properties are set",
|
|
|
ref: &testingfake.PushSecretData{RemoteKey: "secret", Property: "foo"},
|
|
|
args: args{
|
|
|
@@ -1851,7 +1981,6 @@ func TestDeleteSecret(t *testing.T) {
|
|
|
func TestPushSecret(t *testing.T) {
|
|
|
secretKey := "secret-key"
|
|
|
noPermission := errors.New("no permission")
|
|
|
-
|
|
|
type args struct {
|
|
|
store *esv1beta1.VaultProvider
|
|
|
vLogical util.Logical
|
|
|
@@ -1867,7 +1996,20 @@ func TestPushSecret(t *testing.T) {
|
|
|
data *testingfake.PushSecretData
|
|
|
value []byte
|
|
|
}{
|
|
|
- "SetSecret": {
|
|
|
+ "SetSecretKV1": {
|
|
|
+ reason: "secret is successfully set, with no existing vault secret",
|
|
|
+ args: args{
|
|
|
+ store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV1).Spec.Provider.Vault,
|
|
|
+ vLogical: &fake.Logical{
|
|
|
+ ReadWithDataWithContextFn: fake.NewReadWithContextFn(nil, nil),
|
|
|
+ WriteWithContextFn: fake.NewWriteWithContextFn(nil, nil),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ want: want{
|
|
|
+ err: nil,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "SetSecretKV2": {
|
|
|
reason: "secret is successfully set, with no existing vault secret",
|
|
|
args: args{
|
|
|
store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV2).Spec.Provider.Vault,
|
|
|
@@ -1880,8 +2022,20 @@ func TestPushSecret(t *testing.T) {
|
|
|
err: nil,
|
|
|
},
|
|
|
},
|
|
|
-
|
|
|
- "SetSecretWithWriteError": {
|
|
|
+ "SetSecretWithWriteErrorKV1": {
|
|
|
+ reason: "secret cannot be pushed if write fails",
|
|
|
+ args: args{
|
|
|
+ store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV1).Spec.Provider.Vault,
|
|
|
+ vLogical: &fake.Logical{
|
|
|
+ ReadWithDataWithContextFn: fake.NewReadWithContextFn(nil, nil),
|
|
|
+ WriteWithContextFn: fake.NewWriteWithContextFn(nil, noPermission),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ want: want{
|
|
|
+ err: noPermission,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "SetSecretWithWriteErrorKV2": {
|
|
|
reason: "secret cannot be pushed if write fails",
|
|
|
args: args{
|
|
|
store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV2).Spec.Provider.Vault,
|
|
|
@@ -1894,8 +2048,24 @@ func TestPushSecret(t *testing.T) {
|
|
|
err: noPermission,
|
|
|
},
|
|
|
},
|
|
|
-
|
|
|
- "SetSecretEqualsPushSecret": {
|
|
|
+ "SetSecretEqualsPushSecretV1": {
|
|
|
+ reason: "vault secret kv equals secret to push kv",
|
|
|
+ args: args{
|
|
|
+ store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV1).Spec.Provider.Vault,
|
|
|
+ vLogical: &fake.Logical{
|
|
|
+ ReadWithDataWithContextFn: fake.NewReadWithContextFn(map[string]interface{}{
|
|
|
+ "fake-key": "fake-value",
|
|
|
+ "custom_metadata": map[string]interface{}{
|
|
|
+ "managed-by": "external-secrets",
|
|
|
+ },
|
|
|
+ }, nil),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ want: want{
|
|
|
+ err: nil,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "SetSecretEqualsPushSecretV2": {
|
|
|
reason: "vault secret kv equals secret to push kv",
|
|
|
args: args{
|
|
|
store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV2).Spec.Provider.Vault,
|
|
|
@@ -1914,7 +2084,33 @@ func TestPushSecret(t *testing.T) {
|
|
|
err: nil,
|
|
|
},
|
|
|
},
|
|
|
- "PushSecretProperty": {
|
|
|
+ "PushSecretPropertyKV1": {
|
|
|
+ reason: "push secret with property adds the property",
|
|
|
+ value: []byte("fake-value"),
|
|
|
+ data: &testingfake.PushSecretData{SecretKey: secretKey, RemoteKey: "secret", Property: "foo"},
|
|
|
+ args: args{
|
|
|
+ store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV1).Spec.Provider.Vault,
|
|
|
+ vLogical: &fake.Logical{
|
|
|
+ ReadWithDataWithContextFn: fake.NewReadWithContextFn(map[string]interface{}{
|
|
|
+ "fake-key": "fake-value",
|
|
|
+ "custom_metadata": map[string]interface{}{
|
|
|
+ "managed-by": "external-secrets",
|
|
|
+ },
|
|
|
+ }, nil),
|
|
|
+ WriteWithContextFn: fake.ExpectWriteWithContextValue(map[string]interface{}{
|
|
|
+ "fake-key": "fake-value",
|
|
|
+ "custom_metadata": map[string]string{
|
|
|
+ "managed-by": "external-secrets",
|
|
|
+ },
|
|
|
+ "foo": "fake-value",
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ want: want{
|
|
|
+ err: nil,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "PushSecretPropertyKV2": {
|
|
|
reason: "push secret with property adds the property",
|
|
|
value: []byte("fake-value"),
|
|
|
data: &testingfake.PushSecretData{SecretKey: secretKey, RemoteKey: "secret", Property: "foo"},
|
|
|
@@ -1936,7 +2132,32 @@ func TestPushSecret(t *testing.T) {
|
|
|
err: nil,
|
|
|
},
|
|
|
},
|
|
|
- "PushSecretUpdateProperty": {
|
|
|
+ "PushSecretUpdatePropertyKV1": {
|
|
|
+ reason: "push secret with property only updates the property",
|
|
|
+ value: []byte("new-value"),
|
|
|
+ data: &testingfake.PushSecretData{SecretKey: secretKey, RemoteKey: "secret", Property: "foo"},
|
|
|
+ args: args{
|
|
|
+ store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV1).Spec.Provider.Vault,
|
|
|
+ vLogical: &fake.Logical{
|
|
|
+ ReadWithDataWithContextFn: fake.NewReadWithContextFn(map[string]interface{}{
|
|
|
+ "foo": "fake-value",
|
|
|
+ "custom_metadata": map[string]interface{}{
|
|
|
+ "managed-by": "external-secrets",
|
|
|
+ },
|
|
|
+ }, nil),
|
|
|
+ WriteWithContextFn: fake.ExpectWriteWithContextValue(map[string]interface{}{
|
|
|
+ "foo": "new-value",
|
|
|
+ "custom_metadata": map[string]string{
|
|
|
+ "managed-by": "external-secrets",
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ want: want{
|
|
|
+ err: nil,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "PushSecretUpdatePropertyKV2": {
|
|
|
reason: "push secret with property only updates the property",
|
|
|
value: []byte("new-value"),
|
|
|
data: &testingfake.PushSecretData{SecretKey: secretKey, RemoteKey: "secret", Property: "foo"},
|
|
|
@@ -1958,7 +2179,27 @@ func TestPushSecret(t *testing.T) {
|
|
|
err: nil,
|
|
|
},
|
|
|
},
|
|
|
- "PushSecretPropertyNoUpdate": {
|
|
|
+ "PushSecretPropertyNoUpdateKV1": {
|
|
|
+ reason: "push secret with property only updates the property",
|
|
|
+ value: []byte("fake-value"),
|
|
|
+ data: &testingfake.PushSecretData{SecretKey: secretKey, RemoteKey: "secret", Property: "foo"},
|
|
|
+ args: args{
|
|
|
+ store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV1).Spec.Provider.Vault,
|
|
|
+ vLogical: &fake.Logical{
|
|
|
+ ReadWithDataWithContextFn: fake.NewReadWithContextFn(map[string]interface{}{
|
|
|
+ "foo": "fake-value",
|
|
|
+ "custom_metadata": map[string]interface{}{
|
|
|
+ "managed-by": "external-secrets",
|
|
|
+ },
|
|
|
+ }, nil),
|
|
|
+ WriteWithContextFn: fake.ExpectWriteWithContextNoCall(),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ want: want{
|
|
|
+ err: nil,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "PushSecretPropertyNoUpdateKV2": {
|
|
|
reason: "push secret with property only updates the property",
|
|
|
value: []byte("fake-value"),
|
|
|
data: &testingfake.PushSecretData{SecretKey: secretKey, RemoteKey: "secret", Property: "foo"},
|
|
|
@@ -1980,8 +2221,19 @@ func TestPushSecret(t *testing.T) {
|
|
|
err: nil,
|
|
|
},
|
|
|
},
|
|
|
-
|
|
|
- "SetSecretErrorReadingSecret": {
|
|
|
+ "SetSecretErrorReadingSecretKV1": {
|
|
|
+ reason: "error occurs if secret cannot be read",
|
|
|
+ args: args{
|
|
|
+ store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV1).Spec.Provider.Vault,
|
|
|
+ vLogical: &fake.Logical{
|
|
|
+ ReadWithDataWithContextFn: fake.NewReadWithContextFn(nil, noPermission),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ want: want{
|
|
|
+ err: fmt.Errorf(errReadSecret, noPermission),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "SetSecretErrorReadingSecretKV2": {
|
|
|
reason: "error occurs if secret cannot be read",
|
|
|
args: args{
|
|
|
store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV2).Spec.Provider.Vault,
|
|
|
@@ -1993,8 +2245,24 @@ func TestPushSecret(t *testing.T) {
|
|
|
err: fmt.Errorf(errReadSecret, noPermission),
|
|
|
},
|
|
|
},
|
|
|
-
|
|
|
- "SetSecretNotManagedByESO": {
|
|
|
+ "SetSecretNotManagedByESOV1": {
|
|
|
+ reason: "a secret not managed by ESO cannot be updated",
|
|
|
+ args: args{
|
|
|
+ store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV1).Spec.Provider.Vault,
|
|
|
+ vLogical: &fake.Logical{
|
|
|
+ ReadWithDataWithContextFn: fake.NewReadWithContextFn(map[string]interface{}{
|
|
|
+ "fake-key": "fake-value2",
|
|
|
+ "custom_metadata": map[string]interface{}{
|
|
|
+ "managed-by": "not-external-secrets",
|
|
|
+ },
|
|
|
+ }, nil),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ want: want{
|
|
|
+ err: errors.New("secret not managed by external-secrets"),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "SetSecretNotManagedByESOV2": {
|
|
|
reason: "a secret not managed by ESO cannot be updated",
|
|
|
args: args{
|
|
|
store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV2).Spec.Provider.Vault,
|