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

Commit

Permalink
fix: do not skew binary data (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
arruzk authored and Flydiverny committed Dec 5, 2019
1 parent b9b20a7 commit 01e0ca2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/backends/kv-backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,16 @@ class KVBackend extends AbstractBackend {
}), {})

const encodedEntries = Object.entries(plainValues)
.map(([name, plainValue]) => [
name,
(Buffer.from(`${plainValue}`, 'utf8')).toString('base64')
])
.map(([name, plainValue]) => {
let bufferValue = plainValue
if (!(plainValue instanceof Buffer)) {
bufferValue = Buffer.from(`${plainValue}`, 'utf8')
}
return [
name,
bufferValue.toString('base64')
]
})

return Object.fromEntries(encodedEntries)
}
Expand Down
20 changes: 20 additions & 0 deletions lib/backends/kv-backend.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,5 +382,25 @@ describe('kv-backend', () => {
specOptions: { }
})
})

it('do not skew binary data', async () => {
kvBackend._fetchDataValues
.resolves([{
textProperty: 'text',
binaryProperty: Buffer.from('test', 'utf-8'),
binaryProperty2: Buffer.from([0xEFBFBDEF, 2, 3])
}])

const manifestData = await kvBackend
.getSecretManifestData({
spec: { }
})

expect(manifestData).deep.equals({
textProperty: 'dGV4dA==', // base 64 value of text
binaryProperty: 'dGVzdA==', // base 64 value of test
binaryProperty2: '7wID' // base 64 value of binary data
})
})
})
})

0 comments on commit 01e0ca2

Please sign in to comment.