diff --git a/test/Functional/Porter/Net/Http/HttpConnectorTest.php b/test/Functional/Porter/Net/Http/HttpConnectorTest.php index 4462aa2..47a7a08 100644 --- a/test/Functional/Porter/Net/Http/HttpConnectorTest.php +++ b/test/Functional/Porter/Net/Http/HttpConnectorTest.php @@ -34,8 +34,12 @@ protected function setUp() public function testConnectionToLocalWebserver() { $server = $this->startServer('feedback'); - $response = $this->fetch(new HttpConnector((new HttpOptions)->addHeader($header = 'Foo: Bar'))); - $this->stopServer($server); + + try { + $response = $this->fetch(new HttpConnector((new HttpOptions)->addHeader($header = 'Foo: Bar'))); + } finally { + $this->stopServer($server); + } self::assertRegExp('[\AGET \Q' . self::HOST . self::URI . '\E HTTP/\d+\.\d+$]m', $response); self::assertRegExp("[^$header$]m", $response); @@ -47,12 +51,14 @@ public function testConnectionToLocalWebserver() public function testSslConnectionToLocalWebserver() { $server = $this->startServer('feedback'); - $this->startSsl(); - - $response = $this->fetchViaSsl(self::createUnverifiedSslConnector()); - self::stopSsl(); - $this->stopServer($server); + try { + $certificate = $this->startSsl(); + $response = $this->fetchViaSsl(self::createUnverifiedSslConnector($certificate)); + } finally { + self::stopSsl(); + $this->stopServer($server); + } self::assertRegExp('[\AGET \Q' . self::SSL_HOST . '\E/ HTTP/\d+\.\d+$]m', $response); } @@ -112,7 +118,7 @@ private function startSsl() // Create SSL tunnel process. (new Process( // Generate self-signed SSL certificate in PEM format. - "openssl req -new -x509 -nodes -batch -keyout '$certificate' -out '$certificate' + "openssl req -new -x509 -nodes -subj /CN=::1 -keyout '$certificate' -out '$certificate' { stunnel4 -fd 0 || stunnel -fd 0; } <<. # Disable PID to run as non-root user. @@ -127,9 +133,11 @@ private function startSsl() ." ))->start(); - self::waitForHttpServer(function () { - $this->fetchViaSsl(self::createUnverifiedSslConnector()); + self::waitForHttpServer(function () use ($certificate) { + $this->fetchViaSsl(self::createUnverifiedSslConnector($certificate)); }); + + return $certificate; } private static function stopSsl() @@ -173,14 +181,16 @@ function (\Exception $exception) { } /** + * @param string $certificate + * * @return HttpConnector */ - private static function createUnverifiedSslConnector() + private static function createUnverifiedSslConnector($certificate) { $connector = new HttpConnector($options = new HttpOptions); $options->getSslOptions() - ->setVerifyPeer(false) - ->setVerifyPeerName(false) + ->setCertificateAuthorityFilePath($certificate) +// ->setPeerName('::1') ; return $connector;