Allow wildcards in email domains

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2020-08-28 17:15:59 +02:00
parent fffb627844
commit d18ee78454
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
2 changed files with 17 additions and 1 deletions

View File

@ -222,7 +222,21 @@ class RegistrationService {
foreach ($allowedDomains as $domain) {
// valid domain, everything's fine
if ($mailDomain === $domain) {
// Wildcards
if (strpos($domain, '*') !== false) {
// *.example.com
// Make save for regex:
// \*\.example\.com
$regexDomain = preg_quote($domain, '\\');
// Replace "\*" with an actual regex wildcard and set start and end:
// /^.+\.example\.com$/
$regexDomain = '/^' . str_replace('\\*', '.+', $regexDomain) . '$/';
if (preg_match($regexDomain, $mailDomain)) {
return true;
}
} elseif ($mailDomain === $domain) {
return true;
}
}

View File

@ -110,6 +110,8 @@ class RegistrationServiceTest extends TestCase {
['aaaa@example.com', 'example.com'],
['aaaa@example.com', 'eXample.com'],
['aaaa@eXample.com', 'example.com'],
['aaaa@cloud.example.com', '*.example.com'],
['aaaa@cloud.example.com', 'cloud.example.*'],
];
}