xref: /PHP-5.4/ext/mysqli/tests/bug51647.phpt (revision da541ff5)
1--TEST--
2Bug #51647 (Certificate file without private key (pk in another file) doesn't work)
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7require_once("connect.inc");
8
9if ($IS_MYSQLND && !extension_loaded("openssl"))
10	die("skip PHP streams lack support for SSL. mysqli is compiled to use mysqlnd which uses PHP streams in turn.");
11
12if (!($link = @my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)))
13	die(sprintf("skip Connect failed, [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));
14
15$row = NULL;
16if ($res = $link->query('SHOW VARIABLES LIKE "have_ssl"')) {
17	$row = $res->fetch_row();
18} else {
19	if ($link->errno == 1064 && ($res = $link->query("SHOW VARIABLES"))) {
20		while ($row = $res->fetch_row())
21			if ($row[0] == 'have_ssl')
22				break;
23	} else {
24		die(sprintf("skip Failed to test for MySQL SSL support, [%d] %s", $link->errno, $link->error));
25	}
26}
27
28
29if (empty($row))
30	die(sprintf("skip Failed to test for MySQL SSL support, [%d] %s", $link->errno, $link->error));
31
32if (($row[1] == 'NO') || ($row[1] == 'DISABLED'))
33	die(sprintf("skip MySQL has no SSL support, [%d] %s", $link->errno, $link->error));
34
35$link->close();
36?>
37--FILE--
38<?php
39	include ("connect.inc");
40
41	if (!is_object($link = mysqli_init()))
42		printf("[001] Cannot create link\n");
43
44	$path_to_pems = !$IS_MYSQLND? "ext/mysqli/tests/" : "";
45	if (!$link->ssl_set("{$path_to_pems}client-key.pem", "{$path_to_pems}client-cert.pem", "{$path_to_pems}cacert.pem","",""))
46		printf("[002] [%d] %s\n", $link->errno, $link->error);
47
48	if (!my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket)) {
49		printf("[003] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
50	}
51
52	if (!$res = $link->query('SHOW STATUS like "Ssl_cipher"')) {
53		if (1064 == $link->errno) {
54			/* ERROR 1064 (42000): You have an error in your SQL syntax;  = sql strict mode */
55			if ($res = $link->query("SHOW STATUS")) {
56				while ($row = $res->fetch_assoc())
57					if ($row['Variable_name'] == 'Ssl_cipher')
58						break;
59			} else {
60				printf("[005] [%d] %s\n", $link->errno, $link->error);
61			}
62		} else {
63			printf("[004] [%d] %s\n", $link->errno, $link->error);
64		}
65	} else {
66		if (!$row = $res->fetch_assoc())
67			printf("[006] [%d] %s\n", $link->errno, $link->error);
68	}
69
70	var_dump($row);
71
72	print "done!";
73?>
74--EXPECTF--
75array(2) {
76  ["Variable_name"]=>
77  string(10) "Ssl_cipher"
78  ["Value"]=>
79  string(%d) "%S"
80}
81done!
82