Debian Codegraph @

mysql-test/suite/roles/show_grants.test

raw
1 source include/not_embedded.inc;
2
3 #create a user with no privileges
4 create user test_user@localhost;
5 create role test_role1;
6 create role test_role2;
7
8 grant test_role1 to test_user@localhost;
9 grant test_role2 to test_user@localhost;
10 grant test_role2 to test_role1;
11 --sorted_result
12 select user, host from mysql.user where user not like 'root';
13 --sorted_result
14 select * from mysql.roles_mapping;
15
16 --sorted_result
17 select user, host from mysql.db;
18
19 grant select on mysql.* to test_role2;
20 flush privileges;
21
22 --sorted_result
23 select * from information_schema.applicable_roles;
24
25 change_user 'test_user';
26
27 --sorted_result
28 select * from information_schema.applicable_roles;
29
30 --sorted_result
31 show grants;
32 select current_user(), current_role();
33 set role test_role1;
34 --sorted_result
35 select * from information_schema.enabled_roles;
36 select current_user(), current_role();
37 --sorted_result
38 show grants;
39 set role none;
40 --sorted_result
41 select * from information_schema.enabled_roles;
42 select current_user(), current_role();
43 --sorted_result
44 show grants;
45
46 --sorted_result
47 show grants for test_user@localhost;
48 --error ER_DBACCESS_DENIED_ERROR
49 show grants for test_role1;
50 --error ER_DBACCESS_DENIED_ERROR
51 show grants for test_role2;
52 --sorted_result
53 show grants for CURRENT_USER;
54 --sorted_result
55 show grants for CURRENT_USER();
56 --error ER_NONEXISTING_GRANT
57 show grants for CURRENT_ROLE;
58 --error ER_NONEXISTING_GRANT
59 show grants for CURRENT_ROLE();
60
61 set role test_role2;
62 --sorted_result
63 select * from information_schema.enabled_roles;
64 select current_user(), current_role();
65 --sorted_result
66 show grants;
67 --sorted_result
68 show grants for test_user@localhost;
69 --sorted_result
70 show grants for test_role1;
71 --sorted_result
72 show grants for test_role2;
73 --sorted_result
74 show grants for CURRENT_USER;
75 --sorted_result
76 show grants for CURRENT_USER();
77 --sorted_result
78 show grants for CURRENT_ROLE;
79 --sorted_result
80 show grants for CURRENT_ROLE();
81
82
83 change_user 'root';
84 drop user 'test_user'@'localhost';
85 revoke select on mysql.* from test_role2;
86 drop role test_role1;
87 drop role test_role2;
88 delete from mysql.roles_mapping where Role='test_role1';
89 delete from mysql.roles_mapping where Role='test_role2';
90 flush privileges;
91
92 --echo #
93 --echo # MDEV-24289: show grants missing with grant option
94 --echo #
95 create role anel;
96 GRANT SELECT, UPDATE, DELETE, ALTER ON *.* TO 'anel';
97 SHOW GRANTS for 'anel';
98
99 create role MariaDB_admin;
100 GRANT SELECT, UPDATE, DELETE, ALTER ON *.* TO 'MariaDB_admin' WITH GRANT OPTION;
101 SHOW GRANTS for 'MariaDB_admin';
102 drop role MariaDB_admin;
103 drop role anel;