Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion platform/php/MailChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ public static function isBlacklisted(string $email): bool
$parts = explode('@', $email);
$domain = end($parts);

foreach (self::allDomainSuffixes($domain) as $domainSuffix) {
return self::isDomainBlocked($domain, true);
}

public static function isDomainBlocked(string $domain, bool $checkSubdomain): bool
{
$domainSuffixes = $checkSubdomain ? self::allDomainSuffixes($domain) : [$domain];
foreach ($domainSuffixes as $domainSuffix) {
if (isset(self::$blocklist[$domainSuffix])) {
return true;
}
Expand Down
9 changes: 9 additions & 0 deletions test/platform.php.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,13 @@ public function testAddCustomDomains()
$this->isInvalid('foo@google.com');
$this->isValid('ok@gmail.com');
}

#[DataProvider('provideBlackListTests')]
public function testIsDomainBlocked($blacklistedDomain)
{
$this->assertEquals(true, MailChecker::isDomainBlocked($blacklistedDomain, true));
$this->assertEquals(true, MailChecker::isDomainBlocked('subdomain.'.$blacklistedDomain, true));
$this->assertEquals(true, MailChecker::isDomainBlocked($blacklistedDomain, false));
$this->assertEquals(false, MailChecker::isDomainBlocked('subdomain.'.$blacklistedDomain, false));
}
}
Loading