Skip to content

Node.js based forum software built for the modern web

closes #5907

Baris Usakli1358a8930577
diff --git a/src/controllers/authentication.js b/src/controllers/authentication.js
index f0f64f42fd..e8ea4ff5b5 100644
--- a/src/controllers/authentication.js
+++ b/src/controllers/authentication.js
@@ -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]]'));
}
diff --git a/test/authentication.js b/test/authentication.js
index 55602777a2..6dd781710c 100644
--- a/test/authentication.js
+++ b/test/authentication.js
@@ -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: '[email protected]',
+ }, 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: '[email protected]',
+ }, 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: '[email protected]',
+ }, 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: '[email protected]',
+ }, 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',
diff --git a/test/helpers/index.js b/test/helpers/index.js
index 29a66e00dd..79c510c88b 100644
--- a/test/helpers/index.js
+++ b/test/helpers/index.js
@@ -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);
});
});
};