xref: /php-src/ext/openssl/tests/bug46127.phpt (revision 74859783)
1--TEST--
2#46127 php_openssl_tcp_sockop_accept forgets to set context on accepted stream
3--EXTENSIONS--
4openssl
5--SKIPIF--
6<?php
7if (!function_exists("proc_open")) die("skip no proc_open");
8?>
9--FILE--
10<?php
11$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'bug46127.pem.tmp';
12
13$serverCode = <<<'CODE'
14    $serverUri = "ssl://127.0.0.1:64321";
15    $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN;
16    $serverCtx = stream_context_create(['ssl' => [
17        'local_cert' => '%s',
18    ]]);
19
20    $sock = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx);
21    phpt_notify();
22
23    $link = stream_socket_accept($sock);
24    fwrite($link, "Sending bug 46127\n");
25CODE;
26$serverCode = sprintf($serverCode, $certFile);
27
28$clientCode = <<<'CODE'
29    $serverUri = "ssl://127.0.0.1:64321";
30    $clientFlags = STREAM_CLIENT_CONNECT;
31
32    $clientCtx = stream_context_create(['ssl' => [
33        'verify_peer' => false,
34        'verify_peer_name' => false
35    ]]);
36
37    phpt_wait();
38    $sock = stream_socket_client($serverUri, $errno, $errstr, 2, $clientFlags, $clientCtx);
39
40    echo fgets($sock);
41CODE;
42
43include 'CertificateGenerator.inc';
44$certificateGenerator = new CertificateGenerator();
45$certificateGenerator->saveNewCertAsFileWithKey('bug46127', $certFile);
46
47include 'ServerClientTestCase.inc';
48ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
49?>
50--CLEAN--
51<?php
52@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'bug46127.pem.tmp');
53?>
54--EXPECT--
55Sending bug 46127
56