#6434 - signIn_issue #1892

Merged
jsegarra merged 20 commits from 6434-signIn_issue into dev 2023-12-22 09:36:33 +00:00
4 changed files with 16 additions and 15 deletions

View File

@ -27,8 +27,10 @@ describe('Renew Token', () => {
jasmine.clock().uninstall(); jasmine.clock().uninstall();
}); });
it('should renew process', async() => { it('should renew token', async() => {
jasmine.clock().mockDate(new Date(startingTime + 21600000)); const mockDate = new Date(startingTime + 26600000);
jasmine.clock().mockDate(mockDate);
console.log(startingTime, mockDate)
Review

Console.log.
Lo he visto una vez mergeado en dev. Lo quito directamente de la rama

Console.log. Lo he visto una vez mergeado en dev. Lo quito directamente de la rama
const {id} = await models.VnUser.renewToken(ctx); const {id} = await models.VnUser.renewToken(ctx);
expect(id).not.toEqual(ctx.req.accessToken.id); expect(id).not.toEqual(ctx.req.accessToken.id);

View File

@ -20,10 +20,7 @@ describe('VnUser Sign-in()', () => {
let ctx = {req: {accessToken: accessToken}}; let ctx = {req: {accessToken: accessToken}};
let signInLog = await SignInLog.find({where: {token: accessToken.id}}); let signInLog = await SignInLog.find({where: {token: accessToken.id}});
expect(signInLog.length).toEqual(1); expect(signInLog.length).toEqual(0);
expect(signInLog[0].userFk).toEqual(accessToken.userId);
expect(signInLog[0].owner).toEqual(true);
expect(login.token).toBeDefined();
await VnUser.logout(ctx.req.accessToken.id); await VnUser.logout(ctx.req.accessToken.id);
}); });

View File

@ -134,15 +134,16 @@ module.exports = function(Self) {
Self.signInValidate = async(user, userToken, token, ctx) => { Self.signInValidate = async(user, userToken, token, ctx) => {
const [[key, value]] = Object.entries(Self.userUses(user)); const [[key, value]] = Object.entries(Self.userUses(user));
const isOwner = Self.rawSql(`SELECT ? = ? `, [userToken[key], value]); const isOwner = Self.rawSql(`SELECT ? = ? `, [userToken[key], value]);
await Self.app.models.SignInLog.create({ if (!isOwner) {
userName: user, await Self.app.models.SignInLog.create({
token: token.id, userName: user,
userFk: userToken.id, token: token.id,
ip: ctx.req.ip, userFk: userToken.id,
owner: isOwner ip: ctx.req.ip,
}); owner: isOwner
if (!isOwner) });
throw new UserError('Try again'); throw new UserError('Try again');
}
}; };
jsegarra marked this conversation as resolved Outdated
Outdated
Review

El throw también debería ir dentro del if.

El `throw` también debería ir dentro del `if`.
/** /**

View File

@ -0,0 +1 @@
DELETE FROM `account`.`signInLog` where owner <> FALSE