1# This is test file for  connection & authentication handling without ssl.
2#
3# Comment:
4#
5#   Mysqlx_connections_closed status variable is incremented after releasing
6#   client network resources. Because of it, it is a best suitable for synchronization.
7#   Other session/connection release/error status variables must be checked after waiting
8#   for concrete value on this timer.
9#
10
11--source include/xplugin_preamble.inc
12--source include/xplugin_create_user.inc
13
14call mtr.add_suppression("Plugin mysqlx reported: 'Unable to switch context to user mysql.session'");
15call mtr.add_suppression("Plugin mysqlx reported: 'Unable to accept connection, disconnecting client'");
16call mtr.add_suppression("Plugin mysqlx reported: 'Could not open internal MySQL session'");
17call mtr.add_suppression("Plugin mysqlx reported: '.*: Error initializing session for connection: Too many connections'");
18call mtr.add_suppression("Plugin 'mysqlx' has ref_count=5 after shutdown");
19call mtr.add_suppression("Plugin 'mysqlx' will be forced to shutdown");
20
21## Test starts here
22--write_file $MYSQL_TMP_DIR/mysqlx-connection.tmp
23-->sql
24SELECT PLUGIN_NAME,PLUGIN_VERSION,PLUGIN_STATUS,PLUGIN_TYPE from information_schema.plugins where PLUGIN_NAME LIKE '%mysqlx%';
25create user xplugin@localhost identified by 'xplugin';
26alter user xplugin@localhost password expire;
27create user nonblank@localhost identified by 'nonblank';
28create user blank@localhost identified by '';
29CREATE USER 'abc'@'localhost' IDENTIFIED BY 'abc' ACCOUNT LOCK;
30#CREATE USER noauth@localhost IDENTIFIED WITH 'mysql_no_login';
31create user ''@localhost identified by 'ramana';
32create user special@localhost identified by '1aram@&Tpu';
33create user session@localhost identified by 'session';
34grant all on *.* to session@localhost;
35show status like 'Mysqlx_connections_closed';
36show status like 'Mysqlx_connections_accepted';
37show status like 'Mysqlx_connection_accept_errors';
38#### show status like 'Mysqlx_connection_errors'; Bug #21782329
39show status where `Variable_name` like  'Mysqlx_sessions%' and not `Variable_name` like  'Mysqlx_sessions_fatal_error';
40-->endsql
41EOF
42
43--write_file $MYSQL_TMP_DIR/mysqlx-connection_current_user.tmp
44-->stmtsql select user(),current_user(),@@bind_address
45-->expecterror %EXPECT_ERROR%
46-->recvresult
47
48-->stmtsql show status like 'Mysqlx_connections_closed'
49-->expecterror %EXPECT_ERROR%
50-->recvresult
51
52-->stmtsql show status like 'Mysqlx_connections_accepted'
53-->expecterror %EXPECT_ERROR%
54-->recvresult
55
56-->stmtsql show status like 'Mysqlx_connection_accept_errors'
57-->expecterror %EXPECT_ERROR%
58-->recvresult
59
60#### show status like 'Mysqlx_connection_errors'; Bug #21782329
61-->stmtsql show status where `Variable_name` like  'Mysqlx_sessions%' and not `Variable_name` like  'Mysqlx_sessions_fatal_error'
62-->expecterror %EXPECT_ERROR%
63-->recvresult
64
65EOF
66
67--write_file $MYSQL_TMP_DIR/mysqlx-connection_locked_user.tmp
68-->expecterror ER_ACCOUNT_HAS_BEEN_LOCKED
69-->newsession bla	abc	abc
70EOF
71
72
73--write_file $MYSQL_TMP_DIR/mysqlx-connection_session_track.tmp
74-->sql
75SET @@session.session_track_system_variables='mysqlx_port,mysqlx_idle_worker_thread_timeout,mysqlx_max_allowed_packet,mysqlx_max_connections,mysqlx_min_worker_threads';
76show variables like '%session_track%';
77-->endsql
78
79-->stmtsql uninstall plugin mysqlx;
80-->expecterror ER_PLUGGABLE_PROTOCOL_COMMAND_NOT_SUPPORTED
81-->recvresult
82
83-->sql
84show warnings;
85show variables like '%mysqlx_max_connections%';
86set @@global.mysqlx_max_connections=100;
87show variables like '%mysqlx_max_connections%';
88show status like 'Mysqlx_connections_closed';
89show status like 'Mysqlx_connections_accepted';
90show status like 'Mysqlx_connection_accept_errors';
91#### show status like 'Mysqlx_connection_errors'; Bug #21782329
92show status where `Variable_name` like  'Mysqlx_sessions%' and not `Variable_name` like  'Mysqlx_sessions_fatal_error';
93-->endsql
94EOF
95
96--write_file $MYSQL_TMP_DIR/mysqlx-connection_uninstallplugin.tmp
97-->sql
98uninstall plugin mysqlx;
99-->endsql
100EOF
101
102--echo #
103--echo # Login with valid account
104--echo #
105exec $MYSQLXTEST -ux_root --password=''
106  --file=$MYSQL_TMP_DIR/mysqlx-connection.tmp 2>&1;
107let $wait_for_status_variable = 'Mysqlx_connections_closed';
108let $wait_for_status_value = 1;
109source ../include/wait_for_status_variables.inc;
110source ../include/connection_test_helpers.inc;
111
112--echo #
113--echo # Try to login with bogus accounts that could match a valid account by collation
114--echo #
115exec $MYSQLXTEST --expect-error 2510 -uX_root --password=''  --sql "SELECT THIS_MUST_NOT_BE_EXECUTED()" 2>&1;
116
117
118exec $MYSQLXTEST --expect-error 2510 -u"x_root  " --password=''  --sql "SELECT THIS_MUST_NOT_BE_EXECUTED()" 2>&1;
119let $wait_for_status_variable =
120  'Mysqlx_sessions_rejected',
121  'Mysqlx_connections_closed';
122let $wait_for_status_value = 2, 3;
123
124source ../include/wait_for_status_variables.inc;
125source ../include/connection_test_helpers.inc;
126
127
128--echo #
129--echo # Try login with user having special characters in password when mysqlxplugin installed
130--echo #
131--exec $MYSQLXTEST -uspecial --password="1aram@&Tpu" -v%EXPECT_ERROR%=ER_SUCCESS --file=$MYSQL_TMP_DIR/mysqlx-connection_current_user.tmp 2>&1
132let $wait_for_status_variable =
133  'Mysqlx_sessions_rejected',
134  'Mysqlx_connections_closed';
135let $wait_for_status_value = 2, 4;
136source ../include/wait_for_status_variables.inc;
137source ../include/connection_test_helpers.inc;
138
139#### Not a Bug, anon user doesn't exist in xplugin
140####try login with annonymous user when mysqx plugin is installed
141####Test for Bug#21372364
142####--exec $MYSQLXTEST -ut --password='ramana' -v%EXPECT_ERROR%=ER_MUST_CHANGE_PASSWORD --file=$MYSQL_TMP_DIR/mysqlx-connection_current_user.tmp 2>&1
143
144--echo #
145--echo # try login with invalid host when mysqx plugin is installed
146--echo #
147--exec $MYSQLXTEST --expect-error CR_UNKNOWN_HOST -ux_root --password='' -hmtr_test_invalid_mysql_host  --sql "SELECT THIS_MUST_NOT_BE_EXECUTED()" 2>&1
148
149# replace_regex did consume last character in line, lets put it back
150--echo
151
152# Nothing changed in X Plugin, lets do sleep for giving a change on
153# for propagating the signals
154--sleep 1
155let $wait_for_status_variable =
156  'Mysqlx_sessions_rejected',
157  'Mysqlx_connections_closed';
158let $wait_for_status_value = 2, 4;
159source ../include/wait_for_status_variables.inc;
160source ../include/connection_test_helpers.inc;
161
162--echo #
163--echo # Trying with valid user when mysqlx is not installed
164--echo #
165
166let $restart_parameters = restart: --skip-mysqlx;
167source include/restart_mysqld.inc;
168
169replace_regex /( *No connection could be made because the target machine actively refused it connecting to*| *Connection refused connecting to*) .*:[0-9]*/ERROR: Connection refused connecting to HOST:PORT/;
170exec $MYSQLXTEST --expect-error CR_CONNECTION_ERROR -ux_root --password=''
171  --file=$MYSQL_TMP_DIR/mysqlx-connection.tmp 2>&1;
172source ../include/connection_test_helpers.inc;
173
174--echo #
175--echo # Try login using mysqlx protocol when server and mysqlx loaded with super user
176--echo #
177replace_regex /\.dll/.so/;
178let $restart_parameters = restart: ;
179source include/restart_mysqld.inc;
180exec $MYSQLXTEST -u x_root --password='' -v%EXPECT_ERROR%=ER_SUCCESS
181  --file=$MYSQL_TMP_DIR/mysqlx-connection_current_user.tmp 2>&1;
182let $wait_for_status_variable = 'Mysqlx_connections_closed';
183let $wait_for_status_value = 1;
184source ../include/wait_for_status_variables.inc;
185source ../include/connection_test_helpers.inc;
186
187--echo #
188--echo # Try login with valid user but incorrect password
189--echo #
190exec $MYSQLXTEST --expect-error 2510 -ux_root --password='x_root'  --sql "SELECT THIS_MUST_NOT_BE_EXECUTED()" 2>&1;
191let $wait_for_status_variable =
192  'Mysqlx_sessions_rejected',
193  'Mysqlx_connections_closed';
194let $wait_for_status_value = 1, 2;
195source ../include/wait_for_status_variables.inc;
196source ../include/connection_test_helpers.inc;
197
198--echo #
199--echo # Try login with user doesn't exists when mysqlx installed
200--echo #
201exec $MYSQLXTEST --expect-error 2510 -u rt --password='x_root'  --sql "SELECT THIS_MUST_NOT_BE_EXECUTED()" 2>&1;
202let $wait_for_status_variable =
203  'Mysqlx_sessions_rejected',
204  'Mysqlx_connections_closed';
205let $wait_for_status_value = 2, 3;
206source ../include/wait_for_status_variables.inc;
207source ../include/connection_test_helpers.inc;
208
209--echo #
210--echo # Try login with user whose password expired when mysqlx installed
211--echo #
212exec $MYSQLXTEST --expect-error ER_MUST_CHANGE_PASSWORD_LOGIN -u xplugin --password='xplugin' --sql "SELECT THIS_MUST_NOT_BE_EXECUTED()" 2>&1;
213let $wait_for_status_variable =
214  'Mysqlx_sessions_rejected',
215  'Mysqlx_connections_closed';
216let $wait_for_status_value = 3, 4;
217source ../include/wait_for_status_variables.inc;
218source ../include/connection_test_helpers.inc;
219
220--echo #
221--echo # Try login with user whose account is locked when mysqlx installed
222--echo #
223--exec $MYSQLXTEST --expect-error ER_ACCOUNT_HAS_BEEN_LOCKED -u abc --password='abc' --sql "SELECT THIS_MUST_NOT_BE_EXECUTED()" 2>&1
224let $wait_for_status_variable =
225  'Mysqlx_sessions_rejected',
226  'Mysqlx_connections_closed';
227let $wait_for_status_value = 4, 5;
228source ../include/wait_for_status_variables.inc;
229source ../include/connection_test_helpers.inc;
230
231--echo #
232--echo # Try login with internal user account and expect account is locked error
233--echo #
234--exec $MYSQLXTEST --expect-error 2510 -u'mysql.session' --password='' --sql "SELECT THIS_MUST_NOT_BE_EXECUTED()"
235let $wait_for_status_variable =
236  'Mysqlx_sessions_rejected',
237  'Mysqlx_connections_closed';
238let $wait_for_status_value = 5, 6;
239source ../include/wait_for_status_variables.inc;
240source ../include/connection_test_helpers.inc;
241
242--echo #
243--echo # Login with valid user and valid password when mysqlx installed
244--echo #
245--exec $MYSQLXTEST -u nonblank --password='nonblank' -v%EXPECT_ERROR%=ER_SUCCESS --file=$MYSQL_TMP_DIR/mysqlx-connection_current_user.tmp 2>&1
246let $wait_for_status_variable =
247  'Mysqlx_sessions_closed',
248  'Mysqlx_connections_closed';
249let $wait_for_status_value = 2, 7;
250source ../include/wait_for_status_variables.inc;
251source ../include/connection_test_helpers.inc;
252
253--echo #
254--echo # Login with valid user and blank password when mysqlx installed
255--echo #
256--exec $MYSQLXTEST -u blank --password='' -v%EXPECT_ERROR%=ER_SUCCESS --file=$MYSQL_TMP_DIR/mysqlx-connection_current_user.tmp 2>&1
257let $wait_for_status_variable =
258  'Mysqlx_sessions_closed',
259  'Mysqlx_connections_closed';
260let $wait_for_status_value = 3, 8;
261source ../include/wait_for_status_variables.inc;
262source ../include/connection_test_helpers.inc;
263
264--remove_file $MYSQL_TMP_DIR/mysqlx-connection.tmp
265
266--write_file $MYSQL_TMP_DIR/mysqlx-connection.tmp
267-->sql
268SELECT PLUGIN_NAME,PLUGIN_VERSION,PLUGIN_STATUS,PLUGIN_TYPE,PLUGIN_TYPE_VERSION,PLUGIN_LIBRARY,PLUGIN_LIBRARY_VERSION,PLUGIN_AUTHOR,PLUGIN_DESCRIPTION,PLUGIN_LICENSE,LOAD_OPTION from information_schema.plugins where PLUGIN_NAME LIKE '%xplugin%';
269show status like 'Mysqlx_connections_closed';
270show status like 'Mysqlx_connections_accepted';
271show status like 'Mysqlx_connection_accept_errors';
272#### show status like 'Mysqlx_connection_errors'; Bug #21782329
273show status where `Variable_name` like  'Mysqlx_sessions%' and not `Variable_name` like  'Mysqlx_sessions_fatal_error';
274-->endsql
275EOF
276
277--echo #
278--echo # Try login with valid user when server started with localhost as bind-address and mysqlx loaded
279--echo #
280let $restart_parameters = restart: --bind-address=localhost;
281replace_regex /\.dll/.so/;
282source include/restart_mysqld.inc;
283exec $MYSQLXTEST -u nonblank --password='nonblank'
284  -v%EXPECT_ERROR%=ER_SUCCESS
285  --file=$MYSQL_TMP_DIR/mysqlx-connection_current_user.tmp 2>&1;
286exec $MYSQLXTEST -u nonblank --password='nonblank' -hlocalhost
287  -v%EXPECT_ERROR%=ER_SUCCESS
288  --file=$MYSQL_TMP_DIR/mysqlx-connection_current_user.tmp 2>&1;
289let $wait_for_status_variable =
290  'Mysqlx_sessions_closed',
291  'Mysqlx_connections_closed';
292let $wait_for_status_value = 2, 2;
293source ../include/wait_for_status_variables.inc;
294source ../include/connection_test_helpers.inc;
295
296--echo #
297--echo # Try login with valid user when server started with 127.0.0.1 as bind-address and mysqlx loaded
298--echo #
299let $restart_parameters = restart: --bind-address=127.0.0.1;
300replace_regex /\.dll/.so/;
301source include/restart_mysqld.inc;
302exec $MYSQLXTEST -u nonblank --password='nonblank'
303  -v%EXPECT_ERROR%=ER_SUCCESS
304  --file=$MYSQL_TMP_DIR/mysqlx-connection_current_user.tmp 2>&1;
305let $wait_for_status_variable =
306  'Mysqlx_sessions_closed',
307  'Mysqlx_connections_closed';
308let $wait_for_status_value = 1, 1;
309source ../include/wait_for_status_variables.inc;
310source ../include/connection_test_helpers.inc;
311
312exec $MYSQLXTEST -u nonblank --password='nonblank' -h127.0.0.1
313  -v%EXPECT_ERROR%=ER_SUCCESS
314  --file=$MYSQL_TMP_DIR/mysqlx-connection_current_user.tmp 2>&1;
315let $wait_for_status_variable =
316  'Mysqlx_sessions_closed',
317  'Mysqlx_connections_closed';
318let $wait_for_status_value = 2, 2;
319source ../include/wait_for_status_variables.inc;
320source ../include/connection_test_helpers.inc;
321
322--echo #
323--echo # Try login with valid non-super and super user when server is in offline mode and mysqlx loaded
324--echo #
325let $restart_parameters = restart: --offline_mode=ON;
326replace_regex /\.dll/.so/;
327source include/restart_mysqld.inc;
328exec $MYSQLXTEST --expect-error ER_SERVER_OFFLINE_MODE -u nonblank --password='nonblank'  --sql "SELECT THIS_MUST_NOT_BE_EXECUTED()" 2>&1;
329let $wait_for_status_variable =
330  'Mysqlx_sessions_rejected',
331  'Mysqlx_connections_closed';
332let $wait_for_status_value = 1, 1;
333source ../include/wait_for_status_variables.inc;
334source ../include/connection_test_helpers.inc;
335
336--exec $MYSQLXTEST -u x_root --password='' -v%EXPECT_ERROR%=ER_SUCCESS --file=$MYSQL_TMP_DIR/mysqlx-connection_current_user.tmp 2>&1
337let $wait_for_status_variable =
338  'Mysqlx_sessions_closed',
339  'Mysqlx_connections_closed';
340let $wait_for_status_value = 1, 2;
341source ../include/wait_for_status_variables.inc;
342source ../include/connection_test_helpers.inc;
343
344--echo #
345--echo # Start server with session tracking variables and monitor them using xprotocol
346--echo #
347let $restart_parameters = restart: ;
348replace_regex /\.dll/.so/;
349source include/restart_mysqld.inc;
350exec $MYSQLXTEST -u session --password='session'
351  --file=$MYSQL_TMP_DIR/mysqlx-connection_session_track.tmp 2>&1;
352let $wait_for_status_variable =
353  'Mysqlx_sessions_closed',
354  'Mysqlx_connections_closed';
355let $wait_for_status_value = 1, 1;
356source ../include/wait_for_status_variables.inc;
357source ../include/connection_test_helpers.inc;
358
359--echo #
360--echo # Try login with user whose password expired when mysqlx installed and when server started with skip-disconnect-on-expired-password option
361--echo #
362let $restart_parameters = restart:  --skip-disconnect-on-expired-password;
363replace_regex /\.dll/.so/;
364source include/restart_mysqld.inc;
365
366exec $MYSQLXTEST -u xplugin --password='xplugin'
367  -v%EXPECT_ERROR%=ER_MUST_CHANGE_PASSWORD
368  --file=$MYSQL_TMP_DIR/mysqlx-connection_current_user.tmp 2>&1;
369let $wait_for_status_variable =
370  'Mysqlx_sessions_closed',
371  'Mysqlx_connections_closed';
372let $wait_for_status_value = 1, 1;
373source ../include/wait_for_status_variables.inc;
374source ../include/connection_test_helpers.inc;
375
376--write_file $MYSQL_TMP_DIR/open_max_mysqlx_connection.tmp
377-->sql
378create user con1@localhost identified by 'con1';
379create user con2@localhost identified by 'con2';
380grant all on *.* to con2@localhost;
381-->endsql
382-->echo Test data
383-->stmtadmin list_clients
384-->echo expect Mysqlx.Sql.StmtExecuteOk
385-->recvresult client_id user host
386
387-->echo create and activate new session con1
388-->newsession con1	con1	con1
389
390-->stmtadmin list_clients
391-->echo expect Mysqlx.Sql.StmtExecuteOk
392-->recvresult client_id user host
393
394-->echo open 3rd xprotocol connection where 2 sessions already opened (may fail)
395-->newsession con2	-
396-->peerdisc 1000 1000
397
398-->sleep 2
399-->stmtadmin list_clients
400-->recvresult client_id user host
401
402-->sql
403show status like 'Mysqlx_connections_closed';
404show status like 'Mysqlx_connections_accepted';
405show status like 'Mysqlx_connection_accept_errors';
406#### show status like 'Mysqlx_connection_errors'; Bug #21782329
407-->endsql
408EOF
409
410--echo #
411--echo # Try to open xprotocol sessions more than mysqlx_max_connections,
412--echo # expect error for last connection
413--echo #
414let $restart_parameters = restart: --mysqlx_max_connections=2;
415replace_regex /\.dll/.so/;
416source include/restart_mysqld.inc;
417exec $MYSQLXTEST -u x_root --password=''
418  --file=$MYSQL_TMP_DIR/open_max_mysqlx_connection.tmp 2>&1;
419let $wait_for_status_variable =
420  'Mysqlx_connections_closed',
421  'Mysqlx_connections_accepted';
422let $wait_for_status_value = 2, 2;
423source ../include/wait_for_status_variables.inc;
424let $skip_show_mysqlx_sessions_variables=1;
425source ../include/connection_test_helpers.inc;
426
427--write_file $MYSQL_TMP_DIR/open_max_mysqlx_connection2.tmp
428-->sql
429create user con1@localhost identified by 'con1';
430create user con2@localhost identified by 'con2';
431grant all on *.* to con2@localhost;
432-->endsql
433-->echo Test data
434-->stmtadmin list_clients
435-->echo expect Mysqlx.Sql.StmtExecuteOk
436-->recvresult client_id user host
437
438-->echo create and activate new session con1
439-->newsession con1	con1	con1
440
441-->stmtadmin list_clients
442-->echo expect Mysqlx.Sql.StmtExecuteOk
443-->recvresult client_id user host
444
445-->echo open 3rd xprotocol connection where 2 sessions already opened
446-->newsession con2	con2	con2
447
448-->stmtadmin list_clients
449-->recvresult client_id user host
450
451-->sql
452show status like 'Mysqlx_connections_closed';
453show status like 'Mysqlx_connections_accepted';
454show status like 'Mysqlx_connection_accept_errors';
455#### show status like 'Mysqlx_connection_errors'; Bug #21782329
456-->endsql
457EOF
458
459--echo #
460--echo # Try to open xprotocol sessions as that of mysqlx_max_connections set
461--echo #
462drop user con1@localhost;
463drop user con2@localhost;
464let $restart_parameters = restart: --mysqlx_max_connections=3;
465--replace_regex /\.dll/.so/
466--source include/restart_mysqld.inc
467--exec $MYSQLXTEST -u x_root --password='' --file=$MYSQL_TMP_DIR/open_max_mysqlx_connection2.tmp 2>&1
468let $wait_for_status_variable =
469  'Mysqlx_connections_closed',
470  'Mysqlx_connections_accepted';
471let $wait_for_status_value = 3, 3;
472source ../include/wait_for_status_variables.inc;
473let $skip_show_mysqlx_sessions_variables=1;
474source ../include/connection_test_helpers.inc;
475
476--write_file $MYSQL_TMP_DIR/allconn_root.tmp
477-->sql
478create user xcon1@localhost identified by 'xcon1';
479create user xcon2@localhost identified by 'xcon2';
480grant all on *.* to xcon2@localhost;
481set @@global.mysqlx_max_connections=2;
482-->endsql
483-->echo Test data
484-->stmtadmin list_clients
485-->echo expect Mysqlx.Sql.StmtExecuteOk
486-->recvresult client_id user host
487
488-->sql
489show status like 'Mysqlx_connections_closed';
490show status like 'Mysqlx_connections_accepted';
491show status like 'Mysqlx_connection_accept_errors';
492#### show status like 'Mysqlx_connection_errors'; Bug #21782329
493-->endsql
494
495-->echo create and activate new session con1
496-->newsession xcon1	xcon1	xcon1
497
498-->stmtadmin list_clients
499-->echo expect Mysqlx.Sql.StmtExecuteOk
500-->recvresult client_id user host
501
502-->sql
503show status like 'Mysqlx_connections_closed';
504show status like 'Mysqlx_connections_accepted';
505show status like 'Mysqlx_connection_accept_errors';
506#### show status like 'Mysqlx_connection_errors'; Bug #21782329
507-->endsql
508
509-->echo open 3rd xprotocol connection where 2 sessions already opened
510-->echo this scenario is related to Bug#21374656
511-->newsession xcon2	-
512-->peerdisc 1500 1500
513
514## switch back to default session
515-->setsession
516-->sleep 2
517-->stmtadmin list_clients
518-->recvresult client_id user host
519
520-->sql
521set @@global.mysqlx_max_connections=3;
522show status like 'Mysqlx_connections_closed';
523show status like 'Mysqlx_connections_accepted';
524show status like 'Mysqlx_connection_accept_errors';
525#### show status like 'Mysqlx_connection_errors'; Bug #21782329
526-->endsql
527
528-->newsession xcon2	xcon2	xcon2
529
530-->stmtadmin list_clients
531-->recvresult client_id user host
532
533-->sql
534drop user xcon1@localhost;
535drop user xcon2@localhost;
536set @@global.mysqlx_max_connections=100;
537show status like 'Mysqlx_connections_closed';
538show status like 'Mysqlx_connections_accepted';
539show status like 'Mysqlx_connection_accept_errors';
540#### show status like 'Mysqlx_connection_errors'; Bug #21782329
541-->endsql
542EOF
543
544--echo #
545--echo # Open max allowed connections and expect error for new connections and changes value and connect again,expect success
546--echo #
547--exec $MYSQLXTEST -u x_root --password='' --file=$MYSQL_TMP_DIR/allconn_root.tmp 2>&1
548let $wait_for_status_variable =
549  'Mysqlx_connections_closed',
550  'Mysqlx_connections_accepted';
551let $wait_for_status_value = 6, 6;
552source ../include/wait_for_status_variables.inc;
553let $skip_show_mysqlx_sessions_variables=1;
554source ../include/connection_test_helpers.inc;
555
556--write_file $MYSQL_TMP_DIR/admin_xkill_parallel.tmp
557-->echo kill xprotocol session when some operations are going on there using mysqx protocol
558-->sql
559create user xcon1@localhost identified by 'xcon1';
560create user xcon2@localhost identified by 'xcon2';
561grant all on *.* to xcon2@localhost;
562SET GLOBAL mysqlx_connect_timeout = 300;
563-->endsql
564-->echo Test data
565-->stmtadmin list_clients
566-->echo expect Mysqlx.Sql.StmtExecuteOk
567-->recvresult client_id user host
568
569-->sql
570show status like 'Mysqlx_connections_closed';
571show status like 'Mysqlx_connections_accepted';
572show status like 'Mysqlx_connection_accept_errors';
573#### show status like 'Mysqlx_connection_errors'; Bug #21782329
574-->endsql
575
576-->echo create and activate new session con1
577-->newsession xcon1	xcon1	xcon1
578
579-->sql
580show status like 'Mysqlx_connections_closed';
581show status like 'Mysqlx_connections_accepted';
582show status like 'Mysqlx_connection_accept_errors';
583#### show status like 'Mysqlx_connection_errors'; Bug #21782329
584-->endsql
585
586-->stmtadmin list_clients
587-->echo expect Mysqlx.Sql.StmtExecuteOk
588-->recvresult client_id user host
589
590Mysqlx.Sql.StmtExecute {
591  stmt: "select sleep(100);"
592}
593
594-->echo open 3rd xprotocol connection where 2 sessions already opened
595-->newsession xcon2	xcon2	xcon2
596-->sql
597#select ID,USER,COMMAND,STATE from information_schema.processlist order by ID desc;
598show status like 'Mysqlx_connections_closed';
599show status like 'Mysqlx_connections_accepted';
600show status like 'Mysqlx_connection_accept_errors';
601#### show status like 'Mysqlx_connection_errors'; Bug #21782329
602-->endsql
603
604## switch back to default session
605-->setsession
606
607-->stmtadmin list_clients
608-->recvresult client_id user host
609
610-->sql
611show status like 'Mysqlx_connections_closed';
612show status like 'Mysqlx_connections_accepted';
613show status like 'Mysqlx_connection_accept_errors';
614#### show status like 'Mysqlx_connection_errors'; Bug #21782329
615-->endsql
616
617-->newsession xcon3	xcon2	xcon2
618
619-->stmtadmin list_clients
620-->recvresult client_id user host
621
622
623-->stmtadmin kill_client	{"id":9}
624-->echo expect Mysqlx.Sql.StmtExecuteOk
625-->recvresult
626
627-->setsession xcon1
628-->recvuntildisc
629
630# Ensure that all connection disconnected until now
631# were released. The test must wait for Mysqlx_connections_closed.
632quiet;
633noquery_result;
634-->wait_for 7	SELECT variable_value FROM performance_schema.global_status WHERE variable_name LIKE 'Mysqlx_connections_closed'
635noquiet;
636query_result;
637
638-->stmtadmin list_clients
639-->recvresult client_id user host
640
641-->sql
642drop user xcon1@localhost;
643drop user xcon2@localhost;
644show status like 'Mysqlx_connections_closed';
645show status like 'Mysqlx_connections_accepted';
646show status like 'Mysqlx_connection_accept_errors';
647#### show status like 'Mysqlx_connection_errors'; Bug #21782329
648-->endsql
649EOF
650
651
652--write_file $MYSQL_TMP_DIR/open_max_mysql_connection.tmp
653-->echo open more xconnections than specified max_connections,expect error
654-->sql
655create user mysqlcon1@localhost identified by 'mysqlcon1';
656create user mysqlcon2@localhost identified by 'mysqlcon2';
657set @@global.max_connections=2;
658-->endsql
659-->echo Test data
660-->stmtadmin list_clients
661-->echo expect Mysqlx.Sql.StmtExecuteOk
662-->recvresult client_id user host
663
664-->echo create and activate new session con1
665-->newsession con1	mysqlcon1	mysqlcon1
666
667-->sleep 2
668-->stmtadmin list_clients
669-->echo expect Mysqlx.Sql.StmtExecuteOk
670-->recvresult client_id user host
671
672-->echo open 3rd xprotocol connection where 2 sessions already opened
673-->newsession con2	-
674-->recvtype Mysqlx.Error
675-->peerdisc 1000 1000
676
677-->sleep 2
678-->stmtadmin list_clients
679-->recvresult client_id user host
680
681-->sql
682show status like 'Mysqlx_connections_closed';
683show status like 'Mysqlx_connections_accepted';
684show status like 'Mysqlx_connection_accept_errors';
685set @@global.max_connections=150;
686#### show status like 'Mysqlx_connection_errors'; Bug #21782329
687-->endsql
688EOF
689
690##kill xprotocol session when some operations are going on there using mysqx protocol
691--exec $MYSQLXTEST -u x_root --password='' --file=$MYSQL_TMP_DIR/admin_xkill_parallel.tmp 2>&1
692--sleep 1
693
694let $wait_for_status_variable =
695  'Mysqlx_connections_closed',
696  'Mysqlx_connections_accepted';
697let $wait_for_status_value = 10, 10;
698source ../include/wait_for_status_variables.inc;
699let $skip_show_mysqlx_sessions_variables=1;
700source ../include/connection_test_helpers.inc;
701
702##try open more xconnections than specified max_connections,expect error
703--exec $MYSQLXTEST -u x_root --password='' --file=$MYSQL_TMP_DIR/open_max_mysql_connection.tmp 2>&1
704--sleep 1
705
706##ensure proper error for locked account
707#TODO move error handling here
708--exec $MYSQLXTEST -uabc --no-auth --file=$MYSQL_TMP_DIR/mysqlx-connection_locked_user.tmp 2>&1
709--sleep 2
710
711show status like 'Mysqlx_connections_closed';
712show status like 'Mysqlx_connections_accepted';
713show status like 'Mysqlx_connection_accept_errors';
714
715## Cleanup
716--let $restart_parameters = restart:
717--source include/restart_mysqld.inc
718
719drop user xplugin@localhost;
720drop user nonblank@localhost;
721drop user blank@localhost;
722drop user abc@localhost;
723drop user con1@localhost;
724drop user con2@localhost;
725drop user mysqlcon1@localhost;
726drop user mysqlcon2@localhost;
727drop user ''@localhost;
728drop user special@localhost;
729drop user session@localhost;
730
731SET GLOBAL mysqlx_connect_timeout = DEFAULT;
732--remove_file $MYSQL_TMP_DIR/mysqlx-connection_session_track.tmp
733--remove_file $MYSQL_TMP_DIR/mysqlx-connection_uninstallplugin.tmp
734--remove_file $MYSQL_TMP_DIR/mysqlx-connection_current_user.tmp
735--remove_file $MYSQL_TMP_DIR/mysqlx-connection.tmp
736--remove_file $MYSQL_TMP_DIR/open_max_mysqlx_connection.tmp
737--remove_file $MYSQL_TMP_DIR/open_max_mysqlx_connection2.tmp
738--remove_file $MYSQL_TMP_DIR/open_max_mysql_connection.tmp
739--remove_file $MYSQL_TMP_DIR/allconn_root.tmp
740--remove_file $MYSQL_TMP_DIR/admin_xkill_parallel.tmp
741--remove_file $MYSQL_TMP_DIR/mysqlx-connection_locked_user.tmp
742--source include/xplugin_drop_user.inc
743