Test coverages for hashed password

* Test coverages for hashed password for replaceAttributes
* Test coverages for hashed password for updateAttribute
This commit is contained in:
Amir Jafarian 2016-04-06 13:14:56 -04:00
parent cd5f8b0ee7
commit 11ef948854
1 changed files with 42 additions and 0 deletions

View File

@ -37,6 +37,15 @@ describe('manipulation', function() {
before(function setupStubUserModel(done) {
StubUser = db.createModel('StubUser', { password: String }, { forceId: true });
StubUser.setter.password = function(plain) {
var hashed = false;
if (!plain) return;
var pos = plain.indexOf('-');
if (pos !== -1) {
var head = plain.substr(0, pos);
var tail = plain.substr(pos + 1, plain.length);
hashed = head.toUpperCase() === tail;
}
if (hashed) return;
this.$password = plain + '-' + plain.toUpperCase();
};
db.automigrate('StubUser', done);
@ -464,6 +473,22 @@ describe('manipulation', function() {
done();
});
it('should have updated password hashed with updateAttribute',
function(done) {
StubUser.create({ password: 'foo' }, function(err, created) {
if (err) return done(err);
created.updateAttribute('password', 'test', function(err, created) {
if (err) return done(err);
created.password.should.equal('test-TEST');
StubUser.findById(created.id, function(err, found) {
if (err) return done(err);
found.password.should.equal('test-TEST');
done();
});
});
});
});
it('should update one attribute', function(done) {
person.updateAttribute('name', 'Paul Graham', function(err, p) {
if (err) return done(err);
@ -943,6 +968,23 @@ describe('manipulation', function() {
});
});
it('should have updated password hashed with replaceAttributes',
function(done) {
StubUser.create({ password: 'foo' }, function(err, created) {
if (err) return done(err);
created.replaceAttributes({ password: 'test' },
function(err, created) {
if (err) return done(err);
created.password.should.equal('test-TEST');
StubUser.findById(created.id, function(err, found) {
if (err) return done(err);
found.password.should.equal('test-TEST');
done();
});
});
});
});
it('works without options(promise variant)', function(done) {
Post.findById(postInstance.id)
.then(function(p) {