From 1c0b1e730824a2de4e6f619870cdac75ff6c1c6e Mon Sep 17 00:00:00 2001 From: reecebrend Date: Tue, 11 Dec 2018 09:46:02 +0000 Subject: [PATCH] fix(get-crypto-value): align with s&w process --- .../state-resources/get-crypto-entry/index.js | 11 ++++++----- test/crypto-spec.js | 3 ++- .../state-machines/get-crypto-value.json | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/components/state-resources/get-crypto-entry/index.js b/lib/components/state-resources/get-crypto-entry/index.js index 924188d..3ecb947 100644 --- a/lib/components/state-resources/get-crypto-entry/index.js +++ b/lib/components/state-resources/get-crypto-entry/index.js @@ -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( { @@ -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() @@ -46,5 +46,6 @@ module.exports = class GetCryptoEntry { } } } + context.sendTaskSuccess(event) } } diff --git a/test/crypto-spec.js b/test/crypto-spec.js index 3487867..5017c02 100644 --- a/test/crypto-spec.js +++ b/test/crypto-spec.js @@ -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') }) }) diff --git a/test/fixtures/test-blueprint/state-machines/get-crypto-value.json b/test/fixtures/test-blueprint/state-machines/get-crypto-value.json index 5e00d1a..7036d7c 100644 --- a/test/fixtures/test-blueprint/state-machines/get-crypto-value.json +++ b/test/fixtures/test-blueprint/state-machines/get-crypto-value.json @@ -13,7 +13,7 @@ } } }, - "ResultPath": "decryptionTarget", + "ResultPath": "$.data.decryptionTarget", "Next": "DecryptValue" }, "DecryptValue": { @@ -22,7 +22,7 @@ "ResourceConfig": { "source": "test_cryptoTest", "pathToDecryptionTargets": [ - "$.decryptionTarget" + "$.data.decryptionTarget" ], "values": [ "$.encryptThisOne"