From b85fcf58ed034b62c0f788208fcf4efaa84bee3f Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Mon, 4 Aug 2025 00:02:58 +0530 Subject: [PATCH 1/6] Add CAA record --- src/DNS/Client.php | 11 +++++++++++ tests/DNS/ClientTest.php | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/DNS/Client.php b/src/DNS/Client.php index e17c340..a540eaf 100644 --- a/src/DNS/Client.php +++ b/src/DNS/Client.php @@ -36,6 +36,7 @@ class Client 'TXT' => 16, 'AAAA' => 28, 'SRV' => 33, + 'CAA' => 257, ]; public function __construct(string $server = '127.0.0.1', int $port = 53, int $timeout = 5) @@ -241,6 +242,16 @@ private function parseRdata(string $packet, int &$offset, int $type, int $rdleng $offset += 6; $target = $this->decodeDomainName($packet, $offset); return "Priority: {$priority[1]}, Weight: {$weight[1]}, Port: {$port[1]}, Target: {$target}"; + case 257: // CAA record + $flags = ord($packet[$offset]); + $offset++; + $tagLength = ord($packet[$offset]); + $offset++; + $tag = substr($packet, $offset, $tagLength); + $offset += $tagLength; + $value = substr($packet, $offset, $rdlength - 2 - $tagLength); + $offset += $rdlength - 2 - $tagLength; + return "Flags: {$flags}, Tag: {$tag}, Value: {$value}"; case 6: // SOA record $mname = $this->decodeDomainName($packet, $offset); $rname = $this->decodeDomainName($packet, $offset); diff --git a/tests/DNS/ClientTest.php b/tests/DNS/ClientTest.php index c18b786..34701c9 100644 --- a/tests/DNS/ClientTest.php +++ b/tests/DNS/ClientTest.php @@ -135,4 +135,20 @@ public function testNSRecords(): void $records = $this->client->query('dev3.appwrite.io', 'NS'); $this->assertCount(0, $records); } + + public function testCAARecords(): void + { + $records = $this->client->query('github.com', 'CAA'); + + $this->assertCount(1, $records); + $this->assertEquals('github.com', $records[0]->getName()); + $this->assertEquals('IN', $records[0]->getClass()); + $this->assertIsNumeric($records[0]->getTTL()); + $this->assertEquals('CAA', $records[0]->getTypeName()); + + $rdata = $records[0]->getRdata(); + $this->assertStringContainsString('Flags:', $rdata); + $this->assertStringContainsString('Tag:', $rdata); + $this->assertStringContainsString('Value:', $rdata); + } } From a7d45e4c5dfc7020c0467de9587ccd7e15488206 Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Mon, 4 Aug 2025 00:16:13 +0530 Subject: [PATCH 2/6] Update return format --- src/DNS/Client.php | 2 +- tests/DNS/ClientTest.php | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/DNS/Client.php b/src/DNS/Client.php index a540eaf..37ec9eb 100644 --- a/src/DNS/Client.php +++ b/src/DNS/Client.php @@ -251,7 +251,7 @@ private function parseRdata(string $packet, int &$offset, int $type, int $rdleng $offset += $tagLength; $value = substr($packet, $offset, $rdlength - 2 - $tagLength); $offset += $rdlength - 2 - $tagLength; - return "Flags: {$flags}, Tag: {$tag}, Value: {$value}"; + return "{$flags} {$tag} \"{$value}\""; case 6: // SOA record $mname = $this->decodeDomainName($packet, $offset); $rname = $this->decodeDomainName($packet, $offset); diff --git a/tests/DNS/ClientTest.php b/tests/DNS/ClientTest.php index 34701c9..d66a364 100644 --- a/tests/DNS/ClientTest.php +++ b/tests/DNS/ClientTest.php @@ -138,17 +138,15 @@ public function testNSRecords(): void public function testCAARecords(): void { - $records = $this->client->query('github.com', 'CAA'); + $records = $this->client->query('google.com', 'CAA'); $this->assertCount(1, $records); - $this->assertEquals('github.com', $records[0]->getName()); + $this->assertEquals('google.com', $records[0]->getName()); $this->assertEquals('IN', $records[0]->getClass()); $this->assertIsNumeric($records[0]->getTTL()); $this->assertEquals('CAA', $records[0]->getTypeName()); $rdata = $records[0]->getRdata(); - $this->assertStringContainsString('Flags:', $rdata); - $this->assertStringContainsString('Tag:', $rdata); - $this->assertStringContainsString('Value:', $rdata); + $this->assertEquals('0 issue "pki.goog"', $rdata); } } From 8e0a7d087693ed4f38578ed8956b3ffd77a15fcc Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Mon, 4 Aug 2025 01:52:31 +0530 Subject: [PATCH 3/6] Resolve lint issue --- tests/DNS/ClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/DNS/ClientTest.php b/tests/DNS/ClientTest.php index d66a364..4c34503 100644 --- a/tests/DNS/ClientTest.php +++ b/tests/DNS/ClientTest.php @@ -145,7 +145,7 @@ public function testCAARecords(): void $this->assertEquals('IN', $records[0]->getClass()); $this->assertIsNumeric($records[0]->getTTL()); $this->assertEquals('CAA', $records[0]->getTypeName()); - + $rdata = $records[0]->getRdata(); $this->assertEquals('0 issue "pki.goog"', $rdata); } From 3549d616b709cab10c6ebd6b8e9ba13ca657b7f9 Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Mon, 4 Aug 2025 02:03:57 +0530 Subject: [PATCH 4/6] Improve code --- src/DNS/Client.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/DNS/Client.php b/src/DNS/Client.php index 37ec9eb..8784d3f 100644 --- a/src/DNS/Client.php +++ b/src/DNS/Client.php @@ -243,10 +243,11 @@ private function parseRdata(string $packet, int &$offset, int $type, int $rdleng $target = $this->decodeDomainName($packet, $offset); return "Priority: {$priority[1]}, Weight: {$weight[1]}, Port: {$port[1]}, Target: {$target}"; case 257: // CAA record - $flags = ord($packet[$offset]); - $offset++; - $tagLength = ord($packet[$offset]); - $offset++; + if ($rdlength < 2) { + throw new Exception("CAA record too short (rdlength={$rdlength})"); + } + $flags = ord($packet[$offset++]); + $tagLength = ord($packet[$offset++]); $tag = substr($packet, $offset, $tagLength); $offset += $tagLength; $value = substr($packet, $offset, $rdlength - 2 - $tagLength); From d14231d8e318cc7d900ee0b81d065c1b18c4ead4 Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Mon, 4 Aug 2025 02:08:39 +0530 Subject: [PATCH 5/6] Fix tests --- tests/DNS/ClientTest.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/DNS/ClientTest.php b/tests/DNS/ClientTest.php index 4c34503..aac1a3a 100644 --- a/tests/DNS/ClientTest.php +++ b/tests/DNS/ClientTest.php @@ -138,15 +138,21 @@ public function testNSRecords(): void public function testCAARecords(): void { - $records = $this->client->query('google.com', 'CAA'); + $records = $this->client->query('dev.appwrite.io', 'CAA'); $this->assertCount(1, $records); - $this->assertEquals('google.com', $records[0]->getName()); + $this->assertEquals('dev.appwrite.io', $records[0]->getName()); $this->assertEquals('IN', $records[0]->getClass()); $this->assertIsNumeric($records[0]->getTTL()); $this->assertEquals('CAA', $records[0]->getTypeName()); $rdata = $records[0]->getRdata(); - $this->assertEquals('0 issue "pki.goog"', $rdata); + $this->assertEquals('0 issue "letsencrypt.org"', $rdata); + + $records = $this->client->query('dev2.appwrite.io', 'CAA'); + + $this->assertCount(2, $records); + $this->assertEquals('0 issue "letsencrypt.org"', $records[0]->getRdata()); + $this->assertEquals('0 issue "sectigo.com"', $records[1]->getRdata()); } } From 023a0bb26ea53d5e43e13ca487388f1b0bdff14b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 4 Aug 2025 10:32:48 +0000 Subject: [PATCH 6/6] Improve tests coverage --- composer.json | 6 ++++++ tests/DNS/ClientTest.php | 5 +++++ tests/DNS/ServerMemory.php | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/composer.json b/composer.json index 4cd2d69..1f9b98f 100755 --- a/composer.json +++ b/composer.json @@ -32,5 +32,11 @@ "laravel/pint": "1.2.*", "phpstan/phpstan": "1.8.*", "rregeer/phpunit-coverage-check": "^0.3.1" + }, + "config": { + "allow-plugins": { + "php-http/discovery": true, + "tbachert/spi": true + } } } diff --git a/tests/DNS/ClientTest.php b/tests/DNS/ClientTest.php index aac1a3a..93feab8 100644 --- a/tests/DNS/ClientTest.php +++ b/tests/DNS/ClientTest.php @@ -154,5 +154,10 @@ public function testCAARecords(): void $this->assertCount(2, $records); $this->assertEquals('0 issue "letsencrypt.org"', $records[0]->getRdata()); $this->assertEquals('0 issue "sectigo.com"', $records[1]->getRdata()); + + $records = $this->client->query('dev3.appwrite.io', 'CAA'); + + $this->assertCount(1, $records); + $this->assertEquals('255 issuewild "certainly.com;validationmethods=tls-alpn-01;retrytimeout=3600"', $records[0]->getRdata()); } } diff --git a/tests/DNS/ServerMemory.php b/tests/DNS/ServerMemory.php index 5a747cc..f605324 100644 --- a/tests/DNS/ServerMemory.php +++ b/tests/DNS/ServerMemory.php @@ -77,6 +77,10 @@ 'value' => 'issue "sectigo.com"' ]); +$resolver->addRecord('dev3.appwrite.io', 'CAA', [ + 'value' => '255 issuewild "certainly.com;validationmethods=tls-alpn-01;retrytimeout=3600"' +]); + $resolver->addRecord('dev.appwrite.io', 'NS', [ 'value' => 'ns.appwrite.io', 'ttl' => 60