Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
feat(users): Supporting valid email according to HTML5 and RFC 822
Browse files Browse the repository at this point in the history
Supporting valid email (i.e. root@admin) according to HTML5 and RFC 822
proposed by @jloveland

Fixes #934
  • Loading branch information
jloveland committed Dec 1, 2015
1 parent e03cae9 commit 33258f1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
4 changes: 2 additions & 2 deletions modules/users/server/models/user.server.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
};

/**
Expand Down Expand Up @@ -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
Expand Down
29 changes: 24 additions & 5 deletions modules/users/tests/server/user.server.model.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!';

Expand All @@ -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+';

Expand All @@ -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!!!';

Expand Down Expand Up @@ -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) {
Expand All @@ -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);

Expand Down

0 comments on commit 33258f1

Please sign in to comment.