43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
const config = require('./settings/config.js');
|
|
require('app-module-path').addPath(config.BASE_DIR);
|
|
require('app-module-path').addPath(config.UTILS_DIR);
|
|
require('app-module-path').addPath(config.CONTROLLERS_DIR);
|
|
|
|
const model = require('./utils/model.js');
|
|
const User = require('./controllers/auth/models.js');
|
|
const log = require('./utils/log');
|
|
|
|
model.reinitialize(() => {
|
|
|
|
log.debug('Database reinitialized');
|
|
|
|
let user = new User();
|
|
user.email = "toto";
|
|
user.password = "tata";
|
|
user.resources = 23;
|
|
user.project_id = 42;
|
|
user.save((err, u) => {
|
|
|
|
log.debug('New user created');
|
|
|
|
// Test password
|
|
User.getById(1, (err, user) => {
|
|
if (model.PasswordField.testSync("tata", user.password)) {
|
|
log.debug("Password authentication succeed");
|
|
} else {
|
|
log.error("Password should have succeeded but failed");
|
|
}
|
|
|
|
if (!model.PasswordField.testSync("toto", user.password)) {
|
|
log.debug("Password authentication failed as it was supposed to");
|
|
} else {
|
|
log.error("Password should have failed but succeded");
|
|
}
|
|
|
|
process.exit(0);
|
|
|
|
});
|
|
});
|
|
|
|
});
|