Debian Codegraph @

mysql-test/suite/funcs_1/t/is_table_privileges.test

raw
1 # suite/funcs_1/t/is_table_privileges.test
2 #
3 # Check the layout of information_schema.table_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
20 let $engine_type = InnoDB;
21 let $other_engine_type = InnoDB;
22
23 let $is_table = TABLE_PRIVILEGES;
24
25 # The table INFORMATION_SCHEMA.TABLE_PRIVILEGES must exist
26 eval SHOW TABLES FROM information_schema LIKE '$is_table';
27
28 --echo #######################################################################
29 --echo # Testcase 3.2.1.1: INFORMATION_SCHEMA tables can be queried via SELECT
30 --echo #######################################################################
31 # Ensure that every INFORMATION_SCHEMA table can be queried with a SELECT
32 # statement, just as if it were an ordinary user-defined table.
33 #
34 --source suite/funcs_1/datadict/is_table_query.inc
35
36
37 --echo #########################################################################
38 --echo # Testcase 3.2.11.1: INFORMATION_SCHEMA.TABLE_PRIVILEGES layout
39 --echo #########################################################################
40 # Ensure that the INFORMATION_SCHEMA.TABLE_PRIVILEGES table has the following
41 # columns, in the following order:
42 #
43 # GRANTEE (shows the name of a user who has either granted, or been granted a
44 # table privilege),
45 # TABLE_CATALOG (always shows NULL),
46 # TABLE_SCHEMA (shows the name of the schema, or database, in which the table
47 # for which a privilege has been granted resides),
48 # TABLE_NAME (shows the name of the table),
49 # PRIVILEGE_TYPE (shows the type of privilege that was granted; must be either
50 # SELECT, INSERT, UPDATE, DELETE, REFERENCES, ALTER, INDEX, DROP or
51 # CREATE VIEW),
52 # IS_GRANTABLE (shows whether that privilege was granted WITH GRANT OPTION).
53 #
54 --source suite/funcs_1/datadict/datadict_bug_12777.inc
55 eval DESCRIBE information_schema.$is_table;
56 --source suite/funcs_1/datadict/datadict_bug_12777.inc
57 eval SHOW CREATE TABLE information_schema.$is_table;
58 --source suite/funcs_1/datadict/datadict_bug_12777.inc
59 eval SHOW COLUMNS FROM information_schema.$is_table;
60
61 # Note: Retrieval of information within information_schema.columns
62 # about information_schema.table_privileges is in is_columns_is.test.
63
64 # Show that TABLE_CATALOG is always NULL.
65 --sorted_result
66 SELECT table_catalog, table_schema, table_name, privilege_type
67 FROM information_schema.table_privileges WHERE table_catalog IS NOT NULL;
68
69 --echo ######################################################################
70 --echo # Testcase 3.2.11.2+3.2.11.3+3.2.11.4:
71 --echo # INFORMATION_SCHEMA.TABLE_PRIVILEGES accessible information
72 --echo ######################################################################
73 # 3.2.11.2: Ensure that the table shows the relevant information on every
74 # table privilege which has been granted to the current user or
75 # PUBLIC, or which was granted by the current user.
76 # 3.2.11.3: Ensure that the table does not show any information on any table
77 # privilege which was granted to any user other than the current
78 # user or PUBLIC, or which was granted by any user other than the
79 # current user.
80 # 3.2.11.4: Ensure that the table does not show any information on any
81 # privileges that are not table privileges for the current user.
82 #
83 # To be implemented:
84 # Check of content within information_schema.table_privileges about
85 # databases like 'information_schema' or 'mysql'.
86 # 2008-02-15 Neither root nor a just created low privileged user has table
87 # privileges within these schemas.
88 #
89 --disable_warnings
90 DROP DATABASE IF EXISTS db_datadict;
91 --enable_warnings
92 CREATE DATABASE db_datadict;
93 --replace_result $engine_type <engine_type>
94 eval
95 CREATE TABLE db_datadict.tb1(f1 INT, f2 INT, f3 INT)
96 ENGINE = $engine_type;
97
98 --error 0,ER_CANNOT_USER
99 DROP USER 'testuser1'@'localhost';
100 CREATE USER 'testuser1'@'localhost';
101 GRANT CREATE, SELECT ON db_datadict.*
102 TO 'testuser1'@'localhost' WITH GRANT OPTION;
103 GRANT SELECT ON db_datadict.tb1 TO 'testuser1'@'localhost';
104 --error 0,ER_CANNOT_USER
105 DROP USER 'testuser2'@'localhost';
106 CREATE USER 'testuser2'@'localhost';
107 GRANT ALL ON db_datadict.tb1 TO 'testuser2'@'localhost' WITH GRANT OPTION;
108 --error 0,ER_CANNOT_USER
109 DROP USER 'testuser3'@'localhost';
110 CREATE USER 'testuser3'@'localhost';
111
112 let $my_select = SELECT * FROM information_schema.table_privileges
113 WHERE table_name LIKE 'tb%'
114 ORDER BY grantee,table_schema,table_name,privilege_type;
115
116 --echo # Establish connection testuser1 (user=testuser1)
117 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
118 connect (testuser1, localhost, testuser1, , db_datadict);
119 --replace_result $other_engine_type <other_engine_type>
120 eval
121 CREATE TABLE tb3 (f1 TEXT)
122 ENGINE = $other_engine_type;
123 GRANT SELECT ON db_datadict.tb3 TO 'testuser3'@'localhost';
124 eval $my_select;
125 SHOW GRANTS FOR 'testuser1'@'localhost';
126
127 --echo # Establish connection testuser2 (user=testuser3)
128 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
129 connect (testuser2, localhost, testuser2, , db_datadict);
130 # we see only table privileges for this user, and not any other privileges
131 eval $my_select;
132 SHOW GRANTS FOR 'testuser2'@'localhost';
133
134 --echo # Establish connection testuser3 (user=testuser3)
135 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
136 connect (testuser3, localhost, testuser3, , db_datadict);
137 # we see only table privileges for this user, and not any other privileges
138 eval $my_select;
139 SHOW GRANTS FOR 'testuser3'@'localhost';
140
141 --echo # Switch to connection default and close the other connections
142 connection default;
143 disconnect testuser1;
144 disconnect testuser2;
145 disconnect testuser3;
146
147 # we see only 'public' table privileges
148 eval $my_select;
149 SHOW GRANTS FOR 'testuser1'@'localhost';
150 SHOW GRANTS FOR 'testuser2'@'localhost';
151 SHOW GRANTS FOR 'testuser3'@'localhost';
152
153 # Cleanup
154 DROP USER 'testuser1'@'localhost';
155 DROP USER 'testuser2'@'localhost';
156 DROP USER 'testuser3'@'localhost';
157 DROP DATABASE db_datadict;
158
159
160 --echo ################################################################################
161 --echo # 3.2.1.13+3.2.1.14+3.2.1.15: INFORMATION_SCHEMA.TABLE_PRIVILEGES modifications
162 --echo ################################################################################
163 # 3.2.1.13: Ensure that the creation of any new database object (e.g. table or
164 # column) automatically inserts all relevant information on that
165 # object into every appropriate INFORMATION_SCHEMA table.
166 # 3.2.1.14: Ensure that the alteration of any existing database object
167 # automatically updates all relevant information on that object in
168 # every appropriate INFORMATION_SCHEMA table.
169 # 3.2.1.15: Ensure that the dropping of any existing database object
170 # automatically deletes all relevant information on that object from
171 # every appropriate INFORMATION_SCHEMA table.
172 #
173 # Note (mleich):
174 # The MySQL privilege system allows to GRANT objects before they exist.
175 # (Exception: Grant privileges for columns of not existing tables/views.)
176 # There is also no migration of privileges if objects (tables,views,columns)
177 # are moved to other databases (tables only), renamed or dropped.
178 #
179 --disable_warnings
180 DROP TABLE IF EXISTS test.t1_table;
181 DROP VIEW IF EXISTS test.t1_view;
182 DROP DATABASE IF EXISTS db_datadict;
183 --enable_warnings
184 CREATE DATABASE db_datadict;
185 --replace_result $engine_type <engine_type>
186 eval
187 CREATE TABLE test.t1_table (f1 BIGINT)
188 DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci
189 COMMENT = 'Initial Comment' ENGINE = $engine_type;
190 CREATE VIEW test.t1_view AS SELECT 1;
191
192 --error 0,ER_CANNOT_USER
193 DROP USER 'testuser1'@'localhost';
194 CREATE USER 'testuser1'@'localhost';
195 --error 0,ER_CANNOT_USER
196 DROP USER 'the_user'@'localhost';
197 #
198 # Check granted TABLE and VIEW
199 SELECT table_name FROM information_schema.table_privileges
200 WHERE table_name LIKE 't1_%';
201 GRANT ALL ON test.t1_table TO 'testuser1'@'localhost';
202 GRANT ALL ON test.t1_view TO 'testuser1'@'localhost';
203 SELECT * FROM information_schema.table_privileges
204 WHERE table_name LIKE 't1_%'
205 ORDER BY grantee, table_schema, table_name, privilege_type;
206 #
207 # Check modification of GRANTEE (migration of permissions)
208 SELECT DISTINCT grantee, table_name FROM information_schema.table_privileges
209 WHERE table_name LIKE 't1_%'
210 ORDER BY grantee, table_name;
211 RENAME USER 'testuser1'@'localhost' TO 'the_user'@'localhost';
212 # FIXME: mleich Workaround for bug to be reported
213 # It looks like an immediate reloading of the system tables is missing in case
214 # of RENAME USER.
215 FLUSH PRIVILEGES;
216 SELECT DISTINCT grantee, table_name FROM information_schema.table_privileges
217 WHERE table_name LIKE 't1_%'
218 ORDER BY grantee, table_name;
219 --error ER_NONEXISTING_GRANT
220 SHOW GRANTS FOR 'testuser1'@'localhost';
221 --sorted_result
222 SHOW GRANTS FOR 'the_user'@'localhost';
223 #
224 # Check modification of TABLE_SCHEMA (no migration of permissions)
225 SELECT DISTINCT table_schema,table_name FROM information_schema.table_privileges
226 WHERE table_name LIKE 't1_%'
227 ORDER BY table_schema,table_name;
228 RENAME TABLE test.t1_table TO db_datadict.t1_table;
229 --error ER_FORBID_SCHEMA_CHANGE
230 RENAME TABLE test.t1_view TO db_datadict.t1_view;
231 SELECT DISTINCT table_schema,table_name FROM information_schema.table_privileges
232 WHERE table_name LIKE 't1_%'
233 ORDER BY table_schema,table_name;
234 --sorted_result
235 SHOW GRANTS FOR 'the_user'@'localhost';
236 REVOKE ALL PRIVILEGES ON test.t1_table FROM 'the_user'@'localhost';
237 REVOKE ALL PRIVILEGES ON test.t1_view FROM 'the_user'@'localhost';
238 DROP VIEW test.t1_view;
239 CREATE VIEW db_datadict.t1_view AS SELECT 1;
240 GRANT ALL ON db_datadict.t1_table TO 'the_user'@'localhost';
241 GRANT ALL ON db_datadict.t1_view TO 'the_user'@'localhost';
242 #
243 # Check modification of TABLE_NAME (no migration of permissions)
244 SELECT DISTINCT table_name FROM information_schema.table_privileges
245 WHERE table_name LIKE 't1_%'
246 ORDER BY table_name;
247 RENAME TABLE db_datadict.t1_table TO db_datadict.t1_tablex;
248 RENAME TABLE db_datadict.t1_view TO db_datadict.t1_viewx;
249 SELECT DISTINCT table_name FROM information_schema.table_privileges
250 WHERE table_name LIKE 't1_%'
251 ORDER BY table_name;
252 RENAME TABLE db_datadict.t1_tablex TO db_datadict.t1_table;
253 RENAME TABLE db_datadict.t1_viewx TO db_datadict.t1_view;
254 #
255 # Check impact of DROP TABLE/VIEW (no removal of permissions)
256 SELECT DISTINCT table_name FROM information_schema.table_privileges
257 WHERE table_name LIKE 't1_%'
258 ORDER BY table_name;
259 DROP TABLE db_datadict.t1_table;
260 DROP VIEW db_datadict.t1_view;
261 SELECT DISTINCT table_name FROM information_schema.table_privileges
262 WHERE table_name LIKE 't1_%'
263 ORDER BY table_name;
264 #
265 # Check impact of DROP SCHEMA (no removal of permissions)
266 --replace_result $engine_type <engine_type>
267 eval
268 CREATE TABLE db_datadict.t1_table
269 ENGINE = $engine_type AS
270 SELECT 1;
271 CREATE VIEW db_datadict.t1_view AS SELECT 1;
272 GRANT ALL ON db_datadict.t1_table TO 'the_user'@'localhost';
273 GRANT ALL ON db_datadict.t1_view TO 'the_user'@'localhost';
274 SELECT DISTINCT table_name FROM information_schema.table_privileges
275 WHERE table_name LIKE 't1_%'
276 ORDER BY table_name;
277 DROP DATABASE db_datadict;
278 SELECT DISTINCT table_name FROM information_schema.table_privileges
279 WHERE table_name LIKE 't1_%'
280 ORDER BY table_name;
281
282 # Cleanup
283 DROP USER 'the_user'@'localhost';
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.table_privileges
321 SELECT * FROM information_schema.table_privileges;
322
323 --error ER_DBACCESS_DENIED_ERROR
324 UPDATE information_schema.table_privileges SET table_schema = 'test'
325 WHERE table_name = 't1';
326
327 --error ER_DBACCESS_DENIED_ERROR
328 DELETE FROM information_schema.table_privileges WHERE table_name = 't1';
329 --error ER_DBACCESS_DENIED_ERROR
330 TRUNCATE information_schema.table_privileges;
331
332 --error ER_DBACCESS_DENIED_ERROR
333 CREATE INDEX my_idx_on_tables
334 ON information_schema.table_privileges(table_schema);
335 --error ER_DBACCESS_DENIED_ERROR
336 ALTER TABLE information_schema.table_privileges ADD f1 INT;
337
338 --error ER_DBACCESS_DENIED_ERROR
339 DROP TABLE information_schema.table_privileges;
340
341 --error ER_DBACCESS_DENIED_ERROR
342 ALTER TABLE information_schema.table_privileges
343 RENAME db_datadict.table_privileges;
344 --error ER_DBACCESS_DENIED_ERROR
345 ALTER TABLE information_schema.table_privileges
346 RENAME information_schema.xtable_privileges;
347
348 # Cleanup
349 DROP DATABASE db_datadict;
350 DROP USER 'testuser1'@'localhost';
351