refs #5472 test(changePassword): back
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2023-05-23 15:12:28 +02:00
parent ddab59a10c
commit c35e2e155f
4 changed files with 21 additions and 14 deletions

View File

@ -125,14 +125,14 @@ module.exports = function(Self) {
try { try {
await Self.rawSql(`CALL account.user_setPassword(?, ?)`, [id, newPassword], options); await Self.rawSql(`CALL account.user_setPassword(?, ?)`, [id, newPassword], options);
await _setPassword.call(this, id, newPassword, options, options); await _setPassword.call(this, id, newPassword, options, cb);
const user = await Self.findById(id, null, options); const user = await Self.findById(id, null, options);
await user.updateAttribute('passExpired', null, options); await user.updateAttribute('passExpired', null, options);
if (tx) await tx.commit(); if (tx) await tx.commit();
return; return;
} catch (e) { } catch (e) {
if (tx) await tx.rollback(); if (tx) await tx.rollback();
console.error('Error changing password, contact with informatica', e); // console.error('Error changing password, contact with informatica', e);
throw new UserError(e); throw new UserError(e);
} }
}; };
@ -154,14 +154,14 @@ module.exports = function(Self) {
try { try {
await Self.rawSql(`CALL account.user_changePassword(?, ?, ?)`, [id, oldPassword, newPassword], options); await Self.rawSql(`CALL account.user_changePassword(?, ?, ?)`, [id, oldPassword, newPassword], options);
await _changePassword.call(this, id, oldPassword, newPassword, options); await _changePassword.call(this, id, oldPassword, newPassword, options, cb);
const user = await Self.findById(id, null, options); const user = await Self.findById(id, null, options);
await user.updateAttribute('passExpired', null, options); await user.updateAttribute('passExpired', null, options);
if (tx) await tx.commit(); if (tx) await tx.commit();
return; return;
} catch (error) { } catch (error) {
if (tx) await tx.rollback(); if (tx) await tx.rollback();
console.error('Error changing password, contact with informatica', error); // console.error('Error changing password, contact with informatica', error);
throw new UserError(error.sqlMessage || 'Error changing password, contact with informatica'); throw new UserError(error.sqlMessage || 'Error changing password, contact with informatica');
} }
}; };

View File

@ -13,6 +13,10 @@
"type": "number", "type": "number",
"id": true "id": true
}, },
"name": {
"type": "string",
"required": true
},
"username": { "username": {
"type": "string", "type": "string",
"mysql": { "mysql": {
@ -38,6 +42,9 @@
"lang": { "lang": {
"type": "string" "type": "string"
}, },
"bcryptPassword": {
"type": "string"
},
"active": { "active": {
"type": "boolean" "type": "boolean"
}, },

View File

@ -28,7 +28,6 @@ module.exports = Self => {
}); });
Self.changePassword = async function(id, oldPassword, newPassword) { Self.changePassword = async function(id, oldPassword, newPassword) {
const response = await Self.app.models.VnUser.changePassword(id, oldPassword, newPassword); await Self.app.models.VnUser.changePassword(id, oldPassword, newPassword);
console.log(response);
}; };
}; };

View File

@ -1,14 +1,15 @@
const {models} = require('vn-loopback/server/server'); const {models} = require('vn-loopback/server/server');
fdescribe('account changePassword()', () => { describe('account changePassword()', () => {
fit('should throw an error when old password is wrong', async() => { it('should throw an error when old password is wrong', async() => {
let err; let error;
await models.Account.changePassword(1, 'wrongPassword2', 'nightmare.9999') try {
.catch(error => { await models.Account.changePassword(1, 'wrongPassword', 'nightmare.9999');
err = error.sqlMessage; } catch (e) {
}); error = e.message;
}
expect(err).toEqual('Invalid password'); expect(error).toContain('Invalid password');
}); });
it('should change password', async() => { it('should change password', async() => {