summaryrefslogtreecommitdiff
path: root/mysql-test/main/events_grant.test
blob: 8db4333cc03fbfb1403249708f932dc31ec0e61f (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Can't test with embedded server that doesn't support grants
-- source include/not_embedded.inc

CREATE DATABASE IF NOT EXISTS events_test;
use events_test;
#
# Events grants test begin
#
CREATE EVENT one_event ON SCHEDULE EVERY 10 SECOND DO SELECT 123;
--replace_column 8 # 9 #
SHOW EVENTS;
SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_DEFINITION, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME;
CREATE DATABASE events_test2;
CREATE USER ev_test@localhost;
GRANT ALL ON events_test.* to ev_test@localhost;
GRANT ALL ON events_test2.* to ev_test@localhost;
REVOKE EVENT ON events_test2.* FROM ev_test@localhost;
#now we are on con1
connect (ev_con1,localhost,ev_test,,events_test2);
select "NEW CONNECTION";
SELECT USER(), DATABASE();
SHOW GRANTS;
--echo "Here comes an error:";
#NO EVENT_ACL on events_test2
--error 1044
SHOW EVENTS;
USE events_test;
--echo "We should see one event";
--replace_column 8 # 9 #
SHOW EVENTS;
#now create an event with the same name but we are different user
SELECT CONCAT("Let's create some new events from the name of ", USER());
--error ER_EVENT_ALREADY_EXISTS
CREATE EVENT one_event ON SCHEDULE EVERY 20 SECOND DO SELECT 123;
CREATE EVENT two_event ON SCHEDULE EVERY 20 SECOND ON COMPLETION NOT PRESERVE COMMENT "two event" DO SELECT 123;
CREATE EVENT three_event ON SCHEDULE EVERY 20 SECOND ON COMPLETION PRESERVE COMMENT "three event" DO SELECT 123;

--echo "Now we should see 3 events:";
--replace_column 8 # 9 #
SHOW EVENTS;

--echo "This should show us only 2 events:";
--replace_column 8 # 9 #
SHOW EVENTS LIKE 't%event';

--echo "This should show us no events:";
--replace_column 8 # 9 #
SHOW EVENTS FROM test LIKE '%';
#ok, we are back
connection default;
GRANT EVENT ON events_test2.* TO ev_test@localhost;
connection ev_con1;
USE events_test2;
CREATE EVENT four_event ON SCHEDULE EVERY 20 SECOND DO SELECT 42;
connection default;
USE events_test;
--echo "We should see 4 events : one_event, two_event, three_event & four_event"
SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_DEFINITION, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME;
DROP DATABASE events_test2;
--echo "We should see 3 events : one_event, two_event, three_event"
SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_DEFINITION, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME;

connection default;
CREATE DATABASE events_test2;
USE events_test2;
CREATE EVENT five_event ON SCHEDULE EVERY 20 SECOND DO SELECT 42;

connection ev_con1;
--echo "Should see 4 events - one, two, three & five"
SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_DEFINITION, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME;
connection default;
REVOKE EVENT ON events_test2.* FROM ev_test@localhost;
connection ev_con1;
USE test;
--echo "Should see 3 events - one, two & three"
SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_DEFINITION, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME;
--echo "Let's test ALTER EVENT which changes the definer"
USE events_test;
ALTER EVENT one_event ON SCHEDULE EVERY 10 SECOND;
--echo "The definer should be ev_test@localhost"
SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_DEFINITION, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_NAME='one_event';
connection default;
USE events_test;
ALTER EVENT one_event COMMENT "comment";
connection ev_con1;
--echo "The definer should be root@localhost"
SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_DEFINITION, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_NAME='one_event';
ALTER EVENT one_event DO SELECT 12;
--echo "The definer should be ev_test@localhost"
SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_DEFINITION, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_NAME='one_event';
connection default;
--echo "make the definer again root@localhost"
ALTER EVENT one_event COMMENT "new comment";
connection ev_con1;
--echo "test DROP by another user"
DROP EVENT one_event;
connection default;
--echo "One event should not be there"
SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_DEFINITION, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME;
connection ev_con1;
disconnect ev_con1;
--source include/wait_until_disconnected.inc
connection default;
DROP USER ev_test@localhost;
DROP DATABASE events_test2;

# 
# End of tests
#

--source include/check_events_off.inc

DROP DATABASE events_test;