Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dblythy committed May 16, 2023
1 parent 63b5174 commit 5a6ba11
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion spec/RateLimit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ describe('rate limit', () => {
validateRateLimit({
rateLimit: [{ requestPath: 'a', requestTimeWindow: 1000, requestCount: 3, zone: 'abc' }],
})
).toThrow('rateLimit.zone must be one of global, session, user or ip');
).toThrow('rateLimit.zone must be one of global, session, user, or ip');
expect(() =>
validateRateLimit({
rateLimit: [
Expand Down
7 changes: 5 additions & 2 deletions src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
SchemaOptions,
SecurityOptions,
} from './Options/Definitions';
import ParseServer from './cloud-code/Parse.Server';

function removeTrailingSlash(str) {
if (!str) {
Expand Down Expand Up @@ -599,8 +600,10 @@ export class Config {
if (option.errorResponseMessage && typeof option.errorResponseMessage !== 'string') {
throw `rateLimit.errorResponseMessage must be a string`;
}
if (option.zone && !['global', 'session', 'user', 'ip'].includes(option.zone)) {
throw `rateLimit.zone must be one of global, session, user or ip`;
const options = Object.keys(ParseServer.RateLimitZone);
if (option.zone && !options.includes(option.zone)) {
const formatter = new Intl.ListFormat('en', { style: 'short', type: 'disjunction' });
throw `rateLimit.zone must be one of ${formatter.format(options)}`;
}
}
}
Expand Down

0 comments on commit 5a6ba11

Please sign in to comment.