Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally exclude tests that rely on working internet connection #66

Merged
merged 1 commit into from
Sep 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,13 @@ To run the test suite, go to the project root and run:
$ php vendor/bin/phpunit
```

The test suite contains a number of tests that rely on a working internet
connection, alternatively you can also run it like this:

```bash
$ php vendor/bin/phpunit --exclude-group internet
```

## License

MIT, see LICENSE
Expand Down
23 changes: 22 additions & 1 deletion tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use Clue\React\Socks\Client;
use Clue\React\Socks\Server;
use Clue\React\Block;
use React\Promise\PromiseInterface;
use React\Socket\TimeoutConnector;
use React\Socket\SecureConnector;
use React\Socket\TcpConnector;
Expand Down Expand Up @@ -34,11 +33,13 @@ public function setUp()
$this->client = new Client('127.0.0.1:' . $this->port, $this->connector);
}

/** @group internet */
public function testConnection()
{
$this->assertResolveStream($this->client->connect('www.google.com:80'));
}

/** @group internet */
public function testConnectionInvalid()
{
$this->assertRejectPromise($this->client->connect('www.google.com.invalid:80'));
Expand All @@ -53,13 +54,15 @@ public function testConnectionWithIpViaSocks4()
$this->assertResolveStream($this->client->connect('127.0.0.1:' . $this->port));
}

/** @group internet */
public function testConnectionWithHostnameViaSocks4Fails()
{
$this->client = new Client('socks4://127.0.0.1:' . $this->port, $this->connector);

$this->assertRejectPromise($this->client->connect('www.google.com:80'));
}

/** @group internet */
public function testConnectionWithInvalidPortFails()
{
$this->assertRejectPromise($this->client->connect('www.google.com:100000'));
Expand All @@ -72,6 +75,7 @@ public function testConnectionWithIpv6ViaSocks4Fails()
$this->assertRejectPromise($this->client->connect('[::1]:80'));
}

/** @group internet */
public function testConnectionSocks4a()
{
$this->server->setProtocolVersion('4a');
Expand All @@ -80,6 +84,7 @@ public function testConnectionSocks4a()
$this->assertResolveStream($this->client->connect('www.google.com:80'));
}

/** @group internet */
public function testConnectionSocks5()
{
$this->server->setProtocolVersion(5);
Expand All @@ -88,6 +93,7 @@ public function testConnectionSocks5()
$this->assertResolveStream($this->client->connect('www.google.com:80'));
}

/** @group internet */
public function testConnectionAuthenticationFromUri()
{
$this->server->setAuthArray(array('name' => 'pass'));
Expand All @@ -97,6 +103,7 @@ public function testConnectionAuthenticationFromUri()
$this->assertResolveStream($this->client->connect('www.google.com:80'));
}

/** @group internet */
public function testConnectionAuthenticationCallback()
{
$called = 0;
Expand All @@ -116,6 +123,7 @@ public function testConnectionAuthenticationCallback()
$this->assertEquals(1, $called);
}

/** @group internet */
public function testConnectionAuthenticationCallbackWillNotBeInvokedIfClientsSendsNoAuth()
{
$called = 0;
Expand All @@ -131,6 +139,7 @@ public function testConnectionAuthenticationCallbackWillNotBeInvokedIfClientsSen
$this->assertEquals(0, $called);
}

/** @group internet */
public function testConnectionAuthenticationFromUriEncoded()
{
$this->server->setAuthArray(array('name' => 'p@ss:w0rd'));
Expand All @@ -140,6 +149,7 @@ public function testConnectionAuthenticationFromUriEncoded()
$this->assertResolveStream($this->client->connect('www.google.com:80'));
}

/** @group internet */
public function testConnectionAuthenticationFromUriWithOnlyUserAndNoPassword()
{
$this->server->setAuthArray(array('empty' => ''));
Expand All @@ -149,6 +159,7 @@ public function testConnectionAuthenticationFromUriWithOnlyUserAndNoPassword()
$this->assertResolveStream($this->client->connect('www.google.com:80'));
}

/** @group internet */
public function testConnectionAuthenticationEmptyPassword()
{
$this->server->setAuthArray(array('user' => ''));
Expand All @@ -157,6 +168,7 @@ public function testConnectionAuthenticationEmptyPassword()
$this->assertResolveStream($this->client->connect('www.google.com:80'));
}

/** @group internet */
public function testConnectionAuthenticationUnused()
{
$this->client = new Client('name:[email protected]:' . $this->port, $this->connector);
Expand Down Expand Up @@ -198,16 +210,19 @@ public function testConnectionInvalidAuthenticationMismatch()
$this->assertRejectPromise($this->client->connect('www.google.com:80'), '', SOCKET_EACCES);
}

/** @group internet */
public function testConnectorOkay()
{
$this->assertResolveStream($this->client->connect('www.google.com:80'));
}

/** @group internet */
public function testConnectorInvalidDomain()
{
$this->assertRejectPromise($this->client->connect('www.google.commm:80'));
}

/** @group internet */
public function testConnectorCancelConnection()
{
$promise = $this->client->connect('www.google.com:80');
Expand All @@ -216,6 +231,7 @@ public function testConnectorCancelConnection()
$this->assertRejectPromise($promise);
}

/** @group internet */
public function testConnectorInvalidUnboundPortTimeout()
{
// time out the connection attempt in 0.1s (as expected)
Expand All @@ -224,6 +240,7 @@ public function testConnectorInvalidUnboundPortTimeout()
$this->assertRejectPromise($tcp->connect('www.google.com:8080'));
}

/** @group internet */
public function testSecureConnectorOkay()
{
if (!function_exists('stream_socket_enable_crypto')) {
Expand All @@ -235,6 +252,7 @@ public function testSecureConnectorOkay()
$this->assertResolveStream($ssl->connect('www.google.com:443'));
}

/** @group internet */
public function testSecureConnectorToBadSslWithVerifyFails()
{
if (!function_exists('stream_socket_enable_crypto')) {
Expand All @@ -246,6 +264,7 @@ public function testSecureConnectorToBadSslWithVerifyFails()
$this->assertRejectPromise($ssl->connect('self-signed.badssl.com:443'));
}

/** @group internet */
public function testSecureConnectorToBadSslWithoutVerifyWorks()
{
if (!function_exists('stream_socket_enable_crypto')) {
Expand All @@ -257,6 +276,7 @@ public function testSecureConnectorToBadSslWithoutVerifyWorks()
$this->assertResolveStream($ssl->connect('self-signed.badssl.com:443'));
}

/** @group internet */
public function testSecureConnectorInvalidPlaintextIsNotSsl()
{
if (!function_exists('stream_socket_enable_crypto')) {
Expand All @@ -268,6 +288,7 @@ public function testSecureConnectorInvalidPlaintextIsNotSsl()
$this->assertRejectPromise($ssl->connect('www.google.com:80'));
}

/** @group internet */
public function testSecureConnectorInvalidUnboundPortTimeout()
{
$ssl = new SecureConnector($this->client, $this->loop);
Expand Down