From 54da5def4bbfbb4f74cbf02ae23e45103d250dd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20S=C3=B3jko?= Date: Tue, 27 Sep 2022 15:20:37 +0200 Subject: [PATCH] fix(auth): ttl for lock counter on login lockout --- packages/auth/src/Infra/Redis/LockRepository.spec.ts | 3 +-- packages/auth/src/Infra/Redis/LockRepository.ts | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/auth/src/Infra/Redis/LockRepository.spec.ts b/packages/auth/src/Infra/Redis/LockRepository.spec.ts index f0b2bc7cb..d529a6d33 100644 --- a/packages/auth/src/Infra/Redis/LockRepository.spec.ts +++ b/packages/auth/src/Infra/Redis/LockRepository.spec.ts @@ -15,7 +15,6 @@ describe('LockRepository', () => { redisClient.expire = jest.fn() redisClient.del = jest.fn() redisClient.get = jest.fn() - redisClient.set = jest.fn() redisClient.setex = jest.fn() }) @@ -88,6 +87,6 @@ describe('LockRepository', () => { it('should update a lock counter', async () => { await createRepository().updateLockCounter('123', 3) - expect(redisClient.set).toHaveBeenCalledWith('lock:123', 3) + expect(redisClient.setex).toHaveBeenCalledWith('lock:123', 120, 3) }) }) diff --git a/packages/auth/src/Infra/Redis/LockRepository.ts b/packages/auth/src/Infra/Redis/LockRepository.ts index 359143346..ae19da51b 100644 --- a/packages/auth/src/Infra/Redis/LockRepository.ts +++ b/packages/auth/src/Infra/Redis/LockRepository.ts @@ -30,7 +30,7 @@ export class LockRepository implements LockRepositoryInterface { } async updateLockCounter(userIdentifier: string, counter: number): Promise { - await this.redisClient.set(`${this.PREFIX}:${userIdentifier}`, counter) + await this.redisClient.setex(`${this.PREFIX}:${userIdentifier}`, this.failedLoginLockout, counter) } async getLockCounter(userIdentifier: string): Promise {