dns-over-https/test/HttpsSocketTest.php

32 lines
846 B
PHP
Raw Normal View History

2019-06-11 19:07:51 +02:00
<?php
namespace Amp\DoH\Test;
use Amp\Dns;
2019-06-11 20:07:46 +02:00
use Amp\DoH;
use Amp\DoH\Internal\Socket;
2019-06-11 19:07:51 +02:00
use Amp\DoH\Nameserver;
2019-12-12 22:27:22 +01:00
use Amp\Http\Client\HttpClientBuilder;
2019-06-11 19:07:51 +02:00
use LibDNS\Records\QuestionFactory;
2019-06-11 20:07:46 +02:00
use function Amp\Promise\wait;
2019-06-11 19:07:51 +02:00
class HttpsSocketTest extends SocketTest
{
protected function connect(Nameserver $nameserver): Socket
{
2019-12-12 22:27:22 +01:00
return DoH\Internal\HttpsSocket::connect(HttpClientBuilder::buildDefault(), $nameserver);
2019-06-11 19:07:51 +02:00
}
public function testTimeout()
{
$this->expectException(Dns\TimeoutException::class);
/** @var DoH\Internal\HttpsSocket $socket */
$socket = self::connect(new Nameserver('https://mozilla.cloudflare-dns.com/dns-query'));
$question = (new QuestionFactory)->create(Dns\Record::A);
$question->setName("google.com");
wait($socket->ask($question, 0));
}
}