From 94315b29e6549165d691fa56678f35db727f7830 Mon Sep 17 00:00:00 2001 From: luisccastillo Date: Wed, 24 Apr 2024 14:04:20 +0200 Subject: [PATCH] [SDK] v2 fix secrets schema for process protected data parameter validation --- packages/sdk/src/utils/validators.ts | 3 --- .../processProtectedData.test.ts | 11 +++++++++ .../processProtectedData.test.ts | 23 +++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/packages/sdk/src/utils/validators.ts b/packages/sdk/src/utils/validators.ts index 52fac66f2..494e6991b 100644 --- a/packages/sdk/src/utils/validators.ts +++ b/packages/sdk/src/utils/validators.ts @@ -115,9 +115,6 @@ export const secretsSchema = () => ({ label }) => `${label} must be an object with numeric keys and string values`, (value) => { - if (!value || typeof value !== 'object') { - return false; - } for (const key in value) { const val = value[key]; if (typeof Number(key) !== 'number' || typeof val !== 'string') { diff --git a/packages/sdk/tests/e2e/dataProtectorCore/processProtectedData.test.ts b/packages/sdk/tests/e2e/dataProtectorCore/processProtectedData.test.ts index 1e27491f1..b071b1a2e 100644 --- a/packages/sdk/tests/e2e/dataProtectorCore/processProtectedData.test.ts +++ b/packages/sdk/tests/e2e/dataProtectorCore/processProtectedData.test.ts @@ -77,4 +77,15 @@ describe('dataProtectorCore.processProtectedData()', () => { }, 2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME ); + it( + 'should successfully process a protected data with the minimum parameters', + async () => { + const taskId = await dataProtectorCore.processProtectedData({ + protectedData: protectedData.address, + app: appAddress, + }); + expect(taskId).toBeDefined(); + }, + 2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME + ); }); diff --git a/packages/sdk/tests/unit/dataProtectorCore/processProtectedData.test.ts b/packages/sdk/tests/unit/dataProtectorCore/processProtectedData.test.ts index f0c38a9f8..86882352a 100644 --- a/packages/sdk/tests/unit/dataProtectorCore/processProtectedData.test.ts +++ b/packages/sdk/tests/unit/dataProtectorCore/processProtectedData.test.ts @@ -156,4 +156,27 @@ describe('processProtectedData', () => { workerpoolorder: MOCK_WORKERPOOL_ORDER.orders[0]?.order, }); }); + it( + 'should throw WorkflowError for invalid secret type', + async () => { + mockFetchDatasetOrderbook = jest.fn().mockImplementationOnce(() => { + return Promise.resolve({}); + }); + iexec.orderbook.fetchDatasetOrderbook = mockFetchDatasetOrderbook; + const secretsValue = 'invalid value'; + await expect( + processProtectedData({ + iexec, + protectedData: protectedData.address, + app: '0x4605e8af487897faaef16f0709391ef1be828591', + secrets: secretsValue, + }) + ).rejects.toThrow( + new WorkflowError( + `secrets must be a \`object\` type, but the final value was: \`\"${secretsValue}\"\`.` + ) + ); + }, + 2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME + ); });