summaryrefslogtreecommitdiff
path: root/mysql-test/suite/roles/prepare_stmt_with_role.test
blob: 516e9ddab345f0b32fd8902f39fbe2c7ff793a92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
--source include/not_embedded.inc


--echo #
--echo # Test user to check if we can grant the created role to it.
--echo #
create user test_user;
--echo #
--echo # First create the role.
--echo #
SET @createRole = 'CREATE ROLE developers';
PREPARE stmtCreateRole FROM @createRole;
EXECUTE stmtCreateRole;
--echo #
--echo # Test to see if the role is created.
--echo #
SELECT user, host,is_role FROM mysql.user
WHERE user = 'developers';
SHOW GRANTS;

--echo # Test reexecution.
--error ER_CANNOT_USER
EXECUTE stmtCreateRole;

--echo #
--echo # Now grant the role to the test user.
--echo #
SET @grantRole = 'GRANT developers to test_user';
PREPARE stmtGrantRole FROM @grantRole;
EXECUTE stmtGrantRole;
--echo # Test reexecution.
EXECUTE stmtGrantRole;

--echo #
--echo # We should see 2 entries in the roles_mapping table.
--echo #
--sorted_result
SELECT * FROM mysql.roles_mapping;
SHOW GRANTS FOR test_user;

--echo #
--echo # Test revoking a role.
--echo #
SET @revokeRole = 'REVOKE developers FROM test_user';
PREPARE stmtRevokeRole FROM @revokeRole;
EXECUTE stmtRevokeRole;
--error ER_CANNOT_REVOKE_ROLE
EXECUTE stmtRevokeRole;
SHOW GRANTS FOR test_user;

EXECUTE stmtGrantRole;
SHOW GRANTS FOR test_user;
EXECUTE stmtRevokeRole;
SHOW GRANTS FOR test_user;

--echo #
--echo # Now drop the role.
--echo #
SET @dropRole = 'DROP ROLE developers';
PREPARE stmtDropRole FROM @dropRole;
EXECUTE stmtDropRole;

--echo #
--echo # Check both user and roles_mapping table for traces of our role.
--echo #
SELECT user, host,is_role FROM mysql.user
WHERE user = 'developers';
SELECT * FROM mysql.roles_mapping;
SHOW GRANTS;
SHOW GRANTS FOR test_user;

--echo #
--echo # Test reexecution.
--echo #
EXECUTE stmtCreateRole;
SELECT user, host,is_role FROM mysql.user
WHERE user = 'developers';
SELECT * FROM mysql.roles_mapping;

SHOW GRANTS;
SHOW GRANTS FOR test_user;
EXECUTE stmtDropRole;

--echo # Cleanup.
DROP USER test_user;