Substantially increase unit tests that log in User

25 views
Skip to first unread message

Brett Kotch

unread,
Jun 1, 2016, 6:17:18 PM6/1/16
to loopb...@googlegroups.com
If you are logging in User, even if you are using the native version of bcrypt you may have noticed a significant decrease in performance. 

This blog post ... http://collectiveidea.com/blog/archives/2012/11/12/tests-oddly-slow-might-be-bcrypt/ introduced the idea of changing the security strength for tests. 

After digging around in the bcrypt repository, I found the following: 

User.hashPassword = function(plain)
{
this.validatePassword(plain);
var salt = bcrypt.genSaltSync(this.settings.saltWorkFactor || SALT_WORK_FACTOR);
   return bcrypt.hashSync(plain, salt);
};

Which led me to the idea of just setting the saltWorkFactor on the User object as such: 

user.saltWorkFactor = 4;


After setting the value to 4 (default is 10), my tests ran over 8 times faster! 


a...@peermatch.com

unread,
Jun 18, 2016, 6:38:23 AM6/18/16
to LoopbackJS
You could also configure that option in model-config.test.json



{
 
"MyUser": {
   
"dataSource": "db",
   
"public": true,
   
"options": {
     
"saltWorkFactor": 2
   
}
 
}
}
Reply all
Reply to author
Forward
0 new messages