init
This commit is contained in:
189
vendor/react/dns/tests/Config/ConfigTest.php
vendored
Executable file
189
vendor/react/dns/tests/Config/ConfigTest.php
vendored
Executable file
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
namespace React\Tests\Dns\Config;
|
||||
|
||||
use React\Tests\Dns\TestCase;
|
||||
use React\Dns\Config\Config;
|
||||
|
||||
class ConfigTest extends TestCase
|
||||
{
|
||||
public function testLoadsSystemDefault()
|
||||
{
|
||||
$config = Config::loadSystemConfigBlocking();
|
||||
|
||||
$this->assertInstanceOf('React\Dns\Config\Config', $config);
|
||||
}
|
||||
|
||||
public function testLoadsDefaultPath()
|
||||
{
|
||||
if (DIRECTORY_SEPARATOR === '\\') {
|
||||
$this->markTestSkipped('Not supported on Windows');
|
||||
}
|
||||
|
||||
$config = Config::loadResolvConfBlocking();
|
||||
|
||||
$this->assertInstanceOf('React\Dns\Config\Config', $config);
|
||||
}
|
||||
|
||||
public function testLoadsFromExplicitPath()
|
||||
{
|
||||
$config = Config::loadResolvConfBlocking(__DIR__ . '/../Fixtures/etc/resolv.conf');
|
||||
|
||||
$this->assertEquals(array('8.8.8.8'), $config->nameservers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException RuntimeException
|
||||
*/
|
||||
public function testLoadThrowsWhenPathIsInvalid()
|
||||
{
|
||||
Config::loadResolvConfBlocking(__DIR__ . '/invalid.conf');
|
||||
}
|
||||
|
||||
public function testParsesSingleEntryFile()
|
||||
{
|
||||
$contents = 'nameserver 8.8.8.8';
|
||||
$expected = array('8.8.8.8');
|
||||
|
||||
$config = Config::loadResolvConfBlocking('data://text/plain;base64,' . base64_encode($contents));
|
||||
$this->assertEquals($expected, $config->nameservers);
|
||||
}
|
||||
|
||||
public function testParsesNameserverEntriesFromAverageFileCorrectly()
|
||||
{
|
||||
$contents = '#
|
||||
# Mac OS X Notice
|
||||
#
|
||||
# This file is not used by the host name and address resolution
|
||||
# or the DNS query routing mechanisms used by most processes on
|
||||
# this Mac OS X system.
|
||||
#
|
||||
# This file is automatically generated.
|
||||
#
|
||||
domain v.cablecom.net
|
||||
nameserver 127.0.0.1
|
||||
nameserver ::1
|
||||
';
|
||||
$expected = array('127.0.0.1', '::1');
|
||||
|
||||
$config = Config::loadResolvConfBlocking('data://text/plain;base64,' . base64_encode($contents));
|
||||
$this->assertEquals($expected, $config->nameservers);
|
||||
}
|
||||
|
||||
public function testParsesEmptyFileWithoutNameserverEntries()
|
||||
{
|
||||
$contents = '';
|
||||
$expected = array();
|
||||
|
||||
$config = Config::loadResolvConfBlocking('data://text/plain;base64,');
|
||||
$this->assertEquals($expected, $config->nameservers);
|
||||
}
|
||||
|
||||
public function testParsesFileAndIgnoresCommentsAndInvalidNameserverEntries()
|
||||
{
|
||||
$contents = '
|
||||
# nameserver 1.2.3.4
|
||||
; nameserver 2.3.4.5
|
||||
|
||||
nameserver 3.4.5.6 # nope
|
||||
nameserver 4.5.6.7 5.6.7.8
|
||||
nameserver 6.7.8.9
|
||||
NameServer 7.8.9.10
|
||||
';
|
||||
$expected = array();
|
||||
|
||||
$config = Config::loadResolvConfBlocking('data://text/plain;base64,' . base64_encode($contents));
|
||||
$this->assertEquals($expected, $config->nameservers);
|
||||
}
|
||||
|
||||
public function testLoadsFromWmicOnWindows()
|
||||
{
|
||||
if (DIRECTORY_SEPARATOR !== '\\') {
|
||||
$this->markTestSkipped('Only on Windows');
|
||||
}
|
||||
|
||||
$config = Config::loadWmicBlocking();
|
||||
|
||||
$this->assertInstanceOf('React\Dns\Config\Config', $config);
|
||||
}
|
||||
|
||||
public function testLoadsSingleEntryFromWmicOutput()
|
||||
{
|
||||
$contents = '
|
||||
Node,DNSServerSearchOrder
|
||||
ACE,
|
||||
ACE,{192.168.2.1}
|
||||
ACE,
|
||||
';
|
||||
$expected = array('192.168.2.1');
|
||||
|
||||
$config = Config::loadWmicBlocking($this->echoCommand($contents));
|
||||
|
||||
$this->assertEquals($expected, $config->nameservers);
|
||||
}
|
||||
|
||||
public function testLoadsEmptyListFromWmicOutput()
|
||||
{
|
||||
$contents = '
|
||||
Node,DNSServerSearchOrder
|
||||
ACE,
|
||||
';
|
||||
$expected = array();
|
||||
|
||||
$config = Config::loadWmicBlocking($this->echoCommand($contents));
|
||||
|
||||
$this->assertEquals($expected, $config->nameservers);
|
||||
}
|
||||
|
||||
public function testLoadsSingleEntryForMultipleNicsFromWmicOutput()
|
||||
{
|
||||
$contents = '
|
||||
Node,DNSServerSearchOrder
|
||||
ACE,
|
||||
ACE,{192.168.2.1}
|
||||
ACE,
|
||||
ACE,{192.168.2.2}
|
||||
ACE,
|
||||
';
|
||||
$expected = array('192.168.2.1', '192.168.2.2');
|
||||
|
||||
$config = Config::loadWmicBlocking($this->echoCommand($contents));
|
||||
|
||||
$this->assertEquals($expected, $config->nameservers);
|
||||
}
|
||||
|
||||
public function testLoadsMultipleEntriesForSingleNicWithSemicolonFromWmicOutput()
|
||||
{
|
||||
$contents = '
|
||||
Node,DNSServerSearchOrder
|
||||
ACE,
|
||||
ACE,{192.168.2.1;192.168.2.2}
|
||||
ACE,
|
||||
';
|
||||
$expected = array('192.168.2.1', '192.168.2.2');
|
||||
|
||||
$config = Config::loadWmicBlocking($this->echoCommand($contents));
|
||||
|
||||
$this->assertEquals($expected, $config->nameservers);
|
||||
}
|
||||
|
||||
public function testLoadsMultipleEntriesForSingleNicWithQuotesFromWmicOutput()
|
||||
{
|
||||
$contents = '
|
||||
Node,DNSServerSearchOrder
|
||||
ACE,
|
||||
ACE,{"192.168.2.1","192.168.2.2"}
|
||||
ACE,
|
||||
';
|
||||
$expected = array('192.168.2.1', '192.168.2.2');
|
||||
|
||||
$config = Config::loadWmicBlocking($this->echoCommand($contents));
|
||||
|
||||
$this->assertEquals($expected, $config->nameservers);
|
||||
}
|
||||
|
||||
private function echoCommand($output)
|
||||
{
|
||||
return 'echo ' . escapeshellarg($output);
|
||||
}
|
||||
}
|
||||
70
vendor/react/dns/tests/Config/FilesystemFactoryTest.php
vendored
Executable file
70
vendor/react/dns/tests/Config/FilesystemFactoryTest.php
vendored
Executable file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace React\Test\Dns\Config;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use React\Dns\Config\FilesystemFactory;
|
||||
|
||||
class FilesystemFactoryTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function parseEtcResolvConfShouldParseCorrectly()
|
||||
{
|
||||
$contents = '#
|
||||
# Mac OS X Notice
|
||||
#
|
||||
# This file is not used by the host name and address resolution
|
||||
# or the DNS query routing mechanisms used by most processes on
|
||||
# this Mac OS X system.
|
||||
#
|
||||
# This file is automatically generated.
|
||||
#
|
||||
domain v.cablecom.net
|
||||
nameserver 127.0.0.1
|
||||
nameserver 8.8.8.8
|
||||
';
|
||||
$expected = array('127.0.0.1', '8.8.8.8');
|
||||
|
||||
$capturedConfig = null;
|
||||
|
||||
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
|
||||
$factory = new FilesystemFactory($loop);
|
||||
$factory->parseEtcResolvConf($contents)->then(function ($config) use (&$capturedConfig) {
|
||||
$capturedConfig = $config;
|
||||
});
|
||||
|
||||
$this->assertNotNull($capturedConfig);
|
||||
$this->assertSame($expected, $capturedConfig->nameservers);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function createShouldLoadStuffFromFilesystem()
|
||||
{
|
||||
$this->markTestIncomplete('Filesystem API is incomplete');
|
||||
|
||||
$expected = array('8.8.8.8');
|
||||
|
||||
$triggerListener = null;
|
||||
$capturedConfig = null;
|
||||
|
||||
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
|
||||
$loop
|
||||
->expects($this->once())
|
||||
->method('addReadStream')
|
||||
->will($this->returnCallback(function ($stream, $listener) use (&$triggerListener) {
|
||||
$triggerListener = function () use ($stream, $listener) {
|
||||
call_user_func($listener, $stream);
|
||||
};
|
||||
}));
|
||||
|
||||
$factory = new FilesystemFactory($loop);
|
||||
$factory->create(__DIR__.'/../Fixtures/etc/resolv.conf')->then(function ($config) use (&$capturedConfig) {
|
||||
$capturedConfig = $config;
|
||||
});
|
||||
|
||||
$triggerListener();
|
||||
|
||||
$this->assertNotNull($capturedConfig);
|
||||
$this->assertSame($expected, $capturedConfig->nameservers);
|
||||
}
|
||||
}
|
||||
170
vendor/react/dns/tests/Config/HostsFileTest.php
vendored
Executable file
170
vendor/react/dns/tests/Config/HostsFileTest.php
vendored
Executable file
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
namespace React\Tests\Dns\Config;
|
||||
|
||||
use React\Tests\Dns\TestCase;
|
||||
use React\Dns\Config\HostsFile;
|
||||
|
||||
class HostsFileTest extends TestCase
|
||||
{
|
||||
public function testLoadsFromDefaultPath()
|
||||
{
|
||||
$hosts = HostsFile::loadFromPathBlocking();
|
||||
|
||||
$this->assertInstanceOf('React\Dns\Config\HostsFile', $hosts);
|
||||
}
|
||||
|
||||
public function testDefaultShouldHaveLocalhostMapped()
|
||||
{
|
||||
if (DIRECTORY_SEPARATOR === '\\') {
|
||||
$this->markTestSkipped('Not supported on Windows');
|
||||
}
|
||||
|
||||
$hosts = HostsFile::loadFromPathBlocking();
|
||||
|
||||
$this->assertContains('127.0.0.1', $hosts->getIpsForHost('localhost'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException RuntimeException
|
||||
*/
|
||||
public function testLoadThrowsForInvalidPath()
|
||||
{
|
||||
HostsFile::loadFromPathBlocking('does/not/exist');
|
||||
}
|
||||
|
||||
public function testContainsSingleLocalhostEntry()
|
||||
{
|
||||
$hosts = new HostsFile('127.0.0.1 localhost');
|
||||
|
||||
$this->assertEquals(array('127.0.0.1'), $hosts->getIpsForHost('localhost'));
|
||||
$this->assertEquals(array(), $hosts->getIpsForHost('example.com'));
|
||||
}
|
||||
|
||||
public function testNonIpReturnsNothingForInvalidHosts()
|
||||
{
|
||||
$hosts = new HostsFile('a b');
|
||||
|
||||
$this->assertEquals(array(), $hosts->getIpsForHost('a'));
|
||||
$this->assertEquals(array(), $hosts->getIpsForHost('b'));
|
||||
}
|
||||
|
||||
public function testIgnoresIpv6ZoneId()
|
||||
{
|
||||
$hosts = new HostsFile('fe80::1%lo0 localhost');
|
||||
|
||||
$this->assertEquals(array('fe80::1'), $hosts->getIpsForHost('localhost'));
|
||||
}
|
||||
|
||||
public function testSkipsComments()
|
||||
{
|
||||
$hosts = new HostsFile('# start' . PHP_EOL .'#127.0.0.1 localhost' . PHP_EOL . '127.0.0.2 localhost # example.com');
|
||||
|
||||
$this->assertEquals(array('127.0.0.2'), $hosts->getIpsForHost('localhost'));
|
||||
$this->assertEquals(array(), $hosts->getIpsForHost('example.com'));
|
||||
}
|
||||
|
||||
public function testContainsSingleLocalhostEntryWithCaseIgnored()
|
||||
{
|
||||
$hosts = new HostsFile('127.0.0.1 LocalHost');
|
||||
|
||||
$this->assertEquals(array('127.0.0.1'), $hosts->getIpsForHost('LOCALHOST'));
|
||||
}
|
||||
|
||||
public function testEmptyFileContainsNothing()
|
||||
{
|
||||
$hosts = new HostsFile('');
|
||||
|
||||
$this->assertEquals(array(), $hosts->getIpsForHost('example.com'));
|
||||
}
|
||||
|
||||
public function testSingleEntryWithMultipleNames()
|
||||
{
|
||||
$hosts = new HostsFile('127.0.0.1 localhost example.com');
|
||||
|
||||
$this->assertEquals(array('127.0.0.1'), $hosts->getIpsForHost('example.com'));
|
||||
$this->assertEquals(array('127.0.0.1'), $hosts->getIpsForHost('localhost'));
|
||||
}
|
||||
|
||||
public function testMergesEntriesOverMultipleLines()
|
||||
{
|
||||
$hosts = new HostsFile("127.0.0.1 localhost\n127.0.0.2 localhost\n127.0.0.3 a localhost b\n127.0.0.4 a localhost");
|
||||
|
||||
$this->assertEquals(array('127.0.0.1', '127.0.0.2', '127.0.0.3', '127.0.0.4'), $hosts->getIpsForHost('localhost'));
|
||||
}
|
||||
|
||||
public function testMergesIpv4AndIpv6EntriesOverMultipleLines()
|
||||
{
|
||||
$hosts = new HostsFile("127.0.0.1 localhost\n::1 localhost");
|
||||
|
||||
$this->assertEquals(array('127.0.0.1', '::1'), $hosts->getIpsForHost('localhost'));
|
||||
}
|
||||
|
||||
public function testReverseLookup()
|
||||
{
|
||||
$hosts = new HostsFile('127.0.0.1 localhost');
|
||||
|
||||
$this->assertEquals(array('localhost'), $hosts->getHostsForIp('127.0.0.1'));
|
||||
$this->assertEquals(array(), $hosts->getHostsForIp('192.168.1.1'));
|
||||
}
|
||||
|
||||
public function testReverseSkipsComments()
|
||||
{
|
||||
$hosts = new HostsFile("# start\n#127.0.0.1 localhosted\n127.0.0.2\tlocalhost\t# example.com\n\t127.0.0.3\t\texample.org\t\t");
|
||||
|
||||
$this->assertEquals(array(), $hosts->getHostsForIp('127.0.0.1'));
|
||||
$this->assertEquals(array('localhost'), $hosts->getHostsForIp('127.0.0.2'));
|
||||
$this->assertEquals(array('example.org'), $hosts->getHostsForIp('127.0.0.3'));
|
||||
}
|
||||
|
||||
public function testReverseNonIpReturnsNothing()
|
||||
{
|
||||
$hosts = new HostsFile('127.0.0.1 localhost');
|
||||
|
||||
$this->assertEquals(array(), $hosts->getHostsForIp('localhost'));
|
||||
$this->assertEquals(array(), $hosts->getHostsForIp('127.0.0.1.1'));
|
||||
}
|
||||
|
||||
public function testReverseNonIpReturnsNothingForInvalidHosts()
|
||||
{
|
||||
$hosts = new HostsFile('a b');
|
||||
|
||||
$this->assertEquals(array(), $hosts->getHostsForIp('a'));
|
||||
$this->assertEquals(array(), $hosts->getHostsForIp('b'));
|
||||
}
|
||||
|
||||
public function testReverseLookupReturnsLowerCaseHost()
|
||||
{
|
||||
$hosts = new HostsFile('127.0.0.1 LocalHost');
|
||||
|
||||
$this->assertEquals(array('localhost'), $hosts->getHostsForIp('127.0.0.1'));
|
||||
}
|
||||
|
||||
public function testReverseLookupChecksNormalizedIpv6()
|
||||
{
|
||||
$hosts = new HostsFile('FE80::00a1 localhost');
|
||||
|
||||
$this->assertEquals(array('localhost'), $hosts->getHostsForIp('fe80::A1'));
|
||||
}
|
||||
|
||||
public function testReverseLookupIgnoresIpv6ZoneId()
|
||||
{
|
||||
$hosts = new HostsFile('fe80::1%lo0 localhost');
|
||||
|
||||
$this->assertEquals(array('localhost'), $hosts->getHostsForIp('fe80::1'));
|
||||
}
|
||||
|
||||
public function testReverseLookupReturnsMultipleHostsOverSingleLine()
|
||||
{
|
||||
$hosts = new HostsFile("::1 ip6-localhost ip6-loopback");
|
||||
|
||||
$this->assertEquals(array('ip6-localhost', 'ip6-loopback'), $hosts->getHostsForIp('::1'));
|
||||
}
|
||||
|
||||
public function testReverseLookupReturnsMultipleHostsOverMultipleLines()
|
||||
{
|
||||
$hosts = new HostsFile("::1 ip6-localhost\n::1 ip6-loopback");
|
||||
|
||||
$this->assertEquals(array('ip6-localhost', 'ip6-loopback'), $hosts->getHostsForIp('::1'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user