Skip to content

Fake Domain Connect

Fake Domain Connect

The same InteractsWithDns trait that provides fakeDns() also fakes Domain Connect, so discovery and apply URLs run with no network I/O and no real key.

  • fakeDomainConnect(): FakeTransport binds a FakeTransport as the Transport and a FakeSigner as the Signer, and allows non-public provider hosts. It returns the transport so you can stub the provider's settings and template URLs.
  • fakeSigner(): FakeSigner returns the bound signer (faking Domain Connect first if needed) so you can assert what was signed. FakeSigner signs to a fixed value.
  • It shares the FakeResolver with fakeDns(), whichever you call first, so discovery lookups use the records you stub there.
  • The real Discoverer, SyncUrlBuilder, and DomainConnect are rebuilt from the container on first use, so config set after faking (such as dns.domain_connect.provider_id) takes effect. If a test resolved DomainConnect before changing config, forget those instances yourself.
use Cbox\Dns\DomainConnect\ApplyRequest;
use Cbox\Dns\DomainConnect\Template;
use Cbox\Dns\Enums\RecordType;
use Cbox\Dns\ValueObjects\DnsRecord;
use Cbox\LaravelDns\Facades\DomainConnect;

$template = Template::fromJson(file_get_contents(__DIR__.'/example.com.mail.json'));

$this->stubZone('acme.example', ['ns1.acme.example' => '192.0.2.1']);
$this->fakeDns()
    ->stubRecords('acme.example', RecordType::SOA, [new DnsRecord(RecordType::SOA, 'acme.example', 'ns1. host. 1 1 1 1 1')])
    ->stub('_domainconnect.acme.example', RecordType::TXT, ['dc.example'])
    ->stub('dc.example', RecordType::A, ['203.0.113.1']);

$this->fakeDomainConnect()
    ->stub('https://dc.example/v2/acme.example/settings', 200, [
        'providerId' => 'p', 'providerName' => 'P',
        'urlSyncUX' => 'https://dc.example', 'urlAPI' => 'https://dc.example/api',
    ])
    ->stub('https://dc.example/api/v2/domainTemplates/providers/example.com/services/mail', 200, '');

config()->set('dns.domain_connect.provider_id', 'example.com');

$discovery = DomainConnect::discover('acme.example', $template);

expect($discovery->supportsTemplate())->toBeTrue();

$url = DomainConnect::applyUrl(
    new ApplyRequest($template, $discovery->zone, ['token' => 'abc']),
    $discovery->settings,
);

expect($url)->toEndWith('&sig=ZmFrZS1zaWc%3D&key=_dcpubkeyv1')
    ->and($this->fakeSigner()->signed())->toHaveCount(1);

Adapt the stubbed URLs to your template's provider id and service id. For FakeTransport and FakeSigner themselves, see the cboxdk/dns testing docs.