File: ndb_dist_priv.test

package info (click to toggle)
percona-xtrabackup 2.2.3-2.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 293,260 kB
  • ctags: 146,881
  • sloc: cpp: 1,051,960; ansic: 570,217; java: 54,595; perl: 53,495; pascal: 44,194; sh: 27,826; yacc: 15,314; python: 12,142; xml: 7,848; sql: 4,125; makefile: 1,459; awk: 785; lex: 758
file content (223 lines) | stat: -rw-r--r-- 7,256 bytes parent folder | download
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
--source include/not_embedded.inc
--source include/have_multi_ndb.inc

--source have_ndb_dist_priv.inc

let $load_sql_file = $NDB_DIST_PRIV_SQL;

connection server1;
--disable_query_log
--disable_result_log
--exec $MYSQL < $load_sql_file
call mysql.mysql_cluster_backup_privileges();
 --enable_result_log
 --enable_query_log

connection server2;
--disable_query_log
--disable_result_log
let $MYSQL2 = $EXE_MYSQL --defaults-file=$MYSQLTEST_VARDIR/my.cnf;
let $MYSQL2 = $MYSQL2 --defaults-group-suffix=.2.1;
--exec $MYSQL2 < $load_sql_file
call mysql.mysql_cluster_backup_privileges();
 --enable_result_log
 --enable_query_log

connection server1;
call mysql.mysql_cluster_move_privileges();
select mysql.mysql_cluster_privileges_are_distributed();

CREATE TABLE t1 (pk INT PRIMARY KEY, a INT) engine = ndb;
INSERT INTO t1 VALUES(0,0),(1,1),(2,2);
CREATE USER 'user'@'localhost' IDENTIFIED by 'mypass';
GRANT UPDATE ON t1 TO 'user'@'localhost';
SET PASSWORD FOR 'user'@'localhost'= PASSWORD('newpass');
RENAME USER 'user'@'localhost' TO 'newuser'@'localhost';
GRANT SELECT ON test.* TO 'newuser'@'localhost' IDENTIFIED by 'mypass2';
CREATE USER 'user2'@'localhost' IDENTIFIED by 'mypass';
GRANT SELECT ON test.t1 TO 'user2'@'localhost';
select distinct User,Password from mysql.user order by User;
select User,Table_priv from mysql.tables_priv ORDER BY User;
grant ALL PRIVILEGES on test.* to user@localhost with GRANT OPTION;
select User,Table_priv from mysql.tables_priv ORDER BY User;
GRANT SELECT ON test.t1 TO 'user'@'localhost';
select User,Table_priv from mysql.tables_priv ORDER BY User;

connection server2;
FLUSH PRIVILEGES;
select User,Table_priv from mysql.tables_priv ORDER BY User;
REVOKE SELECT ON test.t1 FROM 'user'@'localhost';
select User,Table_priv from mysql.tables_priv ORDER BY User;
CREATE USER 'user3'@'localhost' IDENTIFIED by 'mypass';
select distinct User,Password from mysql.user order by User;
select User,Table_priv from mysql.tables_priv ORDER BY User;
REVOKE UPDATE ON t1 FROM 'newuser'@'localhost';
REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'user'@'localhost';
select User,Table_priv from mysql.tables_priv ORDER BY User;
GRANT SELECT (a) ON test.t1 TO 'user'@'localhost';
select User, Table_name, Column_name from mysql.columns_priv ORDER BY User;

connection server1;
FLUSH PRIVILEGES;
select distinct User,Password from mysql.user order by User;
select User,Table_priv from mysql.tables_priv ORDER BY User;
select User, Table_name, Column_name from mysql.columns_priv ORDER BY User;

connection server2;
REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'user2'@'localhost';
select User,Table_priv from mysql.tables_priv ORDER BY User;

connection server1;
select distinct User,Password from mysql.user order by User;
select User,Table_priv from mysql.tables_priv ORDER BY User;

#
# Test connecting with a user that does not exist
#
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
--error ER_ACCESS_DENIED_ERROR
connect (server1_should_fail,127.0.0.1,magnus,,test,$MASTER_MYPORT,);
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT1 MASTER_PORT1
--error ER_ACCESS_DENIED_ERROR
connect (server2_should_fail,127.0.0.1,magnus,,test,$MASTER_MYPORT1,);

#
# Create a new user with CREATE USER and check that it's possible
# to connect as that user on second mysqld
#
connection server1;
CREATE USER 'billy1'@'127.0.0.1' IDENTIFIED by 'mypass';

connect (server2_as_billy1,127.0.0.1,billy1,mypass,test,$MASTER_MYPORT1,);
connection server2_as_billy1;
SELECT USER();
SELECT * FROM t1 order by pk;

# Test connecting with blank password
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT1 MASTER_PORT1
--error ER_ACCESS_DENIED_ERROR
connect (server2_should_fail,127.0.0.1,billy1,,test,$MASTER_MYPORT1,);

# Test connecting with wrong password
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT1 MASTER_PORT1
--error ER_ACCESS_DENIED_ERROR
connect (server2_should_fail,127.0.0.1,billy1,wrongpass,test,$MASTER_MYPORT1,);

#
# Testing failed DDL transaction
#
connection server1;
BEGIN;
UPDATE mysql.user SET Password = ''
WHERE User = 'billy1';

connection server2;
--error ER_PASSWORD_NO_MATCH
SET PASSWORD FOR 'billy1'@'127.0.0.1' = PASSWORD('newpass');
SHOW WARNINGS;

connection server1;
ROLLBACK;

connection server2;
DROP USER 'billy1'@'127.0.0.1';

#
# Create a new user with GRANT ALL and check that it's possible
# to connect as that user on second mysqld
#
connection server1;
GRANT ALL ON *.* TO 'billy2'@'127.0.0.1';

connect (server2_as_billy2,127.0.0.1,billy2,,test,$MASTER_MYPORT1,);
connection server2_as_billy2;
SELECT USER();
SELECT * FROM t1 order by pk;

connection server2;
DROP USER 'billy2'@'127.0.0.1';

--echo === making backup of new users ===

connection server1;
call mysql.mysql_cluster_backup_privileges();

--echo ==== clean up ====
connection server1;
DROP USER 'newuser'@'localhost';
DROP USER 'user2'@'localhost';
DROP USER 'user3'@'localhost';

DROP TABLE t1;

# Restore local privileges
connection server1;
call mysql.mysql_cluster_backup_privileges();
connection server2;
call mysql.mysql_cluster_backup_privileges();
connection server1;
call mysql.mysql_cluster_restore_local_privileges();
connection server2;
call mysql.mysql_cluster_restore_local_privileges();


--disable_query_log
--disable_result_log

connection server1;

# Drop the local backup tables
drop table mysql.user_backup;
drop table mysql.db_backup;
drop table mysql.tables_priv_backup;
drop table mysql.columns_priv_backup;
drop table mysql.procs_priv_backup;
drop table mysql.host_backup;

# Drop the distributed backup tables
drop table mysql.ndb_user_backup;
drop table mysql.ndb_db_backup;
drop table mysql.ndb_tables_priv_backup;
drop table mysql.ndb_columns_priv_backup;
drop table mysql.ndb_procs_priv_backup;
drop table mysql.ndb_host_backup;

# Drop the function and sprocs
drop function mysql.mysql_cluster_privileges_are_distributed;
drop procedure mysql.mysql_cluster_backup_privileges;
drop procedure mysql.mysql_cluster_move_grant_tables;
drop procedure mysql.mysql_cluster_restore_local_privileges;
drop procedure mysql.mysql_cluster_restore_privileges;
drop procedure mysql.mysql_cluster_restore_privileges_from_local;
drop procedure mysql.mysql_cluster_move_privileges;

connection server2;

# Drop the local backup tables
drop table mysql.user_backup;
drop table mysql.db_backup;
drop table mysql.tables_priv_backup;
drop table mysql.columns_priv_backup;
drop table mysql.procs_priv_backup;
drop table mysql.host_backup;

# The distributed backup tables should already have been dropped
--error ER_NO_SUCH_TABLE
select * from mysql.ndb_user_backup;

# Drop the function and sprocs
drop function mysql.mysql_cluster_privileges_are_distributed;
drop procedure mysql.mysql_cluster_backup_privileges;
drop procedure mysql.mysql_cluster_move_grant_tables;
drop procedure mysql.mysql_cluster_restore_local_privileges;
drop procedure mysql.mysql_cluster_restore_privileges;
drop procedure mysql.mysql_cluster_restore_privileges_from_local;
drop procedure mysql.mysql_cluster_move_privileges;

# Force restart since other tests depend on the _exact_
# order of rows in for example mysql.user
--source include/force_restart.inc

--enable_result_log
--enable_query_log