This repository was archived by the owner on Jul 26, 2022. It is now read-only.
File tree 2 files changed +30
-4
lines changed
2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -108,10 +108,16 @@ class KVBackend extends AbstractBackend {
108
108
} ) , { } )
109
109
110
110
const encodedEntries = Object . entries ( plainValues )
111
- . map ( ( [ name , plainValue ] ) => [
112
- name ,
113
- ( Buffer . from ( `${ plainValue } ` , 'utf8' ) ) . toString ( 'base64' )
114
- ] )
111
+ . map ( ( [ name , plainValue ] ) => {
112
+ let bufferValue = plainValue
113
+ if ( ! ( plainValue instanceof Buffer ) ) {
114
+ bufferValue = Buffer . from ( `${ plainValue } ` , 'utf8' )
115
+ }
116
+ return [
117
+ name ,
118
+ bufferValue . toString ( 'base64' )
119
+ ]
120
+ } )
115
121
116
122
return Object . fromEntries ( encodedEntries )
117
123
}
Original file line number Diff line number Diff line change @@ -382,5 +382,25 @@ describe('kv-backend', () => {
382
382
specOptions : { }
383
383
} )
384
384
} )
385
+
386
+ it ( 'do not skew binary data' , async ( ) => {
387
+ kvBackend . _fetchDataValues
388
+ . resolves ( [ {
389
+ textProperty : 'text' ,
390
+ binaryProperty : Buffer . from ( 'test' , 'utf-8' ) ,
391
+ binaryProperty2 : Buffer . from ( [ 0xEFBFBDEF , 2 , 3 ] )
392
+ } ] )
393
+
394
+ const manifestData = await kvBackend
395
+ . getSecretManifestData ( {
396
+ spec : { }
397
+ } )
398
+
399
+ expect ( manifestData ) . deep . equals ( {
400
+ textProperty : 'dGV4dA==' , // base 64 value of text
401
+ binaryProperty : 'dGVzdA==' , // base 64 value of test
402
+ binaryProperty2 : '7wID' // base 64 value of binary data
403
+ } )
404
+ } )
385
405
} )
386
406
} )
You can’t perform that action at this time.
0 commit comments