Rename and clean up OpenSSL tests

This commit is contained in:
Jakub Zelenka 2016-02-03 16:20:27 +00:00
parent e0332ea1a9
commit 1f3906c1ce
32 changed files with 85 additions and 89 deletions

View File

@ -1,32 +0,0 @@
--TEST--
openssl_seal() tests
--SKIPIF--
<?php if (!extension_loaded("openssl")) print "skip"; ?>
--FILE--
<?php
$a = 1;
$b = array(1);
$c = array(1);
$d = array(1);
var_dump(openssl_seal($a, $b, $c, $d));
var_dump(openssl_seal($a, $a, $a, array()));
var_dump(openssl_seal($c, $c, $c, 1));
var_dump(openssl_seal($b, $b, $b, ""));
echo "Done\n";
?>
--EXPECTF--
Warning: openssl_seal(): not a public key (1th member of pubkeys) in %s on line %d
bool(false)
Warning: openssl_seal(): Fourth argument to openssl_seal() must be a non-empty array in %s on line %d
bool(false)
Warning: openssl_seal() expects parameter 1 to be string, array given in %s on line %d
NULL
Warning: openssl_seal() expects parameter 1 to be string, array given in %s on line %d
NULL
Done

View File

@ -1,27 +0,0 @@
--TEST--
openssl_seal() error tests
--SKIPIF--
<?php if (!extension_loaded("openssl")) print "skip"; ?>
--FILE--
<?php
$data = "openssl_open() test";
$pub_key = "file://" . dirname(__FILE__) . "/public.key";
$wrong = "wrong";
openssl_seal($data, $sealed, $ekeys, array($pub_key)); // no output
openssl_seal($data, $sealed, $ekeys, array($pub_key, $pub_key)); // no output
openssl_seal($data, $sealed, $ekeys, array($pub_key, $wrong));
openssl_seal($data, $sealed, $ekeys, $pub_key);
openssl_seal($data, $sealed, $ekeys, array());
openssl_seal($data, $sealed, $ekeys, array($wrong));
?>
--EXPECTF--
Warning: openssl_seal(): not a public key (2th member of pubkeys) in %s on line %d
Warning: openssl_seal() expects parameter 4 to be array, string given in %s on line %d
Warning: openssl_seal(): Fourth argument to openssl_seal() must be a non-empty array in %s on line %d
Warning: openssl_seal(): not a public key (1th member of pubkeys) in %s on line %d

View File

@ -1,12 +0,0 @@
--TEST--
Options type checks
--SKIPIF--
<?php if (!extension_loaded("openssl")) print "skip"; ?>
--FILE--
<?php
$x = openssl_pkey_new();
$csr = openssl_csr_new(["countryName" => "DE"], $x, ["x509_extensions" => 0xDEADBEEF]);
?>
DONE
--EXPECT--
DONE

View File

@ -14,7 +14,7 @@ $dn = array(
"localityName" => "Porto Alegre",
"commonName" => "Henrique do N. Angelo",
"emailAddress" => "hnangelo@php.net"
);
);
$args = array(
"digest_alg" => "sha1",
@ -22,7 +22,7 @@ $args = array(
"private_key_type" => OPENSSL_KEYTYPE_DSA,
"encrypt_key" => true,
"config" => $config,
);
);
$privkey = openssl_pkey_new($config_arg);
$csr = openssl_csr_new($dn, $privkey, $args);

View File

@ -8,7 +8,7 @@ if (!function_exists("utf8_decode")) die("skip");
--FILE--
<?php
$csr = file_get_contents(dirname(__FILE__) . '/005_crt.txt');
$csr = file_get_contents(dirname(__FILE__) . '/cert.csr');
if ($out = openssl_csr_get_subject($csr, 1)) {
var_dump($out);
}

View File

@ -11,11 +11,15 @@ var_dump(openssl_csr_new(1,$a,1,1));
$a = array();
var_dump(openssl_csr_new(array(), $a, array('config' => __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf'), array()));
//this leaks
// this leaks
$a = array(1,2);
$b = array(1,2);
var_dump(openssl_csr_new($a, $b, array('config' => __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf')));
// options type check
$x = openssl_pkey_new();
var_dump(openssl_csr_new(["countryName" => "DE"], $x, ["x509_extensions" => 0xDEADBEEF]));
echo "Done\n";
?>
@ -31,4 +35,5 @@ Warning: openssl_csr_new(): key array must be of the form array(0 => key, 1 => p
Warning: openssl_csr_new(): add1_attr_by_txt challengePassword_min -> 4 (failed; check error queue and value of string_mask OpenSSL option if illegal characters are reported) in %s on line %d
bool(false)
resource(%d) of type (OpenSSL X.509 CSR)
resource(%d) of type (OpenSSL X.509 CSR)
Done

View File

@ -1,5 +1,5 @@
--TEST--
openssl_encrypt() and openssl_decrypt() tests
openssl_decrypt() tests dependent on openssl_encrypt
--SKIPIF--
<?php if (!extension_loaded("openssl")) print "skip"; ?>
--FILE--

View File

@ -6,7 +6,7 @@ openssl_pkcs7_decrypt() and invalid parameters
<?php
function myErrorHandler($errno, $errstr, $errfile, $errline) {
var_dump($errstr);
var_dump($errstr);
}
set_error_handler("myErrorHandler");

View File

@ -6,8 +6,9 @@ openssl_pkcs7_sign() tests
<?php
$infile = dirname(__FILE__) . "/cert.crt";
$outfile = tempnam("/tmp", "ssl");
if ($outfile === false)
if ($outfile === false) {
die("failed to get a temporary filename!");
}
$privkey = "file://" . dirname(__FILE__) . "/private_rsa_1024.key";
$single_cert = "file://" . dirname(__FILE__) . "/cert.crt";

View File

@ -1,5 +1,5 @@
--TEST--
openssl_pkey_new() with an empty sub-array arg generates a malformed resource
openssl_pkey_new() tests
--SKIPIF--
<?php if (!extension_loaded("openssl")) print "skip"; ?>
--FILE--

View File

@ -8,10 +8,11 @@ $data = "Testing openssl_private_encrypt()";
$privkey = "file://" . dirname(__FILE__) . "/private_rsa_1024.key";
$pubkey = "file://" . dirname(__FILE__) . "/public.key";
$wrong = "wrong";
class test {
function __toString() {
return "test";
}
function __toString() {
return "test";
}
}
$obj = new test;

View File

@ -8,10 +8,11 @@ $data = "Testing openssl_public_encrypt()";
$privkey = "file://" . dirname(__FILE__) . "/private_rsa_1024.key";
$pubkey = "file://" . dirname(__FILE__) . "/public.key";
$wrong = "wrong";
class test {
function __toString() {
return "test";
}
function __toString() {
return "test";
}
}
$obj = new test;

View File

@ -0,0 +1,58 @@
--TEST--
openssl_seal() tests
--SKIPIF--
<?php if (!extension_loaded("openssl")) print "skip"; ?>
--FILE--
<?php
// simple tests
$a = 1;
$b = array(1);
$c = array(1);
$d = array(1);
var_dump(openssl_seal($a, $b, $c, $d));
var_dump(openssl_seal($a, $a, $a, array()));
var_dump(openssl_seal($c, $c, $c, 1));
var_dump(openssl_seal($b, $b, $b, ""));
// tests with cert
$data = "openssl_open() test";
$pub_key = "file://" . dirname(__FILE__) . "/public.key";
$wrong = "wrong";
var_dump(openssl_seal($data, $sealed, $ekeys, array($pub_key))); // no output
var_dump(openssl_seal($data, $sealed, $ekeys, array($pub_key, $pub_key))); // no output
var_dump(openssl_seal($data, $sealed, $ekeys, array($pub_key, $wrong)));
var_dump(openssl_seal($data, $sealed, $ekeys, $pub_key));
var_dump(openssl_seal($data, $sealed, $ekeys, array()));
var_dump(openssl_seal($data, $sealed, $ekeys, array($wrong)));
echo "Done\n";
?>
--EXPECTF--
Warning: openssl_seal(): not a public key (1th member of pubkeys) in %s on line %d
bool(false)
Warning: openssl_seal(): Fourth argument to openssl_seal() must be a non-empty array in %s on line %d
bool(false)
Warning: openssl_seal() expects parameter 1 to be string, array given in %s on line %d
NULL
Warning: openssl_seal() expects parameter 1 to be string, array given in %s on line %d
NULL
int(19)
int(19)
Warning: openssl_seal(): not a public key (2th member of pubkeys) in %s on line %d
bool(false)
Warning: openssl_seal() expects parameter 4 to be array, string given in %s on line %d
NULL
Warning: openssl_seal(): Fourth argument to openssl_seal() must be a non-empty array in %s on line %d
bool(false)
Warning: openssl_seal(): not a public key (1th member of pubkeys) in %s on line %d
bool(false)
Done

View File

@ -20,8 +20,9 @@ var_dump(openssl_x509_export($d, $output4)); // read cert from a resource
var_dump(openssl_x509_export($e, $output5)); // read an array, fails
$outfilename = tempnam("/tmp", "ssl");
if ($outfilename === false)
die("failed to get a temporary filename!");
if ($outfilename === false) {
die("failed to get a temporary filename!");
}
echo "---\n";
@ -34,7 +35,7 @@ echo "---\n";
var_dump($exists = file_exists($outfilename));
if ($exists) {
@unlink($outfilename);
@unlink($outfilename);
}
echo "---\n";

View File

@ -1,5 +1,5 @@
--TEST--
openssl_x509_read() and openssl_x509_free() tests
openssl_x509_read() tests with testing openssl_x509_free as well
--SKIPIF--
<?php if (!extension_loaded("openssl")) print "skip"; ?>
--FILE--