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