|
|
|
@ -332,173 +332,194 @@ describe('Controllers', () => {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('registration interstitials', () => {
|
|
|
|
|
let jar;
|
|
|
|
|
let token;
|
|
|
|
|
|
|
|
|
|
it('email interstitial should still apply if empty email entered and requireEmailAddress is enabled', async () => {
|
|
|
|
|
meta.config.requireEmailAddress = 1;
|
|
|
|
|
describe.only('registration interstitials', () => {
|
|
|
|
|
describe('email update', () => {
|
|
|
|
|
let jar;
|
|
|
|
|
let token;
|
|
|
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
|
jar = await helpers.registerUser({
|
|
|
|
|
username: utils.generateUUID().slice(0, 10),
|
|
|
|
|
password: utils.generateUUID(),
|
|
|
|
|
});
|
|
|
|
|
console.log(jar);
|
|
|
|
|
token = await helpers.getCsrfToken(jar);
|
|
|
|
|
|
|
|
|
|
jar = await helpers.registerUser({
|
|
|
|
|
username: 'testEmailReg',
|
|
|
|
|
password: 'asdasd',
|
|
|
|
|
meta.config.requireEmailAddress = 1;
|
|
|
|
|
});
|
|
|
|
|
token = await helpers.getCsrfToken(jar);
|
|
|
|
|
|
|
|
|
|
let 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: '',
|
|
|
|
|
},
|
|
|
|
|
after(() => {
|
|
|
|
|
meta.config.requireEmailAddress = 0;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.headers.location, `${nconf.get('relative_path')}/register/complete`);
|
|
|
|
|
it('email interstitial should still apply if empty email entered and requireEmailAddress is enabled', async () => {
|
|
|
|
|
let 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: '',
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
res = await requestAsync(`${nconf.get('url')}/api/register/complete`, {
|
|
|
|
|
jar,
|
|
|
|
|
json: true,
|
|
|
|
|
resolveWithFullResponse: true,
|
|
|
|
|
assert.strictEqual(res.headers.location, `${nconf.get('relative_path')}/register/complete`);
|
|
|
|
|
|
|
|
|
|
res = await requestAsync(`${nconf.get('url')}/api/register/complete`, {
|
|
|
|
|
jar,
|
|
|
|
|
json: true,
|
|
|
|
|
resolveWithFullResponse: true,
|
|
|
|
|
});
|
|
|
|
|
assert.strictEqual(res.statusCode, 200);
|
|
|
|
|
assert(res.body.errors.length);
|
|
|
|
|
assert(res.body.errors.includes('[[error:invalid-email]]'));
|
|
|
|
|
});
|
|
|
|
|
console.log(res.statusCode, JSON.stringify(res.body, null, 4));
|
|
|
|
|
assert.strictEqual(res.statusCode, 200);
|
|
|
|
|
assert(res.body.errors.length);
|
|
|
|
|
assert(res.body.errors.includes('[[error:invalid-email]]'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('gdpr interstitial should still apply if email requirement is disabled', async () => {
|
|
|
|
|
meta.config.requireEmailAddress = 0;
|
|
|
|
|
it('gdpr interstitial should still apply if email requirement is disabled', async () => {
|
|
|
|
|
meta.config.requireEmailAddress = 0;
|
|
|
|
|
|
|
|
|
|
const res = await requestAsync(`${nconf.get('url')}/api/register/complete`, {
|
|
|
|
|
jar,
|
|
|
|
|
json: true,
|
|
|
|
|
resolveWithFullResponse: true,
|
|
|
|
|
const res = await requestAsync(`${nconf.get('url')}/api/register/complete`, {
|
|
|
|
|
jar,
|
|
|
|
|
json: true,
|
|
|
|
|
resolveWithFullResponse: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
assert(!res.body.errors.includes('[[error:invalid-email]]'));
|
|
|
|
|
assert(!res.body.errors.includes('[[error:gdpr_consent_denied]]'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
assert(!res.body.errors.includes('[[error:invalid-email]]'));
|
|
|
|
|
assert(!res.body.errors.includes('[[error:gdpr_consent_denied]]'));
|
|
|
|
|
});
|
|
|
|
|
it('should error if userData is falsy', async () => {
|
|
|
|
|
try {
|
|
|
|
|
await user.interstitials.email({ userData: null });
|
|
|
|
|
assert(false);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
assert.strictEqual(err.message, '[[error:invalid-data]]');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('registration should succeed once gdpr prompts are agreed to', async () => {
|
|
|
|
|
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: {
|
|
|
|
|
gdpr_agree_data: 'on',
|
|
|
|
|
gdpr_agree_email: 'on',
|
|
|
|
|
},
|
|
|
|
|
it('should throw error if email is not valid', async () => {
|
|
|
|
|
const uid = await user.create({ username: 'interstiuser1' });
|
|
|
|
|
try {
|
|
|
|
|
const result = await user.interstitials.email({
|
|
|
|
|
userData: { uid: uid, updateEmail: true },
|
|
|
|
|
req: { uid: uid },
|
|
|
|
|
interstitials: [],
|
|
|
|
|
});
|
|
|
|
|
assert.strictEqual(result.interstitials[0].template, 'partials/email_update');
|
|
|
|
|
await result.interstitials[0].callback({ uid: uid }, {
|
|
|
|
|
email: 'invalidEmail',
|
|
|
|
|
});
|
|
|
|
|
assert(false);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
assert.strictEqual(err.message, '[[error:invalid-email]]');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.statusCode, 302);
|
|
|
|
|
assert.strictEqual(res.headers.location, `${nconf.get('relative_path')}/`);
|
|
|
|
|
});
|
|
|
|
|
it('should set req.session.emailChanged to 1', async () => {
|
|
|
|
|
const uid = await user.create({ username: 'interstiuser2' });
|
|
|
|
|
const result = await user.interstitials.email({
|
|
|
|
|
userData: { uid: uid, updateEmail: true },
|
|
|
|
|
req: { uid: uid, session: {} },
|
|
|
|
|
interstitials: [],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should error if userData is falsy', async () => {
|
|
|
|
|
try {
|
|
|
|
|
await user.interstitials.email({ userData: null });
|
|
|
|
|
assert(false);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
assert.strictEqual(err.message, '[[error:invalid-data]]');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
await result.interstitials[0].callback({ uid: uid }, {
|
|
|
|
|
email: 'interstiuser2@nodebb.org',
|
|
|
|
|
});
|
|
|
|
|
assert.strictEqual(result.req.session.emailChanged, 1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should throw error if email is not valid', async () => {
|
|
|
|
|
const uid = await user.create({ username: 'interstiuser1' });
|
|
|
|
|
try {
|
|
|
|
|
it('should set email if admin is changing it', async () => {
|
|
|
|
|
const uid = await user.create({ username: 'interstiuser3' });
|
|
|
|
|
const result = await user.interstitials.email({
|
|
|
|
|
userData: { uid: uid, updateEmail: true },
|
|
|
|
|
req: { uid: uid },
|
|
|
|
|
req: { uid: adminUid },
|
|
|
|
|
interstitials: [],
|
|
|
|
|
});
|
|
|
|
|
assert.strictEqual(result.interstitials[0].template, 'partials/email_update');
|
|
|
|
|
|
|
|
|
|
await result.interstitials[0].callback({ uid: uid }, {
|
|
|
|
|
email: 'invalidEmail',
|
|
|
|
|
email: 'interstiuser3@nodebb.org',
|
|
|
|
|
});
|
|
|
|
|
assert(false);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
assert.strictEqual(err.message, '[[error:invalid-email]]');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should set req.session.emailChanged to 1', async () => {
|
|
|
|
|
const uid = await user.create({ username: 'interstiuser2' });
|
|
|
|
|
const result = await user.interstitials.email({
|
|
|
|
|
userData: { uid: uid, updateEmail: true },
|
|
|
|
|
req: { uid: uid, session: {} },
|
|
|
|
|
interstitials: [],
|
|
|
|
|
const userData = await user.getUserData(uid);
|
|
|
|
|
assert.strictEqual(userData.email, 'interstiuser3@nodebb.org');
|
|
|
|
|
assert.strictEqual(userData['email:confirmed'], 1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await result.interstitials[0].callback({ uid: uid }, {
|
|
|
|
|
email: 'interstiuser2@nodebb.org',
|
|
|
|
|
});
|
|
|
|
|
assert.strictEqual(result.req.session.emailChanged, 1);
|
|
|
|
|
});
|
|
|
|
|
it('should throw error if user tries to edit other users email', async () => {
|
|
|
|
|
const uid = await user.create({ username: 'interstiuser4' });
|
|
|
|
|
try {
|
|
|
|
|
const result = await user.interstitials.email({
|
|
|
|
|
userData: { uid: uid, updateEmail: true },
|
|
|
|
|
req: { uid: 1000 },
|
|
|
|
|
interstitials: [],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should set email if admin is changing it', async () => {
|
|
|
|
|
const uid = await user.create({ username: 'interstiuser3' });
|
|
|
|
|
const result = await user.interstitials.email({
|
|
|
|
|
userData: { uid: uid, updateEmail: true },
|
|
|
|
|
req: { uid: adminUid },
|
|
|
|
|
interstitials: [],
|
|
|
|
|
await result.interstitials[0].callback({ uid: uid }, {
|
|
|
|
|
email: 'derp@derp.com',
|
|
|
|
|
});
|
|
|
|
|
assert(false);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
assert.strictEqual(err.message, '[[error:no-privileges]]');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await result.interstitials[0].callback({ uid: uid }, {
|
|
|
|
|
email: 'interstiuser3@nodebb.org',
|
|
|
|
|
});
|
|
|
|
|
const userData = await user.getUserData(uid);
|
|
|
|
|
assert.strictEqual(userData.email, 'interstiuser3@nodebb.org');
|
|
|
|
|
assert.strictEqual(userData['email:confirmed'], 1);
|
|
|
|
|
});
|
|
|
|
|
it('should remove current email', async () => {
|
|
|
|
|
const uid = await user.create({ username: 'interstiuser5' });
|
|
|
|
|
await user.setUserField(uid, 'email', 'interstiuser5@nodebb.org');
|
|
|
|
|
await user.email.confirmByUid(uid);
|
|
|
|
|
|
|
|
|
|
it('should throw error if user tries to edit other users email', async () => {
|
|
|
|
|
const uid = await user.create({ username: 'interstiuser4' });
|
|
|
|
|
try {
|
|
|
|
|
const result = await user.interstitials.email({
|
|
|
|
|
userData: { uid: uid, updateEmail: true },
|
|
|
|
|
req: { uid: 1000 },
|
|
|
|
|
req: { uid: uid, session: { id: 0 } },
|
|
|
|
|
interstitials: [],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await result.interstitials[0].callback({ uid: uid }, {
|
|
|
|
|
email: 'derp@derp.com',
|
|
|
|
|
email: '',
|
|
|
|
|
});
|
|
|
|
|
assert(false);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
assert.strictEqual(err.message, '[[error:no-privileges]]');
|
|
|
|
|
}
|
|
|
|
|
const userData = await user.getUserData(uid);
|
|
|
|
|
assert.strictEqual(userData.email, '');
|
|
|
|
|
assert.strictEqual(userData['email:confirmed'], 0);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should remove current email', async () => {
|
|
|
|
|
const uid = await user.create({ username: 'interstiuser5' });
|
|
|
|
|
await user.setUserField(uid, 'email', 'interstiuser5@nodebb.org');
|
|
|
|
|
await user.email.confirmByUid(uid);
|
|
|
|
|
describe('gdpr', () => {
|
|
|
|
|
let jar;
|
|
|
|
|
let token;
|
|
|
|
|
|
|
|
|
|
const result = await user.interstitials.email({
|
|
|
|
|
userData: { uid: uid, updateEmail: true },
|
|
|
|
|
req: { uid: uid, session: { id: 0 } },
|
|
|
|
|
interstitials: [],
|
|
|
|
|
before(async () => {
|
|
|
|
|
jar = await helpers.registerUser({
|
|
|
|
|
username: utils.generateUUID(),
|
|
|
|
|
password: utils.generateUUID(),
|
|
|
|
|
});
|
|
|
|
|
token = await helpers.getCsrfToken(jar);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await result.interstitials[0].callback({ uid: uid }, {
|
|
|
|
|
email: '',
|
|
|
|
|
it('registration should succeed once gdpr prompts are agreed to', async () => {
|
|
|
|
|
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: {
|
|
|
|
|
gdpr_agree_data: 'on',
|
|
|
|
|
gdpr_agree_email: 'on',
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.statusCode, 302);
|
|
|
|
|
assert.strictEqual(res.headers.location, `${nconf.get('relative_path')}/`);
|
|
|
|
|
});
|
|
|
|
|
const userData = await user.getUserData(uid);
|
|
|
|
|
assert.strictEqual(userData.email, '');
|
|
|
|
|
assert.strictEqual(userData['email:confirmed'], 0);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|