com php-src: Fix test broken if openssl is compiled without sslv2: ext/openssl/tests/streams_crypto_method.phpt

From: Date: Fri, 14 Feb 2014 20:39:02 +0000
Subject: com php-src: Fix test broken if openssl is compiled without sslv2: ext/openssl/tests/streams_crypto_method.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-75980@lists.php.net to get a copy of this message
Commit: f073588e7529ea12d3023369ddad78167b00e31b Author: Daniel Lowrey <rdlowrey@php.net> Fri, 14 Feb 2014 13:39:02 -0700 Parents: 81c29af865a96af3e12a648d5771f7be6920aa2c Branches: PHP-5.6 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=f073588e7529ea12d3023369ddad78167b00e31b Log: Fix test broken if openssl is compiled without sslv2 Changed paths: M ext/openssl/tests/streams_crypto_method.phpt Diff: diff --git a/ext/openssl/tests/streams_crypto_method.phpt b/ext/openssl/tests/streams_crypto_method.phpt index 981f56b...b7b8e25 100644 --- a/ext/openssl/tests/streams_crypto_method.phpt +++ b/ext/openssl/tests/streams_crypto_method.phpt @@ -1,42 +1,48 @@ --TEST-- Specific crypto method for ssl:// transports. --SKIPIF-- -<?php +<?php if (!extension_loaded('openssl')) die('skip, openssl required'); if (!extension_loaded('pcntl')) die('skip, pcntl required'); ?> --FILE-- <?php -function client($port, $method) { - $ctx = stream_context_create(); - stream_context_set_option($ctx, 'ssl', 'crypto_method', $method); - stream_context_set_option($ctx, 'ssl', 'verify_peer', false); - - $fp = @fopen('https://127.0.0.1:' . $port . '/', 'r', false, $ctx); - if ($fp) { - fpassthru($fp); - fclose($fp); - } -} - -function server($port, $transport) { - $context = stream_context_create(); - - stream_context_set_option($context, 'ssl', 'local_cert', dirname(__FILE__) . '/streams_crypto_method.pem'); - stream_context_set_option($context, 'ssl', 'allow_self_signed', true); - stream_context_set_option($context, 'ssl', 'verify_peer', false); - - $server = stream_socket_server($transport . '127.0.0.1:' . $port, $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context); - - $client = @stream_socket_accept($server); - - if ($client) { - $in = ''; - while (!preg_match('/\r?\n\r?\n/', $in)) { - $in .= fread($client, 2048); - } - - $response = <<<EOS +$serverCtx = stream_context_create(['ssl' => [ + 'local_cert' => dirname(__FILE__) . '/streams_crypto_method.pem', + 'allow_self_signed' => true, + 'verify_peer' => false +]]); +$serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN; +$server = stream_socket_server('sslv3://127.0.0.1:12345', $errno, $errstr, $serverFlags, $serverCtx); + +$pid = pcntl_fork(); + +if ($pid == -1) { + die('could not fork'); +} else if ($pid) { + $clientCtx = stream_context_create(['ssl' => [ + 'crypto_method' => STREAM_CRYPTO_METHOD_SSLv3_CLIENT, + 'verify_peer' => false + ]]); + + $fp = fopen('https://127.0.0.1:12345/', 'r', false, $clientCtx); + + if ($fp) { + fpassthru($fp); + fclose($fp); + } +} else { + @pcntl_wait($status); + + $client = @stream_socket_accept($server); + + if ($client) { + $in = ''; + while (!preg_match('/\r?\n\r?\n/', $in)) { + $in .= fread($client, 2048); + } + + $response = <<<EOS HTTP/1.1 200 OK Content-Type: text/plain Content-Length: 13 @@ -45,34 +51,13 @@ Connection: close Hello World! EOS; + fwrite($client, $response); + fclose($client); - fwrite($client, $response); - fclose($client); - exit(); - } + exit(); + } } - -$port1 = rand(15000, 16000); -$port2 = rand(16001, 17000); - -$pid1 = pcntl_fork(); -$pid2 = pcntl_fork(); - -if ($pid1 == 0 && $pid2 != 0) { - server($port1, 'sslv3://'); - exit; -} - -if ($pid1 != 0 && $pid2 == 0) { - server($port2, 'sslv3://'); - exit; -} - -client($port1, STREAM_CRYPTO_METHOD_SSLv3_CLIENT); -client($port2, STREAM_CRYPTO_METHOD_SSLv2_CLIENT); - -pcntl_waitpid($pid1, $status); -pcntl_waitpid($pid2, $status); ?> --EXPECTF-- Hello World! +

« previous php.cvs (#75980) next »