Skip to content

Commit e634eba

Browse files
authored
fix: definitions for accountLockout and passwordPolicy (#7040)
* fix: definitions for accountLockout and passwordPolicy * redo env prefix
1 parent c8ff445 commit e634eba

File tree

4 files changed

+104
-19
lines changed

4 files changed

+104
-19
lines changed

resources/buildConfigDefinitions.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,17 @@ function getCommentValue(comment) {
4040
}
4141

4242
function getENVPrefix(iface) {
43-
if (iface.id.name === 'ParseServerOptions') {
44-
return 'PARSE_SERVER_';
43+
const options = {
44+
'ParseServerOptions' : 'PARSE_SERVER_',
45+
'CustomPagesOptions' : 'PARSE_SERVER_CUSTOM_PAGES_',
46+
'LiveQueryServerOptions' : 'PARSE_LIVE_QUERY_SERVER_',
47+
'LiveQueryOptions' : 'PARSE_SERVER_LIVEQUERY_',
48+
'IdempotencyOptions' : 'PARSE_SERVER_EXPERIMENTAL_IDEMPOTENCY_',
49+
'AccountLockoutOptions' : 'PARSE_SERVER_ACCOUNT_LOCKOUT_',
50+
'PasswordPolicyOptions' : 'PARSE_SERVER_PASSWORD_POLICY_'
4551
}
46-
if (iface.id.name === 'CustomPagesOptions') {
47-
return 'PARSE_SERVER_CUSTOM_PAGES_';
48-
}
49-
if (iface.id.name === 'LiveQueryServerOptions') {
50-
return 'PARSE_LIVE_QUERY_SERVER_';
51-
}
52-
if (iface.id.name === 'LiveQueryOptions') {
53-
return 'PARSE_SERVER_LIVEQUERY_';
54-
}
55-
if (iface.id.name === 'IdempotencyOptions') {
56-
return 'PARSE_SERVER_EXPERIMENTAL_IDEMPOTENCY_';
52+
if (options[iface.id.name]) {
53+
return options[iface.id.name]
5754
}
5855
}
5956

src/Options/Definitions.js

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ module.exports.ParseServerOptions = {
127127
},
128128
emailVerifyTokenReuseIfValid: {
129129
env: 'PARSE_SERVER_EMAIL_VERIFY_TOKEN_REUSE_IF_VALID',
130-
help:
131-
'an existing email verify token should be reused when resend verification email is requested',
130+
help: 'an existing email verify token should be reused when resend verification email is requested',
132131
action: parsers.booleanParser,
133132
default: false,
134133
},
@@ -552,3 +551,51 @@ module.exports.IdempotencyOptions = {
552551
default: 300,
553552
},
554553
};
554+
module.exports.AccountLockoutOptions = {
555+
duration: {
556+
env: 'PARSE_SERVER_ACCOUNT_LOCKOUT_DURATION',
557+
help:
558+
'number of minutes that a locked-out account remains locked out before automatically becoming unlocked.',
559+
action: parsers.numberParser('duration'),
560+
},
561+
threshold: {
562+
env: 'PARSE_SERVER_ACCOUNT_LOCKOUT_THRESHOLD',
563+
help: 'number of failed sign-in attempts that will cause a user account to be locked',
564+
action: parsers.numberParser('threshold'),
565+
},
566+
};
567+
module.exports.PasswordPolicyOptions = {
568+
doNotAllowUsername: {
569+
env: 'PARSE_SERVER_PASSWORD_POLICY_DO_NOT_ALLOW_USERNAME',
570+
help: 'disallow username in passwords',
571+
action: parsers.booleanParser,
572+
},
573+
maxPasswordAge: {
574+
env: 'PARSE_SERVER_PASSWORD_POLICY_MAX_PASSWORD_AGE',
575+
help: 'days for password expiry',
576+
action: parsers.numberParser('maxPasswordAge'),
577+
},
578+
maxPasswordHistory: {
579+
env: 'PARSE_SERVER_PASSWORD_POLICY_MAX_PASSWORD_HISTORY',
580+
help: 'setting to prevent reuse of previous n passwords',
581+
action: parsers.numberParser('maxPasswordHistory'),
582+
},
583+
resetTokenReuseIfValid: {
584+
env: 'PARSE_SERVER_PASSWORD_POLICY_RESET_TOKEN_REUSE_IF_VALID',
585+
help: "resend token if it's still valid",
586+
action: parsers.booleanParser,
587+
},
588+
resetTokenValidityDuration: {
589+
env: 'PARSE_SERVER_PASSWORD_POLICY_RESET_TOKEN_VALIDITY_DURATION',
590+
help: 'time for token to expire',
591+
action: parsers.numberParser('resetTokenValidityDuration'),
592+
},
593+
validatorCallback: {
594+
env: 'PARSE_SERVER_PASSWORD_POLICY_VALIDATOR_CALLBACK',
595+
help: 'a callback function to be invoked to validate the password',
596+
},
597+
validatorPattern: {
598+
env: 'PARSE_SERVER_PASSWORD_POLICY_VALIDATOR_PATTERN',
599+
help: 'a RegExp object or a regex string representing the pattern to enforce',
600+
},
601+
};

src/Options/docs.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @interface ParseServerOptions
3-
* @property {Any} accountLockout account lockout policy for failed login attempts
3+
* @property {AccountLockoutOptions} accountLockout account lockout policy for failed login attempts
44
* @property {Boolean} allowClientClassCreation Enable (or disable) client class creation, defaults to true
55
* @property {Boolean} allowCustomObjectId Enable (or disable) custom objectId
66
* @property {String[]} allowHeaders Add headers to Access-Control-Allow-Headers
@@ -53,7 +53,7 @@
5353
* @property {String} mountPath Mount path for the server, defaults to /parse
5454
* @property {Boolean} mountPlayground Mounts the GraphQL Playground - never use this option in production
5555
* @property {Number} objectIdSize Sets the number of characters in generated object id's, default 10
56-
* @property {Any} passwordPolicy Password policy for enforcing password related rules
56+
* @property {PasswordPolicyOptions} passwordPolicy Password policy for enforcing password related rules
5757
* @property {String} playgroundPath Mount path for the GraphQL Playground, defaults to /playground
5858
* @property {Number} port The port to run the ParseServer, defaults to 1337.
5959
* @property {Boolean} preserveFileName Enable (or disable) the addition of a unique hash to the file names
@@ -120,3 +120,20 @@
120120
* @property {String[]} paths An array of paths for which the feature should be enabled. The mount path must not be included, for example instead of `/parse/functions/myFunction` specifiy `functions/myFunction`. The entries are interpreted as regular expression, for example `functions/.*` matches all functions, `jobs/.*` matches all jobs, `classes/.*` matches all classes, `.*` matches all paths.
121121
* @property {Number} ttl The duration in seconds after which a request record is discarded from the database, defaults to 300s.
122122
*/
123+
124+
/**
125+
* @interface AccountLockoutOptions
126+
* @property {Number} duration number of minutes that a locked-out account remains locked out before automatically becoming unlocked.
127+
* @property {Number} threshold number of failed sign-in attempts that will cause a user account to be locked
128+
*/
129+
130+
/**
131+
* @interface PasswordPolicyOptions
132+
* @property {Boolean} doNotAllowUsername disallow username in passwords
133+
* @property {Number} maxPasswordAge days for password expiry
134+
* @property {Number} maxPasswordHistory setting to prevent reuse of previous n passwords
135+
* @property {Boolean} resetTokenReuseIfValid resend token if it's still valid
136+
* @property {Number} resetTokenValidityDuration time for token to expire
137+
* @property {Function} validatorCallback a callback function to be invoked to validate the password
138+
* @property {String} validatorPattern a RegExp object or a regex string representing the pattern to enforce
139+
*/

src/Options/index.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ export interface ParseServerOptions {
128128
:DEFAULT: false */
129129
emailVerifyTokenReuseIfValid: ?boolean;
130130
/* account lockout policy for failed login attempts */
131-
accountLockout: ?any;
131+
accountLockout: ?AccountLockoutOptions;
132132
/* Password policy for enforcing password related rules */
133-
passwordPolicy: ?any;
133+
passwordPolicy: ?PasswordPolicyOptions;
134134
/* Adapter module for the cache */
135135
cacheAdapter: ?Adapter<CacheAdapter>;
136136
/* Adapter module for email sending */
@@ -291,3 +291,27 @@ export interface IdempotencyOptions {
291291
:DEFAULT: 300 */
292292
ttl: ?number;
293293
}
294+
295+
export interface AccountLockoutOptions {
296+
/* number of minutes that a locked-out account remains locked out before automatically becoming unlocked. */
297+
duration: ?number;
298+
/* number of failed sign-in attempts that will cause a user account to be locked */
299+
threshold: ?number;
300+
}
301+
302+
export interface PasswordPolicyOptions {
303+
/* a RegExp object or a regex string representing the pattern to enforce */
304+
validatorPattern: ?string;
305+
/* a callback function to be invoked to validate the password */
306+
validatorCallback: ?() => void;
307+
/* disallow username in passwords */
308+
doNotAllowUsername: ?boolean;
309+
/* days for password expiry */
310+
maxPasswordAge: ?number;
311+
/* setting to prevent reuse of previous n passwords */
312+
maxPasswordHistory: ?number;
313+
/* time for token to expire */
314+
resetTokenValidityDuration: ?number;
315+
/* resend token if it's still valid */
316+
resetTokenReuseIfValid: ?boolean;
317+
}

0 commit comments

Comments
 (0)