Skip to content

MX-238: fix integration test auth failures - #140

Merged
IOhacker merged 1 commit into
openMF:developfrom
DeathGun44:MX-238-fix-integration-test-auth
Apr 13, 2026
Merged

MX-238: fix integration test auth failures#140
IOhacker merged 1 commit into
openMF:developfrom
DeathGun44:MX-238-fix-integration-test-auth

Conversation

@DeathGun44

@DeathGun44 DeathGun44 commented Apr 13, 2026

Copy link
Copy Markdown
Contributor
  • Refactor all integration test DB seeding to use centralized executeSqlInPostgres() helpers in SelfServiceIntegrationTestBase
  • Beneficiary/Transfer tests: insert into both m_appuser and m_appselfservice_user (required for JPA audit entity resolution)
  • RunReport/PermissionEnforcement/Clients tests: insert only into m_appselfservice_user (read-only tests, no JPA audit needed)
  • Remove authenticateSelfUser() smoke calls; tests now use direct Basic Auth headers for consistency
  • Add @transactional(rollbackFor=Exception.class) to createForgotPasswordRequest to prevent orphaned records
  • Remove unused accountNo fetch in PermissionEnforcement test

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced transaction handling for password reset requests to ensure data consistency and reliability.
  • Tests

    • Refactored database seeding infrastructure in integration tests for improved maintainability and consistency.
    • Simplified test setup procedures to use direct SQL operations.

@coderabbitai

coderabbitai Bot commented Apr 13, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@DeathGun44 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 44 minutes and 43 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 44 minutes and 43 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ca2b8870-c31a-45fc-90aa-b739b05e17b5

📥 Commits

Reviewing files that changed from the base of the PR and between d008a02 and 4203513.

📒 Files selected for processing (7)
  • src/main/java/org/apache/fineract/selfservice/registration/service/SelfServiceForgotPasswordWritePlatformServiceImpl.java
  • src/test/java/org/apache/fineract/selfservice/account/api/SelfAccountTransferTPTIntegrationTest.java
  • src/test/java/org/apache/fineract/selfservice/account/api/SelfBeneficiaryTPTIntegrationTest.java
  • src/test/java/org/apache/fineract/selfservice/client/api/SelfClientsApiIntegrationTest.java
  • src/test/java/org/apache/fineract/selfservice/runreport/SelfRunReportIntegrationTest.java
  • src/test/java/org/apache/fineract/selfservice/security/api/SelfServicePermissionEnforcementIntegrationTest.java
  • src/test/java/org/apache/fineract/selfservice/testing/support/SelfServiceIntegrationTestBase.java
📝 Walkthrough

Walkthrough

The pull request adds transactional control to a password reset service method and refactors test infrastructure to replace direct JDBC operations with SQL execution via Postgres container utilities. Multiple test classes are updated to use the new SQL execution helpers instead of manual connection and statement management.

Changes

Cohort / File(s) Summary
Service Transactional Annotation
src/main/java/org/apache/fineract/selfservice/registration/service/SelfServiceForgotPasswordWritePlatformServiceImpl.java
Added @Transactional(rollbackFor = Exception.class) annotation to createForgotPasswordRequest() method to enforce transaction management and automatic rollback on exceptions.
Test Infrastructure Utilities
src/test/java/org/apache/fineract/selfservice/testing/support/SelfServiceIntegrationTestBase.java
Added protected methods executeSqlInPostgres(), querySingleValueInPostgres(), and helper sqlLiteral() to execute SQL statements directly against the Postgres test container using psql CLI invocations.
Test Refactoring - Database Seeding
src/test/java/org/apache/fineract/selfservice/account/api/SelfAccountTransferTPTIntegrationTest.java, src/test/java/org/apache/fineract/selfservice/account/api/SelfBeneficiaryTPTIntegrationTest.java, src/test/java/org/apache/fineract/selfservice/client/api/SelfClientsApiIntegrationTest.java, src/test/java/org/apache/fineract/selfservice/runreport/SelfRunReportIntegrationTest.java, src/test/java/org/apache/fineract/selfservice/security/api/SelfServicePermissionEnforcementIntegrationTest.java
Replaced JDBC-based user setup logic (Properties, DriverManager, PreparedStatement, manual transaction control) with single executeSqlInPostgres() calls using multi-statement CTE SQL scripts. Removed authenticateSelfUser() method calls and helper methods. Updated method signatures to remove throws Exception declarations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

⏱️ 10-30 Min Review

Suggested reviewers

  • IOhacker
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main objective of the pull request: fixing integration test authentication failures through refactoring DB seeding and removing authentication smoke calls.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/java/org/apache/fineract/selfservice/registration/service/SelfServiceForgotPasswordWritePlatformServiceImpl.java (1)

101-157: ⚠️ Potential issue | 🟠 Major

Rollback intent is neutralized by swallowed delivery exceptions

@Transactional(rollbackFor = Exception.class) on createForgotPasswordRequest will not roll back when token delivery fails, because trySendAuthorizationToken catches RuntimeException and returns normally (Lines 299-304). This still allows persisted reset requests without successful delivery.

Proposed fix
 private void trySendAuthorizationToken(SelfServiceRegistration selfServiceRegistration, boolean isEmailAuthenticationMode) {
     try {
         sendAuthorizationToken(selfServiceRegistration, isEmailAuthenticationMode);
     } catch (RuntimeException e) {
         log.error("Failed to deliver self-service {} token for request {}", selfServiceRegistration.getRequestType(),
                 selfServiceRegistration.getId(), e);
-    }
+        throw e;
+    }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/apache/fineract/selfservice/registration/service/SelfServiceForgotPasswordWritePlatformServiceImpl.java`
around lines 101 - 157, The transaction currently persists the reset request
before calling trySendAuthorizationToken which swallows delivery exceptions, so
failures don't trigger rollback; change the flow in createForgotPasswordRequest
to ensure delivery failures rollback by either (A) allowing
trySendAuthorizationToken to throw instead of catching RuntimeException (remove
or rethrow inside trySendAuthorizationToken), or (B) catch exceptions in
createForgotPasswordRequest after calling trySendAuthorizationToken, call
selfServiceRegistrationRepository.delete(request) (or deleteById) and rethrow
the exception so the `@Transactional` on createForgotPasswordRequest can roll
back; update references to trySendAuthorizationToken,
createForgotPasswordRequest, selfServiceRegistrationRepository.saveAndFlush and
selfServiceRegistrationRepository.delete accordingly.
🧹 Nitpick comments (1)
src/test/java/org/apache/fineract/selfservice/testing/support/SelfServiceIntegrationTestBase.java (1)

125-179: Consider extracting the seed templates into higher-level helpers.

The m_appselfservice_user / role / client-mapping CTE now exists with small variations in five different test classes. A column change in that fixture will require touching multiple tests again, so this base class is a good place for helpers for the two patterns used in this PR: read-only self-service user seeding, and audited self-service user seeding with a paired m_appuser.

As per coding guidelines, "Apply DRY, SOLID, and Clean Architecture principles."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/test/java/org/apache/fineract/selfservice/testing/support/SelfServiceIntegrationTestBase.java`
around lines 125 - 179, The tests duplicate nearly identical SQL CTE fixtures;
add two reusable helpers in SelfServiceIntegrationTestBase (e.g., methods
seedReadOnlySelfServiceUser(...) and seedAuditedSelfServiceUser(...)) that build
and execute the common SQL using existing helpers sqlLiteral and
executeSqlInPostgres (or return the SQL string for callers to use with
execPsql/querySingleValueInPostgres), parameterize differing columns/values, and
replace the five inline fixtures in test classes with calls to these helpers so
future schema/column changes are fixed in one place.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/test/java/org/apache/fineract/selfservice/testing/support/SelfServiceIntegrationTestBase.java`:
- Around line 130-145: The helper executeSqlInPostgres currently passes
multi-statement SQL straight to execPsql which can leave partial state on
mid-script failures; wrap the supplied SQL in an explicit transaction by
prefixing "BEGIN;" and suffixing "COMMIT;" (i.e. execute "BEGIN; <your-sql>;
COMMIT;") so the entire script runs atomically via execPsql, and let the
existing error handling surface the failure (psql will abort the transaction on
error); update the executeSqlInPostgres implementation (referencing
executeSqlInPostgres and execPsql) to perform this wrapping so callers such as
SelfAccountTransferTPTIntegrationTest and SelfBeneficiaryTPTIntegrationTest need
no changes.

---

Outside diff comments:
In
`@src/main/java/org/apache/fineract/selfservice/registration/service/SelfServiceForgotPasswordWritePlatformServiceImpl.java`:
- Around line 101-157: The transaction currently persists the reset request
before calling trySendAuthorizationToken which swallows delivery exceptions, so
failures don't trigger rollback; change the flow in createForgotPasswordRequest
to ensure delivery failures rollback by either (A) allowing
trySendAuthorizationToken to throw instead of catching RuntimeException (remove
or rethrow inside trySendAuthorizationToken), or (B) catch exceptions in
createForgotPasswordRequest after calling trySendAuthorizationToken, call
selfServiceRegistrationRepository.delete(request) (or deleteById) and rethrow
the exception so the `@Transactional` on createForgotPasswordRequest can roll
back; update references to trySendAuthorizationToken,
createForgotPasswordRequest, selfServiceRegistrationRepository.saveAndFlush and
selfServiceRegistrationRepository.delete accordingly.

---

Nitpick comments:
In
`@src/test/java/org/apache/fineract/selfservice/testing/support/SelfServiceIntegrationTestBase.java`:
- Around line 125-179: The tests duplicate nearly identical SQL CTE fixtures;
add two reusable helpers in SelfServiceIntegrationTestBase (e.g., methods
seedReadOnlySelfServiceUser(...) and seedAuditedSelfServiceUser(...)) that build
and execute the common SQL using existing helpers sqlLiteral and
executeSqlInPostgres (or return the SQL string for callers to use with
execPsql/querySingleValueInPostgres), parameterize differing columns/values, and
replace the five inline fixtures in test classes with calls to these helpers so
future schema/column changes are fixed in one place.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: df399e9b-e7a6-438f-a56c-71bac94e24ab

📥 Commits

Reviewing files that changed from the base of the PR and between 6e56e46 and d008a02.

📒 Files selected for processing (7)
  • src/main/java/org/apache/fineract/selfservice/registration/service/SelfServiceForgotPasswordWritePlatformServiceImpl.java
  • src/test/java/org/apache/fineract/selfservice/account/api/SelfAccountTransferTPTIntegrationTest.java
  • src/test/java/org/apache/fineract/selfservice/account/api/SelfBeneficiaryTPTIntegrationTest.java
  • src/test/java/org/apache/fineract/selfservice/client/api/SelfClientsApiIntegrationTest.java
  • src/test/java/org/apache/fineract/selfservice/runreport/SelfRunReportIntegrationTest.java
  • src/test/java/org/apache/fineract/selfservice/security/api/SelfServicePermissionEnforcementIntegrationTest.java
  • src/test/java/org/apache/fineract/selfservice/testing/support/SelfServiceIntegrationTestBase.java

- Refactor all integration test DB seeding to use centralized
  executeSqlInPostgres() helpers in SelfServiceIntegrationTestBase
- Beneficiary/Transfer tests: insert into both m_appuser and
  m_appselfservice_user (required for JPA audit entity resolution)
- RunReport/PermissionEnforcement/Clients tests: insert only into
  m_appselfservice_user (read-only tests, no JPA audit needed)
- Remove authenticateSelfUser() smoke calls; tests now use
  direct Basic Auth headers for consistency
- Add @transactional(rollbackFor=Exception.class) to
  createForgotPasswordRequest to prevent orphaned records
- Remove unused accountNo fetch in PermissionEnforcement test

All 30 tests pass (0 failures, 0 errors).
@DeathGun44
DeathGun44 force-pushed the MX-238-fix-integration-test-auth branch from d008a02 to 4203513 Compare April 13, 2026 17:46
@IOhacker
IOhacker merged commit 451592d into openMF:develop Apr 13, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants