dns-over-https/test/SocketTest.php

36 lines
976 B
PHP
Raw Normal View History

2019-06-10 19:32:28 +02:00
<?php
2019-06-11 19:07:51 +02:00
namespace Amp\DoH\Test;
2019-06-10 19:32:28 +02:00
use Amp\Dns;
use Amp\Loop;
use Amp\PHPUnit\TestCase;
use Amp\Promise;
use LibDNS\Messages\Message;
use LibDNS\Messages\MessageTypes;
use LibDNS\Records\QuestionFactory;
2019-06-11 19:07:51 +02:00
use Amp\DoH\Internal\Socket;
use Amp\DoH\Nameserver;
2019-06-10 19:32:28 +02:00
abstract class SocketTest extends TestCase
{
2019-06-11 19:07:51 +02:00
abstract protected function connect(Nameserver $nameserver): Socket;
2019-06-10 19:32:28 +02:00
public function testAsk()
{
Loop::run(function () {
$question = (new QuestionFactory)->create(Dns\Record::A);
$question->setName("google.com");
2019-06-11 19:07:51 +02:00
/** @var DoH\Internal\HttpsSocket $socket */
$socket = $this->connect(new Nameserver('https://mozilla.cloudflare-dns.com/dns-query'));
2019-06-10 19:32:28 +02:00
/** @var Message $result */
$result = yield $socket->ask($question, 5000);
$this->assertInstanceOf(Message::class, $result);
$this->assertSame(MessageTypes::RESPONSE, $result->getType());
});
}
}