Skip to content

Commit 1c00821

Browse files
committed
wip
1 parent 74db98e commit 1c00821

File tree

6 files changed

+45
-2
lines changed

6 files changed

+45
-2
lines changed

spec/ValidationAndPasswordsReset.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,10 +1092,33 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
10921092
apiKey: 'k',
10931093
domain: 'd',
10941094
}),
1095+
passwordPolicy: {
1096+
resetPasswordSuccessOnInvalidEmail: false,
1097+
},
10951098
});
10961099

10971100
await expectAsync(Parse.User.requestPasswordReset('[email protected]')).toBeRejectedWith(
10981101
new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'A user with that email does not exist.')
10991102
);
11001103
});
1104+
1105+
it('validate resetPasswordSuccessonInvalidEmail', async () => {
1106+
const invalidValues = [[], {}, 1, 'string'];
1107+
for (const value of invalidValues) {
1108+
await expectAsync(
1109+
reconfigureServer({
1110+
appName: 'coolapp',
1111+
publicServerURL: 'http://localhost:1337/1',
1112+
emailAdapter: MockEmailAdapterWithOptions({
1113+
fromAddress: '[email protected]',
1114+
apiKey: 'k',
1115+
domain: 'd',
1116+
}),
1117+
passwordPolicy: {
1118+
resetPasswordSuccessOnInvalidEmail: value,
1119+
},
1120+
})
1121+
).toBeRejectedWith('resetPasswordSuccessOnInvalidEmail must be a boolean value');
1122+
}
1123+
});
11011124
});

src/Config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,13 @@ export class Config {
369369
if (passwordPolicy.resetTokenReuseIfValid && !passwordPolicy.resetTokenValidityDuration) {
370370
throw 'You cannot use resetTokenReuseIfValid without resetTokenValidityDuration';
371371
}
372+
373+
if (
374+
passwordPolicy.resetPasswordSuccessOnInvalidEmail &&
375+
typeof passwordPolicy.resetPasswordSuccessOnInvalidEmail !== 'boolean'
376+
) {
377+
throw 'resetPasswordSuccessOnInvalidEmail must be a boolean value';
378+
}
372379
}
373380
}
374381

src/Options/Definitions.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,13 @@ module.exports.PasswordPolicyOptions = {
894894
'Set the number of previous password that will not be allowed to be set as new password. If the option is not set or set to `0`, no previous passwords will be considered.<br><br>Valid values are >= `0` and <= `20`.<br>Default is `0`.',
895895
action: parsers.numberParser('maxPasswordHistory'),
896896
},
897+
resetPasswordSuccessOnInvalidEmail: {
898+
env: 'PARSE_SERVER_PASSWORD_POLICY_RESET_PASSWORD_SUCCESS_ON_INVALID_EMAIL',
899+
help:
900+
'Set to true if password resets should return success if the email is invalid<br><br>Default is `true`.',
901+
action: parsers.booleanParser,
902+
default: true,
903+
},
897904
resetTokenReuseIfValid: {
898905
env: 'PARSE_SERVER_PASSWORD_POLICY_RESET_TOKEN_REUSE_IF_VALID',
899906
help:

src/Options/docs.js

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

src/Options/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,11 @@ export interface PasswordPolicyOptions {
520520
Default is `false`.
521521
:DEFAULT: false */
522522
resetTokenReuseIfValid: ?boolean;
523+
/* Set to true if password resets should return success if the email is invalid
524+
<br><br>
525+
Default is `true`.
526+
:DEFAULT: true */
527+
resetPasswordSuccessOnInvalidEmail: ?boolean;
523528
}
524529

525530
export interface FileUploadOptions {

src/Routers/UsersRouter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,12 @@ export class UsersRouter extends ClassesRouter {
435435
};
436436
} catch (err) {
437437
if (err.code === Parse.Error.OBJECT_NOT_FOUND) {
438-
if (!req.config.passwordPolicy) {
438+
if (req.config.passwordPolicy?.resetPasswordSuccessOnInvalidEmail ?? true) {
439439
return {
440440
response: {},
441441
};
442442
}
443-
err.message = `A user with the email ${email} does not exist.`;
443+
err.message = `A user with that email does not exist.`;
444444
}
445445
throw err;
446446
}

0 commit comments

Comments
 (0)