Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions spec/RateLimit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ describe('rate limit', () => {
);
});

it('can limit cloud function with per-function rateLimit defined in cloud code loaded at startup (#8684)', async () => {
await reconfigureServer({
cloud: Parse => {
Parse.Cloud.define('test8684', () => 'Abc', {
rateLimit: {
requestTimeWindow: 10000,
requestCount: 1,
errorResponseMessage: 'Too many requests',
includeInternalRequests: true,
},
});
},
});
const response1 = await Parse.Cloud.run('test8684');
expect(response1).toBe('Abc');
await expectAsync(Parse.Cloud.run('test8684')).toBeRejectedWith(
new Parse.Error(Parse.Error.CONNECTION_FAILED, 'Too many requests')
);
});

it('can skip with masterKey', async () => {
Parse.Cloud.define('test', () => 'Abc');
await reconfigureServer({
Expand Down
2 changes: 1 addition & 1 deletion src/middlewares.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ export function promiseEnforceMasterKeyAccess(request) {

export const addRateLimit = (route, config, cloud) => {
if (typeof config === 'string') {
config = Config.get(config);
config = AppCache.get(config);
}
for (const key in route) {
if (!RateLimitOptions[key]) {
Expand Down
Loading