@@ -695,7 +695,7 @@ func TestKustomizeDecryptor_DecryptResource(t *testing.T) {
695
695
},
696
696
}
697
697
698
- t .Run ("SOPS encrypted resource" , func (t * testing.T ) {
698
+ t .Run ("SOPS- encrypted Secret resource" , func (t * testing.T ) {
699
699
g := NewWithT (t )
700
700
701
701
kus := kustomization .DeepCopy ()
@@ -736,7 +736,7 @@ func TestKustomizeDecryptor_DecryptResource(t *testing.T) {
736
736
g .Expect (got .MarshalJSON ()).To (Equal (secretData ))
737
737
})
738
738
739
- t .Run ("SOPS encrypted binary Secret data field" , func (t * testing.T ) {
739
+ t .Run ("SOPS- encrypted binary-format Secret data field" , func (t * testing.T ) {
740
740
g := NewWithT (t )
741
741
742
742
kus := kustomization .DeepCopy ()
@@ -771,7 +771,7 @@ func TestKustomizeDecryptor_DecryptResource(t *testing.T) {
771
771
g .Expect (got .GetDataMap ()).To (HaveKeyWithValue ("file.ini" , base64 .StdEncoding .EncodeToString (plainData )))
772
772
})
773
773
774
- t .Run ("SOPS encrypted YAML Secret data field" , func (t * testing.T ) {
774
+ t .Run ("SOPS- encrypted YAML-format Secret data field" , func (t * testing.T ) {
775
775
g := NewWithT (t )
776
776
777
777
kus := kustomization .DeepCopy ()
@@ -849,12 +849,14 @@ func TestKustomizeDecryptor_DecryptResource(t *testing.T) {
849
849
850
850
func TestKustomizeDecryptor_decryptKustomizationEnvSources (t * testing.T ) {
851
851
type file struct {
852
- name string
853
- symlink string
854
- data []byte
855
- encrypt bool
856
- expectData bool
852
+ name string
853
+ symlink string
854
+ data []byte
855
+ originalFormat * formats.Format
856
+ encrypt bool
857
+ expectData bool
857
858
}
859
+ binaryFormat := formats .Binary
858
860
tests := []struct {
859
861
name string
860
862
wordirSuffix string
@@ -869,6 +871,9 @@ func TestKustomizeDecryptor_decryptKustomizationEnvSources(t *testing.T) {
869
871
path : "subdir" ,
870
872
files : []file {
871
873
{name : "subdir/app.env" , data : []byte ("var1=value1\n " ), encrypt : true , expectData : true },
874
+ // NB: Despite the file extension representing the SOPS-encrypted JSON output
875
+ // format, the original data is plain text, or "binary."
876
+ {name : "subdir/combination.json" , data : []byte ("The safe combination is ..." ), originalFormat : & binaryFormat , encrypt : true , expectData : true },
872
877
{name : "subdir/file.txt" , data : []byte ("file" ), encrypt : true , expectData : true },
873
878
{name : "secret.env" , data : []byte ("var2=value2\n " ), encrypt : true , expectData : true },
874
879
},
@@ -877,13 +882,13 @@ func TestKustomizeDecryptor_decryptKustomizationEnvSources(t *testing.T) {
877
882
GeneratorArgs : kustypes.GeneratorArgs {
878
883
Name : "envSecret" ,
879
884
KvPairSources : kustypes.KvPairSources {
880
- FileSources : []string {"file.txt" },
885
+ FileSources : []string {"file.txt" , "combo=combination.json" },
881
886
EnvSources : []string {"app.env" , "../secret.env" },
882
887
},
883
888
},
884
889
},
885
890
},
886
- expectVisited : []string {"subdir/app.env" , "subdir/file.txt" , "secret.env" },
891
+ expectVisited : []string {"subdir/app.env" , "subdir/combination.json" , "subdir/ file.txt" , "secret.env" },
887
892
},
888
893
{
889
894
name : "decryption error" ,
@@ -987,7 +992,12 @@ func TestKustomizeDecryptor_decryptKustomizationEnvSources(t *testing.T) {
987
992
}
988
993
data := f .data
989
994
if f .encrypt {
990
- format := formats .FormatForPath (f .name )
995
+ var format formats.Format
996
+ if f .originalFormat != nil {
997
+ format = * f .originalFormat
998
+ } else {
999
+ format = formats .FormatForPath (f .name )
1000
+ }
991
1001
data , err = d .sopsEncryptWithFormat (sops.Metadata {
992
1002
KeyGroups : []sops.KeyGroup {
993
1003
{& sopsage.MasterKey {Recipient : id .Recipient ().String ()}},
@@ -1159,7 +1169,7 @@ func TestKustomizeDecryptor_decryptSopsFile(t *testing.T) {
1159
1169
1160
1170
b , err := os .ReadFile (filepath .Join (tmpDir , f .name ))
1161
1171
g .Expect (err ).ToNot (HaveOccurred ())
1162
- g .Expect (bytes .Compare (f .data , b ) == 0 ).To (Equal (f .expectData ))
1172
+ g .Expect (bytes .Equal (f .data , b )).To (Equal (f .expectData ))
1163
1173
}
1164
1174
})
1165
1175
}
0 commit comments