1--TEST--
2openssl_csr_export_to_file() tests
3--SKIPIF--
4<?php if (!extension_loaded("openssl")) print "skip"; ?>
5--FILE--
6<?php
7$csrfile = dirname(__FILE__) . "/openssl_csr_export_to_file_csr.tmp";
8$wrong = "wrong";
9$config = __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf';
10$phex = 'dcf93a0b883972ec0e19989ac5a2ce310e1d37717e8d9571bb7623731866e61e' .
11		'f75a2e27898b057f9891c2e27a639c3f29b60814581cd3b2ca3986d268370557' .
12		'7d45c2e7e52dc81c7a171876e5cea74b1448bfdfaf18828efd2519f14e45e382' .
13		'6634af1949e5b535cc829a483b8a76223e5d490a257f05bdff16f2fb22c583ab';
14$dh_details = array('p' => $phex, 'g' => '2');
15$dh = openssl_pkey_new(array(
16	'dh'=> array('p' => hex2bin($phex), 'g' => '2'))
17);
18
19$dn = array(
20	"countryName" => "BR",
21	"stateOrProvinceName" => "Rio Grande do Sul",
22	"localityName" => "Porto Alegre",
23	"commonName" => "Henrique do N. Angelo",
24	"emailAddress" => "hnangelo@php.net"
25);
26
27$args = array(
28	"digest_alg" => "sha1",
29	"private_key_bits" => 2048,
30	"private_key_type" => OPENSSL_KEYTYPE_DSA,
31	"encrypt_key" => true,
32	"config" => $config,
33);
34
35$privkey_file = 'file://' . dirname(__FILE__) . '/private_rsa_2048.key';
36$csr = openssl_csr_new($dn, $privkey_file, $args);
37var_dump(openssl_csr_export_to_file($csr, $csrfile));
38var_dump(file_get_contents($csrfile));
39var_dump(openssl_csr_export_to_file($wrong, $csrfile));
40var_dump(openssl_csr_export_to_file($dh, $csrfile));
41var_dump(openssl_csr_export_to_file(array(), $csrfile));
42var_dump(openssl_csr_export_to_file($csr, $csrfile, false));
43?>
44--CLEAN--
45<?php
46$csrfile = dirname(__FILE__) . "/openssl_csr_export_to_file_csr.tmp";
47if (file_exists($csrfile)) {
48	unlink($csrfile);
49}
50?>
51--EXPECTF--
52bool(true)
53string(1086) "-----BEGIN CERTIFICATE REQUEST-----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"
72
73Warning: openssl_csr_export_to_file() expects parameter 1 to be resource, string given in %s on line %d
74NULL
75
76Warning: openssl_csr_export_to_file(): supplied resource is not a valid OpenSSL X.509 CSR resource in %s on line %d
77
78Warning: openssl_csr_export_to_file(): cannot get CSR from parameter 1 in %s on line %d
79bool(false)
80
81Warning: openssl_csr_export_to_file() expects parameter 1 to be resource, array given in %s on line %d
82NULL
83bool(true)
84