Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 2 additions & 4 deletions src/DNS/Zone/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ private static function handleWildcardMatch(array $records, Message $query, Zone

if (!empty($exactTypeRecords)) {
// Synthesize records with the query name
/** @var list<Record> */
$synthesizedRecords = array_map(
fn ($r) => $r->withName($question->name),
$exactTypeRecords
Expand All @@ -266,7 +265,7 @@ private static function handleWildcardMatch(array $records, Message $query, Zone
header: $query->header,
responseCode: Message::RCODE_NOERROR,
questions: $query->questions,
answers: $synthesizedRecords,
answers: array_values($synthesizedRecords),
authoritative: true,
recursionAvailable: false
);
Expand All @@ -277,7 +276,6 @@ private static function handleWildcardMatch(array $records, Message $query, Zone

if (!empty($cnameRecords)) {
// W2: CNAME in wildcard
/** @var list<Record> */
$synthesizedRecords = array_map(
fn ($r) => $r->withName($question->name),
$cnameRecords
Expand All @@ -287,7 +285,7 @@ private static function handleWildcardMatch(array $records, Message $query, Zone
header: $query->header,
responseCode: Message::RCODE_NOERROR,
questions: $query->questions,
answers: $synthesizedRecords,
answers: array_values($synthesizedRecords),
authoritative: true,
recursionAvailable: false
);
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/DNS/Zone/ResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,35 @@ public function testLookupUsesClosestEnclosingWildcard(): void
$this->assertSame(Record::TYPE_A, $answer->type);
}

public function testLookupResolvesWildcardCnameQuery(): void
{
$soa = new Record(
'test-dns.appwrite.org',
Record::TYPE_SOA,
ttl: 300,
rdata: 'ns1-stage.appwrite.zone team.appwrite.io 1 3600 600 86400 300'
);

$zone = new Zone('test-dns.appwrite.org', [
new Record('test-dns.appwrite.org', Record::TYPE_NS, ttl: 3600, rdata: 'ns1.example.org'),
new Record('*.wildcard.test-dns.appwrite.org', Record::TYPE_CNAME, ttl: 3600, rdata: 'stage.appwrite.network'),
], $soa);

$question = new Question('baz.wildcard.test-dns.appwrite.org', Record::TYPE_CNAME);
$query = Message::query($question);

$response = Resolver::lookup($query, $zone);

$this->assertSame(Message::RCODE_NOERROR, $response->header->responseCode);
$this->assertTrue($response->header->authoritative);
$this->assertCount(1, $response->answers);
$answer = $response->answers[0];
$this->assertSame('baz.wildcard.test-dns.appwrite.org', $answer->name);
$this->assertSame(Record::TYPE_CNAME, $answer->type);
$this->assertSame('stage.appwrite.network', $answer->rdata);
$this->assertSame(3600, $answer->ttl);
}

public function testIsAuthoritativeDetectsDelegation(): void
{
$soa = new Record(
Expand Down