-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDoHConfigTest.php
More file actions
158 lines (147 loc) · 4.71 KB
/
Copy pathDoHConfigTest.php
File metadata and controls
158 lines (147 loc) · 4.71 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php declare(strict_types=1);
namespace Amp\DoH\Test;
use Amp\Cache\Cache;
use Amp\Cache\LocalCache;
use Amp\Dns\DnsConfigException;
use Amp\Dns\DnsConfigLoader;
use Amp\Dns\DnsResolver;
use Amp\Dns\Rfc1035StubDnsResolver;
use Amp\Dns\UnixDnsConfigLoader;
use Amp\Dns\WindowsDnsConfigLoader;
use Amp\DoH\DoHConfig;
use Amp\DoH\DoHNameserver;
use Amp\DoH\DoHNameserverType;
use Amp\Http\Client\HttpClient;
use Amp\Http\Client\HttpClientBuilder;
use Amp\PHPUnit\AsyncTestCase;
/** @psalm-suppress PropertyNotSetInConstructor */
class DoHConfigTest extends AsyncTestCase
{
/**
* @param non-empty-list<DoHNameserver> $nameservers Valid server array.
*
* @dataProvider provideValidServers
*/
public function testAcceptsValidServers(array $nameservers): void
{
$this->assertInstanceOf(DoHConfig::class, new DoHConfig($nameservers));
}
/**
* @return list{list{list{DoHNameserver}}, list{list{DoHNameserver}}, list{list{DoHNameserver}}, list{list{DoHNameserver}}, list{list{DoHNameserver}}, list{list{DoHNameserver, DoHNameserver}}}
*/
public function provideValidServers(): array
{
return [
[[new DoHNameserver('https://cloudflare-dns.com/dns-query')]],
[[new DoHNameserver('https://cloudflare-dns.com/dns-query', DoHNameserverType::RFC8484_POST)]],
[[new DoHNameserver('https://cloudflare-dns.com/dns-query', DoHNameserverType::RFC8484_GET)]],
[[new DoHNameserver('https://cloudflare-dns.com/dns-query', DoHNameserverType::GOOGLE_JSON)]],
[[new DoHNameserver('https://dns.google/resolve', DoHNameserverType::GOOGLE_JSON)]],
[[new DoHNameserver('https://cloudflare-dns.com/dns-query', DoHNameserverType::GOOGLE_JSON), new DoHNameserver('https://dns.google/resolve', DoHNameserverType::GOOGLE_JSON)]],
];
}
/**
* @param list<mixed> $nameservers Invalid server array.
*
* @dataProvider provideInvalidServers
*/
public function testRejectsInvalidServers(array $nameservers): void
{
$this->expectException(DnsConfigException::class);
new DoHConfig($nameservers);
}
/**
* @return list<list{mixed}>
*/
public function provideInvalidServers()
{
return [
[[]],
[[42]],
[[null]],
[[true]],
[["foobar"]],
[["foobar.com"]],
[["127.1.1:53"]],
[["127.1.1"]],
[["127.1.1.1.1"]],
[["126.0.0.5", "foobar"]],
[["42"]],
[["::1"]],
[["::1:53"]],
[["[::1]:53"]],
[["[::1]:"]],
[["[::1]:76235"]],
[["[::1]:0"]],
[["[::1]:-1"]],
[["[::1:51"]],
[["[::1]:abc"]],
];
}
/**
* @dataProvider provideValidHttpClient
*/
public function testAcceptsValidHttpClient(HttpClient $client): void
{
$this->assertInstanceOf(DoHConfig::class, new DoHConfig([new DoHNameserver('https://cloudflare-dns.com/dns-query')], $client));
}
/**
* @return list<list{HttpClient}>
*/
public function provideValidHttpClient(): array
{
return [
[HttpClientBuilder::buildDefault()],
];
}
/**
* @dataProvider provideValidResolver
*/
public function testAcceptsValidResolver(DnsResolver $resolver): void
{
$this->assertInstanceOf(DoHConfig::class, new DoHConfig([new DoHNameserver('https://cloudflare-dns.com/dns-query')], null, $resolver));
}
/**
* @return list<list{DnsResolver}>
*/
public function provideValidResolver()
{
return [
[new Rfc1035StubDnsResolver()],
];
}
/**
* @dataProvider provideValidConfigLoader
*/
public function testAcceptsValidConfigLoader(DnsConfigLoader $configLoader): void
{
$this->assertInstanceOf(DoHConfig::class, new DoHConfig([new DoHNameserver('https://cloudflare-dns.com/dns-query')], null, null, $configLoader));
}
/**
* @return list<list{DnsConfigLoader}>
*/
public function provideValidConfigLoader()
{
return [
[\stripos(PHP_OS, "win") === 0
? new WindowsDnsConfigLoader()
: new UnixDnsConfigLoader()],
];
}
/**
* @dataProvider provideValidCache
*/
public function testAcceptsValidCache(Cache $cache): void
{
$this->assertInstanceOf(DoHConfig::class, new DoHConfig([new DoHNameserver('https://cloudflare-dns.com/dns-query')], null, null, null, $cache));
}
/**
* @return list<list{Cache}>
*/
public function provideValidCache()
{
return [
[new LocalCache()],
];
}
}