Debian Codegraph @

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

raw
1 --source include/have_plugin_auth.inc
2 --source include/not_embedded.inc
3 --source include/have_partition.inc
4
5 if (!$SERVER_AUDIT_SO) {
6 skip No SERVER_AUDIT plugin;
7 }
8
9 --disable_ps2_protocol
10 # An unfortunate wait for check-testcase.inc to complete disconnect.
11 let count_sessions= 1;
12 source include/wait_until_count_sessions.inc;
13
14 let $MYSQLD_DATADIR= `SELECT @@datadir`;
15 let SEARCH_FILE= $MYSQLD_DATADIR/server_audit.log;
16
17 install plugin server_audit soname 'server_audit';
18
19 show variables like 'server_audit%';
20 set global server_audit_file_path=null;
21 set global server_audit_incl_users=null;
22 set global server_audit_file_path='server_audit.log';
23 set global server_audit_output_type=file;
24
25 --replace_regex /[1-9][0-9][0-9]+/FN_LEN/
26 set global server_audit_file_path=REPEAT(REPEAT('new_file_name', 50), 50);
27
28 set global server_audit_logging=on;
29
30 --error ER_WRONG_VALUE_FOR_VAR
31 set global server_audit_incl_users= repeat("'root',", 10000);
32 show variables like 'server_audit_incl_users';
33 --error ER_WRONG_VALUE_FOR_VAR
34 set global server_audit_excl_users= repeat("'root',", 10000);
35 show variables like 'server_audit_excl_users';
36 let SEARCH_COUNT= 5;
37 source include/wait_for_line_count_in_file.inc;
38
39 connect (con1,localhost,root,,mysql);
40 disconnect con1;
41 let SEARCH_COUNT= 7;
42 source include/wait_for_line_count_in_file.inc;
43
44 --replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
45 --error ER_ACCESS_DENIED_ERROR
46 connect (con1,localhost,no_such_user,,mysql);
47 let SEARCH_COUNT= 9;
48 source include/wait_for_line_count_in_file.inc;
49
50 connection default;
51 set global server_audit_incl_users='odin, dva, tri';
52 create table t1 (id int);
53 set global server_audit_incl_users='odin, root, dva, tri';
54 create table t2 (id int);
55 set global server_audit_excl_users='odin, dva, tri';
56 insert into t1 values (1), (2);
57 select * from t1;
58 set global server_audit_incl_users='odin, root, dva, tri';
59 insert into t2 values (1), (2);
60 select * from t2;
61 alter table t1 rename renamed_t1;
62 set global server_audit_events='connect,query';
63 select 1,
64 2,
65 # comment
66 3;
67 insert into t2 values (1), (2);
68 select * from t2;
69 --disable_ps_protocol
70 --error ER_NO_SUCH_TABLE
71 select * from t_doesnt_exist;
72 --enable_ps_protocol
73 --error 1064
74 syntax_error_query;
75 drop table renamed_t1, t2;
76 show variables like 'server_audit%';
77 set global server_audit_mode=1;
78 set global server_audit_events='';
79 create database sa_db;
80 let SEARCH_COUNT= 47;
81 source include/wait_for_line_count_in_file.inc;
82
83 connect (con1,localhost,root,,test);
84 create table t1 (id2 int);
85 insert into t1 values (1), (2);
86 select * from t1;
87 drop table t1;
88 use sa_db;
89 create table sa_t1(id int);
90 insert into sa_t1 values (1), (2);
91 drop table sa_t1;
92 drop database sa_db;
93 disconnect con1;
94 let SEARCH_COUNT= 80;
95 source include/wait_for_line_count_in_file.inc;
96
97 connection default;
98 create database sa_db;
99 use sa_db;
100 CREATE USER u1 IDENTIFIED BY 'pwd-123';
101 GRANT ALL ON sa_db TO u2 IDENTIFIED BY "pwd-321";
102 SET PASSWORD FOR u1 = PASSWORD('pwd 098');
103 CREATE USER u3 IDENTIFIED BY '';
104 ALTER USER u3 IDENTIFIED BY 'pwd-456';
105 GRANT SELECT ON sa_db.* TO pwd_test1 IDENTIFIED BY 'grantpwd789';
106 CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_USER='repl', MASTER_PASSWORD='replsecret';
107 CREATE SERVER pwd_server FOREIGN DATA WRAPPER mysql OPTIONS (HOST 'localhost', USER 'remote', PASSWORD 'serverpwd');
108 ALTER SERVER pwd_server OPTIONS (PASSWORD 'newserverpwd');
109 DROP USER pwd_test1;
110 DROP SERVER pwd_server;
111 RESET SLAVE ALL;
112 drop user u1, u2, u3;
113
114 set global server_audit_events='query_ddl';
115 create table t1(id int);
116 insert into t1 values (1), (2);
117 select * from t1;
118 select 2;
119 (select 2);
120 /*! select 2*/;
121 /*comment*/ select 2;
122 drop table t1;
123
124 create procedure pr1() insert into test.t1 values ("foo", 42);
125 create function fn1(i int) returns int deterministic return i+1;
126 drop procedure pr1;
127 drop function fn1;
128
129 set global server_audit_events='query_ddl,query_dml';
130 create table t1(id int);
131 insert into t1 values (1), (2);
132 select * from t1;
133 select 2;
134 drop table t1;
135 set global server_audit_events='query_dml';
136 create table t1(id int);
137 insert into t1 values (1), (2);
138 select * from t1;
139 select 2;
140 (select 2);
141 /*! select 2*/;
142 /*comment*/ select 2;
143 with foo as (select 1) select 6;
144 values (7, 'a'), (8, 'b');
145
146 --echo #
147 --echo # Certain usage of comments and control characters in query strings bypass audit
148 --echo # logging when filtering in QUERY_{DCL/DML/DDL} mode
149 --echo #
150
151 query -- A comment
152 select 1;
153
154 query --A comment
155 select 2;
156
157 query # A comment
158 select 3;
159
160 query /*! SELECT 4 */;
161 query /*M! SELECT 5 */;
162
163 query /*!100100 SELECT 6 */;
164 query /*!999999 SELECT 'should not log' */;
165 query /*M!100100 SELECT 7 */;
166 query /*M!999999 SELECT 'should not log' */;
167
168 drop table t1;
169 set global server_audit_events='query_dcl';
170 create table t1(id int);
171 insert into t1 values (1), (2);
172 select * from t1;
173 CREATE USER u1 IDENTIFIED BY 'pwd-123';
174 GRANT ALL ON sa_db TO u2 IDENTIFIED BY "pwd-321";
175 SET PASSWORD
176 # comment
177 FOR u1 = PASSWORD('pwd 098');
178 --error 1064
179 SET PASSWORD FOR u1=<secret>;
180 CREATE USER u3 IDENTIFIED BY '';
181 drop user u1, u2, u3;
182 select 2;
183 (select 2);
184 /*! select 2*/;
185 /*comment*/ select 2;
186 drop table t1;
187 set global server_audit_events='query_dml_no_select';
188 create table t1(id int);
189 insert into t1 values (1), (2);
190 select * from t1;
191 select 2;
192 drop table t1;
193 create procedure pr1() insert into test.t1 values ("foo", 42);
194 create function fn1(i int) returns int deterministic return i+1;
195 drop procedure pr1;
196 drop function fn1;
197
198 create procedure pr1() insert into test.t1 values ("foo", 42);
199 create function fn1(i int) returns int deterministic return i+1;
200 drop procedure pr1;
201 drop function fn1;
202
203 set global server_audit_events='table';
204 set global server_audit_incl_users='user1';
205
206 create user user1@localhost;
207 grant all on sa_db.* to user1@localhost;
208
209 connect (cn1,localhost,user1,,sa_db);
210 connection cn1;
211
212 create table t1(id int) engine=myisam;
213 insert delayed into t1 values (1);
214
215 connection default;
216
217 --echo # Waiting until INSERT DELAYED thread does the insert.
218 let $wait_condition= SELECT COUNT(*) = 1 FROM t1;
219 --source include/wait_condition.inc
220 drop table t1;
221
222 #
223 # MDEV-7451 Server audit: Table events for partitioned tables are duplicated for each partition.
224 #
225 create table test_partitions (i int) partition by hash (i) partitions 4;
226 drop table test_partitions;
227
228 set global server_audit_logging= off;
229 set global server_audit_incl_users='root';
230 set global server_audit_logging= on;
231 disconnect cn1;
232 let $count_sessions=1;
233 source include/wait_until_count_sessions.inc;
234
235 drop user user1@localhost;
236
237 set global server_audit_events='';
238 set global server_audit_incl_users='root, plug_dest';
239
240 CREATE USER plug IDENTIFIED WITH 'test_plugin_server' AS 'plug_dest';
241 CREATE USER plug_dest IDENTIFIED BY 'plug_dest_passwd';
242 --sleep 2
243 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
244 --error ER_ACCESS_DENIED_ERROR : this should fail : no grant
245 connect(plug_con,localhost,plug,plug_dest);
246 --sleep 2
247 GRANT PROXY ON plug_dest TO plug;
248 --sleep 2
249 connect(plug_con,localhost,plug,plug_dest,"*NO-ONE*");
250 connection plug_con;
251 select USER(),CURRENT_USER();
252 connection default;
253 disconnect plug_con;
254 --sleep 2
255 --sleep 2
256 DROP USER plug;
257 DROP USER plug_dest;
258
259 set global server_audit_query_log_limit= 15;
260 select (1), (2), (3), (4);
261 select 'A', 'B', 'C', 'D';
262 set global server_audit_query_log_limit= 1024;
263 drop database sa_db;
264
265 select length('01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789');
266
267 CREATE TABLE test.t1 (a char(4));
268 set sql_mode="";
269 insert into test.t1 value("12345");
270 set sql_mode=default;
271 drop table test.t1;
272
273 set global server_audit_file_path='.';
274 --replace_regex /\.[\\\/]/HOME_DIR\//
275 show status like 'server_audit_current_log';
276 set global server_audit_file_path='';
277 show status like 'server_audit_current_log';
278 set global server_audit_file_path=' ';
279 show status like 'server_audit_current_log';
280 set global server_audit_file_path='nonexisting_dir/';
281 show status like 'server_audit_current_log';
282 show variables like 'server_audit%';
283 uninstall plugin server_audit;
284
285 # replace the timestamp and the hostname with constant values
286 --replace_regex /[0-9]* [0-9][0-9]:[0-9][0-9]:[0-9][0-9]\,[^,]*\,/TIME,HOSTNAME,/ /\,[1-9][0-9]*\,/,1,/ /\,[1-9][0-9]*/,ID/
287 cat_file $MYSQLD_DATADIR/server_audit.log;
288 remove_file $MYSQLD_DATADIR/server_audit.log;
289 --enable_ps2_protocol
290
291 --echo #
292 --echo # MDEV-27631 Assertion `global_status_var.global_memory_used == 0' failed in mysqld_exit
293 --echo #
294 install plugin server_audit soname 'server_audit';
295 uninstall plugin server_audit;