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