xref: /PHP-7.1/ext/openssl/tests/bug65538_003.phpt (revision 3c42f64e)
1--TEST--
2Bug #65538: SSL context "cafile" supports phar wrapper
3--SKIPIF--
4<?php
5if (!extension_loaded("openssl")) die("skip openssl not loaded");
6if (!extension_loaded("phar")) die("skip phar not loaded");
7if (!function_exists("proc_open")) die("skip no proc_open");
8?>
9--FILE--
10<?php
11$serverCode = <<<'CODE'
12    $serverUri = "ssl://127.0.0.1:64321";
13    $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN;
14    $serverCtx = stream_context_create(['ssl' => [
15        'local_cert' => __DIR__ . '/bug54992.pem',
16    ]]);
17
18    $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx);
19    phpt_notify();
20
21    $client = @stream_socket_accept($server);
22    if ($client) {
23        $in = '';
24        while (!preg_match('/\r?\n\r?\n/', $in)) {
25            $in .= fread($client, 2048);
26        }
27        $response = "HTTP/1.0 200 OK\r\n"
28                  . "Content-Type: text/plain\r\n"
29                  . "Content-Length: 12\r\n"
30                  . "Connection: close\r\n"
31                  . "\r\n"
32                  . "Hello World!";
33        fwrite($client, $response);
34        fclose($client);
35    }
36CODE;
37
38$clientCode = <<<'CODE'
39    $serverUri = "https://127.0.0.1:64321/";
40    $clientCtx = stream_context_create(['ssl' => [
41        'cafile' => 'phar://' . __DIR__ . '/bug65538.phar/bug54992-ca.pem',
42        'peer_name' => 'bug54992.local',
43    ]]);
44
45    phpt_wait();
46    $html = file_get_contents($serverUri, false, $clientCtx);
47
48    var_dump($html);
49CODE;
50
51include 'ServerClientTestCase.inc';
52ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
53?>
54--EXPECTF--
55string(12) "Hello World!"
56