Merge pull request #3511 from strongloop/empty-password-lb3

Add unit test for empty password
This commit is contained in:
Loay 2017-07-25 15:42:22 -04:00 committed by GitHub
commit 131b78dc84
2 changed files with 25 additions and 9 deletions

View File

@ -12,6 +12,7 @@ cache:
directories: directories:
- travis_phantomjs - travis_phantomjs
before_install: before_install:
- npm config set registry http://ci.strongloop.com:4873/
# Upgrade PhantomJS to v2.1.1. # Upgrade PhantomJS to v2.1.1.
- "export PHANTOMJS_VERSION=2.1.1" - "export PHANTOMJS_VERSION=2.1.1"
- "export PATH=$PWD/travis_phantomjs/phantomjs-$PHANTOMJS_VERSION-linux-x86_64/bin:$PATH" - "export PATH=$PWD/travis_phantomjs/phantomjs-$PHANTOMJS_VERSION-linux-x86_64/bin:$PATH"

View File

@ -398,16 +398,31 @@ describe('User', function() {
var pass73Char = pass72Char + '3'; var pass73Char = pass72Char + '3';
var passTooLong = pass72Char + 'WXYZ1234'; var passTooLong = pass72Char + 'WXYZ1234';
it('rejects passwords longer than 72 characters', function(done) { it('rejects empty passwords creation', function(done) {
try { User.create({email: 'b@c.com', password: ''}, function(err) {
User.create({email: 'b@c.com', password: pass73Char}, function(err) { expect(err.code).to.equal('INVALID_PASSWORD');
if (err) return done(err); expect(err.statusCode).to.equal(422);
done(new Error('User.create() should have thrown an error.'));
});
} catch (e) {
expect(e).to.match(/Password too long/);
done(); done();
} });
});
it('rejects updating with empty password', function(done) {
User.create({email: 'blank@c.com', password: pass72Char}, function(err, userCreated) {
if (err) return done(err);
userCreated.updateAttribute('password', '', function(err, userUpdated) {
expect(err.code).to.equal('INVALID_PASSWORD');
expect(err.statusCode).to.equal(422);
done();
});
});
});
it('rejects passwords longer than 72 characters', function(done) {
User.create({email: 'b@c.com', password: pass73Char}, function(err) {
expect(err.code).to.equal('PASSWORD_TOO_LONG');
expect(err.statusCode).to.equal(422);
done();
});
}); });
it('rejects a new user with password longer than 72 characters', function(done) { it('rejects a new user with password longer than 72 characters', function(done) {