Skip to content

Commit af12eda

Browse files
committed
fixed config validation
1 parent cd26ef2 commit af12eda

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

src/Config.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import AppCache from './cache';
66
import SchemaCache from './Controllers/SchemaCache';
77
import DatabaseController from './Controllers/DatabaseController';
88
import net from 'net';
9-
import { IdempotencyOptions } from './Options/Definitions';
9+
import {
10+
IdempotencyOptions,
11+
FileUploadOptions,
12+
} from './Options/Definitions';
1013

1114
function removeTrailingSlash(str) {
1215
if (!str) {
@@ -89,9 +92,7 @@ export class Config {
8992
}
9093

9194
this.validateAccountLockoutPolicy(accountLockout);
92-
9395
this.validatePasswordPolicy(passwordPolicy);
94-
9596
this.validateFileUploadOptions(fileUpload);
9697

9798
if (typeof revokeSessionOnPasswordReset !== 'boolean') {
@@ -247,28 +248,31 @@ export class Config {
247248
throw 'You cannot use emailVerifyTokenReuseIfValid without emailVerifyTokenValidityDuration';
248249
}
249250
}
251+
250252
static validateFileUploadOptions(fileUpload) {
251253
if (!fileUpload) {
252254
fileUpload = {};
253255
}
254-
if (
255-
fileUpload.enableForAnonymousUser &&
256-
typeof fileUpload.enableForAnonymousUser !== 'boolean'
257-
) {
258-
throw 'enableForAnonymousUser must be a boolean value';
256+
if (typeof fileUpload !== 'object' || fileUpload instanceof Array) {
257+
throw 'fileUpload must be an object value.';
259258
}
260-
261-
if (fileUpload.enableForPublic && typeof fileUpload.enableForPublic !== 'boolean') {
262-
throw 'enableForPublic must be a boolean value';
259+
if (fileUpload.enableForAnonymousUser === undefined) {
260+
fileUpload.enableForAnonymousUser = FileUploadOptions.enableForAnonymousUser.default;
261+
} else if (typeof fileUpload.enableForAnonymousUser !== 'boolean') {
262+
throw 'fileUpload.enableForAnonymousUser must be a boolean value.';
263263
}
264-
265-
if (
266-
fileUpload.enableForAuthenticatedUser &&
267-
typeof fileUpload.enableForAuthenticatedUser !== 'boolean'
268-
) {
269-
throw 'enableForAuthenticatedUser must be a boolean value';
264+
if (fileUpload.enableForPublic === undefined) {
265+
fileUpload.enableForPublic = FileUploadOptions.enableForPublic.default;
266+
} else if (typeof fileUpload.enableForPublic !== 'boolean') {
267+
throw 'fileUpload.enableForPublic must be a boolean value.';
268+
}
269+
if (fileUpload.enableForAuthenticatedUser === undefined) {
270+
fileUpload.enableForAuthenticatedUser = FileUploadOptions.enableForAuthenticatedUser.default;
271+
} else if (typeof fileUpload.enableForAuthenticatedUser !== 'boolean') {
272+
throw 'fileUpload.enableForAuthenticatedUser must be a boolean value.';
270273
}
271274
}
275+
272276
static validateMasterKeyIps(masterKeyIps) {
273277
for (const ip of masterKeyIps) {
274278
if (!net.isIP(ip)) {

0 commit comments

Comments
 (0)