Annotation of embedaddon/php/ext/mysqli/tests/mysqli_auth_pam.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: PAM auth plugin
! 3: --SKIPIF--
! 4: <?php
! 5: require_once('skipif.inc');
! 6: require_once('skipifemb.inc');
! 7: require_once('connect.inc');
! 8:
! 9: if (version_compare(PHP_VERSION, '5.3.99') >= 0) {
! 10: die("SKIP Available as of PHP 5.3.99");
! 11: }
! 12:
! 13: if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
! 14: die(sprintf("SKIP Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
! 15: $host, $user, $db, $port, $socket));
! 16: }
! 17:
! 18: if ($link->server_version < 50500)
! 19: die(sprintf("SKIP Needs MySQL 5.5 or newer, found MySQL %s\n", $link->server_info));
! 20:
! 21: if (!$res = $link->query("SHOW PLUGINS"))
! 22: die(sprintf("SKIP [%d] %s\n", $link->errno, $link->error));
! 23:
! 24: $have_pam = false;
! 25: while ($row = $res->fetch_assoc()) {
! 26: if (isset($row['Name']) && ('mysql_clear_password' == $row['Name'])) {
! 27: $have_pam = true;
! 28: break;
! 29: }
! 30: }
! 31: $res->close();
! 32:
! 33: if (!$have_pam)
! 34: die("SKIP Server PAM plugin not installed");
! 35:
! 36:
! 37: mysqli_query($link, 'DROP USER pamtest');
! 38: mysqli_query($link, 'DROP USER pamtest@localhost');
! 39:
! 40: if (!mysqli_query($link, 'CREATE USER pamtest@"%" IDENTIFIED WITH mysql_clear_password') ||
! 41: !mysqli_query($link, 'CREATE USER pamtest@"localhost" IDENTIFIED WITH mysql_clear_password')) {
! 42: printf("skip Cannot create second DB user [%d] %s", mysqli_errno($link), mysqli_error($link));
! 43: mysqli_close($link);
! 44: die("skip CREATE USER failed");
! 45: }
! 46:
! 47: if (!$link->query("CREATE TABLE test (id INT)") || !$link->query("INSERT INTO test(id) VALUES (1)"))
! 48: die(sprintf("SKIP [%d] %s\n", $link->errno, $link->error));
! 49:
! 50:
! 51:
! 52: if (!mysqli_query($link, sprintf("GRANT SELECT ON TABLE %s.test TO pamtest@'%%'", $db)) ||
! 53: !mysqli_query($link, sprintf("GRANT SELECT ON TABLE %s.test TO pamtest@'localhost'", $db))) {
! 54: printf("skip Cannot grant SELECT to user [%d] %s", mysqli_errno($link), mysqli_error($link));
! 55: mysqli_close($link);
! 56: die("skip GRANT failed");
! 57: }
! 58: ?>
! 59: --INI--
! 60: max_execution_time=240
! 61: --FILE--
! 62: <?php
! 63: require_once('connect.inc');
! 64: require_once('table.inc');
! 65:
! 66: if (!$link = my_mysqli_connect($host, 'pamtest', 'pamtest', $db, $port, $socket)) {
! 67: printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
! 68: $host, $user, $db, $port, $socket);
! 69: } else {
! 70:
! 71: if (!$res = $link->query("SELECT id FROM test WHERE id = 1"))
! 72: printf("[002] [%d] %s\n", $link->errno, $link->error);
! 73:
! 74: if (!$row = mysqli_fetch_assoc($res)) {
! 75: printf("[003] [%d] %s\n", $link->errno, $link->error);
! 76: }
! 77:
! 78: if ($row['id'] != 1) {
! 79: printf("[004] Expecting 1 got %s/'%s'", gettype($row['id']), $row['id']);
! 80: }
! 81:
! 82: $res->close();
! 83: $link->close();
! 84: }
! 85:
! 86: print "done!";
! 87: ?>
! 88: --CLEAN--
! 89: <?php
! 90: require_once("clean_table.inc");
! 91: mysqli_query($link, 'DROP USER pamtest');
! 92: mysqli_query($link, 'DROP USER pamtest@localhost');
! 93: ?>
! 94: --EXPECTF--
! 95:
! 96: Warning: mysqli_real_connect(): (28000/1045): Access denied for user %s
! 97: [001] Cannot connect to the server using host=%s
! 98: done!
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>