GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — [Stability] Type identity second-factor boundary by Storypapst · Pull Request #882 · OpenResilienceInitiative/ORISO-UserService Conversation
|
|
Warning Review limit reached
Next review available in: 50 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe change isolates OTP and email-verification operations behind ChangesIdentity second-factor boundary
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant UserTwoFactorAuthControllerDelegate
participant IdentityManager
participant KeycloakService
participant KeycloakMapper
User->>UserTwoFactorAuthControllerDelegate: submit OTP operation
UserTwoFactorAuthControllerDelegate->>IdentityManager: invoke typed second-factor method
IdentityManager->>KeycloakService: call IdentitySecondFactor
KeycloakService->>KeycloakMapper: map provider response
KeycloakMapper-->>KeycloakService: return typed identity result
KeycloakService-->>IdentityManager: return typed result
IdentityManager-->>UserTwoFactorAuthControllerDelegate: return verification status
UserTwoFactorAuthControllerDelegate-->>User: return success or retry response
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
🧪 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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Compose the focused second-factor port with the existing authentication, email-owner, role-read, and username-availability seams on the integration branch. Preserve the original delivery commit and keep the combined branch review-only. Refs #887 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Integrate the focused IdentitySecondFactor port with pre-dev's identity port
split: add IdentitySecondFactor to KeycloakService's implements list and to the
shared @MockitoBean(extraInterfaces = {...}) IdentityClient mocks in every
Spring identity test (replacing the PR's single-item extraInterfaces variant,
which would collide with the same underlying keycloakService bean). Drop the
five OTP methods from IdentityClient (per PR intent) and take pre-dev's
narrowed contract as the base. Preserve pre-dev's dynamically-computed test
count wording in USER_SERVICE_STABILITY.md and fold the second-factor
description into pre-dev's Identity/profile row. Insert the second-factor
boundary test method into pre-dev's larger test_module_boundaries.py.
HandshakeService and TenantAdminOnboardingService (introduced on pre-dev after PR #882's baseline) still called IdentityClient.getOtpCredential and IdentityClient.setUpOtpCredential. Those methods no longer exist on IdentityClient — they moved to the focused IdentitySecondFactor port in this PR. Inject IdentitySecondFactor into both services, switch the calls, and migrate the corresponding tests to stub the focused port with typed IdentityOtpCredential values.
- Remove unused java.util.Map import from KeycloakMapper (dropped when the string-keyed mapOf methods became typed identityEmailVerificationOf). - Reorder IdentityOtpCredential import in TenantAdminOnboardingServiceTest so identity.* precedes model.* alphabetically. - Collapse a two-line return statement in TenantAdminOnboardingService that now fits on one line after switching to IdentityOtpCredential.secret(). - Collapse the wrapped IdentitySecondFactor @mock declaration onto one line to match the neighbouring one-line @mock fields in HandshakeServiceTest.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
src/test/java/de/caritas/cob/userservice/api/service/handshake/HandshakeServiceTest.java (1)
173-182: 🔒 Security & Privacy | 🟡 Minor | ⚡ Quick winVerify that the fail-closed gate stops OTP verification.
The test verifies only that no session is saved. If execution continues after the OTP lookup fails, the unstubbed
keycloakAuthClient.verifyWithOtp(...)returnsfalseand the test still passes. Addverify(keycloakAuthClient, never()).verifyWithOtp(...).As per path instructions, assertions must be able to fail.
🤖 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 `@src/test/java/de/caritas/cob/userservice/api/service/handshake/HandshakeServiceTest.java` around lines 173 - 182, Strengthen initiate_Should_Forbid_When_SupportAdminOtpStateIsUnavailable by verifying that keycloakAuthClient.verifyWithOtp(...) is never invoked when identitySecondFactor.getOtpCredential(...) throws. Keep the existing ForbiddenException and handshakeSessionRepository.save(...) assertions.Source: Path instructions
src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserAccountControllerDelegateTest.java (1)
88-110: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick winKeep the encoded-username contract executable in all second-factor tests.
The tests either make the transcoder return the raw username or use
anyString(). A regression that removes username encoding, or forwards the wrong setup arguments, can therefore pass.
src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserAccountControllerDelegateTest.java#L88-L110: return a distinct encoded username and verify the exactIdentityManager.getOtpCredential(...)argument.src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserAccountControllerDelegateTest.java#L395-L407: use a distinct encoded username instead of returningUSERNAMEfrom the transcoder.src/test/java/de/caritas/cob/userservice/api/service/accountinvite/onboarding/TenantAdminOnboardingServiceTest.java#L260-L261: match and verify the encoded admin username.src/test/java/de/caritas/cob/userservice/api/service/accountinvite/onboarding/TenantAdminOnboardingServiceTest.java#L306-L307: match and verify the encoded admin username.src/test/java/de/caritas/cob/userservice/api/service/accountinvite/onboarding/TenantAdminOnboardingServiceTest.java#L357-L358: match and verify the encoded admin username.src/test/java/de/caritas/cob/userservice/api/service/accountinvite/onboarding/TenantAdminOnboardingServiceTest.java#L513-L514: match and verify the encoded admin username.src/test/java/de/caritas/cob/userservice/api/service/accountinvite/onboarding/TenantAdminOnboardingServiceTest.java#L582-L583: match the encoded username, initial code, and pending secret exactly.src/test/java/de/caritas/cob/userservice/api/service/handshake/HandshakeServiceTest.java#L65-L70: use an exact encoded support-admin username.src/test/java/de/caritas/cob/userservice/api/service/handshake/HandshakeServiceTest.java#L144-L147: use an exact encoded support-admin username.As per path instructions, tests must be able to fail; flag over-mocking that hides the defect and assertions that cannot break.
🤖 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 `@src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserAccountControllerDelegateTest.java` around lines 88 - 110, Make all second-factor tests enforce the encoded-username contract rather than allowing raw or arbitrary values. In UserAccountControllerDelegateTest.java ranges 88-110 and 395-407, configure a distinct encoded username and verify the exact argument passed to IdentityManager.getOtpCredential(...); in TenantAdminOnboardingServiceTest.java ranges 260-261, 306-307, 357-358, 513-514, and 582-583, match and verify the exact encoded admin username, including initial code and pending secret at 582-583; in HandshakeServiceTest.java ranges 65-70 and 144-147, use exact encoded support-admin usernames. Remove anyString() or equivalent over-mocking so each assertion can fail if encoding or setup arguments are incorrect.Source: Path instructions
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
`@src/main/java/de/caritas/cob/userservice/api/adapters/keycloak/KeycloakService.java`:
- Around line 275-289: The initiateEmailVerification method must stop exposing
RestClientException.getMessage() and return a stable sanitized application
failure message instead. Update KeycloakService.java lines 275-289 accordingly,
and update KeycloakServiceTest.java lines 1434-1443 to assert the stable message
rather than provider error text.
In
`@src/main/java/de/caritas/cob/userservice/api/adapters/web/controller/UserTwoFactorAuthControllerDelegate.java`:
- Around line 57-62: In the validationResult.created() branch of
UserTwoFactorAuthControllerDelegate, retain the Optional returned by
accountManager.patchUser(...) and call markTwoFactorActive only when the patch
succeeds; return an appropriate failure response when it is empty instead of
204. Add recovery or an idempotent retry strategy for failures between the patch
and markTwoFactorActive operations, and add a regression test proving
Optional.empty() does not activate 2FA.
In
`@src/test/java/de/caritas/cob/userservice/api/adapters/keycloak/KeycloakMapperTest.java`:
- Around line 39-47: Add a separate HttpStatus.OK case to
KeycloakMapperTest.identityEmailVerificationOfMapsCreatedResponse using
SuccessWithEmail, and assert the mapped IdentityEmailVerification has
created=false, createdBefore=true, attemptsLeft=false. Keep the existing
HttpStatus.CREATED mapping test unchanged.
In
`@src/test/java/de/caritas/cob/userservice/api/adapters/keycloak/KeycloakServiceTest.java`:
- Around line 312-324: Extend
getOtpCredential_Should_Return_Response_When_RequestWasSuccessful with an OK
ResponseEntity whose body is null, then assert keycloakService.getOtpCredential
returns IdentityOtpCredential.empty() and verify keycloakMapper is not invoked.
Keep the existing successful non-null response assertions intact.
In `@src/test/java/de/caritas/cob/userservice/api/IdentityManagerTest.java`:
- Around line 52-74: The existing tests only cover created email-verification
results; add a test for validateOneTimePassword where finishEmailVerification
returns an IdentityEmailVerification with created == false, then verify
identityClient.changeEmailAddress is never called while preserving the existing
successful cases.
---
Outside diff comments:
In
`@src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserAccountControllerDelegateTest.java`:
- Around line 88-110: Make all second-factor tests enforce the encoded-username
contract rather than allowing raw or arbitrary values. In
UserAccountControllerDelegateTest.java ranges 88-110 and 395-407, configure a
distinct encoded username and verify the exact argument passed to
IdentityManager.getOtpCredential(...); in TenantAdminOnboardingServiceTest.java
ranges 260-261, 306-307, 357-358, 513-514, and 582-583, match and verify the
exact encoded admin username, including initial code and pending secret at
582-583; in HandshakeServiceTest.java ranges 65-70 and 144-147, use exact
encoded support-admin usernames. Remove anyString() or equivalent over-mocking
so each assertion can fail if encoding or setup arguments are incorrect.
In
`@src/test/java/de/caritas/cob/userservice/api/service/handshake/HandshakeServiceTest.java`:
- Around line 173-182: Strengthen
initiate_Should_Forbid_When_SupportAdminOtpStateIsUnavailable by verifying that
keycloakAuthClient.verifyWithOtp(...) is never invoked when
identitySecondFactor.getOtpCredential(...) throws. Keep the existing
ForbiddenException and handshakeSessionRepository.save(...) assertions.
Fix all unresolved CodeRabbit comments on this PR:
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 5714173a-ad54-4646-a9fe-0170c25341a0
tests/ci/test_module_boundaries.py is excluded by none and included by nonedocumentation/USER_SERVICE_STABILITY.mdsrc/main/java/de/caritas/cob/userservice/api/IdentityManager.javasrc/main/java/de/caritas/cob/userservice/api/adapters/keycloak/KeycloakMapper.javasrc/main/java/de/caritas/cob/userservice/api/adapters/keycloak/KeycloakService.javasrc/main/java/de/caritas/cob/userservice/api/adapters/web/controller/UserAccountControllerDelegate.javasrc/main/java/de/caritas/cob/userservice/api/adapters/web/controller/UserTwoFactorAuthControllerDelegate.javasrc/main/java/de/caritas/cob/userservice/api/adapters/web/mapping/UserDtoMapper.javasrc/main/java/de/caritas/cob/userservice/api/identity/IdentityEmailVerification.javasrc/main/java/de/caritas/cob/userservice/api/identity/IdentityEmailVerificationStart.javasrc/main/java/de/caritas/cob/userservice/api/identity/IdentityOtpCredential.javasrc/main/java/de/caritas/cob/userservice/api/identity/IdentityOtpType.javasrc/main/java/de/caritas/cob/userservice/api/port/in/IdentityManaging.javasrc/main/java/de/caritas/cob/userservice/api/port/out/IdentityClient.javasrc/main/java/de/caritas/cob/userservice/api/port/out/IdentitySecondFactor.javasrc/main/java/de/caritas/cob/userservice/api/service/accountinvite/onboarding/TenantAdminOnboardingService.javasrc/main/java/de/caritas/cob/userservice/api/service/handshake/HandshakeService.javasrc/test/java/de/caritas/cob/userservice/api/IdentityManagerTest.javasrc/test/java/de/caritas/cob/userservice/api/adapters/keycloak/KeycloakMapperTest.javasrc/test/java/de/caritas/cob/userservice/api/adapters/keycloak/KeycloakServiceTest.javasrc/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserAccountControllerDelegateTest.javasrc/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserAdminControllerE2EIT.javasrc/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserAdminControllerMultiTenancyTrueE2EIT.javasrc/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserControllerAuthorizationIT.javasrc/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserControllerIT.javasrc/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserTwoFactorAuthControllerDelegateTest.javasrc/test/java/de/caritas/cob/userservice/api/adapters/web/mapping/UserDtoMapperTest.javasrc/test/java/de/caritas/cob/userservice/api/admin/service/admin/create/CreateAdminServiceIT.javasrc/test/java/de/caritas/cob/userservice/api/admin/service/admin/update/UpdateAdminServiceIT.javasrc/test/java/de/caritas/cob/userservice/api/admin/service/consultant/create/agencyrelation/ConsultantAgencyRelationCreatorServiceTenantAwareIT.javasrc/test/java/de/caritas/cob/userservice/api/admin/service/consultant/update/ConsultantUpdateServiceBase.javasrc/test/java/de/caritas/cob/userservice/api/service/accountinvite/onboarding/TenantAdminOnboardingServiceTest.javasrc/test/java/de/caritas/cob/userservice/api/service/handshake/HandshakeServiceTest.java
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| public IdentityEmailVerificationStart initiateEmailVerification(String username, String email) { | ||
| var otpSetupDTO = keycloakMapper.otpSetupDtoOf(null, null, email); | ||
| var requestUrl = getOtpUrl(ENDPOINT_OTP_VERIFY_EMAIL, username); | ||
|
|
||
| try { | ||
| withFreshAdminTokenOnUnauthorized( | ||
| "email-verification-start", | ||
| () -> | ||
| keycloakClient.putForEntity( | ||
| keycloakClient.getBearerToken(), requestUrl, otpSetupDTO, Success.class)); | ||
| return Optional.empty(); | ||
| return IdentityEmailVerificationStart.success(); | ||
| } catch (RestClientException exception) { | ||
| return Optional.of("Keycloak answered: " + exception.getMessage()); | ||
| return IdentityEmailVerificationStart.failure( | ||
| "Identity provider answered: " + exception.getMessage()); | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Remove raw provider error propagation from email-verification initiation.
RestClientException.getMessage() can contain request and provider details. The request URL includes the decoded username. Return a stable application message and update the test.
src/main/java/de/caritas/cob/userservice/api/adapters/keycloak/KeycloakService.java#L275-L289: replace the provider exception message with a stable public failure message.src/test/java/de/caritas/cob/userservice/api/adapters/keycloak/KeycloakServiceTest.java#L1434-L1443: assert the stable sanitized message instead of provider error text.src/main/java/de/caritas/cob/userservice/api/adapters/keycloak/KeycloakService.java#L275-L289 (this comment)src/test/java/de/caritas/cob/userservice/api/adapters/keycloak/KeycloakServiceTest.java#L1434-L1443Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@src/main/java/de/caritas/cob/userservice/api/adapters/keycloak/KeycloakService.java`
around lines 275 - 289, The initiateEmailVerification method must stop exposing
RestClientException.getMessage() and return a stable sanitized application
failure message instead. Update KeycloakService.java lines 275-289 accordingly,
and update KeycloakServiceTest.java lines 1434-1443 to assert the stable message
rather than provider error text.
Source: Path instructions
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (validationResult.created()) { | ||
| var patchMap = userDtoMapper.mapOf(validationResult.email(), authenticatedUser); | ||
| accountManager.patchUser(patchMap); | ||
| accountInviteService.markTwoFactorActive(authenticatedUser.getUserId()); | ||
| return ResponseEntity.noContent().build(); | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Do not activate 2FA after an unsuccessful email patch.
AccountManaging.patchUser(...) returns Optional<Map<String, Object>>, but this result is discarded. If it returns Optional.empty(), the code still calls markTwoFactorActive(...) and returns 204. The email state and local 2FA state can then become inconsistent.
Check the patch result before activating 2FA. Because the patch and local state transition are separate operations, also define recovery or idempotent retry for a failure between them. Add a regression test for Optional.empty() and verify that markTwoFactorActive(...) is not called.
- accountManager.patchUser(patchMap); + var patchResponse = accountManager.patchUser(patchMap); + if (patchResponse.isEmpty()) { + throw new NotFoundException("Authenticated user was not found"); + } accountInviteService.markTwoFactorActive(authenticatedUser.getUserId());
As per path instructions, this main flow must handle missing transaction boundaries and external-call failures.
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@src/main/java/de/caritas/cob/userservice/api/adapters/web/controller/UserTwoFactorAuthControllerDelegate.java`
around lines 57 - 62, In the validationResult.created() branch of
UserTwoFactorAuthControllerDelegate, retain the Optional returned by
accountManager.patchUser(...) and call markTwoFactorActive only when the patch
succeeds; return an appropriate failure response when it is empty instead of
204. Add recovery or an idempotent retry strategy for failures between the patch
and markTwoFactorActive operations, and add a regression test proving
Optional.empty() does not activate 2FA.
Source: Path instructions
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @Test | ||
| void identityEmailVerificationOfMapsCreatedResponse() { | ||
| var response = | ||
| new ResponseEntity<>( | ||
| new SuccessWithEmail().email("[email protected]"), HttpStatus.CREATED); | ||
|
|
||
| assertThat(mapper.identityEmailVerificationOf(response)) | ||
| .isEqualTo(new IdentityEmailVerification(true, false, false, "[email protected]")); | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Test the HttpStatus.OK mapping.
Add a SuccessWithEmail response with HttpStatus.OK. Assert created == false, createdBefore == true, and attemptsLeft == false. The controller uses this result to return PRECONDITION_FAILED.
As per path instructions, tests must cover missing edge cases.
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@src/test/java/de/caritas/cob/userservice/api/adapters/keycloak/KeycloakMapperTest.java`
around lines 39 - 47, Add a separate HttpStatus.OK case to
KeycloakMapperTest.identityEmailVerificationOfMapsCreatedResponse using
SuccessWithEmail, and assert the mapped IdentityEmailVerification has
created=false, createdBefore=true, attemptsLeft=false. Keep the existing
HttpStatus.CREATED mapping test unchanged.
Source: Path instructions
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| public void getOtpCredential_Should_Return_Response_When_RequestWasSuccessful() { | ||
| var outboundHttpMetrics = mock(OutboundHttpMetrics.class); | ||
| keycloakService.setOutboundHttpMetrics(outboundHttpMetrics); | ||
| var credential = new IdentityOtpCredential(true, "secret", "QrCode", IdentityOtpType.APP); | ||
| when(keycloakClient.getBearerToken()).thenReturn(BEARER_TOKEN); | ||
| var entity = new ResponseEntity(OTP_INFO_DTO, HttpStatus.OK); | ||
| when(this.keycloakClient.get(anyString(), any(), any())).thenReturn(entity); | ||
| when(keycloakMapper.identityOtpCredentialOf(OTP_INFO_DTO)).thenReturn(credential); | ||
|
|
||
| assertEquals(OTP_INFO_DTO, keycloakService.getOtpCredential(USERNAME)); | ||
| assertEquals(credential, keycloakService.getOtpCredential(USERNAME)); | ||
|
|
||
| verify(keycloakClient).get(anyString(), any(), eq(OtpInfoDTO.class)); | ||
| verifyNoInteractions(outboundHttpMetrics); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Test the empty OTP response body.
Add a response with HttpStatus.OK and a null body. Assert that getOtpCredential returns IdentityOtpCredential.empty() and does not invoke keycloakMapper. This covers the new fallback branch.
As per path instructions, tests must cover missing edge cases.
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@src/test/java/de/caritas/cob/userservice/api/adapters/keycloak/KeycloakServiceTest.java`
around lines 312 - 324, Extend
getOtpCredential_Should_Return_Response_When_RequestWasSuccessful with an OK
ResponseEntity whose body is null, then assert keycloakService.getOtpCredential
returns IdentityOtpCredential.empty() and verify keycloakMapper is not invoked.
Keep the existing successful non-null response assertions intact.
Source: Path instructions
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| void validateOneTimePasswordShouldUseRawUsernameForKeycloakEmailUpdate() { | ||
| var encodedUsername = usernameTranscoder.encodeUsername(RAW_USERNAME); | ||
| var validationResult = Map.of("created", "true", "email", EMAIL); | ||
| when(identityClient.finishEmailVerification(encodedUsername, "123456")) | ||
| var validationResult = new IdentityEmailVerification(true, false, false, EMAIL); | ||
| when(identitySecondFactor.finishEmailVerification(encodedUsername, "123456")) | ||
| .thenReturn(validationResult); | ||
|
|
||
| assertThat(identityManager.validateOneTimePassword(encodedUsername, "123456")) | ||
| .isEqualTo(validationResult); | ||
|
|
||
| verify(identityClient).finishEmailVerification(encodedUsername, "123456"); | ||
| verify(identitySecondFactor).finishEmailVerification(encodedUsername, "123456"); | ||
| verify(identityClient).changeEmailAddress(RAW_USERNAME, EMAIL); | ||
| } | ||
|
|
||
| @Test | ||
| void validateOneTimePasswordShouldKeepAlreadyRawUsernameForKeycloakEmailUpdate() { | ||
| var validationResult = Map.of("created", "true", "email", EMAIL); | ||
| when(identityClient.finishEmailVerification(RAW_USERNAME, "123456")) | ||
| var validationResult = new IdentityEmailVerification(true, false, false, EMAIL); | ||
| when(identitySecondFactor.finishEmailVerification(RAW_USERNAME, "123456")) | ||
| .thenReturn(validationResult); | ||
|
|
||
| identityManager.validateOneTimePassword(RAW_USERNAME, "123456"); | ||
|
|
||
| verify(identityClient).changeEmailAddress(RAW_USERNAME, EMAIL); | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Test the non-created email-verification result.
Add a test where finishEmailVerification returns created == false. Verify that identityClient.changeEmailAddress is never called. This protects the email-update boundary from invalid or already-created OTP results.
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/test/java/de/caritas/cob/userservice/api/IdentityManagerTest.java` around
lines 52 - 74, The existing tests only cover created email-verification results;
add a test for validateOneTimePassword where finishEmailVerification returns an
IdentityEmailVerification with created == false, then verify
identityClient.changeEmailAddress is never called while preserving the existing
successful cases.
Source: Path instructions
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.