Skip to content

Commit d27a4ef

Browse files
authored
Merge branch 'master' into validateValidator
2 parents cd13ef6 + 91a0108 commit d27a4ef

File tree

6 files changed

+110
-10
lines changed

6 files changed

+110
-10
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@ jobs:
3232
run: npm ci
3333
- name: CI Self-Check
3434
run: npm run ci:check
35+
check-lint:
36+
name: Lint
37+
timeout-minutes: 30
38+
runs-on: ubuntu-18.04
39+
steps:
40+
- uses: actions/checkout@v2
41+
- name: Use Node.js ${{ matrix.NODE_VERSION }}
42+
uses: actions/setup-node@v1
43+
with:
44+
node-version: ${{ matrix.node-version }}
45+
- name: Cache Node.js modules
46+
uses: actions/cache@v2
47+
with:
48+
path: ~/.npm
49+
key: ${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-${{ hashFiles('**/package-lock.json') }}
50+
restore-keys: |
51+
${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-
52+
- name: Install dependencies
53+
run: npm ci
54+
- run: npm run lint
3555
check-mongo:
3656
strategy:
3757
matrix:
@@ -106,8 +126,6 @@ jobs:
106126
${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-
107127
- name: Install dependencies
108128
run: npm ci
109-
- if: ${{ matrix.name == 'Mongo 3.6.21' }}
110-
run: npm run lint
111129
- run: npm run pretest
112130
- run: npm run coverage
113131
env:

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
__BREAKING CHANGES:__
1616
- NEW: Added file upload restriction. File upload is now only allowed for authenticated users by default for improved security. To allow file upload also for Anonymous Users or Public, set the `fileUpload` parameter in the [Parse Server Options](https://parseplatform.org/parse-server/api/master/ParseServerOptions.html). [#7071](https://github.com/parse-community/parse-server/pull/7071). Thanks to [dblythy](https://github.com/dblythy), [Manuel Trezza](https://github.com/mtrezza).
1717
___
18+
- IMPROVE: Allow Cloud Validator `options` to be async [#7155](https://github.com/parse-community/parse-server/pull/7155). Thanks to [dblythy](https://github.com/dblythy)
1819
- NEW (EXPERIMENTAL): Added new page router with placeholder rendering and localization of custom and feature pages such as password reset and email verification. **Caution, this is an experimental feature that may not be appropriate for production.** [#6891](https://github.com/parse-community/parse-server/issues/6891). Thanks to [Manuel Trezza](https://github.com/mtrezza).
1920
- NEW: Added convenience method `Parse.Cloud.sendEmail(...)` to send email via email adapter in Cloud Code. [#7089](https://github.com/parse-community/parse-server/pull/7089). Thanks to [dblythy](https://github.com/dblythy)
2021
- NEW: LiveQuery support for $and, $nor, $containedBy, $geoWithin, $geoIntersects queries [#7113](https://github.com/parse-community/parse-server/pull/7113). Thanks to [dplewis](https://github.com/dplewis)
@@ -26,6 +27,7 @@ ___
2627
- IMPROVE: Parse Server is from now on continuously tested against all recent MongoDB versions that have not reached their end-of-life support date. Added MongoDB compatibility table to Parse Server docs. [7161](https://github.com/parse-community/parse-server/pull/7161). Thanks to [Manuel Trezza](https://github.com/mtrezza).
2728
- IMPROVE: Parse Server is from now on continuously tested against all recent Node.js versions that have not reached their end-of-life support date. [7161](https://github.com/parse-community/parse-server/pull/7177). Thanks to [Manuel Trezza](https://github.com/mtrezza).
2829
- IMPROVE: Cloud Validators will now log on invalid configuration [#7154](https://github.com/parse-community/parse-server/pull/7154). Thanks to [dblythy](https://github.com/dblythy)
30+
- IMPROVE: Allow Cloud Validator `options` to be async [#7155](https://github.com/parse-community/parse-server/pull/7155). Thanks to [dblythy](https://github.com/dblythy)
2931
- IMPROVE: Optimize queries on classes with pointer permissions. [#7061](https://github.com/parse-community/parse-server/pull/7061). Thanks to [Pedro Diaz](https://github.com/pdiaz)
3032
- IMPROVE: Parse Server will from now on be continuously tested against all relevant Postgres versions (minor versions). Added Postgres compatibility table to Parse Server docs. [#7176](https://github.com/parse-community/parse-server/pull/7176). Thanks to [Corey Baker](https://github.com/cbaker6).
3133
- FIX: Fix error when a not yet inserted job is updated [#7196](https://github.com/parse-community/parse-server/pull/7196). Thanks to [Antonio Davi Macedo Coelho de Castro](https://github.com/davimacedo).

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"jsonwebtoken": "8.5.1",
4444
"jwks-rsa": "1.12.2",
4545
"ldapjs": "2.2.3",
46-
"lodash": "4.17.20",
46+
"lodash": "4.17.21",
4747
"lru-cache": "5.1.1",
4848
"mime": "2.5.0",
4949
"mongodb": "3.6.3",

spec/CloudCode.Validator.spec.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,4 +1511,80 @@ describe('cloud validator', () => {
15111511
'Invalid type for Parse.Cloud validator key error. Expected string, actual array'
15121512
);
15131513
});
1514+
1515+
it('set params options function async', async () => {
1516+
Parse.Cloud.define(
1517+
'hello',
1518+
() => {
1519+
return 'Hello world!';
1520+
},
1521+
{
1522+
fields: {
1523+
data: {
1524+
type: String,
1525+
required: true,
1526+
options: async val => {
1527+
await new Promise(resolve => {
1528+
setTimeout(resolve, 500);
1529+
});
1530+
return val === 'f';
1531+
},
1532+
error: 'Validation failed.',
1533+
},
1534+
},
1535+
}
1536+
);
1537+
try {
1538+
await Parse.Cloud.run('hello', { data: 'd' });
1539+
fail('validation should have failed');
1540+
} catch (error) {
1541+
expect(error.code).toEqual(Parse.Error.VALIDATION_ERROR);
1542+
expect(error.message).toEqual('Validation failed.');
1543+
}
1544+
const result = await Parse.Cloud.run('hello', { data: 'f' });
1545+
expect(result).toBe('Hello world!');
1546+
});
1547+
1548+
it('basic beforeSave requireUserKey as custom async function', async () => {
1549+
Parse.Cloud.beforeSave(Parse.User, () => {}, {
1550+
fields: {
1551+
accType: {
1552+
default: 'normal',
1553+
constant: true,
1554+
},
1555+
},
1556+
});
1557+
Parse.Cloud.define(
1558+
'secureFunction',
1559+
() => {
1560+
return "Here's all the secure data!";
1561+
},
1562+
{
1563+
requireUserKeys: {
1564+
accType: {
1565+
options: async val => {
1566+
await new Promise(resolve => {
1567+
setTimeout(resolve, 500);
1568+
});
1569+
return ['admin', 'admin2'].includes(val);
1570+
},
1571+
error: 'Unauthorized.',
1572+
},
1573+
},
1574+
}
1575+
);
1576+
const user = new Parse.User();
1577+
user.set('username', 'testuser');
1578+
user.set('password', 'p@ssword');
1579+
user.set('accType', 'admin');
1580+
await user.signUp();
1581+
expect(user.get('accType')).toBe('normal');
1582+
try {
1583+
await Parse.Cloud.run('secureFunction');
1584+
fail('function should only be available to admin users');
1585+
} catch (error) {
1586+
expect(error.code).toEqual(Parse.Error.VALIDATION_ERROR);
1587+
expect(error.message).toEqual('Unauthorized.');
1588+
}
1589+
});
15141590
});

src/triggers.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -662,11 +662,11 @@ async function builtInTriggerValidator(options, request, auth) {
662662
}
663663
};
664664

665-
const validateOptions = (opt, key, val) => {
665+
const validateOptions = async (opt, key, val) => {
666666
let opts = opt.options;
667667
if (typeof opts === 'function') {
668668
try {
669-
const result = opts(val);
669+
const result = await opts(val);
670670
if (!result && result != null) {
671671
throw opt.error || `Validation failed. Invalid value for ${key}.`;
672672
}
@@ -699,6 +699,7 @@ async function builtInTriggerValidator(options, request, auth) {
699699
requiredParam(key);
700700
}
701701
} else {
702+
const optionPromises = [];
702703
for (const key in options.fields) {
703704
const opt = options.fields[key];
704705
let val = params[key];
@@ -731,10 +732,11 @@ async function builtInTriggerValidator(options, request, auth) {
731732
}
732733
}
733734
if (opt.options) {
734-
validateOptions(opt, key, val);
735+
optionPromises.push(validateOptions(opt, key, val));
735736
}
736737
}
737738
}
739+
await Promise.all(optionPromises);
738740
}
739741
let userRoles = options.requireAnyUserRoles;
740742
let requireAllRoles = options.requireAllUserRoles;
@@ -780,12 +782,14 @@ async function builtInTriggerValidator(options, request, auth) {
780782
}
781783
}
782784
} else if (typeof userKeys === 'object') {
785+
const optionPromises = [];
783786
for (const key in options.requireUserKeys) {
784787
const opt = options.requireUserKeys[key];
785788
if (opt.options) {
786-
validateOptions(opt, key, reqUser.get(key));
789+
optionPromises.push(validateOptions(opt, key, reqUser.get(key)));
787790
}
788791
}
792+
await Promise.all(optionPromises);
789793
}
790794
}
791795

0 commit comments

Comments
 (0)