Skip to content

Commit 4df0f22

Browse files
[SDK] Add optional path param in processProtectedData (#394)
2 parents 040f8b7 + d4dd59d commit 4df0f22

File tree

7 files changed

+154
-1
lines changed

7 files changed

+154
-1
lines changed

packages/sdk/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
## Next
66

7+
### Added
8+
9+
- Added optional `path` parameter to `processProtectedData` method
10+
711
### Changed
812

913
- Moved `getResultFromCompletedTask` method from DataProtectorSharing module (DPS) to DataProtectorCore module (DPC).

packages/sdk/src/lib/dataProtectorCore/processProtectedData.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const processProtectedData = async ({
4141
app,
4242
userWhitelist,
4343
maxPrice = DEFAULT_MAX_PRICE,
44+
path,
4445
args,
4546
inputFiles,
4647
secrets,
@@ -62,6 +63,7 @@ export const processProtectedData = async ({
6263
const vMaxPrice = positiveNumberSchema()
6364
.label('maxPrice')
6465
.validateSync(maxPrice);
66+
const vPath = stringSchema().label('path').validateSync(path);
6567
const vInputFiles = urlArraySchema()
6668
.label('inputFiles')
6769
.validateSync(inputFiles);
@@ -236,6 +238,7 @@ export const processProtectedData = async ({
236238
const { result } = await getResultFromCompletedTask({
237239
iexec,
238240
taskId,
241+
path: vPath,
239242
onStatusUpdate: vOnStatusUpdate,
240243
});
241244

packages/sdk/src/lib/dataProtectorSharing/consumeProtectedData.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
throwIfMissing,
1818
validateOnStatusUpdateCallback,
1919
positiveNumberSchema,
20+
stringSchema,
2021
} from '../../utils/validators.js';
2122
import {
2223
ConsumeProtectedDataParams,
@@ -56,6 +57,7 @@ export const consumeProtectedData = async ({
5657
const vMaxPrice = positiveNumberSchema()
5758
.label('maxPrice')
5859
.validateSync(maxPrice);
60+
const vPath = stringSchema().label('path').validateSync(path);
5961
let vApp = addressOrEnsSchema().required().label('app').validateSync(app);
6062
let vWorkerpool = addressOrEnsSchema()
6163
.label('workerpool')
@@ -215,7 +217,7 @@ export const consumeProtectedData = async ({
215217
const { result } = await getResultFromCompletedTask({
216218
iexec,
217219
taskId,
218-
path,
220+
path: vPath,
219221
pemPrivateKey: privateKey,
220222
onStatusUpdate: vOnStatusUpdate,
221223
});

packages/sdk/src/lib/types/coreTypes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,11 @@ export type ProcessProtectedDataParams = {
308308
*/
309309
maxPrice?: number;
310310

311+
/**
312+
* The file name of the desired file in the returned ZIP file.
313+
*/
314+
path?: string;
315+
311316
/**
312317
* Arguments to pass to the application during execution.
313318
*/

packages/sdk/tests/e2e/dataProtectorCore/processProtectedData.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ describe.skip('dataProtectorCore.processProtectedData()', () => {
108108
2: 'email content for test processData',
109109
},
110110
args: '_args_test_process_data_',
111+
path: 'computed.json',
111112
onStatusUpdate: onStatusUpdateMock,
112113
});
113114

packages/sdk/tests/unit/dataProtectorCore/processProtectedData/processProtectedData.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,26 @@ describe('processProtectedData', () => {
153153
});
154154
});
155155

156+
describe('When given path is NOT a valid string', () => {
157+
it('should throw a yup ValidationError with the correct message', async () => {
158+
// --- GIVEN
159+
const invalidPath = 42;
160+
161+
await expect(
162+
// --- WHEN
163+
processProtectedData({
164+
// @ts-expect-error No need for iexec here
165+
iexec: {},
166+
protectedData: getRandomAddress(),
167+
app: getRandomAddress(),
168+
// @ts-expect-error Type 'number' is not assignable to type 'string'
169+
path: invalidPath,
170+
})
171+
// --- THEN
172+
).rejects.toThrow(new ValidationError('path should be a string'));
173+
});
174+
});
175+
156176
describe('When maxPrice is not a positive number', () => {
157177
it('should throw a yup ValidationError with the correct message', async () => {
158178
// --- GIVEN
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import { describe, expect, it } from '@jest/globals';
2+
import { ValidationError } from 'yup';
3+
import { consumeProtectedData } from '../../../src/lib/dataProtectorSharing/consumeProtectedData.js';
4+
import { getRandomAddress, getRequiredFieldMessage } from '../../test-utils.js';
5+
import { DEFAULT_SHARING_CONTRACT_ADDRESS } from '../../../src/config/config.js';
6+
7+
describe('consumeProtectedData', () => {
8+
describe('Check validation for input parameters', () => {
9+
describe('When protected data is NOT given', () => {
10+
it('should throw a yup ValidationError with the correct message', async () => {
11+
const missingProtectedData = undefined;
12+
13+
await expect(
14+
consumeProtectedData({
15+
// @ts-expect-error No need for iexec here
16+
iexec: {},
17+
sharingContractAddress: DEFAULT_SHARING_CONTRACT_ADDRESS,
18+
protectedData: missingProtectedData,
19+
app: getRandomAddress(),
20+
})
21+
).rejects.toThrow(
22+
new ValidationError(getRequiredFieldMessage('protectedData'))
23+
);
24+
});
25+
});
26+
27+
describe('When given protected data is NOT valid', () => {
28+
it('should throw a yup ValidationError with the correct message', async () => {
29+
const invalidProtectedData = '0x123456...';
30+
31+
await expect(
32+
consumeProtectedData({
33+
// @ts-expect-error No need for iexec here
34+
iexec: {},
35+
sharingContractAddress: DEFAULT_SHARING_CONTRACT_ADDRESS,
36+
protectedData: invalidProtectedData,
37+
app: getRandomAddress(),
38+
})
39+
).rejects.toThrow(
40+
new ValidationError(
41+
'protectedData should be an ethereum address or a ENS name'
42+
)
43+
);
44+
});
45+
});
46+
47+
describe('When app address is NOT given', () => {
48+
it('should throw a yup ValidationError with the correct message', async () => {
49+
const missingAppAddress = undefined;
50+
51+
await expect(
52+
consumeProtectedData({
53+
// @ts-expect-error No need for iexec here
54+
iexec: {},
55+
sharingContractAddress: DEFAULT_SHARING_CONTRACT_ADDRESS,
56+
protectedData: getRandomAddress(),
57+
app: missingAppAddress,
58+
})
59+
).rejects.toThrow(new ValidationError(getRequiredFieldMessage('app')));
60+
});
61+
});
62+
63+
describe('When given app address is NOT valid', () => {
64+
it('should throw a yup ValidationError with the correct message', async () => {
65+
const invalidAppAddress = '0x123456...';
66+
67+
await expect(
68+
consumeProtectedData({
69+
// @ts-expect-error No need for iexec here
70+
iexec: {},
71+
sharingContractAddress: DEFAULT_SHARING_CONTRACT_ADDRESS,
72+
protectedData: getRandomAddress(),
73+
app: invalidAppAddress,
74+
})
75+
).rejects.toThrow(
76+
new ValidationError('app should be an ethereum address or a ENS name')
77+
);
78+
});
79+
});
80+
81+
describe('When maxPrice is not a positive number', () => {
82+
it('should throw a yup ValidationError with the correct message', async () => {
83+
const invalidMaxPrice = -1;
84+
85+
await expect(
86+
consumeProtectedData({
87+
// @ts-expect-error No need for iexec here
88+
iexec: {},
89+
sharingContractAddress: DEFAULT_SHARING_CONTRACT_ADDRESS,
90+
protectedData: getRandomAddress(),
91+
app: getRandomAddress(),
92+
maxPrice: invalidMaxPrice,
93+
})
94+
).rejects.toThrow(
95+
new ValidationError('maxPrice must be greater than or equal to 0')
96+
);
97+
});
98+
});
99+
100+
describe('When path is not a valid string', () => {
101+
it('should throw a yup ValidationError with the correct message', async () => {
102+
const invalidPath = 42;
103+
104+
await expect(
105+
consumeProtectedData({
106+
// @ts-expect-error No need for iexec here
107+
iexec: {},
108+
sharingContractAddress: DEFAULT_SHARING_CONTRACT_ADDRESS,
109+
protectedData: getRandomAddress(),
110+
app: getRandomAddress(),
111+
// @ts-expect-error Type 'number' is not assignable to type 'string'
112+
path: invalidPath,
113+
})
114+
).rejects.toThrow(new ValidationError('path should be a string'));
115+
});
116+
});
117+
});
118+
});

0 commit comments

Comments
 (0)