File: unix_socket_osuser_match_auth_string.test

package info (click to toggle)
mariadb 1%3A11.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 765,428 kB
  • sloc: ansic: 2,382,827; cpp: 1,803,532; asm: 378,315; perl: 63,176; sh: 46,496; pascal: 40,776; java: 39,363; yacc: 20,428; python: 19,506; sql: 17,864; xml: 12,463; ruby: 8,544; makefile: 6,059; cs: 5,855; ada: 1,700; lex: 1,193; javascript: 1,039; objc: 80; tcl: 73; awk: 46; php: 22
file content (160 lines) | stat: -rw-r--r-- 7,741 bytes parent folder | download | duplicates (2)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
--source include/have_unix_socket.inc

--let $OS_USER=$USER
--write_file $MYSQLTEST_VARDIR/tmp/peercred_test.txt
select user(), current_user(), database();
select @@external_user;
EOF

--echo ########################################################################
--echo # Test for case:
--echo #     - create user A identified via unix_socket as 'B' or unix_socket as 'C';
--echo #     - connect as database user A using unix user of B
--echo # Expected result:
--echo #     - connection succeed
--echo ########################################################################
--replace_result $OS_USER "OS_USER"
eval create user 'DB_USER1' identified via unix_socket as '$OS_USER' or unix_socket as '-Cannot-Match-Any-Legal-Unix-User-Name';
--replace_result $OS_USER "OS_USER"
eval grant select on test.* to 'DB_USER1';
--echo #
--echo # Auth succeed with OS user matches the first authentication string.
--echo # @@external_user is set to OS_USER name.
--echo #
--replace_result $OS_USER "OS_USER"
--exec $MYSQL_TEST -u DB_USER1 < $MYSQLTEST_VARDIR/tmp/peercred_test.txt
--replace_result $OS_USER "OS_USER"
select host, user, json_value(priv, '$.authentication_string') as authentication_string,
    json_value(priv, '$.auth_or[0].authentication_string') as optional_authentication_string from mysql.global_priv where user='DB_USER1';


--echo
--echo ########################################################################
--echo # Test for case:
--echo #     - create user A identified via unix_socket as 'B' or unix_socket as 'C';
--echo #     - connect as database user A using unix user of C
--echo # Expected result:
--echo #     - connection succeed
--echo ########################################################################
--replace_result $OS_USER "OS_USER"
eval create user 'DB_USER2' identified via unix_socket as '-Cannot-Match-Any-Legal-Unix-User-Name' or unix_socket as '$OS_USER';
--replace_result $OS_USER "OS_USER"
eval grant select on test.* to 'DB_USER2';
--echo #
--echo # Auth succeed with OS user matches the optional authentication string.
--echo # @@external_user is set to OS_USER name.
--echo #
--replace_result $OS_USER "OS_USER"
--exec $MYSQL_TEST -u DB_USER2 < $MYSQLTEST_VARDIR/tmp/peercred_test.txt
--replace_result $OS_USER "OS_USER"
select host, user, json_value(priv, '$.authentication_string') as authentication_string,
    json_value(priv, '$.auth_or[0].authentication_string') as optional_authentication_string from mysql.global_priv where user='DB_USER1';


--echo
--echo ########################################################################
--echo # Test for case:
--echo #     - create user A identified via unix_socket as 'B';
--echo #     - connect as database user A using unix user of D
--echo # Expected result:
--echo #     - connection is refused
--echo ########################################################################
eval create user 'DB_USER3' identified via unix_socket as '-Cannot-Match-Any-Legal-Unix-User-Name';
eval grant select on test.* to 'DB_USER3';
--echo #
--echo # Auth fail with OS user that does not match the authentication string.
--echo #
--error 1
--exec $MYSQL_TEST -u DB_USER3 < $MYSQLTEST_VARDIR/tmp/peercred_test.txt


--echo #
--echo ########################################################################
--echo # Test for case:
--echo #     - create user A identified via unix_socket as 'B' or unix_socket as 'C';
--echo #     - connect as database user A using unix user of D
--echo # Expected result:
--echo #     - connection is refused
--echo ########################################################################
eval create user 'DB_USER4' identified via unix_socket as '-Cannot-Match-Any-Legal-Unix-User-Name-1'
                                        or unix_socket as '-Cannot-Match-Any-Legal-Unix-User-Name-2';
eval grant select on test.* to 'DB_USER4';
--echo #
--echo # Auth fail with OS user that does not match the authentication string.
--echo #
--error 1
--exec $MYSQL_TEST -u DB_USER4 < $MYSQLTEST_VARDIR/tmp/peercred_test.txt
--replace_result $OS_USER "OS_USER"
select host, user, json_value(priv, '$.authentication_string') as authentication_string,
    json_value(priv, '$.auth_or[0].authentication_string') as optional_authentication_string from mysql.global_priv where user='DB_USER1';


--echo ########################################################################
--echo # Test for case:
--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';
--echo #     - connect as database user A using unix user of 'D'
--echo # Expected result:
--echo #     - connection succeed
--echo ########################################################################
--replace_result $OS_USER "OS_USER"
eval create user 'DB_USER5' identified via unix_socket as '-Cannot-Match-Any-Legal-Unix-User-Name-B'
                                        or unix_socket as '-Cannot-Match-Any-Legal-Unix-User-Name-C'
                                        or unix_socket as '$OS_USER'
                                        or unix_socket as '-Cannot-Match-Any-Legal-Unix-User-Name-E'
                                        or unix_socket as '-Cannot-Match-Any-Legal-Unix-User-Name-F';
--replace_result $OS_USER "OS_USER"
eval grant select on test.* to 'DB_USER5';
--echo #
--echo # Auth succeed with OS user matches the first authentication string.
--echo # @@external_user is set to OS_USER name.
--echo #
--replace_result $OS_USER "OS_USER"
--exec $MYSQL_TEST -u DB_USER5 < $MYSQLTEST_VARDIR/tmp/peercred_test.txt
--replace_result $OS_USER "OS_USER"
select host, user, json_value(priv, '$.authentication_string') as authentication_string,
    json_value(priv, '$.auth_or[0].authentication_string') as optional_authentication_string_0,
    json_value(priv, '$.auth_or[1].authentication_string') as optional_authentication_string_1,
    json_value(priv, '$.auth_or[2].authentication_string') as optional_authentication_string_2,
    json_value(priv, '$.auth_or[3].authentication_string') as optional_authentication_string_3
    from mysql.global_priv where user='DB_USER5';


--echo
--echo ########################################################################
--echo # Test for case:
--echo #     - create user A identified via unix_socket as 'B';
--echo #     - connect as database user A using unix user of A
--echo # Expected result:
--echo #     - connection is rejected
--echo ########################################################################
--echo #
--echo # Create DB user different with the OS user name, but using OS user name as the authentication string.
--echo #
--replace_result $OS_USER "OS_USER"
eval create user '$OS_USER' identified via unix_socket as '-Cannot-Match-Any-Legal-Unix-User-Name';
--replace_result $OS_USER "OS_USER"
eval grant select on test.* to '$OS_USER';
--echo #
--echo # Auth fail with OS user that does not match the authentication string.
--echo #
--error 1
--exec $MYSQL_TEST -u $OS_USER < $MYSQLTEST_VARDIR/tmp/peercred_test.txt


--echo
--echo ########################################################################
--echo # Removing the test user.
--echo ########################################################################
eval drop user 'DB_USER1';
eval drop user 'DB_USER2';
eval drop user 'DB_USER3';
eval drop user 'DB_USER4';
eval drop user 'DB_USER5';
--replace_result $OS_USER "OS_USER"
eval drop user '$OS_USER';
FLUSH PRIVILEGES;

--echo ########################################################################
--echo # Removing the test file.
--echo ########################################################################
--remove_file $MYSQLTEST_VARDIR/tmp/peercred_test.txt