Use new function to get verified domains
It uses the overall status set by the shop instead of checking the records. [MAILPOET-5832]
This commit is contained in:
committed by
Aschepikov
parent
db9813a3aa
commit
78faadc126
@ -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();
|
||||
|
@ -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([
|
||||
|
@ -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([]);
|
||||
|
@ -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,
|
||||
];
|
||||
|
Reference in New Issue
Block a user