mirror of
https://github.com/external-secrets/external-secrets.git
synced 2024-12-14 11:57:59 +00:00
Issue 3436 (#3444)
* utiliy for comparing byteslice and string Signed-off-by: himasagaratluri <himasagar.atluri@gmail.com> * unit test for utility Signed-off-by: himasagaratluri <himasagar.atluri@gmail.com> * add validation for StringType Signed-off-by: himasagaratluri <himasagar.atluri@gmail.com> * if clause to consider binary Signed-off-by: himasagaratluri <himasagar.atluri@gmail.com> * Test case: if clause to consider binary Signed-off-by: himasagaratluri <himasagar.atluri@gmail.com> --------- Signed-off-by: himasagaratluri <himasagar.atluri@gmail.com>
This commit is contained in:
parent
6252ad9394
commit
f22c53fca0
3 changed files with 78 additions and 1 deletions
|
@ -588,7 +588,7 @@ func (sm *SecretsManager) putSecretValueWithContext(ctx context.Context, secretI
|
|||
if !isManagedByESO(data) {
|
||||
return fmt.Errorf("secret not managed by external-secrets")
|
||||
}
|
||||
if awsSecret != nil && bytes.Equal(awsSecret.SecretBinary, value) {
|
||||
if awsSecret != nil && bytes.Equal(awsSecret.SecretBinary, value) || utils.CompareStringAndByteSlices(awsSecret.SecretString, value) {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -507,3 +507,21 @@ func dig[T any](key string, data map[string]any) (t T, _ error) {
|
|||
|
||||
return t, errKeyNotFound
|
||||
}
|
||||
|
||||
func CompareStringAndByteSlices(valueString *string, valueByte []byte) bool {
|
||||
if valueString == nil {
|
||||
return false
|
||||
}
|
||||
stringToByteSlice := []byte(*valueString)
|
||||
if len(stringToByteSlice) != len(valueByte) {
|
||||
return false
|
||||
}
|
||||
|
||||
for sb := range valueByte {
|
||||
if stringToByteSlice[sb] != valueByte[sb] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/oracle/oci-go-sdk/v65/vault"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||
|
@ -845,3 +846,61 @@ func TestGetByteValue(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompareStringAndByteSlices(t *testing.T) {
|
||||
type args struct {
|
||||
stringValue *string
|
||||
byteValueSlice []byte
|
||||
}
|
||||
type testCase struct {
|
||||
name string
|
||||
args args
|
||||
want bool
|
||||
wantErr bool
|
||||
}
|
||||
tests := []testCase{
|
||||
{
|
||||
name: "same contents",
|
||||
args: args{
|
||||
stringValue: aws.String("value"),
|
||||
byteValueSlice: []byte("value"),
|
||||
},
|
||||
want: true,
|
||||
wantErr: true,
|
||||
}, {
|
||||
name: "different contents",
|
||||
args: args{
|
||||
stringValue: aws.String("value89"),
|
||||
byteValueSlice: []byte("value"),
|
||||
},
|
||||
want: true,
|
||||
wantErr: false,
|
||||
}, {
|
||||
name: "same contents with random",
|
||||
args: args{
|
||||
stringValue: aws.String("value89!3#@212"),
|
||||
byteValueSlice: []byte("value89!3#@212"),
|
||||
},
|
||||
want: true,
|
||||
wantErr: true,
|
||||
}, {
|
||||
name: "check Nil",
|
||||
args: args{
|
||||
stringValue: nil,
|
||||
byteValueSlice: []byte("value89!3#@212"),
|
||||
},
|
||||
want: false,
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := CompareStringAndByteSlices(tt.args.stringValue, tt.args.byteValueSlice)
|
||||
if got != tt.wantErr {
|
||||
t.Errorf("CompareStringAndByteSlices() got = %v, want = %v", got, tt.wantErr)
|
||||
return
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue