Skip to content

Commit f80d5c3

Browse files
committed
refactor: rateLimiter.canTry logic to check >= 1
1 parent 7a50421 commit f80d5c3

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/node/routes/login.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export class RateLimiter {
1818
private readonly hourLimiter = new Limiter(12, "hour")
1919

2020
public canTry(): boolean {
21-
return this.minuteLimiter.getTokensRemaining() > 0 || this.hourLimiter.getTokensRemaining() > 0
21+
// Note: we must check using >= 1 because technically when there are no tokens left
22+
// you get back a number like 0.00013333333333333334
23+
// which would cause fail if the logic were > 0
24+
return this.minuteLimiter.getTokensRemaining() >= 1 || this.hourLimiter.getTokensRemaining() >= 1
2225
}
2326

2427
public removeToken(): boolean {

test/e2e/login.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ test.describe("login", () => {
5454
// The current RateLimiter allows 2 logins per minute plus
5555
// 12 logins per hour for a total of 14
5656
// See: src/node/routes/login.ts
57-
for (let i = 1; i <= 13; i++) {
57+
for (let i = 1; i <= 14; i++) {
5858
await page.click(".submit")
5959
await page.waitForLoadState("networkidle")
6060
// We double-check that the correct error message shows

0 commit comments

Comments
 (0)