~stewart/drizzle/embedded-innodb-create-select-transaction-arrgh

« back to all changes in this revision

Viewing changes to mysql-test/suite/funcs_1/t/is_column_privileges.test

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# suite/funcs_1/t/is_column_privileges.test
 
2
#
 
3
# Check the layout of information_schema.column_privileges and the impact of
 
4
# CREATE/ALTER/DROP TABLE/VIEW/SCHEMA ... on it.
 
5
#
 
6
# Note:
 
7
#    This test is not intended
 
8
#    - to show information about the all time existing tables
 
9
#      within the databases information_schema and mysql
 
10
#    - for checking storage engine properties
 
11
#      Therefore please do not alter $engine_type and $other_engine_type.
 
12
#
 
13
# Author:
 
14
# 2008-01-23 mleich WL#4203 Reorganize and fix the data dictionary tests of
 
15
#                           testsuite funcs_1
 
16
#                   Create this script based on older scripts and new code.
 
17
#
 
18
 
 
19
# --source suite/funcs_1/datadict/datadict.pre
 
20
 
 
21
let $engine_type       = MEMORY;
 
22
let $other_engine_type = MyISAM;
 
23
 
 
24
let $is_table = COLUMN_PRIVILEGES;
 
25
 
 
26
# The table INFORMATION_SCHEMA.COLUMN_PRIVILEGES must exist
 
27
eval SHOW TABLES FROM information_schema LIKE '$is_table';
 
28
 
 
29
--echo #######################################################################
 
30
--echo # Testcase 3.2.1.1: INFORMATION_SCHEMA tables can be queried via SELECT
 
31
--echo #######################################################################
 
32
# Ensure that every INFORMATION_SCHEMA table can be queried with a SELECT
 
33
# statement, just as if it were an ordinary user-defined table.
 
34
#
 
35
--source suite/funcs_1/datadict/is_table_query.inc
 
36
 
 
37
 
 
38
--echo #########################################################################
 
39
--echo # Testcase 3.2.5.1: INFORMATION_SCHEMA.COLUMN_PRIVILEGES layout
 
40
--echo #########################################################################
 
41
# Ensure that the INFORMATION_SCHEMA.COLUMN_PRIVILEGES table has the following
 
42
# columns, in the following order:
 
43
#
 
44
# GRANTEE (shows the name of a user who has either granted,
 
45
#                          or been granted a column privilege),
 
46
# TABLE_CATALOG (always shows NULL),
 
47
# TABLE_SCHEMA (shows the name of the schema, or database, in which the table
 
48
#       for which a column privilege has been granted resides),
 
49
# TABLE_NAME (shows the name of the table),
 
50
# COLUMN_NAME (shows the name of the column on which a column privilege has
 
51
#       been granted),
 
52
# PRIVILEGE_TYPE (shows the type of privilege that was granted; must be either
 
53
#       SELECT, INSERT, UPDATE, or REFERENCES),
 
54
# IS_GRANTABLE (shows whether that privilege was granted WITH GRANT OPTION).
 
55
#
 
56
--source suite/funcs_1/datadict/datadict_bug_12777.inc
 
57
eval DESCRIBE          information_schema.$is_table;
 
58
--source suite/funcs_1/datadict/datadict_bug_12777.inc
 
59
eval SHOW CREATE TABLE information_schema.$is_table;
 
60
--source suite/funcs_1/datadict/datadict_bug_12777.inc
 
61
eval SHOW COLUMNS FROM information_schema.$is_table;
 
62
 
 
63
# Note: Retrieval of information within information_schema.columns
 
64
#       about information_schema.column_privileges is in is_columns_is.test.
 
65
 
 
66
# Show that TABLE_CATALOG is always NULL.
 
67
SELECT table_catalog, table_schema, table_name, column_name, privilege_type
 
68
FROM information_schema.column_privileges WHERE table_catalog IS NOT NULL;
 
69
 
 
70
 
 
71
--echo ######################################################################
 
72
--echo # Testcase 3.2.5.2+3.2.5.3+3.2.5.4:
 
73
--echo #          INFORMATION_SCHEMA.COLUMN_PRIVILEGES accessible information
 
74
--echo ######################################################################
 
75
# 3.2.5.2:  Ensure that the table shows the relevant information on every
 
76
#           column privilege which has been granted to the current user or
 
77
#           PUBLIC, or which was granted by the current user.
 
78
# 3.2.5.3:  Ensure that the table does not show any information on any column
 
79
#           privilege which was granted to any user other than the current user
 
80
#           or PUBLIC, or which was granted by any user other than
 
81
#           the current user.
 
82
# 3.2.5.4:  Ensure that the table does not show any information on any
 
83
#           privileges that are not column privileges for the current user.
 
84
#
 
85
# Note: Check of content within information_schema.column_privileges about the
 
86
#       databases information_schema, mysql and test is in
 
87
#       is_column_privileges_is_mysql_test.test
 
88
#
 
89
--disable_warnings
 
90
DROP DATABASE IF EXISTS db_datadict;
 
91
--enable_warnings
 
92
CREATE DATABASE db_datadict;
 
93
--replace_result $other_engine_type <other_engine_type>
 
94
eval
 
95
CREATE TABLE db_datadict.t1 (f1 INT, f2 DECIMAL, f3 TEXT)
 
96
ENGINE = $other_engine_type;
 
97
 
 
98
USE db_datadict;
 
99
--error 0,ER_CANNOT_USER
 
100
DROP   USER 'testuser1'@'localhost';
 
101
CREATE USER 'testuser1'@'localhost';
 
102
--error 0,ER_CANNOT_USER
 
103
DROP   USER 'testuser2'@'localhost';
 
104
CREATE USER 'testuser2'@'localhost';
 
105
--error 0,ER_CANNOT_USER
 
106
DROP   USER 'testuser3'@'localhost';
 
107
CREATE USER 'testuser3'@'localhost';
 
108
 
 
109
GRANT SELECT(f1, f3) ON db_datadict.t1 TO 'testuser1'@'localhost';
 
110
GRANT INSERT(f1)     ON db_datadict.t1 TO 'testuser1'@'localhost';
 
111
GRANT UPDATE(f2)     ON db_datadict.t1 TO 'testuser1'@'localhost';
 
112
GRANT SELECT(f2)     ON db_datadict.t1 TO 'testuser2'@'localhost';
 
113
GRANT INSERT, SELECT ON db_datadict.t1 TO 'testuser3'@'localhost';
 
114
GRANT SELECT(f3)     ON db_datadict.t1 TO 'testuser3'@'localhost';
 
115
 
 
116
GRANT INSERT, SELECT ON db_datadict.t1 TO 'testuser3'@'localhost'
 
117
WITH GRANT OPTION;
 
118
GRANT ALL            ON db_datadict.*  TO 'testuser3'@'localhost';
 
119
 
 
120
let $select= SELECT * FROM information_schema.column_privileges
 
121
WHERE grantee LIKE '''testuser%'''
 
122
ORDER BY grantee, table_schema,table_name,column_name,privilege_type;
 
123
eval $select;
 
124
 
 
125
# Note: WITH GRANT OPTION applies to all privileges on this table
 
126
#       and not to the columns mentioned only.
 
127
GRANT UPDATE(f3)     ON db_datadict.t1 TO 'testuser1'@'localhost'
 
128
WITH GRANT OPTION;
 
129
 
 
130
eval $select;
 
131
 
 
132
--echo # Establish connection testuser1 (user=testuser1)
 
133
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 
134
connect (testuser1, localhost, testuser1, , db_datadict);
 
135
eval $select;
 
136
 
 
137
--echo # Establish connection testuser2 (user=testuser2)
 
138
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 
139
connect (testuser2, localhost, testuser2, , db_datadict);
 
140
eval $select;
 
141
 
 
142
--echo # Establish connection testuser3 (user=testuser3)
 
143
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 
144
connect (testuser3, localhost, testuser3, , db_datadict);
 
145
 
 
146
--echo # FIXME: Is it correct that granted TABLES do not occur in COLUMN_PRIVILEGES?
 
147
SELECT * FROM information_schema.table_privileges
 
148
WHERE grantee LIKE '''testuser%'''
 
149
ORDER BY grantee,table_schema,table_name,privilege_type;
 
150
SELECT * FROM information_schema.schema_privileges
 
151
WHERE grantee LIKE '''testuser%'''
 
152
ORDER BY grantee,table_schema,privilege_type;
 
153
eval $select;
 
154
GRANT SELECT(f1, f3) ON db_datadict.t1 TO 'testuser2'@'localhost';
 
155
 
 
156
--echo # FIXME: Is it intended that *my* grants to others are *NOT* shown here?
 
157
eval $select;
 
158
 
 
159
--echo # Switch to connection testuser2 (user=testuser2)
 
160
connection testuser2;
 
161
eval $select;
 
162
 
 
163
# Cleanup
 
164
--echo # Switch to connection default and close connections testuser1,testuser2,testuser3
 
165
connection default;
 
166
disconnect testuser1;
 
167
disconnect testuser2;
 
168
disconnect testuser3;
 
169
DROP DATABASE db_datadict;
 
170
DROP USER 'testuser1'@'localhost';
 
171
DROP USER 'testuser2'@'localhost';
 
172
DROP USER 'testuser3'@'localhost';
 
173
 
 
174
 
 
175
--echo ################################################################################
 
176
--echo # 3.2.1.13+3.2.1.14+3.2.1.15: INFORMATION_SCHEMA.COLUMN_PRIVILEGES modifications
 
177
--echo ################################################################################
 
178
# 3.2.1.13: Ensure that the creation of any new database object (e.g. table or
 
179
#           column) automatically inserts all relevant information on that
 
180
#           object into every appropriate INFORMATION_SCHEMA table.
 
181
# 3.2.1.14: Ensure that the alteration of any existing database object
 
182
#           automatically updates all relevant information on that object in
 
183
#           every appropriate INFORMATION_SCHEMA table.
 
184
# 3.2.1.15: Ensure that the dropping of any existing database object
 
185
#           automatically deletes all relevant information on that object from
 
186
#           every appropriate INFORMATION_SCHEMA table.
 
187
#
 
188
# Note (mleich):
 
189
#    The MySQL privilege system allows to GRANT objects before they exist.
 
190
#    (Exception: Grant privileges for columns of not existing tables/views.)
 
191
#    There is also no migration of privileges if objects (tables, views, columns)
 
192
#    are moved to other databases (tables only), renamed or dropped.
 
193
#
 
194
--disable_warnings
 
195
DROP DATABASE IF EXISTS db_datadict;
 
196
--enable_warnings
 
197
CREATE DATABASE db_datadict;
 
198
--replace_result $engine_type <engine_type>
 
199
eval
 
200
CREATE TABLE db_datadict.my_table (f1 BIGINT, f2 CHAR(10), f3 DATE)
 
201
ENGINE = $engine_type;
 
202
 
 
203
--error 0,ER_CANNOT_USER
 
204
DROP   USER 'testuser1'@'localhost';
 
205
CREATE USER 'testuser1'@'localhost';
 
206
GRANT ALL ON test.* TO 'testuser1'@'localhost';
 
207
 
 
208
let $my_select = SELECT * FROM information_schema.column_privileges
 
209
WHERE table_name = 'my_table'
 
210
ORDER BY grantee, table_schema,table_name,column_name,privilege_type;
 
211
let $my_show = SHOW GRANTS FOR 'testuser1'@'localhost';
 
212
eval $my_select;
 
213
eval $my_show;
 
214
 
 
215
--echo # Establish connection testuser1 (user=testuser1)
 
216
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 
217
connect (testuser1, localhost, testuser1, , test);
 
218
eval $my_select;
 
219
eval $my_show;
 
220
 
 
221
--echo # Switch to connection default
 
222
connection default;
 
223
GRANT SELECT (f1,f3) ON db_datadict.my_table TO 'testuser1'@'localhost';
 
224
eval $my_select;
 
225
eval $my_show;
 
226
 
 
227
--echo # Switch to connection testuser1
 
228
connection testuser1;
 
229
eval $my_select;
 
230
eval $my_show;
 
231
 
 
232
--echo # Switch to connection default
 
233
connection default;
 
234
ALTER TABLE db_datadict.my_table DROP COLUMN f3;
 
235
GRANT UPDATE (f1) ON db_datadict.my_table TO 'testuser1'@'localhost';
 
236
eval $my_select;
 
237
eval $my_show;
 
238
 
 
239
--echo # Switch to connection testuser1
 
240
connection testuser1;
 
241
eval $my_select;
 
242
eval $my_show;
 
243
--error ER_BAD_FIELD_ERROR
 
244
SELECT f1, f3 FROM db_datadict.my_table;
 
245
 
 
246
--echo # Switch to connection default
 
247
connection default;
 
248
ALTER TABLE db_datadict.my_table CHANGE COLUMN f1 my_col BIGINT;
 
249
eval $my_select;
 
250
eval $my_show;
 
251
 
 
252
--echo # Switch to connection testuser1
 
253
connection testuser1;
 
254
eval $my_select;
 
255
eval $my_show;
 
256
 
 
257
--echo # Switch to connection default
 
258
connection default;
 
259
DROP TABLE db_datadict.my_table;
 
260
eval $my_select;
 
261
eval $my_show;
 
262
 
 
263
--echo # Switch to connection testuser1
 
264
connection testuser1;
 
265
eval $my_select;
 
266
eval $my_show;
 
267
 
 
268
--echo # Switch to connection default
 
269
connection default;
 
270
REVOKE ALL ON db_datadict.my_table FROM 'testuser1'@'localhost';
 
271
eval $my_select;
 
272
eval $my_show;
 
273
 
 
274
--echo # Switch to connection testuser1
 
275
connection testuser1;
 
276
eval $my_select;
 
277
eval $my_show;
 
278
 
 
279
--echo # Switch to connection default and close connection testuser1
 
280
connection default;
 
281
disconnect testuser1;
 
282
DROP USER 'testuser1'@'localhost';
 
283
DROP DATABASE db_datadict;
 
284
 
 
285
 
 
286
--echo ########################################################################
 
287
--echo # Testcases 3.2.1.3-3.2.1.5 + 3.2.1.8-3.2.1.12: INSERT/UPDATE/DELETE and
 
288
--echo #           DDL on INFORMATION_SCHEMA table are not supported
 
289
--echo ########################################################################
 
290
# 3.2.1.3:  Ensure that no user may execute an INSERT statement on any
 
291
#           INFORMATION_SCHEMA table.
 
292
# 3.2.1.4:  Ensure that no user may execute an UPDATE statement on any
 
293
#           INFORMATION_SCHEMA table.
 
294
# 3.2.1.5:  Ensure that no user may execute a DELETE statement on any
 
295
#           INFORMATION_SCHEMA table.
 
296
# 3.2.1.8:  Ensure that no user may create an index on an
 
297
#           INFORMATION_SCHEMA table.
 
298
# 3.2.1.9:  Ensure that no user may alter the definition of an
 
299
#           INFORMATION_SCHEMA table.
 
300
# 3.2.1.10: Ensure that no user may drop an INFORMATION_SCHEMA table.
 
301
# 3.2.1.11: Ensure that no user may move an INFORMATION_SCHEMA table to any
 
302
#           other database.
 
303
# 3.2.1.12: Ensure that no user may directly add to, alter, or delete any data
 
304
#           in an INFORMATION_SCHEMA table.
 
305
#
 
306
--disable_warnings
 
307
DROP DATABASE IF EXISTS db_datadict;
 
308
--enable_warnings
 
309
CREATE DATABASE db_datadict;
 
310
--replace_result $engine_type <engine_type>
 
311
eval
 
312
CREATE TABLE db_datadict.t1 (f1 BIGINT, f2 BIGINT)
 
313
ENGINE = $engine_type;
 
314
--error 0,ER_CANNOT_USER
 
315
DROP   USER 'testuser1'@'localhost';
 
316
CREATE USER 'testuser1'@'localhost';
 
317
GRANT SELECT (f1) ON db_datadict.t1 TO 'testuser1'@'localhost';
 
318
 
 
319
--error ER_DBACCESS_DENIED_ERROR
 
320
INSERT INTO information_schema.column_privileges
 
321
SELECT * FROM information_schema.column_privileges;
 
322
 
 
323
--error ER_DBACCESS_DENIED_ERROR
 
324
UPDATE information_schema.column_privileges SET table_schema = 'test'
 
325
WHERE table_name = 't1';
 
326
 
 
327
--error ER_DBACCESS_DENIED_ERROR
 
328
DELETE FROM information_schema.column_privileges WHERE table_name = 't1';
 
329
--error ER_DBACCESS_DENIED_ERROR
 
330
TRUNCATE information_schema.column_privileges;
 
331
 
 
332
--error ER_DBACCESS_DENIED_ERROR
 
333
CREATE INDEX my_idx_on_tables
 
334
ON information_schema.column_privileges(table_schema);
 
335
--error ER_DBACCESS_DENIED_ERROR
 
336
ALTER TABLE information_schema.column_privileges ADD f1 INT;
 
337
 
 
338
--error ER_DBACCESS_DENIED_ERROR
 
339
DROP TABLE information_schema.column_privileges;
 
340
 
 
341
--error ER_DBACCESS_DENIED_ERROR
 
342
ALTER TABLE information_schema.column_privileges
 
343
RENAME db_datadict.column_privileges;
 
344
--error ER_DBACCESS_DENIED_ERROR
 
345
ALTER TABLE information_schema.column_privileges
 
346
RENAME information_schema.xcolumn_privileges;
 
347
 
 
348
# Cleanup
 
349
DROP DATABASE db_datadict;
 
350
DROP USER 'testuser1'@'localhost';
 
351