Skip to content
This repository was archived by the owner on Jul 26, 2022. It is now read-only.

Commit 01e0ca2

Browse files
arruzkFlydiverny
authored andcommitted
fix: do not skew binary data (#244)
1 parent b9b20a7 commit 01e0ca2

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

lib/backends/kv-backend.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,16 @@ class KVBackend extends AbstractBackend {
108108
}), {})
109109

110110
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+
})
115121

116122
return Object.fromEntries(encodedEntries)
117123
}

lib/backends/kv-backend.test.js

+20
Original file line numberDiff line numberDiff line change
@@ -382,5 +382,25 @@ describe('kv-backend', () => {
382382
specOptions: { }
383383
})
384384
})
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+
})
385405
})
386406
})

0 commit comments

Comments
 (0)