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

Update tests to remove defunct badssl.com #116

Merged
merged 1 commit into from
May 28, 2024
Merged
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
29 changes: 23 additions & 6 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Clue\React\Socks\Client;
use Clue\React\Socks\Server;
use React\EventLoop\Loop;
use React\Promise\Promise;
use React\Socket\Connector;
use React\Socket\SecureConnector;
use React\Socket\SocketServer;
Expand Down Expand Up @@ -440,28 +441,44 @@ public function testSecureConnectorOkay()
$this->assertResolveStream($ssl->connect('www.google.com:443'));
}

/** @group internet */
public function testSecureConnectorToBadSslWithVerifyFails()
public function testSecureConnectionToTlsServerWithSelfSignedCertificateFailsWithVerifyPeer()
{
if (!function_exists('stream_socket_enable_crypto')) {
$this->markTestSkipped('Required function does not exist in your environment (HHVM?)');
}

$socket = new SocketServer('tls://127.0.0.1:0', array(
'tls' => array(
'local_cert' => __DIR__ . '/../examples/localhost.pem',
)
));
$socket->on('connection', $this->expectCallableNever());

$ssl = new SecureConnector($this->client, null, array('verify_peer' => true));

$this->assertRejectPromise($ssl->connect('self-signed.badssl.com:443'));
$this->assertRejectPromise($ssl->connect($socket->getAddress()));
}

/** @group internet */
public function testSecureConnectorToBadSslWithoutVerifyWorks()
public function testSecureConnectionToTlsServerWithSelfSignedCertificateWorksWithoutVerifyPeer()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('Not supported on HHVM');
}

$socket = new SocketServer('tls://127.0.0.1:0', array(
'tls' => array(
'local_cert' => __DIR__ . '/../examples/localhost.pem',
)
));
$socket->on('connection', $this->expectCallableOnce());
$promise = new Promise(function ($resolve) use ($socket) {
$socket->on('connection', $resolve);
});

$ssl = new SecureConnector($this->client, null, array('verify_peer' => false));

$this->assertResolveStream($ssl->connect('self-signed.badssl.com:443'));
$this->assertResolveStream($ssl->connect($socket->getAddress()));
$this->assertResolveStream($promise);
}

/** @group internet */
Expand Down