mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-12-20 23:40:10 +00:00
bypass rate limits when factor is 0
This commit is contained in:
parent
6fa0f2230e
commit
91c9b67cb0
2 changed files with 14 additions and 11 deletions
|
@ -35,7 +35,7 @@ export class SkRateLimiterService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async limit(limit: RateLimit, actor: string, factor = 1): Promise<LimitInfo> {
|
public async limit(limit: RateLimit, actor: string, factor = 1): Promise<LimitInfo> {
|
||||||
if (this.disabled) {
|
if (this.disabled || factor === 0) {
|
||||||
return {
|
return {
|
||||||
blocked: false,
|
blocked: false,
|
||||||
remaining: Number.MAX_SAFE_INTEGER,
|
remaining: Number.MAX_SAFE_INTEGER,
|
||||||
|
@ -46,7 +46,7 @@ export class SkRateLimiterService {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (factor <= 0) {
|
if (factor < 0) {
|
||||||
throw new Error(`Rate limit factor is zero or negative: ${factor}`);
|
throw new Error(`Rate limit factor is zero or negative: ${factor}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -300,10 +300,11 @@ describe(SkRateLimiterService, () => {
|
||||||
expect(counter?.t).toBe(0);
|
expect(counter?.t).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw if factor is zero', async () => {
|
it('should skip if factor is zero', async () => {
|
||||||
const promise = serviceUnderTest().limit(limit, actor, 0);
|
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 () => {
|
it('should throw if factor is negative', async () => {
|
||||||
|
@ -537,10 +538,11 @@ describe(SkRateLimiterService, () => {
|
||||||
expect(minCounter?.t).toBe(0);
|
expect(minCounter?.t).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw if factor is zero', async () => {
|
it('should skip if factor is zero', async () => {
|
||||||
const promise = serviceUnderTest().limit(limit, actor, 0);
|
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 () => {
|
it('should throw if factor is negative', async () => {
|
||||||
|
@ -693,10 +695,11 @@ describe(SkRateLimiterService, () => {
|
||||||
expect(i2.blocked).toBeFalsy();
|
expect(i2.blocked).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw if factor is zero', async () => {
|
it('should skip if factor is zero', async () => {
|
||||||
const promise = serviceUnderTest().limit(limit, actor, 0);
|
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 () => {
|
it('should throw if factor is negative', async () => {
|
||||||
|
|
Loading…
Reference in a new issue