summaryrefslogtreecommitdiff
path: root/mysql-test/suite/plugins/t/unix_socket.test
blob: 5869e2717c901049d3a7262d8040b29e4ad0df34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
--source include/not_embedded.inc
# If we run this as root, $USER gets authenticated as the `root' user, and we
# get .result differences from CURRENT_USER().
--source include/not_as_root.inc

# The previous check verifies that the user does not have root permissions. 
# However in some cases tests are run under a user named 'root',
# even although this user does not have real root permissions. 
# This test should be skipped in this case, since it does not expect
# that there are records in mysql.user where user=<username>
if ($USER=="root") {
  skip Cannot be run by user named 'root' even if it does not have all privileges;
}

if (!$AUTH_SOCKET_SO) {
  skip No auth_socket plugin;
}

if (!$USER) {
  skip USER variable is undefined;
}

let $plugindir=`SELECT @@global.plugin_dir`;

eval install plugin unix_socket soname '$AUTH_SOCKET_SO';

--echo #
--echo # with named user
--echo #

--replace_result $USER USER
eval create user $USER identified via unix_socket;

--write_file $MYSQLTEST_VARDIR/tmp/peercred_test.txt
--replace_result $USER USER
select user(), current_user(), database();
EOF

--echo #
--echo # name match = ok
--echo #
--exec $MYSQL_TEST -u $USER --plugin-dir=$plugindir < $MYSQLTEST_VARDIR/tmp/peercred_test.txt

--echo #
--echo # name does not match = failure
--echo #
--error 1
--exec $MYSQL_TEST -u foobar --plugin-dir=$plugindir < $MYSQLTEST_VARDIR/tmp/peercred_test.txt

--replace_result $USER USER
eval drop user $USER;

--echo #
--echo # and now with anonymous user
--echo #
grant SELECT ON test.* TO '' identified via unix_socket;
--echo #
--echo # name match = ok
--echo #
--exec $MYSQL_TEST -u $USER --plugin-dir=$plugindir < $MYSQLTEST_VARDIR/tmp/peercred_test.txt

--echo #
--echo # name does not match = failure
--echo #
--error 1
--exec $MYSQL_TEST -u foobar --plugin-dir=$plugindir < $MYSQLTEST_VARDIR/tmp/peercred_test.txt

# restoring mysql.user to the original state.
delete from mysql.user where user='';
uninstall plugin unix_socket;
--remove_file $MYSQLTEST_VARDIR/tmp/peercred_test.txt