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