# Checking if perl Expect module is installed on the system. # If not, the test will be skipped. --source include/have_expect.inc --source include/not_windows.inc --source include/have_validate_password_component.inc SELECT plugin into @plugin from mysql.user where user= 'root' and host='localhost'; SELECT password_last_changed into @plc from mysql.user where user= 'root' and host='localhost'; SELECT authentication_string into @auth_str from mysql.user where user= 'root' and host='localhost'; SELECT user_attributes into @user_attrib from mysql.user where user='root' and host='localhost'; SELECT plugin into @sys_plugin from mysql.user where user= 'mysql.sys' and host='localhost'; SELECT password_last_changed into @sys_plc from mysql.user where user= 'mysql.sys' and host='localhost'; SELECT authentication_string into @sys_auth_str from mysql.user where user= 'mysql.sys' and host='localhost'; call mtr.add_suppression("Dictionary file not specified"); SET PASSWORD for root@localhost = ''; # The execution of mysql_secure_installation using perl which uses the # Expect module as mysql_secure_installation is user interactive. --perl use strict; require Expect; # Declaring variables for Expect my @texp; my $i; # Aggregating the commands which are executed post the password is input to # mysql_secure_installation into a function with the values no. sub after_commands() { $texp[$i]->expect(15,' -re ',[ 'Remove anonymous users?' => sub { $texp[$i]->send("n\n");}]); $texp[$i]->expect(15,' -re ',[ 'Disallow root login remotely?' => sub { $texp[$i]->send("n\n");}]); $texp[$i]->expect(15,' -re ',[ 'Remove test database and access to it?' => sub { $texp[$i]->send("n\n");}]); $texp[$i]->expect(15,' -re ',[ 'Reload privilege tables now?' => sub { $texp[$i]->send("n\n");}]); print "Execution number $i was successful\n"; } # Defining a new Expect object and invoking mysql_secure_installation sub initial_commands() { $texp[$i] = new Expect(); $texp[$i]->raw_pty(1); } # Aggregating the commands which are executed post the password is input to # mysql_secure_installation into a function with the values yes. sub after_effects() { $texp[$i]->expect(15,' -re ',[ 'Remove anonymous users?' => sub { $texp[$i]->send("y\n");}]); $texp[$i]->expect(15,' -re ',[ 'Disallow root login remotely?' => sub { $texp[$i]->send("y\n");}]); $texp[$i]->expect(15,' -re ',[ 'Remove test database and access to it?' => sub { $texp[$i]->send("y\n");}]); $texp[$i]->expect(15,' -re ',[ 'Reload privilege tables now?' => sub { $texp[$i]->send("y\n");}]); print "Execution number $i was successful\n"; } $i = 1; # Invoking mysql_secure_installation. initial_commands(); if (-e $ENV{MASTER_MYSOCK} ){ $texp[$i]->spawn("$ENV{MYSQL_SECURE_INSTALLATION} -S $ENV{MASTER_MYSOCK }"); } $texp[$i]->expect(15,' -re ',[ 'any other key for No' => sub { $texp[$i]->send("n\n");}]); $texp[$i]->expect(15,' -re ',[ 'New password' => sub { $texp[$i]->send("1\n");}]); $texp[$i]->expect(15,' -re ',[ 'Re-enter' => sub { $texp[$i]->send("1\n");}]); after_commands(); $i++; # Invoking mysql_secure_installation with different password values. initial_commands(); if (-e $ENV{MASTER_MYSOCK} ){ $texp[$i]->spawn("$ENV{MYSQL_SECURE_INSTALLATION} -S $ENV{MASTER_MYSOCK } -p"); } $texp[$i]->expect(15,' -re ',[ 'password' => sub { $texp[$i]->send("1\n");}]); $texp[$i]->expect(15,' -re ',[ 'any other key for No' => sub { $texp[$i]->send("n\n");}]); $texp[$i]->expect(15,' -re ',[ 'Change the password for root' => sub { $texp[$i]->send("y\n");}]); $texp[$i]->expect(15,' -re ',[ 'New password' => sub { $texp[$i]->send("null\n");}]); $texp[$i]->expect(15,' -re ',[ 'Re-enter' => sub { $texp[$i]->send("null\n");}]); after_effects(); $i++; # Invoking mysql_secure_installation and installing the validate_password plugin. initial_commands(); if (-e $ENV{MASTER_MYSOCK} ){ $texp[$i]->spawn("$ENV{MYSQL_SECURE_INSTALLATION} -S $ENV{MASTER_MYSOCK } -p"); } $texp[$i]->expect(15,' -re ',[ 'password' => sub { $texp[$i]->send("null\n");}]); $texp[$i]->expect(15,' -re ',[ 'any other key for No' => sub { $texp[$i]->send("y\n");}]); $texp[$i]->expect(15,' -re ',[ 'Please enter' => sub { $texp[$i]->send("1\n");}]); $texp[$i]->expect(15,' -re ',[ 'Change the password for root' => sub { $texp[$i]->send("y\n");}]); $texp[$i]->expect(15,' -re ',[ 'New password' => sub { $texp[$i]->send("passPASS1234!@#\n");}]); $texp[$i]->expect(15,' -re ',[ 'Re-enter' => sub { $texp[$i]->send("passPASS1234!@#\n");}]); $texp[$i]->expect(15,' -re ',[ 'Do you' => sub { $texp[$i]->send("y\n");}]); after_effects(); $i++; initial_commands(); if (-e $ENV{MASTER_MYSOCK} ){ $texp[$i]->spawn("$ENV{MYSQL_SECURE_INSTALLATION} -S $ENV{MASTER_MYSOCK } -p"); } $texp[$i]->expect(15,' -re ',[ 'password' => sub { $texp[$i]->send("passPASS1234!@#\n");}]); $texp[$i]->expect(15,' -re ',[ 'any other key for No' => sub { $texp[$i]->send("y\n");}]); $texp[$i]->expect(15,' -re ',[ 'New password' => sub { $texp[$i]->send("secure\n");}]); $texp[$i]->expect(15,' -re ',[ 'Re-enter new password' => sub { $texp[$i]->send("secure\n");}]); $texp[$i]->expect(15,' -re ',[ 'Do you' => sub { $texp[$i]->send("y\n");}]); $texp[$i]->expect(15,' -re ',[ 'New password' => sub { $texp[$i]->send("secureINSTALL09#)(\n");}]); $texp[$i]->expect(15,' -re ',[ 'Re-enter new password' => sub { $texp[$i]->send("secureINSTALL09#)(\n");}]); $texp[$i]->expect(15,' -re ',[ 'Do you' => sub { $texp[$i]->send("y\n");}]); after_effects(); $i++; initial_commands(); if (-e $ENV{MASTER_MYSOCK} ){ $texp[$i]->spawn("$ENV{MYSQL_SECURE_INSTALLATION} -S $ENV{MASTER_MYSOCK } -D -p"); } $texp[$i]->expect(15,' -re ',[ 'password' => sub { $texp[$i]->send("secureINSTALL09#)(\n");}]); print("Execution ".$i." was successful\n"); $i++; EOF # Uninstalling validate_password plugin UNINSTALL COMPONENT "file://component_validate_password"; # Restoring the server to the state prior to this test. SET PASSWORD for root@localhost = ''; CREATE DATABASE test; REPLACE INTO mysql.user VALUES ('localhost','root','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','','N',NULL,NULL,'N','Y','Y', NULL, NULL,NULL,NULL); REPLACE INTO mysql.user VALUES ('localhost','mysql.sys','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0,0,'mysql_native_password','*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE','N',NULL,NULL,'Y','N','N', NULL, NULL,NULL,NULL); INSERT INTO mysql.db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','N','N','Y','Y'); UPDATE mysql.user SET password_last_changed=@plc, authentication_string=@auth_str, plugin= @plugin, user_attributes=@user_attrib where user='root'; UPDATE mysql.user SET password_last_changed=@sys_plc, authentication_string=@sys_auth_str, plugin= @sys_plugin where user='mysql.sys'; FLUSH PRIVILEGES;