File: user_privileges.sb.pl

package info (click to toggle)
mysql-sandbox 3.2.05-1.1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 916 kB
  • sloc: perl: 9,878; sh: 191; makefile: 8
file content (386 lines) | stat: -rw-r--r-- 11,502 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
###########################################
# checking default user privileges
###########################################
#

my $TEST_VERSION = $ENV{TEST_VERSION};
my ($bare_version, $version, $major, $minor, $rev) = get_bare_version ($TEST_VERSION);
my $SANDBOX_HOME= $ENV{SANDBOX_HOME} || "$ENV{HOME}/sandboxes";
my $password_field='password';
my $number_of_users = 8;

if ( (($major ==5) &&  ($minor > 7) )
        or 
    ( ($major ==5) && ($minor == 7) && ($rev > 5) ) 
        or 
    ( ($major ==8) && ($minor == 0) ) 
   )
# Starting with MySQL 5.7.6, the 'password' column in the user table is gone
# There is , instead, a column named 'authentication_string'
{
    $password_field='authentication_string';
}

if ( (($major ==5) &&  ($minor > 7) )
        or 
    ( ($major ==5) && ($minor == 7) && ($rev > 8) ) 
        or 
    ( ($major ==8) && ($minor == 0) ) 
   )
# Starting with MySQL 5.7.9 we have the mysql.sys user created by default.
{
   $number_of_users = 9;
}

ok_exec({
command  => "make_sandbox $TEST_VERSION -- --no_confirm --sandbox_directory=msb_XXXX",
expected => "sandbox server started",
msg      => "sandbox creation",
});

#+-----------+-------------+-------------------------------------------+
#| host      | user        | password                                  |
#+-----------+-------------+-------------------------------------------+
#| localhost | root        | *6C387FC3893DBA1E3BA155E74754DA6682D04747 | 
#| 127.%     | msandbox    | *6C387FC3893DBA1E3BA155E74754DA6682D04747 | 
#| localhost | msandbox    | *6C387FC3893DBA1E3BA155E74754DA6682D04747 | 
#| localhost | msandbox_rw | *6C387FC3893DBA1E3BA155E74754DA6682D04747 | 
#| 127.%     | msandbox_rw | *6C387FC3893DBA1E3BA155E74754DA6682D04747 | 
#| 127.%     | msandbox_ro | *6C387FC3893DBA1E3BA155E74754DA6682D04747 | 
#| localhost | msandbox_ro | *6C387FC3893DBA1E3BA155E74754DA6682D04747 | 
#| 127.%     | rsandbox    | *B07EB15A2E7BD9620DAE47B194D5B9DBA14377AD | 
#+-----------+-------------+-------------------------------------------+

ok_sql({
path     => "$SANDBOX_HOME/msb_XXXX/",
query    => "select count(*) from mysql.user",
expected => "$number_of_users",
msg      => "number of users",
});

ok_sql({
path     => "$SANDBOX_HOME/msb_XXXX/",
query    => "select count(*) from mysql.user where host = '127.%'",
expected => "4",
msg      => "number of users with host '127.%'",
});

ok_sql({
path     => "$SANDBOX_HOME/msb_XXXX/",
query    => "select count(*) from mysql.user where user = 'msandbox'",
expected => "2",
msg      => "number of 'msandbox' users",
});

ok_sql({
path     => "$SANDBOX_HOME/msb_XXXX/",
query    => "select count(*) from mysql.user where $password_field = password('msandbox')",
expected => "7",
msg      => "number of 'msandbox' passwords",
});

ok_sql({
path     => "$SANDBOX_HOME/msb_XXXX/",
query    => "select user from mysql.user where $password_field = password('rsandbox')",
expected => "rsandbox",
msg      => "user with 'rsandbox' password",
});

ok_exec({
command  => "$SANDBOX_HOME/msb_XXXX/use -u msandbox_rw -e 'create table test.t1( i int)'",
expected => "ok",
msg      => "table creation allowed",
});

ok_exec({
command  => "$SANDBOX_HOME/msb_XXXX/use -u msandbox_rw -e 'insert into test.t1 values (2011)'",
expected => "ok",
msg      => "table insertion allowed",
});

ok_exec({
command  => "$SANDBOX_HOME/msb_XXXX/use -u msandbox_ro -e 'create table test.t2(i int)' 2>&1 || echo 1",
expected => "denied",
msg      => "table creation denied",
});

ok_exec({
command  => "$SANDBOX_HOME/msb_XXXX/use -u msandbox_ro -e 'select * from test.t1'",
expected => "2011",
msg      => "table selection allowed",
});

ok_exec({
command  => "$SANDBOX_HOME/msb_XXXX/use -u msandbox_rw -e 'drop table test.t1'",
expected => "ok",
msg      => "table drop allowed",
});


ok_exec({
command  => qq($SANDBOX_HOME/msb_XXXX/use -h 127.0.0.1 -u rsandbox -prsandbox -e 'show grants for rsandbox@"127.%"'),
expected => "REPLICATION SLAVE",
msg      => "replication slave user",
});

###########################################
# checking user privileges in replication
###########################################

ok_exec({
command     => "make_replication_sandbox --replication_directory=rsandbox_XXXX $TEST_VERSION ",
expected    => "replication directory installed",
msg         => "replication started",
});

sleep 1;

ok_sql({
path     => "$SANDBOX_HOME/rsandbox_XXXX/master/",
query    => "select count(*) from mysql.user",
expected => "$number_of_users",
msg      => "number of users (master)",
});

ok_sql({
path     => "$SANDBOX_HOME/rsandbox_XXXX/master/",
query    => "select count(*) from mysql.user where host = '127.%'",
expected => "4",
msg      => "number of users with host '127.%' (master)",
});

ok_sql({
path     => "$SANDBOX_HOME/rsandbox_XXXX/master/",
query    => "select count(*) from mysql.user where user = 'msandbox'",
expected => "2",
msg      => "number of 'msandbox' users (master)",
});

ok_sql({
path     => "$SANDBOX_HOME/rsandbox_XXXX/master/",
query    => "select count(*) from mysql.user where $password_field = password('msandbox')",
expected => "7",
msg      => "number of 'msandbox' passwords (master)",
});

ok_sql({
path     => "$SANDBOX_HOME/rsandbox_XXXX/master/",
query    => "select user from mysql.user where $password_field = password('rsandbox')",
expected => "rsandbox",
msg      => "user with 'rsandbox' password (master)",
});

ok_exec({
command  => "$SANDBOX_HOME/rsandbox_XXXX/master/use -u msandbox_rw -e 'create table test.t1( i int)'",
expected => "ok",
msg      => "table creation allowed (master)",
});

ok_exec({
command  => "$SANDBOX_HOME/rsandbox_XXXX/master/use -u msandbox_rw -e 'insert into test.t1 values (2011)'",
expected => "ok",
msg      => "table insertion allowed (master)",
});

ok_exec({
command  => "$SANDBOX_HOME/rsandbox_XXXX/master/use -u msandbox_ro -e 'create table test.t2(i int)' 2>&1 || echo 1",
expected => "denied",
msg      => "table creation denied (master)",
});

ok_exec({
command  => "$SANDBOX_HOME/rsandbox_XXXX/master/use -u msandbox_ro -e 'select * from test.t1'",
expected => "2011",
msg      => "table selection allowed (master)",
});

ok_exec({
command  => "$SANDBOX_HOME/rsandbox_XXXX/master/use -u msandbox_rw -e 'drop table test.t1'",
expected => "ok",
msg      => "table drop allowed (master)",
});

ok_exec({
command  => qq($SANDBOX_HOME/rsandbox_XXXX/master/use -h 127.0.0.1 -u rsandbox -prsandbox -e 'show grants for rsandbox@"127.%"'),
expected => "REPLICATION SLAVE",
msg      => "replication slave user (master)",
});

ok_sql({
path     => "$SANDBOX_HOME/rsandbox_XXXX/node1/",
query    => "select count(*) from mysql.user",
expected => "$number_of_users",
msg      => "number of users (node1)",
});

ok_sql({
path     => "$SANDBOX_HOME/rsandbox_XXXX/node1/",
query    => "select count(*) from mysql.user where host = '127.%'",
expected => "4",
msg      => "number of users with host '127.%' (node1)",
});

ok_sql({
path     => "$SANDBOX_HOME/rsandbox_XXXX/node1/",
query    => "select count(*) from mysql.user where user = 'msandbox'",
expected => "2",
msg      => "number of 'msandbox' users (node1)",
});

ok_sql({
path     => "$SANDBOX_HOME/rsandbox_XXXX/node1/",
query    => "select count(*) from mysql.user where $password_field = password('msandbox')",
expected => "7",
msg      => "number of 'msandbox' passwords (node1)",
});

ok_sql({
path     => "$SANDBOX_HOME/rsandbox_XXXX/node1/",
query    => "select user from mysql.user where $password_field = password('rsandbox')",
expected => "rsandbox",
msg      => "user with 'rsandbox' password (node1)",
});

ok_exec({
command  => "$SANDBOX_HOME/rsandbox_XXXX/node1/use -u msandbox_rw -e 'create table test.t11( i int)'",
expected => "ok",
msg      => "table creation allowed (node1)",
});

ok_exec({
command  => "$SANDBOX_HOME/rsandbox_XXXX/node1/use -u msandbox_rw -e 'insert into test.t11 values (2011)'",
expected => "ok",
msg      => "table insertion allowed (node1)",
});

ok_exec({
command  => "$SANDBOX_HOME/rsandbox_XXXX/node1/use -u msandbox_ro -e 'create table test.t2(i int)' 2>&1 || echo 1",
expected => "denied",
msg      => "table creation denied (node1)",
});

ok_exec({
command  => "$SANDBOX_HOME/rsandbox_XXXX/node1/use -u msandbox_ro -e 'select * from test.t11'",
expected => "2011",
msg      => "table selection allowed (node1)",
});

ok_exec({
command  => "$SANDBOX_HOME/rsandbox_XXXX/node1/use -u msandbox_rw -e 'drop table test.t11'",
expected => "ok",
msg      => "table drop allowed (node1)",
});

ok_exec({
command  => qq($SANDBOX_HOME/rsandbox_XXXX/node1/use -h 127.0.0.1 -u rsandbox -prsandbox -e 'show grants for rsandbox@"127.%"'),
expected => "REPLICATION SLAVE",
msg      => "replication slave user (node1)",
});

ok_exec({
command  => "sbtool -o delete -s $SANDBOX_HOME/msb_XXXX",
expected => "ok",
msg      => "single sandbox removed",
});


ok_exec({
command  => "sbtool -o delete -s $SANDBOX_HOME/rsandbox_XXXX",
expected => "ok",
msg      => "replication sandbox removed",
});

#################################################
# checking remote access ('%' instead of '127.%')
#################################################

ok_exec({
command  => "make_sandbox $TEST_VERSION -- --no_confirm --sandbox_directory=msb_XXXX --remote_access=%",
expected => "sandbox server started",
msg      => "sandbox creation",
});

ok_sql({
path     => "$SANDBOX_HOME/msb_XXXX/",
query    => "select count(*) from mysql.user",
expected => "$number_of_users",
msg      => "number of users",
});

ok_sql({
path     => "$SANDBOX_HOME/msb_XXXX/",
query    => "select count(*) from mysql.user where host = '127.%'",
expected => "0",
msg      => "number of users with host '127.%'",
});

ok_sql({
path     => "$SANDBOX_HOME/msb_XXXX/",
query    => "select count(*) from mysql.user where host = '%'",
expected => "4",
msg      => "number of users with host '%'",
});

ok_exec({
command     => "make_replication_sandbox --replication_directory=rsandbox_XXXX --remote_access=% $TEST_VERSION ",
expected    => "replication directory installed",
msg         => "replication started",
});

ok_sql({
path     => "$SANDBOX_HOME/rsandbox_XXXX/node1/",
query    => "select count(*) from mysql.user",
expected => "$number_of_users",
msg      => "number of users (node1)",
});

ok_sql({
path     => "$SANDBOX_HOME/rsandbox_XXXX/node1/",
query    => "select count(*) from mysql.user where host = '127.%'",
expected => "0",
msg      => "number of users with host '127.%' (node1)",
});

ok_sql({
path     => "$SANDBOX_HOME/rsandbox_XXXX/node1/",
query    => "select count(*) from mysql.user where host = '%'",
expected => "4",
msg      => "number of users with host '%' (node1)",
});

ok_sql({
path     => "$SANDBOX_HOME/rsandbox_XXXX/master/",
query    => "select count(*) from mysql.user",
expected => "$number_of_users",
msg      => "number of users (master)",
});

ok_sql({
path     => "$SANDBOX_HOME/rsandbox_XXXX/master/",
query    => "select count(*) from mysql.user where host = '127.%'",
expected => "0",
msg      => "number of users with host '127.%' (master)",
});

ok_sql({
path     => "$SANDBOX_HOME/rsandbox_XXXX/master/",
query    => "select count(*) from mysql.user where host = '%'",
expected => "4",
msg      => "number of users with host '%' (master)",
});

ok_exec({
command  => "$SANDBOX_HOME/msb_XXXX/stop",
expected => "OK",
msg      => "stopped ",
});

ok_exec({
command     => "$SANDBOX_HOME/rsandbox_XXXX/stop_all",
expected    => "OK",
msg         => "replication stopped",
});