summaryrefslogtreecommitdiff
path: root/packages/backend/test/unit/server/api
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2024-12-08 11:58:57 -0500
committerHazelnoot <acomputerdog@gmail.com>2024-12-08 11:58:57 -0500
commit91c9b67cb08094fc00eab685c0f24b2668a9d8fc (patch)
treebe839bb46a0ddfa996de3a60d2a5184d72872878 /packages/backend/test/unit/server/api
parentincrease rate limit for `/api/endpoint` based on real-world testing (diff)
downloadsharkey-91c9b67cb08094fc00eab685c0f24b2668a9d8fc.tar.gz
sharkey-91c9b67cb08094fc00eab685c0f24b2668a9d8fc.tar.bz2
sharkey-91c9b67cb08094fc00eab685c0f24b2668a9d8fc.zip
bypass rate limits when factor is 0
Diffstat (limited to 'packages/backend/test/unit/server/api')
-rw-r--r--packages/backend/test/unit/server/api/SkRateLimiterServiceTests.ts21
1 files changed, 12 insertions, 9 deletions
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 () => {