v1.18.x
Baris Usakli 8 years ago
parent bf79857b7d
commit 1358a89305

@ -42,7 +42,7 @@ authenticationController.register = function (req, res) {
return next(new Error('[[error:invalid-email]]'));
}
if (!userData.username || userData.username.length < meta.config.minimumUsernameLength) {
if (!userData.username || userData.username.length < meta.config.minimumUsernameLength || utils.slugify(userData.username).length < meta.config.minimumUsernameLength) {
return next(new Error('[[error:username-too-short]]'));
}

@ -78,6 +78,63 @@ describe('authentication', function () {
});
});
it('should fail to create user if username is too short', function (done) {
helpers.registerUser({
username: 'a',
password: '123456',
'password-confirm': '123456',
email: 'should@error1.com',
}, function (err, jar, response, body) {
assert.ifError(err);
assert.equal(response.statusCode, 400);
assert.equal(body, '[[error:username-too-short]]');
done();
});
});
it('should fail to create user if userslug is too short', function (done) {
helpers.registerUser({
username: '----a-----',
password: '123456',
'password-confirm': '123456',
email: 'should@error2.com',
}, function (err, jar, response, body) {
assert.ifError(err);
assert.equal(response.statusCode, 400);
assert.equal(body, '[[error:username-too-short]]');
done();
});
});
it('should fail to create user if userslug is too short', function (done) {
helpers.registerUser({
username: ' a',
password: '123456',
'password-confirm': '123456',
email: 'should@error3.com',
}, function (err, jar, response, body) {
assert.ifError(err);
assert.equal(response.statusCode, 400);
assert.equal(body, '[[error:username-too-short]]');
done();
});
});
it('should fail to create user if userslug is too short', function (done) {
helpers.registerUser({
username: 'a ',
password: '123456',
'password-confirm': '123456',
email: 'should@error4.com',
}, function (err, jar, response, body) {
assert.ifError(err);
assert.equal(response.statusCode, 400);
assert.equal(body, '[[error:username-too-short]]');
done();
});
});
it('should register and login a user', function (done) {
request({
url: nconf.get('url') + '/api/config',

@ -137,8 +137,8 @@ helpers.registerUser = function (data, callback) {
headers: {
'x-csrf-token': body.csrf_token,
},
}, function (err) {
callback(err, jar);
}, function (err, response, body) {
callback(err, jar, response, body);
});
});
};

Loading…
Cancel
Save