From 6eb2009141fefd05d1c61e86064ba07d2358a4cd Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Fri, 9 Sep 2022 15:53:38 +0200 Subject: [PATCH] fix --- test/spec/Blacklist.ts | 2 +- test/spec/Redis.ts | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/test/spec/Blacklist.ts b/test/spec/Blacklist.ts index f480227..8fb6347 100644 --- a/test/spec/Blacklist.ts +++ b/test/spec/Blacklist.ts @@ -6,7 +6,7 @@ */ import blacklist, { Blacklist } from '../../lib/Blacklist'; -import { generate_token_id, parse_token_id } from '../../lib/token_id'; +import { generate_token_id } from '../../lib/token_id'; import { clock_finalize, clock_setup } from '../Helper'; // eslint-disable-next-line max-lines-per-function diff --git a/test/spec/Redis.ts b/test/spec/Redis.ts index 8c34317..8cce81a 100644 --- a/test/spec/Redis.ts +++ b/test/spec/Redis.ts @@ -10,6 +10,7 @@ import { blacklist } from '../../lib'; import ks from '../../lib/KeyStore'; import { Redis } from '../../lib/Redis'; +import { generate_token_id } from '../../lib/token_id'; import { clock_finalize, clock_setup } from '../Helper'; const frame = 3600; @@ -19,6 +20,10 @@ redis.connect (redis_url); // eslint-disable-next-line max-lines-per-function describe ('redis', () => { + const token1 = generate_token_id (new Date (Date.now () + 3600000)); + const token2 = generate_token_id (new Date (Date.now () + 3600000)); + const token3 = generate_token_id (new Date (Date.now () + 3600000)); + beforeAll (async () => { ks.reset_instance (); ks.sync_redis (redis_url); @@ -80,26 +85,26 @@ describe ('redis', () => { }); it ('should add two keys to the blacklist', async () => { - await blacklist.add_signature ('test'); - await blacklist.add_signature ('foo'); + await blacklist.add_signature (token1); + await blacklist.add_signature (token2); }); it ('should have two keys in redis blacklist', async () => { - expect ((await redis['_redis']?.sismember ('blacklist', 'test')) === 1) + expect ((await redis['_redis']?.exists (`blacklist_${token1}`)) === 1) .toBeTrue (); - expect ((await redis['_redis']?.sismember ('blacklist', 'foo')) === 1) + expect ((await redis['_redis']?.exists (`blacklist_${token2}`)) === 1) .toBeTrue (); - expect ((await redis['_redis']?.sismember ('blacklist', 'bar')) === 1) + expect ((await redis['_redis']?.exists (`blacklist_${token3}`)) === 1) .toBeFalse (); }); it ('should read keys from redis', async () => { blacklist['_signatures'].splice (0, blacklist['_signatures'].length); - expect (await blacklist.is_valid ('test')) + expect (await blacklist.is_valid (token1)) .toBeFalse (); - expect (await blacklist.is_valid ('foo')) + expect (await blacklist.is_valid (token2)) .toBeFalse (); - expect (await blacklist.is_valid ('bar')) + expect (await blacklist.is_valid (token3)) .toBeTrue (); }); });