mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix(emails): registration tests, email no longer passed-in, API tests (confirm email for test accounts)
This commit is contained in:
@@ -111,6 +111,9 @@ describe('API', async () => {
|
|||||||
// Create sample users
|
// Create sample users
|
||||||
const adminUid = await user.create({ username: 'admin', password: '123456', email: 'test@example.org' });
|
const adminUid = await user.create({ username: 'admin', password: '123456', email: 'test@example.org' });
|
||||||
const unprivUid = await user.create({ username: 'unpriv', password: '123456', email: 'unpriv@example.org' });
|
const unprivUid = await user.create({ username: 'unpriv', password: '123456', email: 'unpriv@example.org' });
|
||||||
|
await user.email.confirmByUid(adminUid);
|
||||||
|
await user.email.confirmByUid(unprivUid);
|
||||||
|
|
||||||
for (let x = 0; x < 4; x++) {
|
for (let x = 0; x < 4; x++) {
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
await user.create({ username: 'deleteme', password: '123456' }); // for testing of DELETE /users (uids 5, 6) and DELETE /user/:uid/account (uid 7)
|
await user.create({ username: 'deleteme', password: '123456' }); // for testing of DELETE /users (uids 5, 6) and DELETE /user/:uid/account (uid 7)
|
||||||
|
|||||||
@@ -44,36 +44,6 @@ describe('authentication', () => {
|
|||||||
}
|
}
|
||||||
const loginUserPromisified = util.promisify(loginUser);
|
const loginUserPromisified = util.promisify(loginUser);
|
||||||
|
|
||||||
function registerUser(email, username, password, callback) {
|
|
||||||
const jar = request.jar();
|
|
||||||
request({
|
|
||||||
url: `${nconf.get('url')}/api/config`,
|
|
||||||
json: true,
|
|
||||||
jar: jar,
|
|
||||||
}, (err, response, body) => {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
request.post(`${nconf.get('url')}/register`, {
|
|
||||||
form: {
|
|
||||||
email: email,
|
|
||||||
username: username,
|
|
||||||
password: password,
|
|
||||||
'password-confirm': password,
|
|
||||||
gdpr_consent: true,
|
|
||||||
},
|
|
||||||
json: true,
|
|
||||||
jar: jar,
|
|
||||||
headers: {
|
|
||||||
'x-csrf-token': body.csrf_token,
|
|
||||||
},
|
|
||||||
}, (err, response, body) => {
|
|
||||||
callback(err, response, body, jar);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const jar = request.jar();
|
const jar = request.jar();
|
||||||
let regularUid;
|
let regularUid;
|
||||||
before((done) => {
|
before((done) => {
|
||||||
@@ -88,8 +58,6 @@ describe('authentication', () => {
|
|||||||
helpers.registerUser({
|
helpers.registerUser({
|
||||||
username: 'a',
|
username: 'a',
|
||||||
password: '123456',
|
password: '123456',
|
||||||
'password-confirm': '123456',
|
|
||||||
email: 'should@error1.com',
|
|
||||||
}, (err, jar, response, body) => {
|
}, (err, jar, response, body) => {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(response.statusCode, 400);
|
assert.equal(response.statusCode, 400);
|
||||||
@@ -102,8 +70,6 @@ describe('authentication', () => {
|
|||||||
helpers.registerUser({
|
helpers.registerUser({
|
||||||
username: '----a-----',
|
username: '----a-----',
|
||||||
password: '123456',
|
password: '123456',
|
||||||
'password-confirm': '123456',
|
|
||||||
email: 'should@error2.com',
|
|
||||||
}, (err, jar, response, body) => {
|
}, (err, jar, response, body) => {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(response.statusCode, 400);
|
assert.equal(response.statusCode, 400);
|
||||||
@@ -116,8 +82,6 @@ describe('authentication', () => {
|
|||||||
helpers.registerUser({
|
helpers.registerUser({
|
||||||
username: ' a',
|
username: ' a',
|
||||||
password: '123456',
|
password: '123456',
|
||||||
'password-confirm': '123456',
|
|
||||||
email: 'should@error3.com',
|
|
||||||
}, (err, jar, response, body) => {
|
}, (err, jar, response, body) => {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(response.statusCode, 400);
|
assert.equal(response.statusCode, 400);
|
||||||
@@ -130,8 +94,6 @@ describe('authentication', () => {
|
|||||||
helpers.registerUser({
|
helpers.registerUser({
|
||||||
username: 'a ',
|
username: 'a ',
|
||||||
password: '123456',
|
password: '123456',
|
||||||
'password-confirm': '123456',
|
|
||||||
email: 'should@error4.com',
|
|
||||||
}, (err, jar, response, body) => {
|
}, (err, jar, response, body) => {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(response.statusCode, 400);
|
assert.equal(response.statusCode, 400);
|
||||||
@@ -140,7 +102,6 @@ describe('authentication', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should register and login a user', (done) => {
|
it('should register and login a user', (done) => {
|
||||||
request({
|
request({
|
||||||
url: `${nconf.get('url')}/api/config`,
|
url: `${nconf.get('url')}/api/config`,
|
||||||
@@ -360,7 +321,10 @@ describe('authentication', () => {
|
|||||||
|
|
||||||
it('should fail to register if registraton is disabled', (done) => {
|
it('should fail to register if registraton is disabled', (done) => {
|
||||||
meta.config.registrationType = 'disabled';
|
meta.config.registrationType = 'disabled';
|
||||||
registerUser('some@user.com', 'someuser', 'somepassword', (err, response, body) => {
|
helpers.registerUser({
|
||||||
|
username: 'someuser',
|
||||||
|
password: 'somepassword',
|
||||||
|
}, (err, jar, response, body) => {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(response.statusCode, 403);
|
assert.equal(response.statusCode, 403);
|
||||||
assert.equal(body, 'Forbidden');
|
assert.equal(body, 'Forbidden');
|
||||||
@@ -370,7 +334,10 @@ describe('authentication', () => {
|
|||||||
|
|
||||||
it('should return error if invitation is not valid', (done) => {
|
it('should return error if invitation is not valid', (done) => {
|
||||||
meta.config.registrationType = 'invite-only';
|
meta.config.registrationType = 'invite-only';
|
||||||
registerUser('some@user.com', 'someuser', 'somepassword', (err, response, body) => {
|
helpers.registerUser({
|
||||||
|
username: 'someuser',
|
||||||
|
password: 'somepassword',
|
||||||
|
}, (err, jar, response, body) => {
|
||||||
meta.config.registrationType = 'normal';
|
meta.config.registrationType = 'normal';
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(response.statusCode, 400);
|
assert.equal(response.statusCode, 400);
|
||||||
@@ -379,21 +346,18 @@ describe('authentication', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to register if email is falsy', (done) => {
|
|
||||||
registerUser('', 'someuser', 'somepassword', (err, response, body) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
assert.equal(response.statusCode, 400);
|
|
||||||
assert.equal(body, '[[error:invalid-email]]');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fail to register if username is falsy or too short', (done) => {
|
it('should fail to register if username is falsy or too short', (done) => {
|
||||||
registerUser('some@user.com', '', 'somepassword', (err, response, body) => {
|
helpers.registerUser({
|
||||||
|
username: '',
|
||||||
|
password: 'somepassword',
|
||||||
|
}, (err, jar, response, body) => {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(response.statusCode, 400);
|
assert.equal(response.statusCode, 400);
|
||||||
assert.equal(body, '[[error:username-too-short]]');
|
assert.equal(body, '[[error:username-too-short]]');
|
||||||
registerUser('some@user.com', 'a', 'somepassword', (err, response, body) => {
|
helpers.registerUser({
|
||||||
|
username: 'a',
|
||||||
|
password: 'somepassword',
|
||||||
|
}, (err, jar, response, body) => {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(response.statusCode, 400);
|
assert.equal(response.statusCode, 400);
|
||||||
assert.equal(body, '[[error:username-too-short]]');
|
assert.equal(body, '[[error:username-too-short]]');
|
||||||
@@ -403,7 +367,10 @@ describe('authentication', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to register if username is too long', (done) => {
|
it('should fail to register if username is too long', (done) => {
|
||||||
registerUser('some@user.com', 'thisisareallylongusername', '123456', (err, response, body) => {
|
helpers.registerUser({
|
||||||
|
username: 'thisisareallylongusername',
|
||||||
|
password: '123456',
|
||||||
|
}, (err, jar, response, body) => {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(response.statusCode, 400);
|
assert.equal(response.statusCode, 400);
|
||||||
assert.equal(body, '[[error:username-too-long]]');
|
assert.equal(body, '[[error:username-too-long]]');
|
||||||
@@ -413,7 +380,12 @@ describe('authentication', () => {
|
|||||||
|
|
||||||
it('should queue user if ip is used before', (done) => {
|
it('should queue user if ip is used before', (done) => {
|
||||||
meta.config.registrationApprovalType = 'admin-approval-ip';
|
meta.config.registrationApprovalType = 'admin-approval-ip';
|
||||||
registerUser('another@user.com', 'anotheruser', 'anotherpwd', (err, response, body) => {
|
helpers.registerUser({
|
||||||
|
email: 'another@user.com',
|
||||||
|
username: 'anotheruser',
|
||||||
|
password: 'anotherpwd',
|
||||||
|
gdpr_consent: 1,
|
||||||
|
}, (err, jar, response, body) => {
|
||||||
meta.config.registrationApprovalType = 'normal';
|
meta.config.registrationApprovalType = 'normal';
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(response.statusCode, 200);
|
assert.equal(response.statusCode, 200);
|
||||||
@@ -423,15 +395,11 @@ describe('authentication', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should be able to login with email', (done) => {
|
it('should be able to login with email', async () => {
|
||||||
user.create({ username: 'ginger', password: '123456', email: 'ginger@nodebb.org' }, (err) => {
|
const uid = await user.create({ username: 'ginger', password: '123456', email: 'ginger@nodebb.org' });
|
||||||
assert.ifError(err);
|
await user.email.confirmByUid(uid);
|
||||||
loginUser('ginger@nodebb.org', '123456', (err, response) => {
|
const response = await loginUserPromisified('ginger@nodebb.org', '123456');
|
||||||
assert.ifError(err);
|
assert.equal(response.statusCode, 200);
|
||||||
assert.equal(response.statusCode, 200);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to login if login type is username and an email is sent', (done) => {
|
it('should fail to login if login type is username and an email is sent', (done) => {
|
||||||
|
|||||||
@@ -125,6 +125,10 @@ helpers.registerUser = function (data, callback) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!data.hasOwnProperty('password-confirm')) {
|
||||||
|
data['password-confirm'] = data.password;
|
||||||
|
}
|
||||||
|
|
||||||
request.post(`${nconf.get('url')}/register`, {
|
request.post(`${nconf.get('url')}/register`, {
|
||||||
form: data,
|
form: data,
|
||||||
json: true,
|
json: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user