- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.5k
fix(prevent-null): [PM-27510] AccountController Prevent Null Values #6508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(prevent-null): [PM-27510] AccountController Prevent Null Values #6508
Conversation
…Confirmed and Accepted SSO Users - Added in logic to block existing sso org users who are not in the confirmed or accepted state.
…Confirmed and Accepted SSO Users - Added extra log statement
…Confirmed and Accepted SSO Users - Adding tests, second attempt to do it properly with xunit
…Confirmed and Accepted SSO Users - Fixed up more tests.
…Confirmed and Accepted SSO Users - Fixed csproj to use variable version numbers.
…Confirmed and Accepted SSO Users - Made tests more dry
…Confirmed and Accepted SSO Users - Removed unneeded test code.
…Confirmed and Accepted SSO Users - Made it clear on arrange act assert
…Confirmed and Accepted SSO Users - Fixed up tests and code to make sure there is the correct number of repo calls.
…Confirmed and Accepted SSO Users - Removed unnessessary code
…Confirmed and Accepted SSO Users - Removed more unneeded code
…Confirmed and Accepted SSO Users - Removed even more unneeded code.
…Confirmed and Accepted SSO Users - Removed even even more unneeded code.
…onfirmed and Accepted SSO Users - Whoops, added back in user being assigned.
…onfirmed and Accepted SSO Users - Removed uneeded function.
…onfirmed and Accepted SSO Users - Converted to using bit auto data and sut provider.
…onfirmed and Accepted SSO Users - Now throws when no org found
…onfirmed and Accepted SSO Users - Moved test directory.
…onfirmed and Accepted SSO Users - Fixed slash direction change.
…ting-sso-rejected-users
…onfirmed and Accepted SSO Users - Shuffled around functions and added more tests.
…onfirmed and Accepted SSO Users - Small changes.
…onfirmed and Accepted SSO Users - Changes to parameters being passed. Good state.
…Confirmed and Accepted SSO Users - Added more comments.
…Confirmed and Accepted SSO Users - Jared's ideas + some tweaks and touchups.
…onfirmed and Accepted SSO Users - Added new check and throw for user.
…onfirmed and Accepted SSO Users - Added docs as well as made clear what statuses are permissible.
…onfirmed and Accepted SSO Users - Changed function name.
…Confirmed and Accepted SSO Users - Fixed tests.
…onfirmed and Accepted SSO Users - Moved null check higher.
…onfirmed and Accepted SSO Users - Fixed nullish checking
…onfirmed and Accepted SSO Users - Renaming of users to make code more clear.
…users-nullish-fix
| Jared reviewed the previous pr #6348 so I'm giving him a break and would love your eyes on it Ike! | 
| Claude finished @Patrick-Pimentel-Bitwarden's task —— View job Code Review CompleteSummary of ChangesThis PR addresses null safety in  
 Critical Issues1. Unsafe Null-Forgiving Operator Usage (High Priority)Location:  if (email == null) throw new Exception(_i18nService.T("NoEmailFoundWhenFallingBackToEmailForOrgUserLookup"));This null check occurs after the method has already attempted to use  // Line 780 - orgUser may have been found via user.Id
orgUser = orgUsersByUserId.SingleOrDefault(u => u.OrganizationId == organizationId);
// Line 785 - null check for email
if (email == null) throw new Exception(...);
// Line 787 - uses email
orgUser ??= await _organizationUserRepository.GetByOrganizationEmailAsync(organizationId, email);The null check should occur before attempting any email-based lookup, not after. Additionally, if  Recommendation: Move the null check immediately after checking if  // Try to find OrgUser via existing User Id.
if (user != null)
{
    var orgUsersByUserId = await _organizationUserRepository.GetManyByUserAsync(user.Id);
    orgUser = orgUsersByUserId.SingleOrDefault(u => u.OrganizationId == organizationId);
}
// If no org user found and we need to search by email, ensure email is present
if (orgUser == null)
{
    if (email == null)
    {
        throw new Exception(_i18nService.T("NoEmailFoundWhenFallingBackToEmailForOrgUserLookup"));
    }
    orgUser = await _organizationRepository.GetByOrganizationEmailAsync(organizationId, email);
}2. Null-Forgiving Operators Without JustificationLocations: Multiple places in  The code uses several null-forgiving operators ( 
 Recommendation: Either: 
 3. Inconsistent Null Handling in  | 
| 
 Great job! No new security vulnerabilities introduced in this pull request | 
…Fixed null values.
…users-nullish-fix
…Fixed tiny changes.
| Codecov Report❌ Patch coverage is  
 Additional details and impacted files@@            Coverage Diff             @@
##             main    #6508      +/-   ##
==========================================
+ Coverage   51.49%   51.84%   +0.35%     
==========================================
  Files        1900     1902       +2     
  Lines       84121    84213      +92     
  Branches     7517     7561      +44     
==========================================
+ Hits        43318    43663     +345     
+ Misses      39115    38838     -277     
- Partials     1688     1712      +24     ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
 | 
…Added tests to get more coverage.

🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-27510
📔 Objective
Does not allow for null values in the AccountController.
📸 Screenshots
⏰ Reminders before review
🦮 Reviewer guidelines
:+1:) or similar for great changes:memo:) or ℹ️ (:information_source:) for notes or general info:question:) for questions:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion:art:) for suggestions / improvements:x:) or:warning:) for more significant problems or concerns needing attention:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt:pick:) for minor or nitpick changes