Added unit test & translation fixes
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
4807fcb394
commit
b5f2cf3711
|
@ -0,0 +1,41 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
fdescribe('account validateAuth()', () => {
|
||||
const developerId = 9;
|
||||
|
||||
it('should throw an error for a non existent code', async() => {
|
||||
const ctx = {req: {accessToken: {userId: developerId}}};
|
||||
|
||||
let error;
|
||||
try {
|
||||
await models.Account.validateAuth(ctx, 'developer', 'nightmare', '123456');
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error).toBeDefined();
|
||||
expect(error.statusCode).toBe(400);
|
||||
expect(error.message).toEqual('Invalid or expired verification code');
|
||||
});
|
||||
|
||||
it('should throw an error when a code doesn`t match the login username', async() => {
|
||||
const ctx = {req: {accessToken: {userId: developerId}}};
|
||||
|
||||
let error;
|
||||
try {
|
||||
const authCode = await models.AuthCode.create({
|
||||
userFk: 1,
|
||||
code: '555555',
|
||||
expires: Date.vnNow() + (60 * 1000)
|
||||
});
|
||||
await models.Account.validateAuth(ctx, 'developer', 'nightmare', '555555');
|
||||
await authCode.destroy();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error).toBeDefined();
|
||||
expect(error.statusCode).toBe(400);
|
||||
expect(error.message).toEqual('Authentication failed');
|
||||
});
|
||||
});
|
|
@ -40,7 +40,7 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
const expired = Date.now() > authCode.expires;
|
||||
const expired = authCode && Date.vnNow() > authCode.expires;
|
||||
if (!authCode || expired)
|
||||
throw new UserError('Invalid or expired verification code');
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
alter table `vn`.`department`
|
||||
add `twoFactor` ENUM ('email') null comment 'Default user tow-factor auth type';
|
||||
add `twoFactor` ENUM ('email') null comment 'Default user two-factor auth type';
|
||||
|
||||
drop trigger `vn`.`department_afterUpdate`;
|
||||
|
||||
|
|
|
@ -275,6 +275,6 @@
|
|||
"Insert a date range": "Inserte un rango de fechas",
|
||||
"Added observation": "{{user}} añadió esta observacion: {{text}}",
|
||||
"Comment added to client": "Observación añadida al cliente {{clientFk}}",
|
||||
"Invalid auth code": "Invalid auth code",
|
||||
"Invalid auth code": "Código de verificación incorrecto",
|
||||
"Invalid or expired verification code": "Invalid or expired verification code"
|
||||
}
|
Loading…
Reference in New Issue