From 6cb77e6f54add7cb0b65a3cad25b7457536a1370 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 30 May 2025 13:50:55 +0100 Subject: [PATCH 1/4] chore: extend encrypt decrypt tests to assert that buffer enc/dec works as expected --- e2e/encryptDecrypt.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/e2e/encryptDecrypt.test.js b/e2e/encryptDecrypt.test.js index 9e27b95..289cd7d 100644 --- a/e2e/encryptDecrypt.test.js +++ b/e2e/encryptDecrypt.test.js @@ -172,6 +172,13 @@ describe('Encrypt and Decrypt', () => { expect(payload).to.deep.equal(decrypted); }); + it('encrypts file with metadata and decryption is permitted', async () => { + const payload = Buffer.from([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06]); + const encrypted = await evervaultClient.encrypt(payload, 'permit-all'); + const decrypted = await evervaultClient.decrypt(encrypted); + expect(payload).to.deep.equal(decrypted); + }); + it('encrypts with metadata and decryption is not permitted', async () => { const payload = { string: 'hello', From 66ff7008185bdc58cdae33b18117f6407b3d782b Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 30 May 2025 13:52:19 +0100 Subject: [PATCH 2/4] chore: remove role --- e2e/encryptDecrypt.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/encryptDecrypt.test.js b/e2e/encryptDecrypt.test.js index 289cd7d..d315fab 100644 --- a/e2e/encryptDecrypt.test.js +++ b/e2e/encryptDecrypt.test.js @@ -172,9 +172,9 @@ describe('Encrypt and Decrypt', () => { expect(payload).to.deep.equal(decrypted); }); - it('encrypts file with metadata and decryption is permitted', async () => { + it('encrypts file, and decrypts successfully', async () => { const payload = Buffer.from([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06]); - const encrypted = await evervaultClient.encrypt(payload, 'permit-all'); + const encrypted = await evervaultClient.encrypt(payload); const decrypted = await evervaultClient.decrypt(encrypted); expect(payload).to.deep.equal(decrypted); }); From 9f0f7dde35b6947bc4aeec206a728b96a80e34f2 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 30 May 2025 13:54:22 +0100 Subject: [PATCH 3/4] fix: pass response type through on file decrypt --- lib/core/http.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/core/http.js b/lib/core/http.js index a0bc27c..52531fe 100644 --- a/lib/core/http.js +++ b/lib/core/http.js @@ -14,7 +14,7 @@ module.exports = (appUuid, apiKey, config) => { additionalHeaders = {}, data = undefined, basicAuth = false, - parse = 'json' + responseType = 'json' ) => { const headers = { 'user-agent': config.userAgent, @@ -36,7 +36,8 @@ module.exports = (appUuid, apiKey, config) => { method, headers, data, - validateStatus: (status) => true, + validateStatus: (_) => true, + responseType, }); }; @@ -47,8 +48,8 @@ module.exports = (appUuid, apiKey, config) => { data, headers = { 'Content-Type': 'application/json' }, basicAuth = false, - parse = 'json' - ) => request('POST', path, headers, data, basicAuth, parse); + responseType = 'json' + ) => request('POST', path, headers, data, basicAuth, responseType); const getCageKey = async () => { const getCagesKeyCallback = async () => { @@ -191,14 +192,17 @@ module.exports = (appUuid, apiKey, config) => { const decrypt = async (encryptedData) => { let contentType; let data; + let responseType; if (Buffer.isBuffer(encryptedData)) { contentType = 'application/octet-stream'; data = encryptedData; + responseType = 'arraybuffer'; } else { contentType = 'application/json'; data = { data: encryptedData, }; + responseType = 'json'; } const response = await post( `${config.baseUrl}/decrypt`, @@ -207,7 +211,7 @@ module.exports = (appUuid, apiKey, config) => { 'Content-Type': contentType, }, true, - 'none' + responseType ); if (response.status >= 200 && response.status < 300) { if (contentType === 'application/json') { From ba7d6a5685ec2f8cc9d6956225a816b284e28cae Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 30 May 2025 14:35:24 +0100 Subject: [PATCH 4/4] chore: add changeset --- .changeset/modern-jeans-wave.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/modern-jeans-wave.md diff --git a/.changeset/modern-jeans-wave.md b/.changeset/modern-jeans-wave.md new file mode 100644 index 0000000..c118b22 --- /dev/null +++ b/.changeset/modern-jeans-wave.md @@ -0,0 +1,5 @@ +--- +'@evervault/sdk': patch +--- + +Correct axios response type for file decrypt requests.