Annotation of embedaddon/php/ext/openssl/tests/008.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: openssl_x509_export() and openssl_x509_export_to_file() tests
! 3: --SKIPIF--
! 4: <?php if (!extension_loaded("openssl")) print "skip"; ?>
! 5: --FILE--
! 6: <?php
! 7: $fp = fopen(dirname(__FILE__) . "/cert.crt","r");
! 8: $a = fread($fp,8192);
! 9: fclose($fp);
! 10:
! 11: $b = "file://" . dirname(__FILE__) . "/cert.crt";
! 12: $c = "invalid cert";
! 13: $d = openssl_x509_read($a);
! 14: $e = array();
! 15:
! 16: var_dump(openssl_x509_export($a, $output)); // read cert as a binary string
! 17: var_dump(openssl_x509_export($b, $output2)); // read cert from a filename string
! 18: var_dump(openssl_x509_export($c, $output3)); // read an invalid cert, fails
! 19: var_dump(openssl_x509_export($d, $output4)); // read cert from a resource
! 20: var_dump(openssl_x509_export($e, $output5)); // read an array, fails
! 21:
! 22: $outfilename = tempnam("/tmp", "ssl");
! 23: if ($outfilename === false)
! 24: die("failed to get a temporary filename!");
! 25:
! 26: echo "---\n";
! 27:
! 28: var_dump(openssl_x509_export_to_file($a, $outfilename)); // read cert as a binary string
! 29: var_dump(openssl_x509_export_to_file($b, $outfilename)); // read cert from a filename string
! 30: var_dump(openssl_x509_export_to_file($c, $outfilename)); // read an invalid cert, fails
! 31: var_dump(openssl_x509_export_to_file($d, $outfilename)); // read cert from a resource
! 32: var_dump(openssl_x509_export_to_file($e, $outfilename)); // read an array, fails
! 33: echo "---\n";
! 34:
! 35: var_dump($exists = file_exists($outfilename));
! 36: if ($exists) {
! 37: @unlink($outfilename);
! 38: }
! 39: echo "---\n";
! 40:
! 41: var_dump(strcmp($output, $a));
! 42: var_dump(strcmp($output, $output2));
! 43: var_dump(strcmp($output, $output3));
! 44: var_dump(strcmp($output, $output4)); // different
! 45: var_dump(strcmp($output, $output5)); // different
! 46: ?>
! 47: --EXPECTF--
! 48: bool(true)
! 49: bool(true)
! 50:
! 51: Warning: openssl_x509_export(): cannot get cert from parameter 1 in %s on line %d
! 52: bool(false)
! 53: bool(true)
! 54:
! 55: Warning: openssl_x509_export(): cannot get cert from parameter 1 in %s on line %d
! 56: bool(false)
! 57: ---
! 58: bool(true)
! 59: bool(true)
! 60:
! 61: Warning: openssl_x509_export_to_file(): cannot get cert from parameter 1 in %s on line %d
! 62: bool(false)
! 63: bool(true)
! 64:
! 65: Warning: openssl_x509_export_to_file(): cannot get cert from parameter 1 in %s on line %d
! 66: bool(false)
! 67: ---
! 68: bool(true)
! 69: ---
! 70: int(0)
! 71: int(0)
! 72: int(%d)
! 73: int(0)
! 74: int(%d)
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>