From 33258f1314a0d3149753f344c51d6e3c58702b25 Mon Sep 17 00:00:00 2001 From: jloveland Date: Sat, 26 Sep 2015 22:21:00 -0400 Subject: [PATCH] feat(users): Supporting valid email according to HTML5 and RFC 822 Supporting valid email (i.e. root@admin) according to HTML5 and RFC 822 proposed by @jloveland Fixes #934 --- .../users/server/models/user.server.model.js | 4 +-- .../tests/server/user.server.model.tests.js | 29 +++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/modules/users/server/models/user.server.model.js b/modules/users/server/models/user.server.model.js index ff7a3ef3f9..975c476160 100644 --- a/modules/users/server/models/user.server.model.js +++ b/modules/users/server/models/user.server.model.js @@ -21,7 +21,7 @@ var validateLocalStrategyProperty = function (property) { * A Validation function for local strategy email */ var validateLocalStrategyEmail = function (email) { - return ((this.provider !== 'local' && !this.updated) || validator.isEmail(email)); + return ((this.provider !== 'local' && !this.updated) || validator.isEmail(email, { require_tld: false })); }; /** @@ -177,7 +177,7 @@ UserSchema.statics.generateRandomPassphrase = function () { var password = ''; var repeatingCharacters = new RegExp('(.)\\1{2,}', 'g'); - // iterate until the we have a valid passphrase. + // iterate until the we have a valid passphrase. // NOTE: Should rarely iterate more than once, but we need this to ensure no repeating characters are present. while (password.length < 20 || repeatingCharacters.test(password)) { // build the random password diff --git a/modules/users/tests/server/user.server.model.tests.js b/modules/users/tests/server/user.server.model.tests.js index f5bfd39656..a059bf2d8b 100644 --- a/modules/users/tests/server/user.server.model.tests.js +++ b/modules/users/tests/server/user.server.model.tests.js @@ -263,7 +263,7 @@ describe('User Model Unit Tests:', function () { }); }); - it('should not allow a less than 10 characters long - "P@$$w0rd!"', function (done) { + it('should not allow a password less than 10 characters long - "P@$$w0rd!"', function (done) { var _user1 = new User(user1); _user1.password = 'P@$$w0rd!'; @@ -273,7 +273,7 @@ describe('User Model Unit Tests:', function () { }); }); - it('should not allow a greater than 128 characters long.', function (done) { + it('should not allow a password greater than 128 characters long.', function (done) { var _user1 = new User(user1); _user1.password = ')!/uLT="lh&:`6X!]|15o!$!TJf,.13l?vG].-j],lFPe/QhwN#{Z<[*1nX@n1^?WW-%_.*D)m$toB+N7z}kcN#B_d(f41h%w@0F!]igtSQ1gl~6sEV&r~}~1ub>If1c+'; @@ -283,7 +283,7 @@ describe('User Model Unit Tests:', function () { }); }); - it('should not allow more than 3 or more repeating characters - "P@$$w0rd!!!"', function (done) { + it('should not allow a password with 3 or more repeating characters - "P@$$w0rd!!!"', function (done) { var _user1 = new User(user1); _user1.password = 'P@$$w0rd!!!'; @@ -344,10 +344,10 @@ describe('User Model Unit Tests:', function () { }); - it('should not allow invalid email address - "123@123"', function (done) { + it('should not allow invalid email address - "123@123@123"', function (done) { var _user1 = new User(user1); - _user1.email = '123@123'; + _user1.email = '123@123@123'; _user1.save(function (err) { if (!err) { _user1.remove(function (err_remove) { @@ -363,6 +363,25 @@ describe('User Model Unit Tests:', function () { }); + it('should allow email address - "123@123"', function (done) { + var _user1 = new User(user1); + + _user1.email = '123@123'; + _user1.save(function (err) { + if (!err) { + _user1.remove(function (err_remove) { + should.not.exist(err); + should.not.exist(err_remove); + done(); + }); + } else { + should.not.exist(err); + done(); + } + }); + + }); + it('should not allow invalid email address - "123.com"', function (done) { var _user1 = new User(user1);