Skip to content

Commit

Permalink
don't pass trailing dot to local resolver, add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
chthomas committed Dec 17, 2018
1 parent daaee08 commit 0df7a1c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/Entities/Hostname.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public function getHostName(): string
return $this->hostname;
}

public function getHostnameWithoutTrailingDot(): string
{
return substr($this->hostname, 0, -1);
}

public function isPunycoded(): bool
{
return $this->toUTF8() !== $this->hostname;
Expand Down
6 changes: 5 additions & 1 deletion src/Resolvers/LocalSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ public function getHostnameByAddress(string $IPAddress): Hostname

protected function doQuery(Hostname $hostname, DNSRecordType $type): DNSRecordCollection
{
$results = $this->systemDNS->getRecord($hostname, $this->mapper->getTypeCodeFromType($type));
$results = $this->systemDNS->getRecord(
$hostname->getHostnameWithoutTrailingDot(), // dns_get_record doesn't like trailing dot as much!
$this->mapper->getTypeCodeFromType($type)
);

$collection = new DNSRecordCollection();

foreach ($results as $result) {
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Entities/DNSRecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function isSerializable()
$this->assertSerializable($this->DNSARecord);

$this->assertEquals(unserialize(serialize($this->DNSARecord)), $this->DNSARecord);
$this->assertEquals(unserialize(serialize($this->DNSTXTRecord)), $this->DNSTXTRecord);
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Entities/HostnameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function hasBasicGettersAndIsStringy()
{
$this->assertSame('facebook.com.', (string)$this->hostname);
$this->assertSame('facebook.com.', $this->hostname->getHostName());
$this->assertSame('facebook.com', $this->hostname->getHostnameWithoutTrailingDot());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Resolvers/LocalSystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function hasOrDoesNotHaveRecord()

$this->dnsClient->expects($this->exactly(2))
->method('getRecord')
->with('facebook.com.', 1)
->with('facebook.com', 1)
->willReturnOnConsecutiveCalls(
self::getEmptyResponse(),
self::buildResponse('A')
Expand Down Expand Up @@ -80,7 +80,7 @@ public function getsRecords(string $method, Hostname $hostname, DNSRecordType $t
{
$this->dnsClient->expects($this->once())
->method('getRecord')
->with((string) $hostname, $this->localSystemMapper->getTypeCodeFromType($type))
->with($hostname->getHostnameWithoutTrailingDot(), $this->localSystemMapper->getTypeCodeFromType($type))
->willReturn($response);

$actual = $this->localSystem->{$method}($hostname, $type);
Expand Down

0 comments on commit 0df7a1c

Please sign in to comment.