Skip to content

Commit e7f99a4

Browse files
authored
Unit tests for processProtectedData() (#367)
1 parent 5003042 commit e7f99a4

File tree

12 files changed

+1022
-797
lines changed

12 files changed

+1022
-797
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ import { IExecConsumer } from '../types/internalTypes.js';
3333
import { getWhitelistContract } from './smartContract/getWhitelistContract.js';
3434
import { isAddressInWhitelist } from './smartContract/whitelistContract.read.js';
3535

36+
export type ProcessProtectedData = typeof processProtectedData;
37+
3638
export const processProtectedData = async ({
3739
iexec = throwIfMissing(),
38-
protectedData = throwIfMissing(),
39-
app = throwIfMissing(),
40+
protectedData,
41+
app,
4042
userWhitelist,
4143
maxPrice = DEFAULT_MAX_PRICE,
4244
args,
@@ -46,14 +48,14 @@ export const processProtectedData = async ({
4648
onStatusUpdate = () => {},
4749
}: IExecConsumer &
4850
ProcessProtectedDataParams): Promise<ProcessProtectedDataResponse> => {
49-
const vApp = addressOrEnsSchema()
50-
.required()
51-
.label('authorizedApp')
52-
.validateSync(app);
5351
const vProtectedData = addressOrEnsSchema()
5452
.required()
5553
.label('protectedData')
5654
.validateSync(protectedData);
55+
const vApp = addressOrEnsSchema()
56+
.required()
57+
.label('authorizedApp')
58+
.validateSync(app);
5759
const vUserWhitelist = addressSchema()
5860
.label('userWhitelist')
5961
.validateSync(userWhitelist);
@@ -96,7 +98,7 @@ export const processProtectedData = async ({
9698

9799
if (!isRequesterInWhitelist) {
98100
throw new Error(
99-
`As a user, you are not in the whitelist. So you can't access to the protectedData in order process it`
101+
"As a user, you are not in the whitelist. You can't access the protectedData so you can't process it."
100102
);
101103
}
102104
requester = vUserWhitelist;
@@ -244,6 +246,7 @@ export const processProtectedData = async ({
244246
result,
245247
};
246248
} catch (error) {
249+
console.error('[processProtectedData] ERROR', error);
247250
handleIfProtocolError(error);
248251
throw new WorkflowError({
249252
message: processProtectedDataErrorMessage,

packages/sdk/src/utils/validators.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ export const grantedAccessSchema = () =>
9797
.noUnknown()
9898
.default(undefined);
9999

100-
export const urlArraySchema = () => array().of(urlSchema());
100+
export const urlArraySchema = () =>
101+
array().of(string().matches(/^http[s]?:\/\//, '${value} should be a url'));
101102

102103
export const secretsSchema = () =>
103104
object().test(

0 commit comments

Comments
 (0)