Count email otp reinitiation flow as resend flow#83
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #83 +/- ##
============================================
+ Coverage 51.04% 53.31% +2.26%
+ Complexity 321 262 -59
============================================
Files 10 10
Lines 3111 3123 +12
Branches 943 951 +8
============================================
+ Hits 1588 1665 +77
+ Misses 1287 1227 -60
+ Partials 236 231 -5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
📝 WalkthroughWalkthroughAdds logic to treat implicit OTP reinitiations (retry attempts that lack an entered code and RESEND flag while an OTP token already exists in context) as resend events under a new configurable toggle ( ChangesImplicit OTP Reinitiation Resend Accounting
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@components/org.wso2.carbon.identity.local.auth.emailotp/src/main/java/org/wso2/carbon/identity/local/auth/emailotp/EmailOTPAuthenticator.java`:
- Around line 429-441: The resend count is being incremented and mutated before
confirming that sendEmailOtp() was successful. Move the mutations of
otpResendCount, shouldUpdateUserClaim, and the call to
updateContextOTPResendCount(context) to occur only after the sendEmailOtp() call
completes successfully. This ensures that failed OTP send attempts do not
consume the user's resend limit quota. The increment operations currently happen
before the email dispatch is confirmed, which can incorrectly block users when
sends fail.
In
`@components/org.wso2.carbon.identity.local.auth.emailotp/src/test/java/org/wso2/carbon/identity/local/auth/emailotp/EmailOTPContextBasedRetryResendTest.java`:
- Around line 335-338: The try-catch block in the method invocation is silently
ignoring InvocationTargetException, which can mask real test failures and cause
incorrect test results. Remove the empty catch block for
InvocationTargetException (around the method.invoke call for
emailOTPAuthenticator) and either let the exception propagate naturally or use a
proper assertion mechanism like assertThrows to validate expected exceptions.
This applies to all occurrences in the test class where
InvocationTargetException is being caught and ignored.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ac18cb83-fd65-49a6-844d-889a6d28df0c
📒 Files selected for processing (4)
components/org.wso2.carbon.identity.local.auth.emailotp/src/main/java/org/wso2/carbon/identity/local/auth/emailotp/EmailOTPAuthenticator.javacomponents/org.wso2.carbon.identity.local.auth.emailotp/src/main/java/org/wso2/carbon/identity/local/auth/emailotp/constant/AuthenticatorConstants.javacomponents/org.wso2.carbon.identity.local.auth.emailotp/src/test/java/org/wso2/carbon/identity/local/auth/emailotp/EmailOTPAuthenticatorTest.javacomponents/org.wso2.carbon.identity.local.auth.emailotp/src/test/java/org/wso2/carbon/identity/local/auth/emailotp/EmailOTPContextBasedRetryResendTest.java
| try { | ||
| method.invoke(emailOTPAuthenticator, request, response, context); | ||
| } catch (InvocationTargetException ignored) { | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Don’t swallow invocation failures in these integration tests.
Ignoring InvocationTargetException can mask real failures; the toggle-off case can still pass with resend count staying at the pre-set 0.
✅ Suggested fix
- try {
- method.invoke(emailOTPAuthenticator, request, response, context);
- } catch (InvocationTargetException ignored) {
- }
+ try {
+ method.invoke(emailOTPAuthenticator, request, response, context);
+ } catch (InvocationTargetException e) {
+ Assert.fail("Unexpected exception from initiateAuthenticationRequest: " + e.getCause());
+ }Also applies to: 405-408
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@components/org.wso2.carbon.identity.local.auth.emailotp/src/test/java/org/wso2/carbon/identity/local/auth/emailotp/EmailOTPContextBasedRetryResendTest.java`
around lines 335 - 338, The try-catch block in the method invocation is silently
ignoring InvocationTargetException, which can mask real test failures and cause
incorrect test results. Remove the empty catch block for
InvocationTargetException (around the method.invoke call for
emailOTPAuthenticator) and either let the exception propagate naturally or use a
proper assertion mechanism like assertThrows to validate expected exceptions.
This applies to all occurrences in the test class where
InvocationTargetException is being caught and ignored.
This pull request enhances the Email OTP authenticator to treat implicit reinitiations (when an OTP is silently regenerated without explicit user action) as resend attempts, depending on a new configurable toggle. It also adds comprehensive tests to ensure the correct behavior for both enabled and disabled states of this feature.
Email OTP Resend Logic Improvements:
CountReinitiationsAsResendstoggle is enabled (defaulting to true), count these as resend attempts against the resend limit. This helps prevent abuse by limiting silent OTP regenerations. [1] [2] [3]SENT_OTP_TOKEN_TIME_PREFIXandCOUNT_REINITIATIONS_AS_RESENDSconstants to support the new logic. [1] [2]Testing Enhancements:
Test Utility Updates:
Related PRs
Summary by CodeRabbit
New Features
COUNT_REINITIATIONS_AS_RESENDS) to treat implicit OTP re-requests as resend attempts against rate limits, defaulting to enabled for improved abuse protection.Tests