grant.test 5.1 KB
Newer Older
unknown's avatar
unknown committed
1 2 3
# Test of GRANT commands

# Cleanup
4 5 6 7
--disable_warnings
drop table if exists t1;
--enable_warnings

8 9 10 11 12 13 14 15 16 17
#
# Test that SSL options works properly
#

delete from mysql.user where user='mysqltest_1';
delete from mysql.db where user='mysqltest_1';
flush privileges;
grant select on mysqltest.* to mysqltest_1@localhost require cipher "EDH-RSA-DES-CBC3-SHA";
show grants for mysqltest_1@localhost;
grant delete on mysqltest.* to mysqltest_1@localhost;
unknown's avatar
unknown committed
18
select * from mysql.user where user="mysqltest_1";
19 20 21 22 23 24 25 26 27 28 29
show grants for mysqltest_1@localhost;
revoke delete on mysqltest.* from mysqltest_1@localhost;
show grants for mysqltest_1@localhost;
grant select on mysqltest.* to mysqltest_1@localhost require NONE;
show grants for mysqltest_1@localhost;
grant USAGE on mysqltest.* to mysqltest_1@localhost require cipher "EDH-RSA-DES-CBC3-SHA" AND SUBJECT "testsubject" ISSUER "MySQL AB";
show grants for mysqltest_1@localhost;
revoke all privileges on mysqltest.* from mysqltest_1@localhost;
show grants for mysqltest_1@localhost;
delete from mysql.user where user='mysqltest_1';
flush privileges;
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

#
# Test that the new db privileges are stored/retrieved correctly
#

grant CREATE TEMPORARY TABLES, LOCK TABLES on mysqltest.* to mysqltest_1@localhost;
show grants for mysqltest_1@localhost;
flush privileges;
show grants for mysqltest_1@localhost;
revoke CREATE TEMPORARY TABLES on mysqltest.* from mysqltest_1@localhost;
show grants for mysqltest_1@localhost;
grant ALL PRIVILEGES on mysqltest.* to mysqltest_1@localhost with GRANT OPTION;
flush privileges;
show grants for mysqltest_1@localhost;
revoke LOCK TABLES, ALTER on mysqltest.* from mysqltest_1@localhost;
show grants for mysqltest_1@localhost;
revoke all privileges on mysqltest.* from mysqltest_1@localhost;
delete from mysql.user where user='mysqltest_1';
flush privileges;
49 50 51 52 53 54 55 56 57 58 59
grant usage on test.* to mysqltest_1@localhost with grant option;
show grants for mysqltest_1@localhost;
delete from mysql.user where user='mysqltest_1';
delete from mysql.db where user='mysqltest_1';
delete from mysql.tables_priv where user='mysqltest_1';
delete from mysql.columns_priv where user='mysqltest_1';
flush privileges;

#
# Test what happens when you have same table and colum level grants
#
60

61 62 63 64 65 66 67
create table t1 (a int);
GRANT select,update,insert on t1 to mysqltest_1@localhost;
GRANT select (a), update (a),insert(a), references(a) on t1 to mysqltest_1@localhost;
show grants for mysqltest_1@localhost;
select table_priv,column_priv from mysql.tables_priv where user="mysqltest_1";
REVOKE select (a), update on t1 from mysqltest_1@localhost;
show grants for mysqltest_1@localhost;
unknown's avatar
unknown committed
68
REVOKE select,update,insert,insert (a) on t1 from mysqltest_1@localhost;
69
show grants for mysqltest_1@localhost;
unknown's avatar
unknown committed
70
GRANT select,references on t1 to mysqltest_1@localhost;
71
select table_priv,column_priv from mysql.tables_priv where user="mysqltest_1";
unknown's avatar
unknown committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85
grant all on test.* to mysqltest_3@localhost with grant option;
revoke all on test.* from mysqltest_3@localhost;
show grants for mysqltest_3@localhost;
revoke grant option on test.* from mysqltest_3@localhost;
show grants for mysqltest_3@localhost;
grant all on test.t1 to mysqltest_2@localhost with grant option;
revoke all on test.t1 from mysqltest_2@localhost;
show grants for mysqltest_2@localhost;
revoke grant option on test.t1 from mysqltest_2@localhost;
show grants for mysqltest_2@localhost;
delete from mysql.user where user='mysqltest_1' or user="mysqltest_2" or user="mysqltest_3";
delete from mysql.db where user='mysqltest_1' or user="mysqltest_2" or user="mysqltest_3";
delete from mysql.tables_priv where user='mysqltest_1' or user="mysqltest_2" or user="mysqltest_3";
delete from mysql.columns_priv where user='mysqltest_1' or user="mysqltest_2" or user="mysqltest_3";
86 87
flush privileges;
drop table t1;
unknown's avatar
unknown committed
88 89 90 91

#
# Test some error conditions
#
92
--error  1221
93
GRANT FILE on mysqltest.*  to mysqltest_1@localhost;
unknown's avatar
unknown committed
94
select 1;	-- To test that the previous command didn't cause problems
95

96 97 98 99
#
# Test for 'drop user', 'revoke privileges, grant' 
#

unknown's avatar
unknown committed
100
create table t1 (a int);
101 102
grant ALL PRIVILEGES on *.* to drop_user2@localhost with GRANT OPTION;
show grants for drop_user2@localhost;
103
revoke all privileges, grant option from drop_user2@localhost;
104 105 106 107 108 109
drop user drop_user2@localhost;

grant ALL PRIVILEGES on *.* to drop_user@localhost with GRANT OPTION;
grant ALL PRIVILEGES on test.* to drop_user@localhost with GRANT OPTION;
grant select(a) on test.t1 to drop_user@localhost;
show grants for drop_user@localhost;
110
revoke all privileges, grant option from drop_user@localhost;
111 112
show grants for drop_user@localhost;
drop user drop_user@localhost;
unknown's avatar
unknown committed
113
--error 1268
114
revoke all privileges, grant option from drop_user@localhost;
115 116 117 118 119

grant select(a) on test.t1 to drop_user1@localhost;
grant select on test.t1 to drop_user2@localhost;
grant select on test.* to drop_user3@localhost;
grant select on *.* to drop_user4@localhost;
unknown's avatar
unknown committed
120
--error 1267
121 122
drop user drop_user1@localhost, drop_user2@localhost, drop_user3@localhost,
drop_user4@localhost;
123
revoke all privileges, grant option from drop_user1@localhost, drop_user2@localhost,
124 125 126 127
drop_user3@localhost, drop_user4@localhost;
drop user drop_user1@localhost, drop_user2@localhost, drop_user3@localhost,
drop_user4@localhost;
drop table t1;