mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / suite / funcs_1 / t / is_table_privileges.test
blob5ea0dd7c6a7184720956350de3077072a81752ff
1 # suite/funcs_1/t/is_table_privileges.test
3 # Check the layout of information_schema.table_privileges and the impact of
4 # CREATE/ALTER/DROP TABLE/VIEW/SCHEMA ... on it.
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.
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.
19 # This test cannot be used for the embedded server because we check here
20 # privileges.
21 --source include/not_embedded.inc
23 let $engine_type       = MEMORY;
24 let $other_engine_type = MyISAM;
26 let $is_table = TABLE_PRIVILEGES;
28 # The table INFORMATION_SCHEMA.TABLE_PRIVILEGES must exist
29 eval SHOW TABLES FROM information_schema LIKE '$is_table';
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.
37 --source suite/funcs_1/datadict/is_table_query.inc
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:
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).
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;
64 # Note: Retrieval of information within information_schema.columns
65 #       about information_schema.table_privileges is in is_columns_is.test.
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;
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.
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.
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;
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';
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;
118 --echo # Establish connection testuser1 (user=testuser1)
119 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
120 connect (testuser1, localhost, testuser1, , db_datadict);
121 --replace_result $other_engine_type <other_engine_type>
122 eval
123 CREATE TABLE tb3 (f1 TEXT)
124 ENGINE = $other_engine_type;
125 GRANT SELECT ON db_datadict.tb3 TO 'testuser3'@'localhost';
126 eval $my_select;
127 SHOW GRANTS FOR 'testuser1'@'localhost';
129 --echo # Establish connection testuser2 (user=testuser3)
130 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
131 connect (testuser2, localhost, testuser2, , db_datadict);
132 # we see only table privileges for this user, and not any other privileges
133 eval $my_select;
134 SHOW GRANTS FOR 'testuser2'@'localhost';
136 --echo # Establish connection testuser3 (user=testuser3)
137 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
138 connect (testuser3, localhost, testuser3, , db_datadict);
139 # we see only table privileges for this user, and not any other privileges
140 eval $my_select;
141 SHOW GRANTS FOR 'testuser3'@'localhost';
143 --echo # Switch to connection default and close the other connections
144 connection default;
145 disconnect testuser1;
146 disconnect testuser2;
147 disconnect testuser3;
149 # we see only 'public' table privileges
150 eval $my_select;
151 SHOW GRANTS FOR 'testuser1'@'localhost';
152 SHOW GRANTS FOR 'testuser2'@'localhost';
153 SHOW GRANTS FOR 'testuser3'@'localhost';
155 # Cleanup
156 DROP USER 'testuser1'@'localhost';
157 DROP USER 'testuser2'@'localhost';
158 DROP USER 'testuser3'@'localhost';
159 DROP DATABASE db_datadict;
162 --echo ################################################################################
163 --echo # 3.2.1.13+3.2.1.14+3.2.1.15: INFORMATION_SCHEMA.TABLE_PRIVILEGES modifications
164 --echo ################################################################################
165 # 3.2.1.13: Ensure that the creation of any new database object (e.g. table or
166 #           column) automatically inserts all relevant information on that
167 #           object into every appropriate INFORMATION_SCHEMA table.
168 # 3.2.1.14: Ensure that the alteration of any existing database object
169 #           automatically updates all relevant information on that object in
170 #           every appropriate INFORMATION_SCHEMA table.
171 # 3.2.1.15: Ensure that the dropping of any existing database object
172 #           automatically deletes all relevant information on that object from
173 #           every appropriate INFORMATION_SCHEMA table.
175 # Note (mleich):
176 #    The MySQL privilege system allows to GRANT objects before they exist.
177 #    (Exception: Grant privileges for columns of not existing tables/views.)
178 #    There is also no migration of privileges if objects (tables,views,columns)
179 #    are moved to other databases (tables only), renamed or dropped.
181 --disable_warnings
182 DROP TABLE IF EXISTS test.t1_table;
183 DROP VIEW  IF EXISTS test.t1_view;
184 DROP DATABASE IF EXISTS db_datadict;
185 --enable_warnings
186 CREATE DATABASE db_datadict;
187 --replace_result $engine_type <engine_type>
188 eval
189 CREATE TABLE test.t1_table (f1 BIGINT)
190 DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci
191 COMMENT = 'Initial Comment' ENGINE = $engine_type;
192 CREATE VIEW test.t1_view AS SELECT 1;
194 --error 0,ER_CANNOT_USER
195 DROP   USER 'testuser1'@'localhost';
196 CREATE USER 'testuser1'@'localhost';
197 --error 0,ER_CANNOT_USER
198 DROP   USER 'the_user'@'localhost';
200 # Check granted TABLE and VIEW
201 SELECT table_name FROM information_schema.table_privileges
202 WHERE table_name LIKE 't1_%';
203 GRANT ALL ON test.t1_table TO 'testuser1'@'localhost';
204 GRANT ALL ON test.t1_view  TO 'testuser1'@'localhost';
205 SELECT * FROM information_schema.table_privileges
206 WHERE table_name LIKE 't1_%'
207 ORDER BY grantee, table_schema, table_name, privilege_type;
209 # Check modification of GRANTEE (migration of permissions)
210 SELECT DISTINCT grantee, table_name FROM information_schema.table_privileges
211 WHERE table_name LIKE 't1_%'
212 ORDER BY grantee, table_name;
213 RENAME USER 'testuser1'@'localhost' TO 'the_user'@'localhost';
214 # FIXME: mleich Workaround for bug to be reported
215 # It looks like an immediate reloading of the system tables is missing in case
216 # of RENAME USER.
217 FLUSH PRIVILEGES;
218 SELECT DISTINCT grantee, table_name FROM information_schema.table_privileges
219 WHERE table_name LIKE 't1_%'
220 ORDER BY grantee, table_name;
221 --error ER_NONEXISTING_GRANT
222 SHOW GRANTS FOR 'testuser1'@'localhost';
223 SHOW GRANTS FOR 'the_user'@'localhost';
225 # Check modification of TABLE_SCHEMA (no migration of permissions)
226 SELECT DISTINCT table_schema,table_name FROM information_schema.table_privileges
227 WHERE table_name LIKE 't1_%'
228 ORDER BY table_schema,table_name;
229 RENAME TABLE test.t1_table TO db_datadict.t1_table;
230 --error ER_FORBID_SCHEMA_CHANGE
231 RENAME TABLE test.t1_view  TO db_datadict.t1_view;
232 SELECT DISTINCT table_schema,table_name FROM information_schema.table_privileges
233 WHERE table_name LIKE 't1_%'
234 ORDER BY table_schema,table_name;
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';
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;
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;
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;
282 # Cleanup
283 DROP USER 'the_user'@'localhost';
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.
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';
319 --error ER_DBACCESS_DENIED_ERROR
320 INSERT INTO information_schema.table_privileges
321 SELECT * FROM information_schema.table_privileges;
323 --error ER_DBACCESS_DENIED_ERROR
324 UPDATE information_schema.table_privileges SET table_schema = 'test'
325 WHERE table_name = 't1';
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;
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;
338 --error ER_DBACCESS_DENIED_ERROR
339 DROP TABLE information_schema.table_privileges;
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;
348 # Cleanup
349 DROP DATABASE db_datadict;
350 DROP USER 'testuser1'@'localhost';