diff options
author | Alexander Kurilo <alex@kurilo.me> | 2018-12-02 17:08:01 +0300 |
---|---|---|
committer | Jakub Zelenka <bukka@php.net> | 2019-01-10 20:09:42 +0000 |
commit | 1fab01be5bef046ff6dcbf843cc3db66faacda12 (patch) | |
tree | edd939240295bcb63cba1c5a98912f45c450b608 /ext/openssl/tests/bug74159.phpt | |
parent | 6b4cdbaade1b077e8f0eceecb0e07921fed00aff (diff) | |
download | php-git-1fab01be5bef046ff6dcbf843cc3db66faacda12.tar.gz |
Generate certs for openssl tests on the fly
The idea is to create an easy way to provide a certificate that never
expires. In order to make it cross-platform, PHP is used rather than
openssl CLI app. Using openssl to generate certificates for tests that
test openssl might be not the best idea but pros seem to outweight cons
that this "recursice dependency" adds
Diffstat (limited to 'ext/openssl/tests/bug74159.phpt')
-rw-r--r-- | ext/openssl/tests/bug74159.phpt | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/ext/openssl/tests/bug74159.phpt b/ext/openssl/tests/bug74159.phpt index 6a46fa5082..291bf38346 100644 --- a/ext/openssl/tests/bug74159.phpt +++ b/ext/openssl/tests/bug74159.phpt @@ -7,6 +7,9 @@ if (!function_exists("proc_open")) die("skip no proc_open"); ?> --FILE-- <?php +$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'bug74159.pem.tmp'; +$cacertFile = __DIR__ . DIRECTORY_SEPARATOR . 'bug74159-ca.pem.tmp'; + // the server code is doing many readings in a short interval which is // not really reliable on more powerful machine but cover different // scenarios which might be useful. More reliable test is bug72333.phpt @@ -14,7 +17,7 @@ $serverCode = <<<'CODE' $serverUri = "ssl://127.0.0.1:10012"; $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN; $serverCtx = stream_context_create(['ssl' => [ - 'local_cert' => __DIR__ . '/bug54992.pem', + 'local_cert' => '%s', 'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER, ]]); @@ -39,7 +42,9 @@ $serverCode = <<<'CODE' fclose($client); CODE; +$serverCode = sprintf($serverCode, $certFile); +$peerName = 'bug74159'; $clientCode = <<<'CODE' function streamRead($stream) : int { return strlen(fread($stream, 8192)); @@ -71,8 +76,8 @@ $clientCode = <<<'CODE' $clientFlags = STREAM_CLIENT_CONNECT; $clientCtx = stream_context_create(['ssl' => [ 'verify_peer' => true, - 'cafile' => __DIR__ . '/bug54992-ca.pem', - 'peer_name' => 'bug54992.local', + 'cafile' => '%s', + 'peer_name' => '%s', ]]); phpt_wait(); @@ -91,7 +96,7 @@ $clientCode = <<<'CODE' $data = substr($data, $written); waitForWrite($fp); } - printf("Written %d bytes\n", $total); + printf("Written %%d bytes\n", $total); while(waitForRead($fp)) { streamRead($fp); @@ -102,10 +107,21 @@ $clientCode = <<<'CODE' exit("DONE\n"); CODE; +$clientCode = sprintf($clientCode, $cacertFile, $peerName); + +include 'CertificateGenerator.inc'; +$certificateGenerator = new CertificateGenerator(); +$certificateGenerator->saveCaCert($cacertFile); +$certificateGenerator->saveNewCertAsFileWithKey($peerName, $certFile); include 'ServerClientTestCase.inc'; ServerClientTestCase::getInstance()->run($clientCode, $serverCode); ?> ---EXPECTF-- +--CLEAN-- +<?php +@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'bug74159.pem.tmp'); +@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'bug74159-ca.pem.tmp'); +?> +--EXPECT-- Written 1048575 bytes DONE |