Skip to content

Commit

Permalink
fix(get-crypto-value): align with s&w process
Browse files Browse the repository at this point in the history
  • Loading branch information
reecebrend committed Dec 11, 2018
1 parent f4bd5aa commit 1c0b1e7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
11 changes: 6 additions & 5 deletions lib/components/state-resources/get-crypto-entry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ module.exports = class GetCryptoEntry {
for (const path of this.values) {
const key = path.split('.').pop()
for (const decPath of this.pathToDecryptionTargets) {
const decryptItem = JSONPath({ path: decPath, json: event })
const decryptItem = JSONPath({ path: decPath, json: event, flatten: true })
for (const target of decryptItem) {
const value = JSONPath({ path: path, json: target[0] })
const value = JSONPath({ path: path, json: target })
for (const item of value) {
const doc = await this.sourceModel.find(
{
Expand All @@ -33,10 +33,10 @@ module.exports = class GetCryptoEntry {

try {
const decrypted = await jwt.verify(cryptoRecord.encryptedValue, encryptionKey)
for (const decryptionItem of event.decryptionTarget) {
dottie.set(decryptionItem, key, decrypted.res[0])
for (const decryptionItem of this.pathToDecryptionTargets) {
const data = JSONPath({ path: decryptionItem, json: event, flatten: true })
dottie.set(data[0], key, decrypted.res[0])
}
context.sendTaskSuccess(event.decryptionTarget)
} catch (err) {
console.log('An error occured. Please check your encryption key has been set\n\n', err)
context.sendTaskFailure()
Expand All @@ -46,5 +46,6 @@ module.exports = class GetCryptoEntry {
}
}
}
context.sendTaskSuccess(event)
}
}
3 changes: 2 additions & 1 deletion test/crypto-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ describe('Test general crypto actions', function () {
execName
)

expect(execDesc.ctx[0].encryptThisOne).to.eql('test string')
console.log('***', JSON.stringify(execDesc, null, 2))
expect(execDesc.ctx.data.decryptionTarget[0].encryptThisOne).to.eql('test string')
expect(execDesc.status).to.eql('SUCCEEDED')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
}
},
"ResultPath": "decryptionTarget",
"ResultPath": "$.data.decryptionTarget",
"Next": "DecryptValue"
},
"DecryptValue": {
Expand All @@ -22,7 +22,7 @@
"ResourceConfig": {
"source": "test_cryptoTest",
"pathToDecryptionTargets": [
"$.decryptionTarget"
"$.data.decryptionTarget"
],
"values": [
"$.encryptThisOne"
Expand Down

0 comments on commit 1c0b1e7

Please sign in to comment.