diff --git a/lib/Service/RegistrationService.php b/lib/Service/RegistrationService.php index 26bf83b..a02b2bd 100644 --- a/lib/Service/RegistrationService.php +++ b/lib/Service/RegistrationService.php @@ -217,17 +217,16 @@ class RegistrationService { public function checkAllowedDomains(string $email): bool { $allowedDomains = $this->config->getAppValue($this->appName, 'allowed_domains', ''); if ($allowedDomains !== '') { - $allowedDomains = explode(';', $allowedDomains); - $allowed = false; + [,$mailDomain] = explode('@', strtolower($email), 2); + $allowedDomains = explode(';', strtolower($allowedDomains)); + foreach ($allowedDomains as $domain) { - [,$mailDomain] = explode('@', $email, 2); // valid domain, everything's fine if ($mailDomain === $domain) { - $allowed = true; - break; + return true; } } - return $allowed; + return false; } return true; } diff --git a/tests/Integration/Service/RegistrationServiceTest.php b/tests/Integration/Service/RegistrationServiceTest.php index 4130ffd..00413bf 100644 --- a/tests/Integration/Service/RegistrationServiceTest.php +++ b/tests/Integration/Service/RegistrationServiceTest.php @@ -60,7 +60,6 @@ class RegistrationServiceTest extends TestCase { private $tokenProvider; /** @var ICrypto */ private $crypto; - /** @var RegistrationService */ private $service; @@ -105,31 +104,30 @@ class RegistrationServiceTest extends TestCase { ); } - public function testValidateNewEmail() { - $email = 'aaaa@example.com'; - - $this->config->expects($this->once()) - ->method('getAppValue') - ->with('registration', 'allowed_domains', '') - ->willReturn(''); - - $this->service->validateEmail($email); - } - - public function testValidateNewEmailWithinAllowedDomain() { - $email = 'aaaa@example.com'; - - $this->config->expects($this->atLeastOnce()) - ->method('getAppValue') - ->with('registration', 'allowed_domains', '') - ->willReturn('example.com'); - - $this->service->validateEmail($email); + public function dataValidateEmail(): array { + return [ + ['aaaa@example.com', ''], + ['aaaa@example.com', 'example.com'], + ['aaaa@example.com', 'eXample.com'], + ['aaaa@eXample.com', 'example.com'], + ]; } /** - * @depends testValidateNewEmailWithinAllowedDomain + * @dataProvider dataValidateEmail + * @param string $email + * @param string $allowedDomains + * @throws RegistrationException */ + public function testValidateEmail(string $email, string $allowedDomains) { + $this->config->expects($this->once()) + ->method('getAppValue') + ->with('registration', 'allowed_domains', '') + ->willReturn($allowedDomains); + + $this->service->validateEmail($email); + } + public function testValidateNewEmailNotWithinAllowedDomain() { $email2 = 'bbbb@gmail.com';