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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
|
# Save the initial number of concurrent sessions
--disable_ps_protocol
--source include/count_sessions.inc
if ( !$VERSION_TOKEN ) {
skip Locking service plugin requires the environment variable \$VERSION_TOKEN to be set (normally done by mtr);
}
--echo #
--echo # Bug #23210850: VERSION_TOKEN better protected
--echo #
--echo # Define a UDF before installing the plugin
--replace_regex /\.dll/.so/
eval create function version_tokens_show returns string soname '$VERSION_TOKEN';
--error ER_CANT_INITIALIZE_UDF
SELECT version_tokens_show();
--echo # Testing installing the plugin twice while there's a UDF defined
--replace_regex /\.dll/.so/
eval INSTALL PLUGIN version_tokens SONAME '$VERSION_TOKEN';
UNINSTALL PLUGIN version_tokens;
--source include/disconnect_connections.inc
--replace_regex /\.dll/.so/
eval INSTALL PLUGIN version_tokens SONAME '$VERSION_TOKEN';
UNINSTALL PLUGIN version_tokens;
--source include/disconnect_connections.inc
--echo # Should not crash when unloading the so through removing the UDF
drop function version_tokens_show;
--replace_regex /\.dll/.so/
eval INSTALL PLUGIN version_tokens SONAME '$VERSION_TOKEN';
--replace_regex /\.dll/.so/
eval create function version_tokens_set returns string soname '$VERSION_TOKEN';
--replace_regex /\.dll/.so/
eval create function version_tokens_show returns string soname '$VERSION_TOKEN';
--replace_regex /\.dll/.so/
eval create function version_tokens_edit returns string soname '$VERSION_TOKEN';
--replace_regex /\.dll/.so/
eval create function version_tokens_delete returns string soname '$VERSION_TOKEN';
--replace_regex /\.dll/.so/
eval create function version_tokens_lock_shared returns int soname '$VERSION_TOKEN';
--replace_regex /\.dll/.so/
eval create function version_tokens_lock_exclusive returns int soname '$VERSION_TOKEN';
--replace_regex /\.dll/.so/
eval create function version_tokens_unlock returns int soname '$VERSION_TOKEN';
-- echo
-- echo # Error checks for UDFs
--error ER_CANT_INITIALIZE_UDF
select version_tokens_set("token1 = abc;token2= def",123);
--error ER_CANT_INITIALIZE_UDF
select version_tokens_edit("token1= 123; token3 = asdf",123);
--error ER_CANT_INITIALIZE_UDF
select version_tokens_delete("token1;token3",123);
--error ER_CANT_INITIALIZE_UDF
select version_tokens_show("123");
--error ER_CANT_INITIALIZE_UDF
select version_tokens_set(123);
--error ER_CANT_INITIALIZE_UDF
select version_tokens_edit(123);
--error ER_CANT_INITIALIZE_UDF
select version_tokens_delete(123);
--error ER_CANT_INITIALIZE_UDF
select version_tokens_lock_shared("Less arguments");
--error ER_CANT_INITIALIZE_UDF
select version_tokens_lock_shared(1,"Wrong argument type");
--error ER_CANT_INITIALIZE_UDF
select version_tokens_lock_exclusive("Less arguments");
--error ER_CANT_INITIALIZE_UDF
select version_tokens_lock_exclusive(1,"Wrong argument type");
--error ER_CANT_INITIALIZE_UDF
select version_tokens_unlock("Takes no arguments");
--error ER_DATA_OUT_OF_RANGE
select version_tokens_lock_shared("gizmo", -1);
--error ER_DATA_OUT_OF_RANGE
select version_tokens_lock_exclusive("gizmo", -1);
-- echo
CREATE USER vbhagi@localhost;
-- echo
select version_tokens_set("token1 = abc;token2= def");
select version_tokens_show();
-- echo
select version_tokens_set("");
select version_tokens_show();
-- echo
select version_tokens_set("token1 = abc;token2= def");
select version_tokens_show();
-- echo
select version_tokens_edit("token1= 123; token3 = asdf");
select version_tokens_show();
-- echo
do version_tokens_set("token1 = def;;;; ;invalid_token; token2= abc;;");
select version_tokens_show();
-- echo
do version_tokens_set("token1 = def;; token111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111=123;; ;invalid_token; token2= abc;;");
select version_tokens_show();
-- echo
do version_tokens_set("token1 = none;;;; ;invalid_token; token2= 123;;");
select version_tokens_show();
-- echo
do version_tokens_set("token1=def;token2= abc; ;token3=ghi");
select version_tokens_show();
-- echo
select version_tokens_delete("invalid=token");
select version_tokens_show();
-- echo
select version_tokens_delete("token1;token3");
select version_tokens_show();
-- echo
select version_tokens_delete("*");
select version_tokens_show();
-- echo
do version_tokens_set("token1=def;token2= abc;token3=111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112");
select version_tokens_show();
-- echo
connect (con1,localhost,vbhagi,,test);
connection con1;
-- echo # Connection: con1
-- echo
-- echo # The UDFs fail due to lack of privileges.
--error ER_CANT_INITIALIZE_UDF
select version_tokens_set("token1 = abc;token2= def");
--error ER_CANT_INITIALIZE_UDF
select version_tokens_edit("token1= 123; token3 = asdf");
--error ER_CANT_INITIALIZE_UDF
select version_tokens_delete("token1;token3");
--error ER_CANT_INITIALIZE_UDF
select version_tokens_show();
set @@version_tokens_session= "token1=def";
-- echo
select 1;
select 1;
-- echo
set @@version_tokens_session= "token3=abc";
-- echo
--error ER_VTOKEN_PLUGIN_TOKEN_MISMATCH
select 1;
-- echo
disconnect con1;
--source include/wait_until_disconnected.inc
-- echo # Connection: con1 refreshed
connect (con1,localhost,vbhagi,,test);
connection con1;
-- echo
-- echo # Next statement goes through as the connection is refreshed.
select @@version_tokens_session;
--echo
set @@version_tokens_session= "token111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111=abc;;";
-- echo
disconnect con1;
--source include/wait_until_disconnected.inc
-- echo # Connection: con1 refreshed
connect (con1,localhost,vbhagi,,test);
connection con1;
-- echo
-- echo # Next statement goes through as the connection is refreshed.
select @@version_tokens_session;
-- echo
set @@version_tokens_session= ";;";
set @@version_tokens_session= NULL;
set @@version_tokens_session= "token1=def;;;;;;;;";
set @@version_tokens_session= "token1=def;;; token2 = abc ; = ;;;;";
disconnect con1;
--source include/wait_until_disconnected.inc
connect (con1,localhost,vbhagi,,test);
-- echo
-- echo # Connection: con1 refreshed
-- echo
connection con1;
set @@version_tokens_session= "token1=def;;; token2 = abc ; sdf = ;;;;";
disconnect con1;
--source include/wait_until_disconnected.inc
connect (con1,localhost,vbhagi,,test);
-- echo
-- echo # Connection: con1 refreshed
-- echo
connection con1;
set @@version_tokens_session= "token1=def;; ; token2 = abc ;;;;;";
-- echo # Next queries get through as the session tokens are valid
use test;
create table t1 (c1 int);
drop table t1;
set @@version_tokens_session= "token1=def;;; token2 = abc ; = sdf ;;;;";
-- echo # This query fails as " = sdf" is not a valid token.
--error ER_ACCESS_DENIED_ERROR
create table t1 (c1 int);
disconnect con1;
--source include/wait_until_disconnected.inc
connect (con1,localhost,vbhagi,,test);
-- echo
-- echo # Connection: con1 refreshed
-- echo
connection con1;
set @@version_tokens_session= "token100=def;;; token2 = abc ;;;;;";
--error ER_VTOKEN_PLUGIN_TOKEN_NOT_FOUND
create table t1 (c1 int);
disconnect con1;
-- echo
-- echo # Connection: default
connection default;
--echo # Next statement goes through as it is from a different connection.
select 1;
--echo
--echo # Testing VERSION_TOKEN_ADMIN
--echo
CREATE USER u1@localhost IDENTIFIED BY 'foo';
GRANT VERSION_TOKEN_ADMIN ON *.* TO u1@localhost;
--echo # Tests related to locking
CONNECT (vtcon1, localhost, u1, foo,);
CONNECT (vtcon2, localhost, root,,);
CONNECT (vtcon3, localhost, root,,);
-- echo # Connection: vtcon1
CONNECTION vtcon1;
SELECT version_tokens_set("a=aa;b=bb;c=cc");
set @@version_tokens_session= "a=aa";
--let $t1_vtcon1 = `SELECT sysdate()`
--send SELECT sleep(6); # sleep for 6 seconds in background.
-- echo # Connection: vtcon2
CONNECTION vtcon2;
--let $t1_vtcon2 = `SELECT sysdate()`
SELECT version_tokens_lock_exclusive("b",20);
--let $t2_vtcon2 = `SELECT sysdate()`
--let $t3_vtcon2 = `SELECT time_format(timediff("$t2_vtcon2","$t1_vtcon2"),'%S')`
if ($t3_vtcon2 >= "03") {
--echo vtcon2 - Time difference should not be there or very close to max 3 seconds because no waiting time required to acquire lock on b
}
-- echo # Connection: vtcon3
CONNECTION vtcon3;
let $wait_condition= SELECT COUNT(*) > 0 FROM information_schema.processlist
WHERE info like '%select sleep%' AND state='User sleep';
source include/wait_condition.inc;
SELECT version_tokens_lock_exclusive("a",20);
--let $t2_vtcon3 = `SELECT sysdate()`
--let $t3_vtcon3 = `SELECT time_format(timediff("$t2_vtcon3","$t1_vtcon1"),'%S')`
if ($t3_vtcon3 < "05") {
--echo vtcon2 - Time difference should be not less than 5 seconds, waited till lock on a is released by vtcon1. Actual wait time is : $t3_vtcon3
}
SELECT version_tokens_unlock();
-- echo # Connection: vtcon1
CONNECTION vtcon1;
--reap
disconnect vtcon1;
disconnect vtcon2;
disconnect vtcon3;
connection default;
-- echo
UNINSTALL PLUGIN version_tokens;
--source include/disconnect_connections.inc
--disable_result_log
--disable_query_log
let $mysql_errno = 0;
# 1123=ER_CANT_INITIALIZE_UDF
while ($mysql_errno != 1123)
{
--error 0,1123
SELECT version_tokens_set("token1=abc;token2=def");
--sleep 0.1
}
--enable_query_log
--enable_result_log
-- echo
-- echo # The UDFs fail as the plugin is uninstalled.
--error ER_CANT_INITIALIZE_UDF
select version_tokens_set("token1 = abc;token2= def");
--error ER_CANT_INITIALIZE_UDF
select version_tokens_edit("token1= 123; token3 = asdf");
--error ER_CANT_INITIALIZE_UDF
select version_tokens_delete("token1;token3");
--error ER_CANT_INITIALIZE_UDF
select version_tokens_show();
--echo
--echo # VERSION_TOKEN_ADMIN shouldn't be visible in SHOW PRIVILEGES
--sorted_result
SHOW PRIVILEGES;
--echo
drop function version_tokens_set;
drop function version_tokens_show;
drop function version_tokens_edit;
drop function version_tokens_delete;
drop function version_tokens_lock_shared;
drop function version_tokens_lock_exclusive;
drop function version_tokens_unlock;
drop user vbhagi@localhost;
drop user u1@localhost;
|