-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move IPv6 tests to a separate file. Add a setUp method to detect if P…
…HP has IPv6 support, the host has IPv6 support, and that IPv6 is routable (quick connection to google IPv6 server). Skip tests if we are running on a host or network that cannot do IPv6
- Loading branch information
1 parent
71d129b
commit 58cbbc7
Showing
2 changed files
with
75 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace EdgeTelemetrics\React\Dns\Tests; | ||
|
||
use EdgeTelemetrics\React\Dns\DohExecutor; | ||
use PHPUnit\Framework\TestCase; | ||
use React\Dns\Model\Message; | ||
use React\Dns\Query\Query; | ||
use React\EventLoop\Loop; | ||
|
||
/** | ||
* IPv6 Tests | ||
*/ | ||
class IPv6Test extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
if (!(defined("AF_INET6") && @\stream_socket_client('udp://[::1]:8888') !== false)) { | ||
$this->markTestSkipped('IPv6 Unavailable'); | ||
} | ||
$context = stream_context_create(); | ||
stream_context_set_option($context, 'ssl', 'verify_host', false); | ||
stream_context_set_option($context, 'ssl', 'verify_peer_name', false); | ||
|
||
$dns = 'tls://[2001:4860:4860::8888]:443'; | ||
|
||
$socket = @\stream_socket_client($dns, $errno, $errstr, 5, STREAM_CLIENT_CONNECT, $context); | ||
if ($socket === false) { | ||
$this->markTestSkipped('IPv6 not routable'); | ||
} | ||
} | ||
|
||
public function testResolveGoogleViaIPv6HostResolves() | ||
{ | ||
$executor = new DohExecutor('https://dns64.dns.google/dns-query'); | ||
$query = new Query('google.com', Message::TYPE_A, Message::CLASS_IN); | ||
$promise = $executor->query($query); | ||
|
||
$answer = null; | ||
$exception = null; | ||
$promise->then(function ($message) use (&$answer) { | ||
$answer = $message; | ||
}, function($reason) use (&$exception) { | ||
$exception = $reason; | ||
}); | ||
|
||
Loop::run(); | ||
|
||
$this->assertNull($exception); | ||
$this->assertNotNull($answer); | ||
$this->assertEquals(Message::RCODE_OK, $answer->rcode); | ||
} | ||
|
||
public function testResolveGoogleViaIPv6IpResolves() | ||
{ | ||
$executor = new DohExecutor('https://[2001:4860:4860::8888]/dns-query'); | ||
$query = new Query('google.com', Message::TYPE_A, Message::CLASS_IN); | ||
$promise = $executor->query($query); | ||
|
||
$answer = null; | ||
$exception = null; | ||
$promise->then(function ($message) use (&$answer) { | ||
$answer = $message; | ||
}, function($reason) use (&$exception) { | ||
$exception = $reason; | ||
}); | ||
|
||
Loop::run(); | ||
|
||
$this->assertNull($exception); | ||
$this->assertNotNull($answer); | ||
$this->assertEquals(Message::RCODE_OK, $answer->rcode); | ||
} | ||
} |