test: added test cases for #11562

isekai-main
Julian Lam 2 years ago
parent 84313712a2
commit 393a891379

@ -415,20 +415,28 @@ describe('Controllers', () => {
it('should throw error if email is not valid', async () => { it('should throw error if email is not valid', async () => {
const uid = await user.create({ username: 'interstiuser1' }); const uid = await user.create({ username: 'interstiuser1' });
try { const result = await user.interstitials.email({
const result = await user.interstitials.email({ userData: { uid: uid, updateEmail: true },
userData: { uid: uid, updateEmail: true }, req: { uid: uid },
req: { uid: uid }, interstitials: [],
interstitials: [], });
}); assert.strictEqual(result.interstitials[0].template, 'partials/email_update');
assert.strictEqual(result.interstitials[0].template, 'partials/email_update'); assert.rejects(result.interstitials[0].callback({ uid }, {
await result.interstitials[0].callback({ uid }, { email: 'invalidEmail',
email: 'invalidEmail', }), { message: '[[error:invalid-email]]' });
}); });
assert(false);
} catch (err) { it('should reject an email that comprises only whitespace', async () => {
assert.strictEqual(err.message, '[[error:invalid-email]]'); const uid = await user.create({ username: utils.generateUUID().slice(0, 10) });
} const result = await user.interstitials.email({
userData: { uid: uid, updateEmail: true },
req: { uid: uid },
interstitials: [],
});
assert.strictEqual(result.interstitials[0].template, 'partials/email_update');
assert.rejects(result.interstitials[0].callback({ uid }, {
email: ' ',
}), { message: '[[error:invalid-email]]' });
}); });
it('should set req.session.emailChanged to 1', async () => { it('should set req.session.emailChanged to 1', async () => {
@ -565,6 +573,56 @@ describe('Controllers', () => {
assert.strictEqual(userData.email, `${username}@nodebb.com`); assert.strictEqual(userData.email, `${username}@nodebb.com`);
assert.strictEqual(userData['email:confirmed'], 1); assert.strictEqual(userData['email:confirmed'], 1);
}); });
describe('blocking access for unconfirmed emails', () => {
let jar;
let token;
before(async () => {
jar = await helpers.registerUser({
username: utils.generateUUID().slice(0, 10),
password: utils.generateUUID(),
});
token = await helpers.getCsrfToken(jar);
});
it('should not apply if requireEmailAddress is not enabled', async () => {
meta.config.requireEmailAddress = 0;
const res = await requestAsync(`${nconf.get('url')}/register/complete`, {
method: 'post',
jar,
json: true,
followRedirect: false,
simple: false,
resolveWithFullResponse: true,
headers: {
'x-csrf-token': token,
},
form: {
email: `${utils.generateUUID().slice(0, 10)}@example.org`,
gdpr_agree_data: 'on',
gdpr_agree_email: 'on',
},
});
assert.strictEqual(res.headers.location, `${nconf.get('relative_path')}/`);
meta.config.requireEmailAddress = 1;
});
it('should continue to redirect back to interstitial after an email is entered, as it is not confirmed', async () => {
const res = await requestAsync(`${nconf.get('url')}/recent`, {
jar,
json: true,
resolveWithFullResponse: true,
followRedirect: false,
simple: false,
});
assert.strictEqual(res.statusCode, 307);
assert.strictEqual(res.headers.location, `${nconf.get('relative_path')}/me/edit/email`);
});
});
}); });
describe('gdpr', () => { describe('gdpr', () => {

Loading…
Cancel
Save