xref: /php-src/ext/mysqli/tests/bug55283.phpt (revision 7e5171d1)
1--TEST--
2Bug #55283 (SSL options set by mysqli_ssl_set ignored for MySQLi persistent connections)
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once 'connect.inc';
8
9if (!defined('MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT'))
10    die("skip Requires MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT");
11
12if (!extension_loaded("openssl"))
13    die("skip PHP streams lack support for SSL. mysqli is compiled to use mysqlnd which uses PHP streams in turn.");
14
15if (!($link = @my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)))
16    die(sprintf("skip Connect failed, [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));
17
18if (false === strpos($link->host_info, 'TCP/IP'))
19    die(sprintf("skip SSL only supported on TCP/IP"));
20
21$row = NULL;
22if ($res = $link->query('SHOW VARIABLES LIKE "have_ssl"')) {
23    $row = $res->fetch_row();
24} else {
25    if ($link->errno == 1064 && ($res = $link->query("SHOW VARIABLES"))) {
26        while ($row = $res->fetch_row())
27            if ($row[0] == 'have_ssl')
28                break;
29    } else {
30        die(sprintf("skip Failed to test for MySQL SSL support, [%d] %s", $link->errno, $link->error));
31    }
32}
33
34
35if (empty($row))
36    die(sprintf("skip Failed to test for MySQL SSL support, [%d] %s", $link->errno, $link->error));
37
38if (($row[1] == 'NO') || ($row[1] == 'DISABLED'))
39    die(sprintf("skip MySQL has no SSL support, [%d] %s", $link->errno, $link->error));
40
41$link->close();
42?>
43--FILE--
44<?php
45    require_once 'connect.inc';
46
47    $flags = MYSQLI_CLIENT_SSL | MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT;
48
49    $link = mysqli_init();
50    mysqli_ssl_set($link, null, null, null, null, "AES256-SHA");
51    if (my_mysqli_real_connect($link, 'p:' . $host, $user, $passwd, $db, $port, null, $flags)) {
52        $r = $link->query("SHOW STATUS LIKE 'Ssl_cipher'");
53        var_dump($r->fetch_row());
54    }
55
56    /* non-persistent connection */
57    $link2 = mysqli_init();
58    mysqli_ssl_set($link2, null, null, null, null, "AES256-SHA");
59    if (my_mysqli_real_connect($link2, $host, $user, $passwd, $db, $port, null, $flags)) {
60        $r2 = $link2->query("SHOW STATUS LIKE 'Ssl_cipher'");
61        var_dump($r2->fetch_row());
62    }
63
64    echo "done\n";
65?>
66--EXPECTF--
67array(2) {
68  [0]=>
69  string(10) "Ssl_cipher"
70  [1]=>
71  string(%d) "%rAES256-SHA|TLS_AES_256_GCM_SHA384%r"
72}
73array(2) {
74  [0]=>
75  string(10) "Ssl_cipher"
76  [1]=>
77  string(%d) "%rAES256-SHA|TLS_AES_256_GCM_SHA384%r"
78}
79done
80