diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2024-12-08 08:32:05 -0500 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2024-12-08 08:32:05 -0500 |
| commit | 2781f53d6b60fdb45ddc4344aefd3b39fb7a8bfd (patch) | |
| tree | 69ed6ae1e9e4b459359280d76a6ab378a680852a /packages/backend/test/unit | |
| parent | fix import order in SigninWithPasskeyApiService (diff) | |
| download | sharkey-2781f53d6b60fdb45ddc4344aefd3b39fb7a8bfd.tar.gz sharkey-2781f53d6b60fdb45ddc4344aefd3b39fb7a8bfd.tar.bz2 sharkey-2781f53d6b60fdb45ddc4344aefd3b39fb7a8bfd.zip | |
support fractional rate limit scaling
Diffstat (limited to 'packages/backend/test/unit')
| -rw-r--r-- | packages/backend/test/unit/server/api/SkRateLimiterServiceTests.ts | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/packages/backend/test/unit/server/api/SkRateLimiterServiceTests.ts b/packages/backend/test/unit/server/api/SkRateLimiterServiceTests.ts index 711894095d..07bcfb6309 100644 --- a/packages/backend/test/unit/server/api/SkRateLimiterServiceTests.ts +++ b/packages/backend/test/unit/server/api/SkRateLimiterServiceTests.ts @@ -424,14 +424,13 @@ describe(SkRateLimiterService, () => { expect(info.blocked).toBeFalsy(); }); - it('should scale limit by factor', async () => { + it('should scale interval by factor', async () => { minCounter = { c: 1, t: 0 }; + mockTimeService.now += 500; - const i1 = await serviceUnderTest().limit(limit, actor, 2); // 1 + 1 = 2 - const i2 = await serviceUnderTest().limit(limit, actor, 2); // 2 + 1 = 3 + const info = await serviceUnderTest().limit(limit, actor, 2); - expect(i1.blocked).toBeFalsy(); - expect(i2.blocked).toBeTruthy(); + expect(info.blocked).toBeFalsy(); }); it('should set key expiration', async () => { @@ -662,12 +661,14 @@ describe(SkRateLimiterService, () => { expect(info.blocked).toBeFalsy(); }); - it('should scale limit by factor', async () => { - minCounter = { c: 5, t: 0 }; + it('should scale limit and interval by factor', async () => { + counter = { c: 5, t: 0 }; + minCounter = { c: 1, t: 0 }; + mockTimeService.now += 500; const info = await serviceUnderTest().limit(limit, actor, 2); - expect(info.blocked).toBeTruthy(); + expect(info.blocked).toBeFalsy(); }); it('should set key expiration', async () => { |