dns-over-https/test/Rfc8484StubResolverTest.php

70 lines
2.3 KiB
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
2019-06-11 20:07:46 +02:00
use Amp\Dns\ConfigException;
2019-06-10 19:32:28 +02:00
use Amp\Dns\DnsException;
use Amp\Dns\InvalidNameException;
use Amp\Dns\Record;
2019-06-11 20:07:46 +02:00
use Amp\Dns\Rfc1035StubResolver;
2019-06-11 19:07:51 +02:00
use Amp\DoH;
use Amp\DoH\Rfc8484StubResolver;
2019-06-10 19:32:28 +02:00
use Amp\Loop;
use Amp\PHPUnit\TestCase;
2019-06-11 19:07:51 +02:00
class Rfc8484StubResolverTest extends TestCase
2019-06-10 19:32:28 +02:00
{
2019-06-11 19:07:51 +02:00
public function getResolver()
{
$DohConfig = new DoH\DoHConfig([new DoH\Nameserver('https://mozilla.cloudflare-dns.com/dns-query')]);
return new Rfc8484StubResolver($DohConfig);
}
2019-06-10 19:32:28 +02:00
public function testResolveSecondParameterAcceptedValues()
{
Loop::run(function () {
$this->expectException(\Error::class);
2019-06-11 19:07:51 +02:00
$this->getResolver()->resolve("abc.de", Record::TXT);
2019-06-10 19:32:28 +02:00
});
}
public function testIpAsArgumentWithIPv4Restriction()
{
Loop::run(function () {
$this->expectException(DnsException::class);
2019-06-11 19:07:51 +02:00
yield $this->getResolver()->resolve("::1", Record::A);
2019-06-10 19:32:28 +02:00
});
}
public function testIpAsArgumentWithIPv6Restriction()
{
Loop::run(function () {
$this->expectException(DnsException::class);
2019-06-11 19:07:51 +02:00
yield $this->getResolver()->resolve("127.0.0.1", Record::AAAA);
2019-06-10 19:32:28 +02:00
});
}
public function testInvalidName()
{
Loop::run(function () {
$this->expectException(InvalidNameException::class);
2019-06-11 19:07:51 +02:00
yield $this->getResolver()->resolve("go@gle.com", Record::A);
2019-06-10 19:32:28 +02:00
});
}
2019-06-11 19:56:34 +02:00
public function testValidSubResolver()
{
Loop::run(function () {
$DohConfig = new DoH\DoHConfig([new DoH\Nameserver('https://mozilla.cloudflare-dns.com/dns-query')], null, new Rfc1035StubResolver());
$this->assertInstanceOf(Rfc8484StubResolver::class, new Rfc8484StubResolver($DohConfig));
});
}
public function testInvalidSubResolver()
{
Loop::run(function () {
$DohConfig = new DoH\DoHConfig([new DoH\Nameserver('https://mozilla.cloudflare-dns.com/dns-query')]);
$DohConfig = new DoH\DoHConfig([new DoH\Nameserver('https://mozilla.cloudflare-dns.com/dns-query')], null, new Rfc8484StubResolver($DohConfig));
$this->expectException(ConfigException::class);
new Rfc8484StubResolver($DohConfig);
});
}
2019-06-10 19:32:28 +02:00
}