[PM-33043] Refactor PolicyService, CipherService, and TwoFactorAuthenticationValidator#7214
[PM-33043] Refactor PolicyService, CipherService, and TwoFactorAuthenticationValidator#7214
Conversation
…ticationValidator
|
Claude finished @JimmyVo16's task in 2m 43s —— View job Code Review: PM-33043 Refactor Services for OrganizationAbility
Overall Assessment: APPROVE This PR cleanly refactors three services to use the scoped Detailed AnalysisSecurity: No concerns. The refactoring reduces data exposure by fetching only the necessary organization abilities rather than the entire cache. Correctness: The logic transformations preserve original behavior:
Performance: Positive impact — fetches only the needed organization abilities from cache instead of all of them. Minor Observations (non-blocking)
|
|
Overall Assessment: REQUEST CHANGES Reviewed the refactoring of PolicyService, CipherService, and TwoFactorAuthenticationValidator to use the scoped GetOrganizationAbilitiesAsync(IEnumerable Guid) overload instead of the obsolete parameterless version. The refactored logic in all three services is behaviorally equivalent to the original. However, existing tests still mock the parameterless overload, which will cause test failures. Code Review Details
|
|
Inline Finding on src/Core/Vault/Services/Implementations/CipherService.cs line 1187: ❌ CRITICAL: Test mocks target the wrong overload and will cause failures The code now calls the parameterized GetOrganizationAbilitiesAsync via this helper, but 7 existing tests still mock the parameterless overload. NSubstitute treats these as distinct overloads, so the parameterized call returns null. CipherServiceTests (6 tests at lines 1079, 1141, 1909, 1957, 2256, 2305): The null dictionary causes a NullReferenceException at organizationAbilities.TryGetValue in FilterCiphersByDeletePermission. TwoFactorAuthenticationValidatorTests (1 test at line 138): OrgUsing2fa guards against null, so no NRE, but the test expects result.Item1 to be true and result.Item2 to not be null, which both fail since the org abilities check is silently skipped. Fix: Update all affected test mocks to use the parameterized overload instead of the parameterless .GetOrganizationAbilitiesAsync(). Affected test files:
|
|
Great job! No new security vulnerabilities introduced in this pull request |
…sAbilitiesForUserOrgs
|
Overall Assessment: REQUEST CHANGES Re-reviewed after commit e159f45 which fixed the TwoFactorAuthenticationValidatorTests mock and added a new test verifying scoped org ability fetching. The TwoFactor test fix is correct and the new test is well-structured. However, the CipherServiceTests issue from the previous review remains unaddressed. Code Review Details
|
|
Overall Assessment: REQUEST CHANGES Re-reviewed after commit 8c9e65b which adds a PolicyServiceTests test verifying that GetPoliciesApplicableToUserAsync only fetches organization abilities for filtered (non-provider) org IDs. The new test is correct and well-structured. The previous CRITICAL finding about CipherServiceTests remains unaddressed. Code Review Details
|
|
Overall Assessment: APPROVE Re-reviewed after commit 63d833c which fixes all 6 CipherServiceTests mock setups to target the parameterized GetOrganizationAbilitiesAsync(IEnumerable of Guid) overload and adds a new test verifying the behavior when a cipher organization is not found in the abilities cache. The previous CRITICAL finding is fully resolved. No new issues found. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7214 +/- ##
==========================================
- Coverage 61.58% 57.54% -4.05%
==========================================
Files 2032 2032
Lines 89476 89509 +33
Branches 7957 7958 +1
==========================================
- Hits 55108 51508 -3600
- Misses 32441 36155 +3714
+ Partials 1927 1846 -81 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|




🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-33043
📔 Objective
PolicyService,CipherService, andTwoFactorAuthenticationValidatorto use the newTask<IDictionary<Guid, OrganizationAbility>> GetOrganizationAbilitiesAsync(IEnumerable<Guid> orgIds)instead of the deprecatedGetOrganizationAbilitiesAsync().📸 Screenshots
I feel like the new unit test coverage is sufficient.