Debian Codegraph @

mysql-test/suite/plugins/t/unix_socket_osuser_match_auth_string.test

raw
1 --source include/have_unix_socket.inc
2
3 --let $OS_USER=$USER
4 --write_file $MYSQLTEST_VARDIR/tmp/peercred_test.txt
5 select user(), current_user(), database();
6 select @@external_user;
7 EOF
8
9 --echo ########################################################################
10 --echo # Test for case:
11 --echo # - create user A identified via unix_socket as 'B' or unix_socket as 'C';
12 --echo # - connect as database user A using unix user of B
13 --echo # Expected result:
14 --echo # - connection succeed
15 --echo ########################################################################
16 --replace_result $OS_USER "OS_USER"
17 eval create user 'DB_USER1' identified via unix_socket as '$OS_USER' or unix_socket as '-Cannot-Match-Any-Legal-Unix-User-Name';
18 --replace_result $OS_USER "OS_USER"
19 eval grant select on test.* to 'DB_USER1';
20 --echo #
21 --echo # Auth succeed with OS user matches the first authentication string.
22 --echo # @@external_user is set to OS_USER name.
23 --echo #
24 --replace_result $OS_USER "OS_USER"
25 --exec $MYSQL_TEST -u DB_USER1 < $MYSQLTEST_VARDIR/tmp/peercred_test.txt
26 --replace_result $OS_USER "OS_USER"
27 select host, user, json_value(priv, '$.authentication_string') as authentication_string,
28 json_value(priv, '$.auth_or[0].authentication_string') as optional_authentication_string from mysql.global_priv where user='DB_USER1';
29
30
31 --echo
32 --echo ########################################################################
33 --echo # Test for case:
34 --echo # - create user A identified via unix_socket as 'B' or unix_socket as 'C';
35 --echo # - connect as database user A using unix user of C
36 --echo # Expected result:
37 --echo # - connection succeed
38 --echo ########################################################################
39 --replace_result $OS_USER "OS_USER"
40 eval create user 'DB_USER2' identified via unix_socket as '-Cannot-Match-Any-Legal-Unix-User-Name' or unix_socket as '$OS_USER';
41 --replace_result $OS_USER "OS_USER"
42 eval grant select on test.* to 'DB_USER2';
43 --echo #
44 --echo # Auth succeed with OS user matches the optional authentication string.
45 --echo # @@external_user is set to OS_USER name.
46 --echo #
47 --replace_result $OS_USER "OS_USER"
48 --exec $MYSQL_TEST -u DB_USER2 < $MYSQLTEST_VARDIR/tmp/peercred_test.txt
49 --replace_result $OS_USER "OS_USER"
50 select host, user, json_value(priv, '$.authentication_string') as authentication_string,
51 json_value(priv, '$.auth_or[0].authentication_string') as optional_authentication_string from mysql.global_priv where user='DB_USER1';
52
53
54 --echo
55 --echo ########################################################################
56 --echo # Test for case:
57 --echo # - create user A identified via unix_socket as 'B';
58 --echo # - connect as database user A using unix user of D
59 --echo # Expected result:
60 --echo # - connection is refused
61 --echo ########################################################################
62 eval create user 'DB_USER3' identified via unix_socket as '-Cannot-Match-Any-Legal-Unix-User-Name';
63 eval grant select on test.* to 'DB_USER3';
64 --echo #
65 --echo # Auth fail with OS user that does not match the authentication string.
66 --echo #
67 --error 1
68 --exec $MYSQL_TEST -u DB_USER3 < $MYSQLTEST_VARDIR/tmp/peercred_test.txt
69
70
71 --echo #
72 --echo ########################################################################
73 --echo # Test for case:
74 --echo # - create user A identified via unix_socket as 'B' or unix_socket as 'C';
75 --echo # - connect as database user A using unix user of D
76 --echo # Expected result:
77 --echo # - connection is refused
78 --echo ########################################################################
79 eval create user 'DB_USER4' identified via unix_socket as '-Cannot-Match-Any-Legal-Unix-User-Name-1'
80 or unix_socket as '-Cannot-Match-Any-Legal-Unix-User-Name-2';
81 eval grant select on test.* to 'DB_USER4';
82 --echo #
83 --echo # Auth fail with OS user that does not match the authentication string.
84 --echo #
85 --error 1
86 --exec $MYSQL_TEST -u DB_USER4 < $MYSQLTEST_VARDIR/tmp/peercred_test.txt
87 --replace_result $OS_USER "OS_USER"
88 select host, user, json_value(priv, '$.authentication_string') as authentication_string,
89 json_value(priv, '$.auth_or[0].authentication_string') as optional_authentication_string from mysql.global_priv where user='DB_USER1';
90
91
92 --echo ########################################################################
93 --echo # Test for case:
94 --echo # - create user A identified via unix_socket as 'B' or unix_socket as 'C' or unix_socket as 'D' or unix_socket as 'E' or unix_socket as 'F';
95 --echo # - connect as database user A using unix user of 'D'
96 --echo # Expected result:
97 --echo # - connection succeed
98 --echo ########################################################################
99 --replace_result $OS_USER "OS_USER"
100 eval create user 'DB_USER5' identified via unix_socket as '-Cannot-Match-Any-Legal-Unix-User-Name-B'
101 or unix_socket as '-Cannot-Match-Any-Legal-Unix-User-Name-C'
102 or unix_socket as '$OS_USER'
103 or unix_socket as '-Cannot-Match-Any-Legal-Unix-User-Name-E'
104 or unix_socket as '-Cannot-Match-Any-Legal-Unix-User-Name-F';
105 --replace_result $OS_USER "OS_USER"
106 eval grant select on test.* to 'DB_USER5';
107 --echo #
108 --echo # Auth succeed with OS user matches the first authentication string.
109 --echo # @@external_user is set to OS_USER name.
110 --echo #
111 --replace_result $OS_USER "OS_USER"
112 --exec $MYSQL_TEST -u DB_USER5 < $MYSQLTEST_VARDIR/tmp/peercred_test.txt
113 --replace_result $OS_USER "OS_USER"
114 select host, user, json_value(priv, '$.authentication_string') as authentication_string,
115 json_value(priv, '$.auth_or[0].authentication_string') as optional_authentication_string_0,
116 json_value(priv, '$.auth_or[1].authentication_string') as optional_authentication_string_1,
117 json_value(priv, '$.auth_or[2].authentication_string') as optional_authentication_string_2,
118 json_value(priv, '$.auth_or[3].authentication_string') as optional_authentication_string_3
119 from mysql.global_priv where user='DB_USER5';
120
121
122 --echo
123 --echo ########################################################################
124 --echo # Test for case:
125 --echo # - create user A identified via unix_socket as 'B';
126 --echo # - connect as database user A using unix user of A
127 --echo # Expected result:
128 --echo # - connection is rejected
129 --echo ########################################################################
130 --echo #
131 --echo # Create DB user different with the OS user name, but using OS user name as the authentication string.
132 --echo #
133 --replace_result $OS_USER "OS_USER"
134 eval create user '$OS_USER' identified via unix_socket as '-Cannot-Match-Any-Legal-Unix-User-Name';
135 --replace_result $OS_USER "OS_USER"
136 eval grant select on test.* to '$OS_USER';
137 --echo #
138 --echo # Auth fail with OS user that does not match the authentication string.
139 --echo #
140 --error 1
141 --exec $MYSQL_TEST -u $OS_USER < $MYSQLTEST_VARDIR/tmp/peercred_test.txt
142
143
144 --echo
145 --echo ########################################################################
146 --echo # Removing the test user.
147 --echo ########################################################################
148 eval drop user 'DB_USER1';
149 eval drop user 'DB_USER2';
150 eval drop user 'DB_USER3';
151 eval drop user 'DB_USER4';
152 eval drop user 'DB_USER5';
153 --replace_result $OS_USER "OS_USER"
154 eval drop user '$OS_USER';
155 FLUSH PRIVILEGES;
156
157 --echo ########################################################################
158 --echo # Removing the test file.
159 --echo ########################################################################
160 --remove_file $MYSQLTEST_VARDIR/tmp/peercred_test.txt