Skip to content

fix: totp tests for 9.0 #1180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/test/java/io/supertokens/test/totp/TOTPRecipeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.junit.rules.TestRule;

import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.time.Duration;
Expand Down Expand Up @@ -287,7 +286,7 @@ public int triggerAndCheckRateLimit(Main main, TOTPDevice device) throws Excepti

// Sleep until we finish the current second so that TOTP verification won't change in the time limit
Thread.sleep(1000 - System.currentTimeMillis() % 1000 + 10);
Thread.sleep(1000); // sleep another second so that the rate limit state is kind of reset
Thread.sleep(3000); // sleep another second so that the rate limit state is kind of reset

// First N attempts should fail with invalid code:
// This is to trigger rate limiting
Expand Down Expand Up @@ -363,8 +362,8 @@ public void rateLimitCooldownTest() throws Exception {
LimitReachedException limitReachedException = assertThrows(LimitReachedException.class,
() -> Totp.verifyCode(main, "user", generateTotpCode(main, device)));
assertEquals(3, limitReachedException.currentAttempts);
// Wait for 1 second (Should cool down rate limiting):
Thread.sleep(1000);
// Wait for 3 second (Should cool down rate limiting):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment should use the plural form "seconds" since the duration is 3 seconds: // Wait for 3 seconds (Should cool down rate limiting):

Suggested change
// Wait for 3 second (Should cool down rate limiting):
// Wait for 3 seconds (Should cool down rate limiting):

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

Thread.sleep(3000);

// test that after cool down, we can retry invalid codes N times again
invalidTotpException = assertThrows(InvalidTotpException.class,
Expand Down
Loading