Skip to content

Commit

Permalink
MDEV-9443: Add reexecution test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
cvicentiu committed Mar 22, 2016
1 parent 287f2d2 commit 29753fb
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
36 changes: 36 additions & 0 deletions mysql-test/suite/roles/prepare_stmt_with_role.result
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ Grants for root@localhost
GRANT developers TO 'root'@'localhost' WITH ADMIN OPTION
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION
GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION
# Test reexecution.
EXECUTE stmtCreateRole;
ERROR HY000: Operation CREATE ROLE failed for 'developers'
#
# Now grant the role to the test user.
#
SET @grantRole = 'GRANT developers to test_user';
PREPARE stmtGrantRole FROM @grantRole;
EXECUTE stmtGrantRole;
# Test reexecution.
EXECUTE stmtGrantRole;
#
# We should see 2 entries in the roles_mapping table.
#
Expand All @@ -43,6 +48,17 @@ GRANT USAGE ON *.* TO 'test_user'@'%'
SET @revokeRole = 'REVOKE developers FROM test_user';
PREPARE stmtRevokeRole FROM @revokeRole;
EXECUTE stmtRevokeRole;
EXECUTE stmtRevokeRole;
ERROR HY000: Cannot revoke role 'developers' from: 'test_user'@'%'.
SHOW GRANTS FOR test_user;
Grants for test_user@%
GRANT USAGE ON *.* TO 'test_user'@'%'
EXECUTE stmtGrantRole;
SHOW GRANTS FOR test_user;
Grants for test_user@%
GRANT developers TO 'test_user'@'%'
GRANT USAGE ON *.* TO 'test_user'@'%'
EXECUTE stmtRevokeRole;
SHOW GRANTS FOR test_user;
Grants for test_user@%
GRANT USAGE ON *.* TO 'test_user'@'%'
Expand All @@ -67,5 +83,25 @@ GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION
SHOW GRANTS FOR test_user;
Grants for test_user@%
GRANT USAGE ON *.* TO 'test_user'@'%'
#
# Test reexecution.
#
EXECUTE stmtCreateRole;
SELECT user, host,is_role FROM mysql.user
WHERE user = 'developers';
user host is_role
developers Y
SELECT * FROM mysql.roles_mapping;
Host User Role Admin_option
localhost root developers Y
SHOW GRANTS;
Grants for root@localhost
GRANT developers TO 'root'@'localhost' WITH ADMIN OPTION
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION
GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION
SHOW GRANTS FOR test_user;
Grants for test_user@%
GRANT USAGE ON *.* TO 'test_user'@'%'
EXECUTE stmtDropRole;
# Cleanup.
DROP USER test_user;
24 changes: 24 additions & 0 deletions mysql-test/suite/roles/prepare_stmt_with_role.test
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ 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.
Expand All @@ -38,7 +44,13 @@ SHOW GRANTS FOR test_user;
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 #
Expand All @@ -57,5 +69,17 @@ 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;

0 comments on commit 29753fb

Please sign in to comment.