Skip to content

Commit 29753fb

Browse files
committed
MDEV-9443: Add reexecution test cases.
1 parent 287f2d2 commit 29753fb

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

mysql-test/suite/roles/prepare_stmt_with_role.result

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@ Grants for root@localhost
2020
GRANT developers TO 'root'@'localhost' WITH ADMIN OPTION
2121
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION
2222
GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION
23+
# Test reexecution.
24+
EXECUTE stmtCreateRole;
25+
ERROR HY000: Operation CREATE ROLE failed for 'developers'
2326
#
2427
# Now grant the role to the test user.
2528
#
2629
SET @grantRole = 'GRANT developers to test_user';
2730
PREPARE stmtGrantRole FROM @grantRole;
2831
EXECUTE stmtGrantRole;
32+
# Test reexecution.
33+
EXECUTE stmtGrantRole;
2934
#
3035
# We should see 2 entries in the roles_mapping table.
3136
#
@@ -43,6 +48,17 @@ GRANT USAGE ON *.* TO 'test_user'@'%'
4348
SET @revokeRole = 'REVOKE developers FROM test_user';
4449
PREPARE stmtRevokeRole FROM @revokeRole;
4550
EXECUTE stmtRevokeRole;
51+
EXECUTE stmtRevokeRole;
52+
ERROR HY000: Cannot revoke role 'developers' from: 'test_user'@'%'.
53+
SHOW GRANTS FOR test_user;
54+
Grants for test_user@%
55+
GRANT USAGE ON *.* TO 'test_user'@'%'
56+
EXECUTE stmtGrantRole;
57+
SHOW GRANTS FOR test_user;
58+
Grants for test_user@%
59+
GRANT developers TO 'test_user'@'%'
60+
GRANT USAGE ON *.* TO 'test_user'@'%'
61+
EXECUTE stmtRevokeRole;
4662
SHOW GRANTS FOR test_user;
4763
Grants for test_user@%
4864
GRANT USAGE ON *.* TO 'test_user'@'%'
@@ -67,5 +83,25 @@ GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION
6783
SHOW GRANTS FOR test_user;
6884
Grants for test_user@%
6985
GRANT USAGE ON *.* TO 'test_user'@'%'
86+
#
87+
# Test reexecution.
88+
#
89+
EXECUTE stmtCreateRole;
90+
SELECT user, host,is_role FROM mysql.user
91+
WHERE user = 'developers';
92+
user host is_role
93+
developers Y
94+
SELECT * FROM mysql.roles_mapping;
95+
Host User Role Admin_option
96+
localhost root developers Y
97+
SHOW GRANTS;
98+
Grants for root@localhost
99+
GRANT developers TO 'root'@'localhost' WITH ADMIN OPTION
100+
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION
101+
GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION
102+
SHOW GRANTS FOR test_user;
103+
Grants for test_user@%
104+
GRANT USAGE ON *.* TO 'test_user'@'%'
105+
EXECUTE stmtDropRole;
70106
# Cleanup.
71107
DROP USER test_user;

mysql-test/suite/roles/prepare_stmt_with_role.test

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@ SELECT user, host,is_role FROM mysql.user
1818
WHERE user = 'developers';
1919
SHOW GRANTS;
2020

21+
--echo # Test reexecution.
22+
--error ER_CANNOT_USER
23+
EXECUTE stmtCreateRole;
24+
2125
--echo #
2226
--echo # Now grant the role to the test user.
2327
--echo #
2428
SET @grantRole = 'GRANT developers to test_user';
2529
PREPARE stmtGrantRole FROM @grantRole;
2630
EXECUTE stmtGrantRole;
31+
--echo # Test reexecution.
32+
EXECUTE stmtGrantRole;
2733

2834
--echo #
2935
--echo # We should see 2 entries in the roles_mapping table.
@@ -38,7 +44,13 @@ SHOW GRANTS FOR test_user;
3844
SET @revokeRole = 'REVOKE developers FROM test_user';
3945
PREPARE stmtRevokeRole FROM @revokeRole;
4046
EXECUTE stmtRevokeRole;
47+
--error ER_CANNOT_REVOKE_ROLE
48+
EXECUTE stmtRevokeRole;
49+
SHOW GRANTS FOR test_user;
4150

51+
EXECUTE stmtGrantRole;
52+
SHOW GRANTS FOR test_user;
53+
EXECUTE stmtRevokeRole;
4254
SHOW GRANTS FOR test_user;
4355

4456
--echo #
@@ -57,5 +69,17 @@ SELECT * FROM mysql.roles_mapping;
5769
SHOW GRANTS;
5870
SHOW GRANTS FOR test_user;
5971

72+
--echo #
73+
--echo # Test reexecution.
74+
--echo #
75+
EXECUTE stmtCreateRole;
76+
SELECT user, host,is_role FROM mysql.user
77+
WHERE user = 'developers';
78+
SELECT * FROM mysql.roles_mapping;
79+
80+
SHOW GRANTS;
81+
SHOW GRANTS FOR test_user;
82+
EXECUTE stmtDropRole;
83+
6084
--echo # Cleanup.
6185
DROP USER test_user;

0 commit comments

Comments
 (0)