Skip to content

Commit

Permalink
feat: Add password validation for user with unverified email via `Par…
Browse files Browse the repository at this point in the history
…se.User.verifyPassword` using master key and option `ignoreEmailVerification: true` (#2076)
  • Loading branch information
mtrezza committed Mar 23, 2024
1 parent f56b9ed commit b0adf7e
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 228 deletions.
13 changes: 13 additions & 0 deletions integration/test/ParseUserTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,19 @@ describe('Parse User', () => {
}
});

it('can verify user password for user with unverified email', async () => {
await reconfigureServer({
appName: 'AppName',
publicServerURL: 'http://localhost:1337/',
verifyUserEmails: true,
preventLoginWithUnverifiedEmail: true,
});
await Parse.User.signUp('asd123', 'xyz123');
const res = await Parse.User.verifyPassword('asd123', 'xyz123', { useMasterKey: true, ignoreEmailVerification: true });
expect(typeof res).toBe('object');
expect(res.username).toBe('asd123');
});

it('can encrypt user', async () => {
Parse.User.enableUnsafeCurrentUser();
Parse.enableEncryptedUser();
Expand Down
6 changes: 6 additions & 0 deletions integration/test/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const Parse = require('../../node');
const fs = require('fs');
const path = require('path');
const dns = require('dns');
const MockEmailAdapterWithOptions = require('./support/MockEmailAdapterWithOptions');

// Ensure localhost resolves to ipv4 address first on node v17+
if (dns.setDefaultResultOrder) {
Expand Down Expand Up @@ -83,6 +84,11 @@ const defaultConfiguration = {
revokeSessionOnPasswordReset: false,
allowCustomObjectId: false,
allowClientClassCreation: true,
emailAdapter: MockEmailAdapterWithOptions({
fromAddress: 'parse@example.com',
apiKey: 'k',
domain: 'd',
}),
};

const openConnections = {};
Expand Down
21 changes: 21 additions & 0 deletions integration/test/support/MockEmailAdapterWithOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = options => {
if (!options) {
throw 'Options were not provided';
}
const adapter = {
sendVerificationEmail: () => Promise.resolve(),
sendPasswordResetEmail: () => Promise.resolve(),
sendMail: () => Promise.resolve(),
};
if (options.sendMail) {
adapter.sendMail = options.sendMail;
}
if (options.sendPasswordResetEmail) {
adapter.sendPasswordResetEmail = options.sendPasswordResetEmail;
}
if (options.sendVerificationEmail) {
adapter.sendVerificationEmail = options.sendVerificationEmail;
}

return adapter;
};
Loading

0 comments on commit b0adf7e

Please sign in to comment.