~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to mysql-test/suite/funcs_1/datadict/processlist_priv.inc

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
############ suite/funcs_1/datadict/processlist_priv.inc ###############
 
2
#                                                                      #
 
3
# Testing of privileges around                                         #
 
4
#     SELECT ... PROCESSLIST/SHOW PROCESSLIST                          #
 
5
#                                                                      #
 
6
# Note(mleich):                                                        #
 
7
#     There is a significant risk to get an unstable test because of   #
 
8
#     timing issues.                                                   #
 
9
#     Example1:                                                        #
 
10
#     1. Disconnect connection X                                       #
 
11
#     2. Switch to connection  Y                                       #
 
12
#     3. SHOW PROCESSLIST might present a record like                  #
 
13
#           <ID> <user> <host> <db> Quit 0 cleaning up NULL            #
 
14
#        or even a row where connection X is without                   #
 
15
#        "Quit" or "cleaning up".                                      #
 
16
#        That means our SHOW PROCESSLIST can come too early.           #
 
17
#     Solution:                                                        #
 
18
#        Close the connections at the end of the test.                 #
 
19
#     Example2 (2008-08-14 again observed):                            #
 
20
#     1. connection X: SHOW PROCESSLIST/GRANT ... etc.                 #
 
21
#     2. Switch to connection  Y                                       #
 
22
#     3. SHOW PROCESSLIST might present a record like                  #
 
23
#        <ID> <user> <host> <db> Query TIME cleaning up <command>      #
 
24
#        <ID> <user> <host> <db> Query TIME writing to net <command>   #
 
25
#        Problems happens more often in case of slow filesystem!       #
 
26
#     First Solution:                                                  #
 
27
#        Insert a dummy SQL command where the cleanup is most probably #
 
28
#        fast before switching to another connection and running       #
 
29
#        SHOW/SELECT PROCESSLIST.                                      #
 
30
#        Suppress writing to protocol by assignment to $variable.      #
 
31
#        let $my_var= `SELECT 1`;                                      #
 
32
#        Even the 'SELECT 1' was in some cases in state                #
 
33
#        "writing to net".                                             #
 
34
#     Final Solution:                                                  #
 
35
#        --real_sleep 0.3                                              #
 
36
#        This value was at least on my box sufficient.                 #
 
37
#        Please inform us if this test fails so that we can adjust     #
 
38
#        the sleep time better or switch to poll routines.             #
 
39
#                                                                      #
 
40
#     Storage engine variants of this test do not make sense.          #
 
41
#     -  I_S tables use the MEMORY storage engine whenever possible.   #
 
42
#     -  There are some I_S table which need column data types which   #
 
43
#        are not supported by MEMORY. Example: LONGTEXT/BLOB           #
 
44
#        MyISAM will be used for such tables.                          #
 
45
#        The column PROCESSLIST.INFO is of data type LONGTEXT          #
 
46
#           ----> MyISAM                                               #
 
47
#     -  There is no impact of the GLOBAL(server) or SESSION default   #
 
48
#        storage engine setting on the engine used for I_S tables.     #
 
49
#        That means we cannot get NDB or InnoDB instead.               #
 
50
#                                                                      #
 
51
# Creation:                                                            #
 
52
# 2007-08    hhunger Implement this test as part of                    #
 
53
#                    WL#3982 Test information_schema.processlist       #
 
54
#                                                                      #
 
55
# Last update:                                                         #
 
56
# 2008-08-14 mleich  Bug#38270 Test "processlist_priv_ps" fails on     #
 
57
#                              varying "processlist" output            #
 
58
#                    - Replace one sleep by a poll routines            #
 
59
#                    - Remove or disable superfluous sleeps            #
 
60
#                                                                      #
 
61
########################################################################
 
62
 
 
63
# The following variables are used in "datadict_priv.inc" and here.
 
64
#
 
65
# information_schema table to be tested
 
66
let $table= processlist;
 
67
#
 
68
# columns of the information_schema table e.g. to use in a select.
 
69
let $columns= ID, USER, HOST, DB, COMMAND, TIME, STATE, INFO;
 
70
#
 
71
# Where clause for an update.
 
72
let $update_where= WHERE id=1 ;
 
73
#
 
74
# Column to be used in the SET of an update.
 
75
let $set_column= user='any_user' ;
 
76
#
 
77
# Where clause of a delete.
 
78
let $delete_where= WHERE id=1 ;
 
79
#
 
80
# Column to be dropped.
 
81
let $drop_column= user;
 
82
#
 
83
# Column to be indexed
 
84
let $index_col= user;
 
85
 
 
86
USE information_schema;
 
87
 
 
88
--echo ####################################################################################
 
89
--echo 1 Prepare test.
 
90
--echo   connection default (user=root)
 
91
--echo ####################################################################################
 
92
if (`SELECT COUNT(*) <> 1 FROM processlist`)
 
93
{
 
94
   --echo This test expects one connection to the server.
 
95
   --echo Expectation: USER  HOST       DB                  COMMAND  STATE      INFO
 
96
   --echo Expectation: root  localhost  information_schema  Query    executing  SELECT USER,HOST,DB,COMMAND,STATE,INFO FROM processlist ORDER BY ID
 
97
   --echo But we found in the moment:
 
98
   SELECT USER,HOST,DB,COMMAND,STATE,INFO FROM processlist ORDER BY ID;
 
99
   --echo Maybe
 
100
   --echo - the base configuration (no of parallel auxiliary sessions) of the server has changed
 
101
   --echo - a parallel test intended for another server accidently connected to our current one
 
102
   --echo We cannot proceed in this situation. Abort
 
103
   exit;
 
104
}
 
105
 
 
106
--echo ####################################################################################
 
107
--echo 1.1 Create two user
 
108
--echo ####################################################################################
 
109
# access to info tables as normal user
 
110
--error 0, ER_CANNOT_USER
 
111
DROP USER ddicttestuser1@'localhost';
 
112
--error 0, ER_CANNOT_USER
 
113
DROP USER ddicttestuser2@'localhost';
 
114
CREATE USER ddicttestuser1@'localhost';
 
115
CREATE USER ddicttestuser2@'localhost';
 
116
SET PASSWORD FOR ddicttestuser1@'localhost' = PASSWORD('ddictpass');
 
117
SET PASSWORD FOR ddicttestuser2@'localhost' = PASSWORD('ddictpass');
 
118
 
 
119
--echo ####################################################################################
 
120
--echo 1.2 Establish connection con100 (user=ddicttestuser1 with no PROCESS privilege):
 
121
connect (con100,localhost,ddicttestuser1,ddictpass,information_schema);
 
122
--echo ####################################################################################
 
123
 
 
124
 
 
125
--echo ####################################################################################
 
126
--echo 2 connection default(user=root with default privileges):
 
127
--echo   SHOW/SELECT shows all processes/threads.
 
128
--echo ####################################################################################
 
129
connection default;
 
130
# Avoid Bug#38270 Test "processlist_priv_ps" fails on varying "processlist" output
 
131
#    This subtest expects that the connection con100 is in state 'Sleep'.
 
132
#    Poll till the connection con100 is in state COMMAND = 'Sleep'.
 
133
let $wait_timeout= 10;
 
134
let $wait_condition=
 
135
SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST
 
136
WHERE DB = 'information_schema' AND COMMAND = 'Sleep' AND USER = 'ddicttestuser1';
 
137
--source include/wait_condition.inc
 
138
eval SHOW CREATE TABLE $table;
 
139
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
140
eval SHOW $table;
 
141
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
142
eval SELECT * FROM $table $select_where ORDER BY id;
 
143
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
144
eval SELECT $columns FROM $table $select_where ORDER BY id;
 
145
--source suite/funcs_1/datadict/datadict_priv.inc
 
146
 
 
147
 
 
148
--echo ####################################################################################
 
149
--echo 3 Switch to connection con100 (user=ddicttestuser1 with no PROCESS privilege):
 
150
connection con100;
 
151
--echo   SHOW/SELECT shows only the processes (1) of the user.
 
152
--echo ####################################################################################
 
153
# No need for poll routine here.
 
154
# The current state of the default session might depend on load of testing box
 
155
# but "ddicttestuser1" must not see anything of the root session.
 
156
eval SHOW CREATE TABLE $table;
 
157
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
158
eval SHOW $table;
 
159
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
160
eval SELECT * FROM $table $select_where ORDER BY id;
 
161
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
162
eval SELECT $columns FROM $table $select_where ORDER BY id;
 
163
--source suite/funcs_1/datadict/datadict_priv.inc
 
164
--real_sleep 0.3
 
165
 
 
166
 
 
167
--echo ####################################################################################
 
168
--echo 4 Grant PROCESS privilege to ddicttestuser1
 
169
--echo   connection default (user=root)
 
170
--echo ####################################################################################
 
171
connection default;
 
172
GRANT PROCESS ON *.* TO ddicttestuser1@'localhost' IDENTIFIED BY 'ddictpass';
 
173
--real_sleep 0.3
 
174
 
 
175
--echo ####################################################################################
 
176
--echo 4.1 Existing connection con100 (ddicttestuser1)
 
177
--echo     The user ddicttestuser1 has the PROCESS privilege, but the connection was
 
178
--echo     established before PROCESS was granted.
 
179
--echo     SHOW/SELECT shows only the processes (1) of the user.
 
180
--echo ####################################################################################
 
181
connection con100;
 
182
SHOW GRANTS;
 
183
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
184
SHOW processlist;
 
185
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
186
SELECT * FROM information_schema.processlist;
 
187
--real_sleep 0.3
 
188
 
 
189
--echo ####################################################################################
 
190
--echo 4.2 New connection con101 (ddicttestuser1 with PROCESS privilege)
 
191
--echo     SHOW/SELECT shows all processes/threads.
 
192
--echo ####################################################################################
 
193
connect (con101,localhost,ddicttestuser1,ddictpass,information_schema);
 
194
SHOW GRANTS;
 
195
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
196
SHOW processlist;
 
197
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
198
SELECT * FROM information_schema.processlist;
 
199
--real_sleep 0.3
 
200
 
 
201
 
 
202
--echo ####################################################################################
 
203
--echo 5 Grant PROCESS privilege to anonymous user.
 
204
--echo   connection default (user=root)
 
205
--echo ####################################################################################
 
206
connection default;
 
207
GRANT PROCESS ON *.* TO ''@'localhost';
 
208
--real_sleep 0.3
 
209
 
 
210
--echo ####################################################################################
 
211
--echo 5.1 Establish connection (anonymous1,localhost,'',,information_schema)
 
212
--echo     anonymous user with PROCESS privilege
 
213
--echo     SHOW/SELECT shows all processes/threads.
 
214
--echo ####################################################################################
 
215
connect (anonymous1,localhost,"''",,information_schema);
 
216
SHOW GRANTS;
 
217
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
218
SHOW processlist;
 
219
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
220
SELECT * FROM information_schema.processlist;
 
221
--real_sleep 0.3
 
222
 
 
223
 
 
224
--echo ####################################################################################
 
225
--echo 6 Revoke PROCESS privilege from ddicttestuser1
 
226
--echo   connection default (user=root)
 
227
--echo ####################################################################################
 
228
connection default;
 
229
REVOKE PROCESS ON *.* FROM ddicttestuser1@'localhost' IDENTIFIED BY 'ddictpass';
 
230
--real_sleep 0.3
 
231
 
 
232
--echo ####################################################################################
 
233
--echo 6.1 New connection con102 (ddicttestuser1 has no more PROCESS privilege)
 
234
connect (con102,localhost,ddicttestuser1,ddictpass,information_schema);
 
235
--echo     Again (compared to state before GRANT PROCESS) only the processes of
 
236
--echo     ddicttestuser1 are visible.
 
237
--echo ####################################################################################
 
238
SHOW GRANTS;
 
239
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
240
SHOW processlist;
 
241
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
242
SELECT * FROM information_schema.processlist;
 
243
--real_sleep 0.3
 
244
 
 
245
 
 
246
--echo ####################################################################################
 
247
--echo 7 Revoke PROCESS privilege from anonymous user
 
248
--echo   connection default (user=root)
 
249
--echo ####################################################################################
 
250
connection default;
 
251
REVOKE PROCESS ON *.* FROM ''@'localhost';
 
252
--real_sleep 0.3
 
253
 
 
254
--echo ####################################################################################
 
255
--echo 7.1 New connection (anonymous2,localhost,'',,information_schema)
 
256
connect (anonymous2,localhost,"''",,information_schema);
 
257
--echo     The anonymous user has no more the PROCESS privilege
 
258
--echo     Again only the processes of the anonymous user are visible.
 
259
--echo ####################################################################################
 
260
SHOW GRANTS FOR ''@'localhost';
 
261
if ($fixed_bug_30395)
 
262
{
 
263
# Bug#30395 strange results after REVOKE PROCESS ON *.* FROM ...
 
264
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
265
SHOW processlist;
 
266
}
 
267
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
268
SELECT * FROM information_schema.processlist;
 
269
--real_sleep 0.3
 
270
 
 
271
 
 
272
--echo ####################################################################################
 
273
--echo 8 Grant SUPER (does not imply PROCESS) privilege to ddicttestuser1
 
274
--echo   connection default (user=root)
 
275
--echo ####################################################################################
 
276
connection default;
 
277
GRANT SUPER ON *.* TO 'ddicttestuser1'@'localhost';
 
278
--real_sleep 0.3
 
279
 
 
280
--echo ####################################################################################
 
281
--echo 8.1 New connection con103 (ddicttestuser1 with SUPER privilege)
 
282
connect (con103,localhost,ddicttestuser1,ddictpass,information_schema);
 
283
--echo     Only the processes of ddicttestuser1 user are visible.
 
284
--echo ####################################################################################
 
285
SHOW GRANTS FOR 'ddicttestuser1'@'localhost';
 
286
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
287
SHOW processlist;
 
288
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
289
SELECT * FROM information_schema.processlist;
 
290
--real_sleep 0.3
 
291
 
 
292
 
 
293
--echo ####################################################################################
 
294
--echo 9 Revoke SUPER privilege from user ddicttestuser1
 
295
--echo   connection default (user=root)
 
296
--echo ####################################################################################
 
297
connection default;
 
298
REVOKE SUPER ON *.* FROM 'ddicttestuser1'@'localhost';
 
299
--real_sleep 0.3
 
300
 
 
301
--echo ####################################################################################
 
302
--echo 9.1 New connection con104 (ddicttestuser1 without SUPER privilege)
 
303
connect (con104,localhost,ddicttestuser1,ddictpass,information_schema);
 
304
--echo     ddicttestuser1 has no more the SUPER privilege.
 
305
--echo     Only the processes of ddicttestuser1 are visible.
 
306
--echo ####################################################################################
 
307
SHOW GRANTS FOR 'ddicttestuser1'@'localhost';
 
308
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
309
SHOW processlist;
 
310
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
311
SELECT * FROM information_schema.processlist;
 
312
--real_sleep 0.3
 
313
 
 
314
 
 
315
--echo ####################################################################################
 
316
--echo 10 Grant SUPER privilege with grant option to user ddicttestuser1.
 
317
--echo   connection default (user=root)
 
318
--echo ####################################################################################
 
319
connection default;
 
320
GRANT SUPER ON *.* TO 'ddicttestuser1'@'localhost' WITH GRANT OPTION;
 
321
--real_sleep 0.3
 
322
 
 
323
--echo ####################################################################################
 
324
--echo 10.1 New connection con105 (ddicttestuser1 with SUPER privilege and GRANT OPTION)
 
325
connect (con105,localhost,ddicttestuser1,ddictpass,information_schema);
 
326
--echo      Try to grant PROCESS privilege to user ddicttestuser2 without having it.
 
327
--echo ####################################################################################
 
328
SHOW GRANTS FOR 'ddicttestuser1'@'localhost';
 
329
--error ER_ACCESS_DENIED_ERROR
 
330
GRANT PROCESS ON *.* TO 'ddicttestuser2'@'localhost';
 
331
 
 
332
--echo ####################################################################################
 
333
--echo 10.2 Grant SUPER and PROCESS privilege with grant option to user ddicttestuser1
 
334
--echo   connection default (user=root)
 
335
--echo ####################################################################################
 
336
connection default;
 
337
GRANT SUPER,PROCESS ON *.* TO 'ddicttestuser1'@'localhost' WITH GRANT OPTION;
 
338
--real_sleep 0.3
 
339
 
 
340
--echo ####################################################################################
 
341
--echo 10.3 New connection con106 (ddicttestuser1 with SUPER,PROCESS WITH GRANT OPTION)
 
342
connect (con106,localhost,ddicttestuser1,ddictpass,information_schema);
 
343
--echo      Grant PROCESS privilege to user ddicttestuser2
 
344
--echo ####################################################################################
 
345
SHOW GRANTS FOR 'ddicttestuser1'@'localhost';
 
346
GRANT PROCESS ON *.* TO 'ddicttestuser2'@'localhost';
 
347
--real_sleep 0.3
 
348
 
 
349
--echo ####################################################################################
 
350
--echo 10.4 New connection con200 (ddicttestuser2 with PROCESS privilege)
 
351
connect (con200,localhost,ddicttestuser2,ddictpass,information_schema);
 
352
--echo      ddicttestuser2 has now the PROCESS privilege and sees all connections
 
353
--echo ####################################################################################
 
354
SHOW GRANTS FOR 'ddicttestuser2'@'localhost';
 
355
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
356
SHOW processlist;
 
357
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
358
SELECT * FROM information_schema.processlist;
 
359
--real_sleep 0.3
 
360
 
 
361
 
 
362
--echo ####################################################################################
 
363
--echo 11 User ddicttestuser1 revokes PROCESS privilege from user ddicttestuser2
 
364
--echo    connection ddicttestuser1;
 
365
--echo ####################################################################################
 
366
connection con106;
 
367
REVOKE PROCESS ON *.* FROM 'ddicttestuser2'@'localhost';
 
368
--real_sleep 0.3
 
369
 
 
370
--echo ####################################################################################
 
371
--echo 11.1 New connection con201 (ddicttestuser2)
 
372
connect (con201,localhost,ddicttestuser2,ddictpass,information_schema);
 
373
--echo      ddicttestuser2 has no more the PROCESS privilege and can only see own connects
 
374
--echo ####################################################################################
 
375
SHOW GRANTS;
 
376
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
377
SHOW processlist;
 
378
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
379
SELECT * FROM information_schema.processlist;
 
380
--real_sleep 0.3
 
381
 
 
382
--echo ####################################################################################
 
383
--echo 11.2 Revoke SUPER,PROCESS,GRANT OPTION privilege from user ddicttestuser1
 
384
--echo      connection default (user=root)
 
385
--echo ####################################################################################
 
386
connection default;
 
387
REVOKE SUPER,PROCESS,GRANT OPTION ON *.* FROM 'ddicttestuser1'@'localhost';
 
388
--real_sleep 0.3
 
389
 
 
390
--echo ####################################################################################
 
391
--echo 11.3 New connection con107 (ddicttestuser1)
 
392
connect (con107,localhost,ddicttestuser1,ddictpass,information_schema);
 
393
--echo      ddicttestuser1 has no more the PROCESS privilege and can only see own connects
 
394
--echo      He is also unable to GRANT the PROCESS privilege to ddicttestuser2
 
395
--echo ####################################################################################
 
396
SHOW GRANTS FOR 'ddicttestuser1'@'localhost';
 
397
--error ER_ACCESS_DENIED_ERROR
 
398
GRANT PROCESS ON *.* TO 'ddicttestuser2'@'localhost';
 
399
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
400
SHOW processlist;
 
401
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
402
SELECT * FROM information_schema.processlist;
 
403
--real_sleep 0.3
 
404
 
 
405
 
 
406
--echo ####################################################################################
 
407
--echo 12 Revoke the SELECT privilege from user ddicttestuser1
 
408
--echo    connection default (user=root)
 
409
--echo ####################################################################################
 
410
connection default;
 
411
REVOKE SELECT ON *.* FROM 'ddicttestuser1'@'localhost';
 
412
--real_sleep 0.3
 
413
 
 
414
--echo ####################################################################################
 
415
--echo 12.1 New connection con108 (ddicttestuser1)
 
416
connect (con108,localhost,ddicttestuser1,ddictpass,information_schema);
 
417
--echo      ddicttestuser1 has neither PROCESS nor SELECT privilege
 
418
--echo      Manual says: Each MySQL user has the right to access these tables, but can see
 
419
--echo                   only the rows ...
 
420
--echo      Therefore the missing SELECT privilege does not affect SELECTs on PROCESSLIST.
 
421
--echo ####################################################################################
 
422
SHOW GRANTS FOR 'ddicttestuser1'@'localhost';
 
423
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
424
SHOW processlist;
 
425
--replace_column 1 ID 3 HOST_NAME 6 TIME
 
426
SELECT * FROM information_schema.processlist;
 
427
--real_sleep 0.3
 
428
 
 
429
--echo ####################################################################################
 
430
--echo 12.2 Revoke only the SELECT privilege on the information_schema from ddicttestuser1.
 
431
--echo      connection default (user=root)
 
432
--echo ####################################################################################
 
433
connection default;
 
434
--error ER_DBACCESS_DENIED_ERROR
 
435
REVOKE SELECT ON information_schema.* FROM 'ddicttestuser3'@'localhost';
 
436
--real_sleep 0.3
 
437
 
 
438
 
 
439
--echo ####################################################################################
 
440
--echo    connection default (user=root)
 
441
--echo    Cleanup: close connections, DROP USER etc.
 
442
--echo ####################################################################################
 
443
connection default;
 
444
disconnect con100;
 
445
disconnect con101;
 
446
disconnect con102;
 
447
disconnect con103;
 
448
disconnect con104;
 
449
disconnect con105;
 
450
disconnect con106;
 
451
disconnect con107;
 
452
disconnect con108;
 
453
disconnect con200;
 
454
disconnect con201;
 
455
disconnect anonymous1;
 
456
disconnect anonymous2;
 
457
DROP USER ddicttestuser1@'localhost';
 
458
DROP USER ddicttestuser2@'localhost';
 
459
REVOKE USAGE ON *.* FROM ''@'localhost';
 
460
DROP USER ''@'localhost';