diff --git a/mailpoet/lib/Services/AuthorizedSenderDomainController.php b/mailpoet/lib/Services/AuthorizedSenderDomainController.php index 0d75a6a2af..19cf19e02f 100644 --- a/mailpoet/lib/Services/AuthorizedSenderDomainController.php +++ b/mailpoet/lib/Services/AuthorizedSenderDomainController.php @@ -85,15 +85,17 @@ class AuthorizedSenderDomainController { } /** - * Get all Verified Sender Domains + * Get all Verified Sender Domains. + * + * Note: This includes partially or fully verified domains. */ public function getVerifiedSenderDomains(): array { - return $this->returnVerifiedDomains($this->getAllRecords()); + return $this->getFullyOrPartiallyVerifiedSenderDomains(true); } public function getVerifiedSenderDomainsIgnoringCache(): array { $this->currentRecords = null; - return $this->getVerifiedSenderDomains(); + return $this->getFullyOrPartiallyVerifiedSenderDomains(true); } /** @@ -173,11 +175,17 @@ class AuthorizedSenderDomainController { }); } + /** + * Returns sender domains that have all required records, including DMARC. + */ public function getFullyVerifiedSenderDomains($domainsOnly = false): array { $domainData = $this->getSenderDomainsByStatus([self::OVERALL_STATUS_VERIFIED]); return $domainsOnly ? $this->extractDomains($domainData) : $domainData; } + /** + * Returns sender domains that were verified before DMARC record was required. + */ public function getPartiallyVerifiedSenderDomains($domainsOnly = false): array { $domainData = $this->getSenderDomainsByStatus([self::OVERALL_STATUS_PARTIALLY_VERIFIED]); return $domainsOnly ? $this->extractDomains($domainData) : $domainData; @@ -227,27 +235,6 @@ class AuthorizedSenderDomainController { return $domains; } - /** - * Little helper function to return All verified domains - */ - private function returnVerifiedDomains(array $records): array { - $verifiedDomains = []; - - foreach ($records as $key => $value) { - if (count($value) < 3) continue; - [$domainKey1, $domainKey2, $secretRecord] = $value; - if ( - $domainKey1['status'] === self::DOMAIN_VERIFICATION_STATUS_VALID && - $domainKey2['status'] === self::DOMAIN_VERIFICATION_STATUS_VALID && - $secretRecord['status'] === self::DOMAIN_VERIFICATION_STATUS_VALID - ) { - $verifiedDomains[] = $key; - } - } - - return $verifiedDomains; - } - private function getAllRawData(): array { if ($this->currentRawData === null) { $this->currentRawData = $this->bridge->getRawSenderDomainData(); diff --git a/mailpoet/tests/integration/API/JSON/v1/ServicesTest.php b/mailpoet/tests/integration/API/JSON/v1/ServicesTest.php index d08c757439..a5dbc26953 100644 --- a/mailpoet/tests/integration/API/JSON/v1/ServicesTest.php +++ b/mailpoet/tests/integration/API/JSON/v1/ServicesTest.php @@ -551,7 +551,7 @@ class ServicesTest extends \MailPoetTest { $verifiedDomains = ['email.com']; $senderDomainMock = $this->make(AuthorizedSenderDomainController::class, [ - 'getVerifiedSenderDomains' => Expected::once($verifiedDomains), + 'getVerifiedSenderDomainsIgnoringCache' => Expected::once($verifiedDomains), ]); $servicesEndpoint = $this->createServicesEndpointWithMocks([ diff --git a/mailpoet/tests/integration/Services/AuthorizedSenderDomainControllerTest.php b/mailpoet/tests/integration/Services/AuthorizedSenderDomainControllerTest.php index 2811255410..8edacdc17b 100644 --- a/mailpoet/tests/integration/Services/AuthorizedSenderDomainControllerTest.php +++ b/mailpoet/tests/integration/Services/AuthorizedSenderDomainControllerTest.php @@ -67,13 +67,20 @@ class AuthorizedSenderDomainControllerTest extends \MailPoetTest { public function testItReturnsVerifiedSenderDomains() { $bridgeResponse = [ - 'mailpoet.com' => Bridge\BridgeTestMockAPI::VERIFIED_DOMAIN_RESPONSE['dns'], - 'good' => ['data'], - 'testdomain.com' => ['data'], + [ + 'domain' => 'mailpoet.com', + 'domain_status' => 'verified', + 'dns' => Bridge\BridgeTestMockAPI::VERIFIED_DOMAIN_RESPONSE['dns'], + ], + [ + 'domain' => 'testdomain.com', + 'domain_status' => 'unverified', + 'dns' => [], + ], ]; $bridgeMock = $this->make(Bridge::class, [ - 'getAuthorizedSenderDomains' => Expected::once($bridgeResponse), + 'getRawSenderDomainData' => Expected::once($bridgeResponse), ]); $controller = $this->getController($bridgeMock); @@ -84,16 +91,22 @@ class AuthorizedSenderDomainControllerTest extends \MailPoetTest { public function testItReturnsEmptyArrayWhenNoVerifiedSenderDomains() { $expectation = Expected::once([]); // with empty array - $bridgeMock = $this->make(Bridge::class, ['getAuthorizedSenderDomains' => $expectation]); + $bridgeMock = $this->make(Bridge::class, ['getRawSenderDomainData' => $expectation]); $controller = $this->getController($bridgeMock); $verifiedDomains = $controller->getVerifiedSenderDomains(); verify($verifiedDomains)->same([]); - $domains = ['testdomain.com' => []]; + $domains = [ + [ + 'domain' => 'testdomain.com', + 'domain_status' => 'unverified', + 'dns' => [], + ], + ]; $expectation = Expected::once($domains); - $bridgeMock = $this->make(Bridge::class, ['getAuthorizedSenderDomains' => $expectation]); + $bridgeMock = $this->make(Bridge::class, ['getRawSenderDomainData' => $expectation]); $controller = $this->getController($bridgeMock); $verifiedDomains = $controller->getVerifiedSenderDomains(); verify($verifiedDomains)->same([]); diff --git a/mailpoet/tests/integration/Services/BridgeTestMockAPI.php b/mailpoet/tests/integration/Services/BridgeTestMockAPI.php index cd6d2da492..a67462e717 100644 --- a/mailpoet/tests/integration/Services/BridgeTestMockAPI.php +++ b/mailpoet/tests/integration/Services/BridgeTestMockAPI.php @@ -29,6 +29,13 @@ class BridgeTestMockAPI extends API { 'status' => 'valid', 'message' => '', ], + [ + 'host' => '_dmarc.example.com', + 'value' => 'v=DMARC1; p=none;', + 'type' => 'TXT', + 'status' => 'valid', + 'message' => '', + ], ], 'status' => API::RESPONSE_STATUS_OK, ];