[PM-34776/PM-37797] Add invite link email domain validation endpoint#7683
[PM-34776/PM-37797] Add invite link email domain validation endpoint#7683r-tome wants to merge 10 commits into
Conversation
- Introduced IsEmailDomainAllowed method to check if an email's domain is permitted based on allowed domains. - Added necessary using directives for MailAddress and domain sanitization utilities.
- Removed the IsEmailDomainAllowed method and associated using directives for MailAddress. - Cleaned up the code by eliminating unused methods related to email domain validation.
- Introduced InviteLinkDomainValidator class with IsEmailDomainAllowed method to validate if an email's domain is in the list of allowed domains. - Utilized MailAddress for email parsing and added domain sanitization logic.
- Implemented ValidateEmailDomain method in OrganizationInviteLinksController to check if an email's domain is allowed based on the invite link's permitted domains. - Created OrganizationInviteLinkValidateEmailDomainRequestModel for request validation and OrganizationInviteLinkValidateEmailDomainResponseModel for response formatting. - Integrated IOrganizationInviteLinkRepository to retrieve invite link details by code.
- Created InviteLinkDomainValidatorTests class to validate email domain functionality. - Added tests for various scenarios including invalid emails, empty domain lists, and matching domains. - Ensured comprehensive coverage of the IsEmailDomainAllowed method's behavior.
…eLinksController - Implemented a test to validate that an allowed email domain returns the expected result when checked against an organization invite link. - Ensured the test verifies the creation of an invite link and the subsequent validation of an email domain against the allowed domains list.
… domain - Introduced ValidateOrganizationInviteLinkEmailDomainQuery class to validate if an email's domain is allowed based on the invite link's permitted domains. - Created IValidateOrganizationInviteLinkEmailDomainQuery interface to define the validation method. - Added unit tests for the validation query to ensure correct behavior for various scenarios, including link not found and domain matching.
…r email domain - Updated ValidateEmailDomain method to utilize IValidateOrganizationInviteLinkEmailDomainQuery for domain validation instead of directly accessing the repository. - Removed unnecessary repository dependency and streamlined the response handling for validation results. - Registered the new validation query in OrganizationServiceCollectionExtensions for dependency injection.
Bitwarden Claude Code ReviewOverall Assessment: APPROVE Reviewed the new anonymous Code Review DetailsNo blocking findings. The change is narrowly scoped, well-tested, and consistent with the surrounding invite-link feature. Worth noting (not blocking) that |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7683 +/- ##
==========================================
- Coverage 64.86% 60.45% -4.42%
==========================================
Files 2140 2144 +4
Lines 94629 94656 +27
Branches 8445 8448 +3
==========================================
- Hits 61378 57221 -4157
- Misses 31155 35430 +4275
+ Partials 2096 2005 -91 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| /// </summary> | ||
| public static bool IsEmailDomainAllowed(string? email, IEnumerable<string> allowedDomains) | ||
| { | ||
| if (!MailAddress.TryCreate(email, out var mailAddress)) |
There was a problem hiding this comment.
EmailValidation.IsValidEmail our preferred method of validating. I would validate that way then use the EmailValidation.GetDomain method (which does the same thing but is a shared method).
There was a problem hiding this comment.
I did know that existed! Replaced
… existing email validation method
…ion-endpoint # Conflicts: # src/Api/AdminConsole/Controllers/OrganizationInviteLinksController.cs # src/Core/OrganizationFeatures/OrganizationServiceCollectionExtensions.cs
|



🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-34776
https://bitwarden.atlassian.net/browse/PM-37797
📔 Objective
Add an anonymous
POST /organizations/invite-link/validate-email-domainendpoint so clients can check whether an email belongs to an invite link's allowed domains before login/signup.Introduces
InviteLinkDomainValidator(will be reused by the accept command).Clients PR