UNPKG

cloudboost-tv

Version:

Database Service that does Storage, Search, Real-time and a whole lot more.

51 lines (42 loc) 1.61 kB
describe("CloudObject - Encryption", function (done) { it("should encrypt passwords", function (done) { this.timeout(20000); var obj = new CB.CloudObject('User'); obj.set('username',util.makeEmail()); obj.set('password','password'); obj.set('email',util.makeEmail()); obj.save().then(function(obj){ if(obj.get('password') !== 'password') done(); else throw "Cannot encrypt"; }, function(){ throw "Cannot save a CloudObject"; }); }); it("should not encrypt already encrypted passwords", function (done) { this.timeout(20000); var obj = new CB.CloudObject('User'); obj.set('username',util.makeEmail()); obj.set('password','password'); obj.set('email',util.makeEmail()); obj.save().then(function(obj){ var query = new CB.CloudQuery('User'); query.findById(obj.get('id')).then(function(obj1){ obj1.set('updatedAt',new Date()); obj1.save().then(function(obj2){ if(obj1.get('password') === obj2.get('password')) done(); else throw "password encrypted twice"; },function(){ throw "Encrypted the password field again"; }); }, function (err) { throw "unable to find object by id"; }); }, function(){ throw "Cannot save a CloudObject"; }); }); });