Debian Codegraph @

mysql-test/suite/rpl/t/rpl_default_table_encryption.test

raw
1 # ==== Purpose ====
2 #
3 # Verify that default_table_encryption is replicated when needed.
4 #
5 # ==== Requirements ====
6 #
7 # R1. @@session.default_table_encryption should be replicated for
8 # CREATE TABLESPACE when no ENCRYPTION clause is included in the
9 # statement.
10 #
11 # R2. @@session.default_table_encryption should be replicated for
12 # CREATE DATABASE when no ENCRYPTION clause is included in the
13 # statement.
14 #
15 # R3. @@session.default_table_encryption should not be replicated for
16 # any other statements.
17 #
18 # ==== Implementation ====
19 #
20 # Try all possible combinations of values for
21 # @@global.default_table_encryption on master and slave, as well as
22 # @@session.default_table_encryption on master.
23 #
24 # For each such option combination, try three CREATE DATABASE and
25 # three CREATE TABLESPACE statements: without ENCRYPTION clause, with
26 # ENCRYPTION='Y', and with ENCRYPTION='N'. Also try ALTER DATABASE
27 # and ALTER TABLESPACE.
28 #
29 # For each such option combination and statement, verify that the
30 # value of default_table_encryption is included or excluded in the
31 # binary log according to the requirements, and verify that the actual
32 # encryptedness of the database/tablespace is as expected on both
33 # master and slave.
34 #
35 # ==== References ====
36 #
37 # WL#12261: Control (enforce and disable) table encryption
38 # BUG#29818605: WRONG CONDITION TO REPLICATE AND WRONG PRIVILEGE TO SET DEFAULT_TABLE_ENCRYPTION
39
40 # The test only needs to be executed in one binlog_format.
41 --source include/have_binlog_format_row.inc
42 --source include/master-slave.inc
43
44
45 # Executes CREATE DATABASE or CREATE TABLESPACE,
46 # verifies that binlog contains default_table_encryption if expected,
47 # and verifies that it has the correct encryptedness on master and slave.
48 #
49 # Parameters:
50 #
51 # $desc
52 # Brief text explaining what is expected in the scenario
53 #
54 # $statement
55 # Statement to execute - CREATE DATABASE or CREATE TABLESPACE
56 #
57 # $expect_binlog
58 # If this is 0 or 1, assert that the binary log contains
59 # default_table_encryption set to that value. If set to empty
60 # string, assert that the binary log does not contain
61 # default_table_encryption.
62 #
63 # $check_statement
64 # Statement to check if encryption is enabled.
65 #
66 # $expect
67 # Assert that the result returned by $check_statement matches
68 # (LIKE) $expect on both master and slave.
69 #
70 # $drop_statement
71 # Statement to "undo" the effect of $statement. This will be
72 # executed unless it is set to empty string.
73 #
74 --let $script_dir = $MYSQLTEST_VARDIR
75 --write_file $script_dir/check_encryption.inc
76 --echo ==== $statement [master_session:$master_session master_global:$master_global slave_global:$slave_global] ====
77 --echo # $desc
78 # Restart slave threads to force them take the global value.
79 --source include/rpl_connection_slave.inc
80 --source include/stop_slave_sql.inc
81 --source include/start_slave_sql.inc
82 # Execute statement on master.
83 --source include/rpl_connection_master.inc
84 --source include/save_binlog_position.inc
85 eval $statement;
86 # Verify that the binary log contains the expected value
87 --echo # Assert that binlog is as expected
88 --let $mysqlbinlog_out = $MYSQLTEST_VARDIR/rpl_table_encryption_binlog.sql
89 --exec $MYSQL_BINLOG $binlog_fullpath --start-position=$binlog_position > $mysqlbinlog_out
90 --let $assert_file = $mysqlbinlog_out
91 --let $assert_select = default_table_encryption
92 if ($expect_binlog != '') {
93 --let $assert_count =
94 --let $assert_match = default_table_encryption=$expect_binlog
95 --let $assert_text = Binlog should contain default_table_encryption=$expect_binlog
96 }
97 if ($expect_binlog == '') {
98 --let $assert_count = 0
99 --let $assert_match =
100 --let $assert_text = Binlog should not contain default_table_encryption
101 }
102 --source include/assert_grep.inc
103 --remove_file $mysqlbinlog_out
104 # Verify that the definition is as expected on master.
105 --echo # Assert that object on master is "$expect"
106 --let $output = `$check_statement`
107 --let $result = `SELECT "$output" LIKE "$expect"`
108 # Verify that the definition is as expected on slave.
109 if ($result) {
110 --source include/sync_slave_sql_with_master.inc
111 --echo # Assert that object on slave is "$expect"
112 --let $output = `$check_statement`
113 --let $result = `SELECT "$output" LIKE "$expect"`
114 }
115 # Print error
116 if (!$result) {
117 --let $connection = $CURRENT_CONNECTION
118 --source include/show_rpl_debug_info.inc
119 --echo master_global='$master_global'
120 --echo slave_global='$slave_global'
121 --echo master_session='$master_session'
122 --echo statement='$statement'
123 --echo check_statement='$check_statement'
124 --echo output='$output'
125 --echo expect='$expect'
126 --echo result='$result'
127 --echo connection='$connection'
128 --die Error: the created object did not have the expected encryptedness on slave
129 }
130 # Clean up.
131 --source include/rpl_connection_master.inc
132 if ($drop_statement != '') {
133 eval $drop_statement;
134 }
135 --source include/sync_slave_sql_with_master.inc
136 --source include/rpl_connection_master.inc
137 EOF
138
139
140 --echo #### SETUP ####
141
142 --source include/rpl_connection_master.inc
143 SET @default_table_encryption_save = @@global.default_table_encryption;
144 CALL mtr.add_suppression("Could not flush keys to keyring's backup");
145 CALL mtr.add_suppression("Incorrect Keyring File");
146 --source include/sync_slave_sql_with_master.inc
147 SET @default_table_encryption_save = @@global.default_table_encryption;
148
149 # Loops to try all possible values of
150 # master:@@global.default_table_encryption,
151 # master:@@session.default_table_encryption, and
152 # slave:@@global.default_table_encryption.
153
154
155 --echo #### TEST ####
156
157 --let $master_global = 0
158 while ($master_global <= 1) {
159 --source include/rpl_connection_master.inc
160 eval SET @@global.default_table_encryption = $master_global;
161
162 --let $slave_global = 0
163 while ($slave_global <= 1) {
164 --source include/rpl_connection_slave.inc
165 eval SET @@global.default_table_encryption = $slave_global;
166
167 --let $master_session = 0
168 --let $letter = N
169 while ($master_session <= 1) {
170 --source include/rpl_connection_master.inc
171 eval SET @@session.default_table_encryption = $master_session;
172
173 --let $check_statement = SHOW CREATE DATABASE db
174
175 --let $desc = CREATE without ENCRYPTION: include the variable in the binlog
176 --let $statement = CREATE DATABASE db
177 --let $drop_statement =
178 --let $expect = %ENCRYPTION='$letter'%
179 --let $expect_binlog = $master_session
180 --source $script_dir/check_encryption.inc
181
182 --let $desc = ALTER: exclude the variable from the binlog
183 eval SET @@session.default_table_encryption = 1-$master_session;
184 --let $statement = ALTER DATABASE db CHARACTER SET = utf8
185 --let $drop_statement = DROP DATABASE db
186 --let $expect = %ENCRYPTION='$letter'%
187 --let $expect_binlog =
188 --source $script_dir/check_encryption.inc
189 eval SET @@session.default_table_encryption = $master_session;
190
191 --let $desc = CREATE with ENCRYPTION: exclude the variable from the binlog
192 --let $statement = CREATE DATABASE db DEFAULT ENCRYPTION = 'n'
193 --let $drop_statement = DROP DATABASE db
194 --let $expect = %ENCRYPTION='N'%
195 --let $expect_binlog =
196 --source $script_dir/check_encryption.inc
197
198 --let $desc = CREATE with ENCRYPTION: exclude the variable from the binlog
199 --let $statement = CREATE DATABASE db DEFAULT ENCRYPTION = 'y'
200 --let $drop_statement = DROP DATABASE db
201 --let $expect = %ENCRYPTION='Y'%
202 --let $expect_binlog =
203 --source $script_dir/check_encryption.inc
204
205 --let $check_statement = SELECT ENCRYPTION FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE NAME LIKE 'ts%'
206
207 --let $desc = CREATE without ENCRYPTION: include the variable in the binlog
208 --let $statement = CREATE TABLESPACE ts
209 --let $drop_statement =
210 --let $expect = $letter
211 --let $expect_binlog = $master_session
212 --source $script_dir/check_encryption.inc
213
214 --let $desc = ALTER should not include the variable in the binlog
215 eval SET @@session.default_table_encryption = 1-$master_session;
216 --let $statement = ALTER TABLESPACE ts RENAME TO ts2
217 --let $drop_statement = DROP TABLESPACE ts2
218 --let $expect = $letter
219 --let $expect_binlog =
220 --source $script_dir/check_encryption.inc
221 eval SET @@session.default_table_encryption = $master_session;
222
223 --let $desc = CREATE with ENCRYPTION: exclude the variable from the binlog
224 --let $statement = CREATE TABLESPACE ts ENCRYPTION = 'y'
225 --let $drop_statement = DROP TABLESPACE ts
226 --let $expect = Y
227 --let $expect_binlog =
228 --source $script_dir/check_encryption.inc
229
230 --let $desc = CREATE with ENCRYPTION: exclude the variable from the binlog
231 --let $statement = CREATE TABLESPACE ts ENCRYPTION = 'n'
232 --let $drop_statement = DROP TABLESPACE ts
233 --let $expect = N
234 --let $expect_binlog =
235 --source $script_dir/check_encryption.inc
236
237 --inc $master_session
238 --let $letter = Y
239 }
240 --inc $slave_global
241 }
242 --inc $master_global
243 }
244
245
246 --echo #### CLEANUP ####
247
248 --source include/rpl_connection_master.inc
249 SET @@global.default_table_encryption = @default_table_encryption_save;
250 --source include/rpl_connection_slave.inc
251 SET @@global.default_table_encryption = @default_table_encryption_save;
252
253 --remove_file $script_dir/check_encryption.inc
254
255
256 --source include/rpl_end.inc