Skip to content

Commit e78e839

Browse files
committed
Rewrite openssl_csr_get_subject test to improve coverage
1 parent 528aa54 commit e78e839

File tree

1 file changed

+47
-11
lines changed

1 file changed

+47
-11
lines changed

ext/openssl/tests/openssl_csr_get_subject_basic.phpt

+47-11
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,43 @@
22
openssl_csr_get_subject() tests
33
--SKIPIF--
44
<?php
5-
if (!extension_loaded("openssl")) die("skip");
6-
if (!function_exists("utf8_decode")) die("skip");
5+
if (!extension_loaded("openssl")) die("skip");
76
?>
87
--FILE--
98
<?php
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+
);
1018

11-
$csr = file_get_contents(dirname(__FILE__) . '/cert.csr');
12-
if ($out = openssl_csr_get_subject($csr, 1)) {
13-
var_dump($out);
14-
}
15-
echo "\n";
16-
$cn = utf8_decode($out['CN']);
17-
var_dump($cn);
19+
$dn = array(
20+
"countryName" => "BR",
21+
"stateOrProvinceName" => "Rio Grande do Sul",
22+
"localityName" => "Porto Alegre",
23+
"commonName" => "Henrique do N. Angelo",
24+
"emailAddress" => "[email protected]"
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);
37+
$csr_file = file_get_contents(dirname(__FILE__) . '/cert.csr');
38+
39+
var_dump(openssl_csr_get_subject($csr_file));
40+
var_dump(openssl_csr_get_subject($csr, false));
41+
?>
1842
--EXPECTF--
1943
array(6) {
2044
["C"]=>
@@ -30,5 +54,17 @@ array(6) {
3054
["CN"]=>
3155
string(15) "*.triconnect.nl"
3256
}
33-
34-
string(15) "*.triconnect.nl"
57+
array(6) {
58+
["countryName"]=>
59+
string(2) "BR"
60+
["stateOrProvinceName"]=>
61+
string(17) "Rio Grande do Sul"
62+
["localityName"]=>
63+
string(12) "Porto Alegre"
64+
["commonName"]=>
65+
string(21) "Henrique do N. Angelo"
66+
["emailAddress"]=>
67+
string(16) "[email protected]"
68+
["organizationName"]=>
69+
string(24) "Internet Widgits Pty Ltd"
70+
}

0 commit comments

Comments
 (0)