Fix ProvisioningTestCase user collision on shared external database - #28254
Fix ProvisioningTestCase user collision on shared external database#28254Skynettheone wants to merge 2 commits into
Conversation
createUser() and createUserForSecondServer() never removed the SCIM users they created (directly and via outbound provisioning). With isolated per-run H2 databases this went unnoticed, but against a persistent external database the users from a prior run remain, causing createUserForSecondServer() to fail with UserAlreadyExistingUsername on the next run. Delete the created users in atEnd() so the test is safe to rerun against a shared external database. Fixes wso2#22140
📝 WalkthroughSummary
Testing
WalkthroughThe provisioning test initializes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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: 1
🤖 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
`@modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/provisioning/ProvisioningTestCase.java`:
- Around line 158-178: Update the teardown flow in ProvisioningTestCase so the
four deleteUserIfExists calls execute from a finally path after application and
identity-provider cleanup, even when preceding cleanup fails. Make
deleteUserIfExists record or propagate exceptions from isUserExists and
deleteUser instead of only logging them, while ensuring all four deletions are
attempted and any cleanup failures are aggregated and reported after the
attempts.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 0ef0574f-e0a5-48a8-8ba0-2aefdcc104ec
📒 Files selected for processing (1)
modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/provisioning/ProvisioningTestCase.java
Previously the SP/IdP cleanup loop could throw and abort atEnd() before the user cleanup calls ran, silently defeating the fix. Move user cleanup to a finally block so it always runs, and aggregate cleanup errors instead of only logging them so failures are visible rather than swallowed.
|



Summary
Fixes #22140.
createUser()andcreateUserForSecondServer()inProvisioningTestCasecreate SCIM users both directly and indirectly through outbound SCIM provisioning, butatEnd()only cleaned up the IDP and SP outbound provisioning config, never the users themselves.With the default isolated H2 database, each test run starts from a fresh DB, so this went unnoticed. Against an external database shared across the test server instances, the users created by a prior run persist, so
createUserForSecondServer()fails on the next run withUserAlreadyExistingUsernamewhen it tries to createtestProvisioningUser2, since it already exists in the shared database.Change
USER_MANAGEMENT_CLIENTfor the port-offset-0 server so its created user can be managed for cleanup.isUserExists(String)intoisUserExists(int portOffset, String userName)so existence can be checked against any of the three test server instances.deleteUserIfExists(int portOffset, String userName)and called it fromatEnd()to remove both the directly created users and the users landed via outbound provisioning, so the test is safe to rerun against a shared/persistent external database.Test plan
mvn compileonmodules/integration/tests-integration/tests-backendsucceeds with this change (BUILD SUCCESS).ProvisioningTestCasepasses end-to-end against both H2 and an external database, since running the full multi-server integration suite wasn't possible in this environment.