fix: Incomplete user object in verifyEmail function if both username and email are changed (#8889)
This commit is contained in:
@@ -1,16 +1,12 @@
|
||||
const emailAdapter = require('./support/MockEmailAdapter');
|
||||
const Config = require('../lib/Config');
|
||||
const Auth = require('../lib/Auth');
|
||||
|
||||
describe('UserController', () => {
|
||||
const user = {
|
||||
_email_verify_token: 'testToken',
|
||||
username: 'testUser',
|
||||
email: 'test@example.com',
|
||||
};
|
||||
|
||||
describe('sendVerificationEmail', () => {
|
||||
describe('parseFrameURL not provided', () => {
|
||||
it('uses publicServerURL', async done => {
|
||||
const server = await reconfigureServer({
|
||||
it('uses publicServerURL', async () => {
|
||||
await reconfigureServer({
|
||||
publicServerURL: 'http://www.example.com',
|
||||
customPages: {
|
||||
parseFrameURL: undefined,
|
||||
@@ -19,20 +15,33 @@ describe('UserController', () => {
|
||||
emailAdapter,
|
||||
appName: 'test',
|
||||
});
|
||||
|
||||
let emailOptions;
|
||||
emailAdapter.sendVerificationEmail = options => {
|
||||
expect(options.link).toEqual(
|
||||
'http://www.example.com/apps/test/verify_email?token=testToken&username=testUser'
|
||||
);
|
||||
emailAdapter.sendVerificationEmail = () => Promise.resolve();
|
||||
done();
|
||||
emailOptions = options;
|
||||
return Promise.resolve();
|
||||
};
|
||||
server.config.userController.sendVerificationEmail(user);
|
||||
|
||||
const username = 'verificationUser';
|
||||
const user = new Parse.User();
|
||||
user.setUsername(username);
|
||||
user.setPassword('pass');
|
||||
user.setEmail('verification@example.com');
|
||||
await user.signUp();
|
||||
|
||||
const config = Config.get('test');
|
||||
const rawUser = await config.database.find('_User', { username }, {}, Auth.maintenance(config));
|
||||
const rawUsername = rawUser[0].username;
|
||||
const rawToken = rawUser[0]._email_verify_token;
|
||||
expect(rawToken).toBeDefined();
|
||||
expect(rawUsername).toBe(username);
|
||||
expect(emailOptions.link).toEqual(`http://www.example.com/apps/test/verify_email?token=${rawToken}&username=${username}`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseFrameURL provided', () => {
|
||||
it('uses parseFrameURL and includes the destination in the link parameter', async done => {
|
||||
const server = await reconfigureServer({
|
||||
it('uses parseFrameURL and includes the destination in the link parameter', async () => {
|
||||
await reconfigureServer({
|
||||
publicServerURL: 'http://www.example.com',
|
||||
customPages: {
|
||||
parseFrameURL: 'http://someother.example.com/handle-parse-iframe',
|
||||
@@ -41,14 +50,27 @@ describe('UserController', () => {
|
||||
emailAdapter,
|
||||
appName: 'test',
|
||||
});
|
||||
|
||||
let emailOptions;
|
||||
emailAdapter.sendVerificationEmail = options => {
|
||||
expect(options.link).toEqual(
|
||||
'http://someother.example.com/handle-parse-iframe?link=%2Fapps%2Ftest%2Fverify_email&token=testToken&username=testUser'
|
||||
);
|
||||
emailAdapter.sendVerificationEmail = () => Promise.resolve();
|
||||
done();
|
||||
emailOptions = options;
|
||||
return Promise.resolve();
|
||||
};
|
||||
server.config.userController.sendVerificationEmail(user);
|
||||
|
||||
const username = 'verificationUser';
|
||||
const user = new Parse.User();
|
||||
user.setUsername(username);
|
||||
user.setPassword('pass');
|
||||
user.setEmail('verification@example.com');
|
||||
await user.signUp();
|
||||
|
||||
const config = Config.get('test');
|
||||
const rawUser = await config.database.find('_User', { username }, {}, Auth.maintenance(config));
|
||||
const rawUsername = rawUser[0].username;
|
||||
const rawToken = rawUser[0]._email_verify_token;
|
||||
expect(rawToken).toBeDefined();
|
||||
expect(rawUsername).toBe(username);
|
||||
expect(emailOptions.link).toEqual(`http://someother.example.com/handle-parse-iframe?link=%2Fapps%2Ftest%2Fverify_email&token=${rawToken}&username=${username}`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user