Skip to content
Draft
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:
PHPUnit:
name: PHPUnit (PHP ${{ matrix.php }})
runs-on: ubuntu-20.04
timeout-minutes: 5
strategy:
matrix:
php:
Expand Down
49 changes: 46 additions & 3 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class FunctionalTest extends TestCase
private $connector;
private $client;

private $socket;
private $port;
private $server;

Expand All @@ -26,20 +27,28 @@ class FunctionalTest extends TestCase
*/
public function setUpClientServer()
{
$socket = new SocketServer('127.0.0.1:0');
$address = $socket->getAddress();
$this->socket = new SocketServer('127.0.0.1:0');
$address = $this->socket->getAddress();
if (strpos($address, '://') === false) {
$address = 'tcp://' . $address;
}
$this->port = parse_url($address, PHP_URL_PORT);
$this->assertNotEquals(0, $this->port);

$this->server = new Server();
$this->server->listen($socket);
$this->server->listen($this->socket);
$this->connector = new TcpConnector();
$this->client = new Client('127.0.0.1:' . $this->port, $this->connector);
}

/**
* @after
*/
public function closeSocket()
{
$this->socket->close();
}

/** @group internet */
public function testConnection()
{
Expand Down Expand Up @@ -115,6 +124,8 @@ public function testConnectionSocksOverTls()
$this->client = new Client(str_replace('tls:', 'sockss:', $socket->getAddress()), $this->connector);

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

$socket->close();
}

/**
Expand Down Expand Up @@ -144,6 +155,8 @@ public function testConnectionSocksOverTlsUsesPeerNameFromSocksUri()
$this->client = new Client(str_replace('tls:', 'sockss:', $socket->getAddress()), $this->connector);

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

$socket->close();
}

/** @group internet */
Expand All @@ -164,6 +177,8 @@ public function testConnectionSocksOverUnix()
$this->assertResolveStream($this->client->connect('www.google.com:80'));

unlink($path);

$socket->close();
}

/** @group internet */
Expand All @@ -184,6 +199,8 @@ public function testConnectionSocks5OverUnix()
$this->assertResolveStream($this->client->connect('www.google.com:80'));

unlink($path);

$socket->close();
}

/** @group internet */
Expand All @@ -204,6 +221,8 @@ public function testConnectionSocksWithAuthenticationOverUnix()
$this->assertResolveStream($this->client->connect('www.google.com:80'));

unlink($path);

$socket->close();
}

/** @group internet */
Expand All @@ -218,6 +237,8 @@ public function testConnectionAuthenticationFromUri()
$this->client = new Client('name:[email protected]:' . $this->port, $this->connector);

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

$socket->close();
}

/** @group internet */
Expand All @@ -242,6 +263,8 @@ public function testConnectionAuthenticationCallback()

$this->assertResolveStream($this->client->connect('www.google.com:80'));
$this->assertEquals(1, $called);

$socket->close();
}

/** @group internet */
Expand All @@ -262,6 +285,8 @@ public function testConnectionAuthenticationCallbackWillNotBeInvokedIfClientsSen

$this->assertRejectPromise($this->client->connect('www.google.com:80'));
$this->assertEquals(0, $called);

$socket->close();
}

/** @group internet */
Expand All @@ -276,6 +301,8 @@ public function testConnectionAuthenticationFromUriEncoded()
$this->client = new Client(rawurlencode('name') . ':' . rawurlencode('p@ss:w0rd') . '@127.0.0.1:' . $this->port, $this->connector);

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

$socket->close();
}

/** @group internet */
Expand All @@ -290,6 +317,8 @@ public function testConnectionAuthenticationFromUriWithOnlyUserAndNoPassword()
$this->client = new Client('[email protected]:' . $this->port, $this->connector);

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

$socket->close();
}

/** @group internet */
Expand All @@ -304,6 +333,8 @@ public function testConnectionAuthenticationEmptyPassword()
$this->client = new Client('[email protected]:' . $this->port, $this->connector);

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

$socket->close();
}

/** @group internet */
Expand All @@ -325,6 +356,8 @@ public function testConnectionInvalidNoAuthenticationOverLegacySocks4()
$this->client = new Client('socks4://127.0.0.1:' . $this->port, $this->connector);

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

$socket->close();
}

public function testConnectionInvalidNoAuthentication()
Expand All @@ -338,6 +371,8 @@ public function testConnectionInvalidNoAuthentication()
$this->client = new Client('socks5://127.0.0.1:' . $this->port, $this->connector);

$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, defined('SOCKET_EACCES') ? SOCKET_EACCES : 13);

$socket->close();
}

public function testConnectionInvalidAuthenticationMismatch()
Expand All @@ -351,6 +386,8 @@ public function testConnectionInvalidAuthenticationMismatch()
$this->client = new Client('user:[email protected]:' . $this->port, $this->connector);

$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, defined('SOCKET_EACCES') ? SOCKET_EACCES : 13);

$socket->close();
}

public function testConnectionInvalidAuthenticatorReturnsFalse()
Expand All @@ -366,6 +403,8 @@ public function testConnectionInvalidAuthenticatorReturnsFalse()
$this->client = new Client('user:[email protected]:' . $this->port, $this->connector);

$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, defined('SOCKET_EACCES') ? SOCKET_EACCES : 13);

$socket->close();
}

public function testConnectionInvalidAuthenticatorReturnsPromiseFulfilledWithFalse()
Expand All @@ -381,6 +420,8 @@ public function testConnectionInvalidAuthenticatorReturnsPromiseFulfilledWithFal
$this->client = new Client('user:[email protected]:' . $this->port, $this->connector);

$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, defined('SOCKET_EACCES') ? SOCKET_EACCES : 13);

$socket->close();
}

public function testConnectionInvalidAuthenticatorReturnsPromiseRejected()
Expand All @@ -396,6 +437,8 @@ public function testConnectionInvalidAuthenticatorReturnsPromiseRejected()
$this->client = new Client('user:[email protected]:' . $this->port, $this->connector);

$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, defined('SOCKET_EACCES') ? SOCKET_EACCES : 13);

$socket->close();
}

/** @group internet */
Expand Down