From e35481d25b0cad28b9d6ec3f4a29b4b41b1eb7f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Tue, 28 May 2024 09:41:04 +0200 Subject: [PATCH] Update tests to remove defunct badssl.com --- tests/FunctionalTest.php | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index dc8702f..6ea67fd 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -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; @@ -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 */