]> granicus.if.org Git - php/commitdiff
Split and clean up OpenSSL X509 tests
authorJakub Zelenka <bukka@php.net>
Thu, 4 Feb 2016 16:51:36 +0000 (16:51 +0000)
committerJakub Zelenka <bukka@php.net>
Thu, 4 Feb 2016 16:51:36 +0000 (16:51 +0000)
ext/openssl/tests/openssl_x509_check_private_key_basic.phpt
ext/openssl/tests/openssl_x509_export_basic.phpt
ext/openssl/tests/openssl_x509_export_to_file_basic.phpt [new file with mode: 0644]
ext/openssl/tests/openssl_x509_fingerprint_basic.phpt
ext/openssl/tests/openssl_x509_free_basic.phpt [new file with mode: 0644]
ext/openssl/tests/openssl_x509_parse_basic.phpt
ext/openssl/tests/openssl_x509_read_basic.phpt

index df18322453d3a6dcde54f45449cdb0a9ad9ea594..b4842aae181d8794911b28321977eb06b7b9113d 100644 (file)
@@ -5,11 +5,11 @@ openssl_x509_check_private_key() tests
 --FILE--
 <?php
 $fp = fopen(dirname(__FILE__) . "/cert.crt","r");
-$a = fread($fp,8192);
+$a = fread($fp, 8192);
 fclose($fp);
 
 $fp = fopen(dirname(__FILE__) . "/private_rsa_1024.key","r");
-$b = fread($fp,8192);
+$b = fread($fp, 8192);
 fclose($fp);
 
 $cert = "file://" . dirname(__FILE__) . "/cert.crt";
index e0988c095a33bc1313e645b427a154928e283708..cfe1cad5244210176a8812caabb937f366e37ab9 100644 (file)
@@ -1,49 +1,28 @@
 --TEST--
-openssl_x509_export() and openssl_x509_export_to_file() tests
+openssl_x509_export() tests
 --SKIPIF--
 <?php if (!extension_loaded("openssl")) print "skip"; ?>
 --FILE--
 <?php
-$fp = fopen(dirname(__FILE__) . "/cert.crt","r");
-$a = fread($fp,8192);
-fclose($fp); 
+$cert_file = dirname(__FILE__) . "/cert.crt";
 
-$b = "file://" . dirname(__FILE__) . "/cert.crt";
+$a = file_get_contents($cert_file);
+$b = "file://" . $cert_file;
 $c = "invalid cert";
 $d = openssl_x509_read($a);
 $e = array();
 
-var_dump(openssl_x509_export($a, $output));    // read cert as a binary string
-var_dump(openssl_x509_export($b, $output2));   // read cert from a filename string
-var_dump(openssl_x509_export($c, $output3));   // read an invalid cert, fails
-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!");
-}
-
-echo "---\n";
-
-var_dump(openssl_x509_export_to_file($a, $outfilename));      // read cert as a binary string
-var_dump(openssl_x509_export_to_file($b, $outfilename));      // read cert from a filename string
-var_dump(openssl_x509_export_to_file($c, $outfilename));      // read an invalid cert, fails
-var_dump(openssl_x509_export_to_file($d, $outfilename));      // read cert from a resource
-var_dump(openssl_x509_export_to_file($e, $outfilename));      // read an array, fails
-echo "---\n";
-
-var_dump($exists = file_exists($outfilename));
-if ($exists) {
-       @unlink($outfilename);
-}
-echo "---\n";
+var_dump(openssl_x509_export($a, $output));  // read cert as a binary string
+var_dump(openssl_x509_export($b, $output2)); // read cert from a filename string
+var_dump(openssl_x509_export($c, $output3)); // read an invalid cert, fails
+var_dump(openssl_x509_export($d, $output4)); // read cert from a resource
+var_dump(openssl_x509_export($e, $output5)); // read an array, fails
 
 var_dump(strcmp($output, $a));
 var_dump(strcmp($output, $output2));
 var_dump(strcmp($output, $output3));
-var_dump(strcmp($output, $output4));   // different
-var_dump(strcmp($output, $output5));   // different
+var_dump(strcmp($output, $output4)); // different
+var_dump(strcmp($output, $output5)); // different
 ?>
 --EXPECTF--
 bool(true)
@@ -55,19 +34,6 @@ bool(true)
 
 Warning: openssl_x509_export(): cannot get cert from parameter 1 in %s on line %d
 bool(false)
----
-bool(true)
-bool(true)
-
-Warning: openssl_x509_export_to_file(): cannot get cert from parameter 1 in %s on line %d
-bool(false)
-bool(true)
-
-Warning: openssl_x509_export_to_file(): cannot get cert from parameter 1 in %s on line %d
-bool(false)
----
-bool(true)
----
 int(0)
 int(0)
 int(%d)
diff --git a/ext/openssl/tests/openssl_x509_export_to_file_basic.phpt b/ext/openssl/tests/openssl_x509_export_to_file_basic.phpt
new file mode 100644 (file)
index 0000000..68ba932
--- /dev/null
@@ -0,0 +1,42 @@
+--TEST--
+openssl_x509_export_to_file() tests
+--SKIPIF--
+<?php if (!extension_loaded("openssl")) print "skip"; ?>
+--FILE--
+<?php
+$outfilename = dirname(__FILE__) . "/openssl_x509_export_to_file__outfilename.tmp";
+$cert_file = dirname(__FILE__) . "/cert.crt";
+
+$a = file_get_contents($cert_file);
+$b = "file://" . $cert_file;
+$c = "invalid cert";
+$d = openssl_x509_read($a);
+$e = array();
+
+var_dump(openssl_x509_export_to_file($a, $outfilename)); // read cert as a binary string
+var_dump(openssl_x509_export_to_file($b, $outfilename)); // read cert from a filename string
+var_dump(openssl_x509_export_to_file($c, $outfilename)); // read an invalid cert, fails
+var_dump(openssl_x509_export_to_file($d, $outfilename)); // read cert from a resource
+var_dump(openssl_x509_export_to_file($e, $outfilename)); // read an array, fails
+echo "---\n";
+var_dump($exists = file_exists($outfilename));
+?>
+--CLEAN--
+<?php
+$outfilename = dirname(__FILE__) . "/openssl_x509_export_to_file__outfilename.tmp";
+if (file_exists($outfilename)) {
+       unlink($outfilename);
+}
+?>
+--EXPECTF--
+bool(true)
+bool(true)
+
+Warning: openssl_x509_export_to_file(): cannot get cert from parameter 1 in %s on line %d
+bool(false)
+bool(true)
+
+Warning: openssl_x509_export_to_file(): cannot get cert from parameter 1 in %s on line %d
+bool(false)
+---
+bool(true)
index 6cd464a89487282e6ca6ff9524ed3a7e7b3c2253..766b158fab6f75f041ae82c705abd8659b90d739 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-Testing openssl_x509_fingerprint()
+openssl_x509_fingerprint() tests
 --SKIPIF--
 <?php
 if (!extension_loaded("openssl")) die("skip");
diff --git a/ext/openssl/tests/openssl_x509_free_basic.phpt b/ext/openssl/tests/openssl_x509_free_basic.phpt
new file mode 100644 (file)
index 0000000..d8b586e
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+openssl_x509_free() tests
+--SKIPIF--
+<?php if (!extension_loaded("openssl")) print "skip"; ?>
+--FILE--
+<?php
+var_dump($res = openssl_x509_read("file://" . dirname(__FILE__) . "/cert.crt"));
+openssl_x509_free($res);
+var_dump($res);
+openssl_x509_free(false);
+?>
+--EXPECTF--
+resource(%d) of type (OpenSSL X.509)
+resource(%d) of type (Unknown)
+
+Warning: openssl_x509_free() expects parameter 1 to be resource, boolean given in %s on line %d
index 325b2ee4b9188fa93002bdbf059e51cf0f96998a..00e32c3b6006461d4025024971d25b6ab267f0e5 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-openssl_x509_parse() basic test
+openssl_x509_parse() tests
 --SKIPIF--
 <?php if (!extension_loaded("openssl")) print "skip"; 
 if (OPENSSL_VERSION_NUMBER < 0x10000000) die("skip Output requires OpenSSL 1.0");
index cc36e989c6ccf5f2a611caf4af457dc08f0ae7b4..5f530534ffd17ca19d601170dd54eedeeff14a85 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-openssl_x509_read() tests with testing openssl_x509_free as well
+openssl_x509_read() tests
 --SKIPIF--
 <?php if (!extension_loaded("openssl")) print "skip"; ?>
 --FILE--
@@ -14,47 +14,24 @@ $d = openssl_x509_read($a);
 $e = array();
 $f = array($b);
 
-var_dump($res = openssl_x509_read($a));         // read cert as a string
-openssl_x509_free($res);
-var_dump($res);
-var_dump($res = openssl_x509_read($b));         // read cert as a filename string
-openssl_x509_free($res);
-var_dump($res);
-var_dump($res = openssl_x509_read($c));         // read an invalid cert, fails
-openssl_x509_free($res);
-var_dump($res);
-var_dump($res = openssl_x509_read($d));         // read cert from a resource
-openssl_x509_free($res);
-var_dump($res);
-var_dump($res = openssl_x509_read($e));         // read an array
-openssl_x509_free($res);
-var_dump($res);
-var_dump($res = openssl_x509_read($f));         // read an array with the filename
-openssl_x509_free($res);
-var_dump($res);
+var_dump(openssl_x509_read($a)); // read cert as a string
+var_dump(openssl_x509_read($b)); // read cert as a filename string
+var_dump(openssl_x509_read($c)); // read an invalid cert, fails
+var_dump(openssl_x509_read($d)); // read cert from a resource
+var_dump(openssl_x509_read($e)); // read an array
+var_dump(openssl_x509_read($f)); // read an array with the filename
 ?>
 --EXPECTF--
 resource(%d) of type (OpenSSL X.509)
-resource(%d) of type (Unknown)
 resource(%d) of type (OpenSSL X.509)
-resource(%d) of type (Unknown)
 
 Warning: openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate! in %s on line %d
 bool(false)
-
-Warning: openssl_x509_free() expects parameter 1 to be resource, boolean given in %s on line %d
-bool(false)
 resource(%d) of type (OpenSSL X.509)
-resource(%d) of type (Unknown)
 
 Warning: openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate! in %s on line %d
 bool(false)
 
-Warning: openssl_x509_free() expects parameter 1 to be resource, boolean given in %s on line %d
-bool(false)
-
 Warning: openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate! in %s on line %d
 bool(false)
 
-Warning: openssl_x509_free() expects parameter 1 to be resource, boolean given in %s on line %d
-bool(false)