-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNameserverTest.php
More file actions
84 lines (77 loc) · 3.24 KB
/
Copy pathNameserverTest.php
File metadata and controls
84 lines (77 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php declare(strict_types=1);
namespace Amp\DoH\Test;
use Amp\Dns\DnsConfigException;
use Amp\DoH\DoHNameserver;
use Amp\DoH\DoHNameserverType;
use Amp\PHPUnit\AsyncTestCase;
/** @psalm-suppress PropertyNotSetInConstructor */
class DoHNameserverTest extends AsyncTestCase
{
/**
* @dataProvider provideValidServers
*/
public function testAcceptsValidServers(string $nameserver, DoHNameserverType $type = DoHNameserverType::RFC8484_POST, array $headers = []): void
{
$this->assertInstanceOf(DoHNameserver::class, new DoHNameserver($nameserver, $type, $headers));
}
/**
* @return list<list{0: string, 1?: DoHNameserverType}>
*/
public function provideValidServers()
{
return [
['https://mozilla.cloudflare-dns.com/dns-query'],
['https://mozilla.cloudflare-dns.com/dns-query', DoHNameserverType::RFC8484_POST],
['https://mozilla.cloudflare-dns.com/dns-query', DoHNameserverType::RFC8484_GET],
['https://mozilla.cloudflare-dns.com/dns-query', DoHNameserverType::GOOGLE_JSON],
['https://dns.google/dns-query', DoHNameserverType::RFC8484_GET],
['https://dns.google/dns-query', DoHNameserverType::GOOGLE_JSON],
['https://dns.google/resolve', DoHNameserverType::GOOGLE_JSON],
];
}
/**
* @dataProvider provideInvalidServers
*/
public function testRejectsInvalidServers(string $nameserver, DoHNameserverType $type = DoHNameserverType::RFC8484_POST, array $headers = []): void
{
$this->expectException(DnsConfigException::class);
new DoHNameserver($nameserver, $type, $headers);
}
/**
* @return list<list{0: string, 1?: DoHNameserverType}>
*/
public function provideInvalidServers(): array
{
return [
[''],
["foobar"],
["foobar.com"],
["127.1.1"],
["127.1.1.1.1"],
["126.0.0.5"],
["42"],
["::1"],
["::1:53"],
["[::1]:"],
["[::1]:76235"],
["[::1]:0"],
["[::1]:-1"],
["[::1:51"],
["[::1]:abc"],
['http://mozilla.cloudflare-dns.com/dns-query'],
['http://mozilla.cloudflare-dns.com/dns-query', DoHNameserverType::RFC8484_POST],
['http://mozilla.cloudflare-dns.com/dns-query', DoHNameserverType::RFC8484_GET],
['http://mozilla.cloudflare-dns.com/dns-query', DoHNameserverType::GOOGLE_JSON],
['http://dns.google/dns-query', DoHNameserverType::RFC8484_POST],
['http://dns.google/dns-query', DoHNameserverType::RFC8484_GET],
['http://dns.google/resolve', DoHNameserverType::GOOGLE_JSON],
['mozilla.cloudflare-dns.com/dns-query'],
['mozilla.cloudflare-dns.com/dns-query', DoHNameserverType::RFC8484_POST],
['mozilla.cloudflare-dns.com/dns-query', DoHNameserverType::RFC8484_GET],
['mozilla.cloudflare-dns.com/dns-query', DoHNameserverType::GOOGLE_JSON],
['dns.google/dns-query', DoHNameserverType::RFC8484_POST],
['dns.google/dns-query', DoHNameserverType::RFC8484_GET],
['dns.google/resolve', DoHNameserverType::GOOGLE_JSON],
];
}
}