From 91c9b67cb08094fc00eab685c0f24b2668a9d8fc Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Sun, 8 Dec 2024 11:58:57 -0500 Subject: bypass rate limits when factor is 0 --- .../unit/server/api/SkRateLimiterServiceTests.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'packages/backend/test') diff --git a/packages/backend/test/unit/server/api/SkRateLimiterServiceTests.ts b/packages/backend/test/unit/server/api/SkRateLimiterServiceTests.ts index 215b83b53f..c7fac85706 100644 --- a/packages/backend/test/unit/server/api/SkRateLimiterServiceTests.ts +++ b/packages/backend/test/unit/server/api/SkRateLimiterServiceTests.ts @@ -300,10 +300,11 @@ describe(SkRateLimiterService, () => { expect(counter?.t).toBe(0); }); - it('should throw if factor is zero', async () => { - const promise = serviceUnderTest().limit(limit, actor, 0); + it('should skip if factor is zero', async () => { + const info = await serviceUnderTest().limit(limit, actor, 0); - await expect(promise).rejects.toThrow(/factor is zero or negative/); + expect(info.blocked).toBeFalsy(); + expect(info.remaining).toBe(Number.MAX_SAFE_INTEGER); }); it('should throw if factor is negative', async () => { @@ -537,10 +538,11 @@ describe(SkRateLimiterService, () => { expect(minCounter?.t).toBe(0); }); - it('should throw if factor is zero', async () => { - const promise = serviceUnderTest().limit(limit, actor, 0); + it('should skip if factor is zero', async () => { + const info = await serviceUnderTest().limit(limit, actor, 0); - await expect(promise).rejects.toThrow(/factor is zero or negative/); + expect(info.blocked).toBeFalsy(); + expect(info.remaining).toBe(Number.MAX_SAFE_INTEGER); }); it('should throw if factor is negative', async () => { @@ -693,10 +695,11 @@ describe(SkRateLimiterService, () => { expect(i2.blocked).toBeFalsy(); }); - it('should throw if factor is zero', async () => { - const promise = serviceUnderTest().limit(limit, actor, 0); + it('should skip if factor is zero', async () => { + const info = await serviceUnderTest().limit(limit, actor, 0); - await expect(promise).rejects.toThrow(/factor is zero or negative/); + expect(info.blocked).toBeFalsy(); + expect(info.remaining).toBe(Number.MAX_SAFE_INTEGER); }); it('should throw if factor is negative', async () => { -- cgit v1.2.3-freya