| 1 |
# Checking if perl Expect module is installed on the system. |
| 2 |
# If not, the test will be skipped. |
| 3 |
--source include/have_expect.inc |
| 4 |
--source include/not_windows.inc |
| 5 |
--source include/have_validate_password_component.inc |
| 6 |
|
| 7 |
SELECT plugin into @plugin from mysql.user where user= 'root' and host='localhost'; |
| 8 |
SELECT password_last_changed into @plc from mysql.user where user= 'root' and host='localhost'; |
| 9 |
SELECT authentication_string into @auth_str from mysql.user where user= 'root' and host='localhost'; |
| 10 |
SELECT user_attributes into @user_attrib from mysql.user where user='root' and host='localhost'; |
| 11 |
SELECT plugin into @sys_plugin from mysql.user where user= 'mysql.sys' and host='localhost'; |
| 12 |
SELECT password_last_changed into @sys_plc from mysql.user where user= 'mysql.sys' and host='localhost'; |
| 13 |
SELECT authentication_string into @sys_auth_str from mysql.user where user= 'mysql.sys' and host='localhost'; |
| 14 |
call mtr.add_suppression("Dictionary file not specified"); |
| 15 |
SET PASSWORD for root@localhost = ''; |
| 16 |
# The execution of mysql_secure_installation using perl which uses the |
| 17 |
# Expect module as mysql_secure_installation is user interactive. |
| 18 |
--perl |
| 19 |
|
| 20 |
use strict; |
| 21 |
require Expect; |
| 22 |
|
| 23 |
# Declaring variables for Expect |
| 24 |
my @texp; |
| 25 |
my $i; |
| 26 |
|
| 27 |
# Aggregating the commands which are executed post the password is input to |
| 28 |
# mysql_secure_installation into a function with the values no. |
| 29 |
sub after_commands() |
| 30 |
{ |
| 31 |
$texp[$i]->expect(15,' -re ',[ 'Remove anonymous users?' => sub { |
| 32 |
$texp[$i]->send("n\n");}]); |
| 33 |
$texp[$i]->expect(15,' -re ',[ 'Disallow root login remotely?' => sub { |
| 34 |
$texp[$i]->send("n\n");}]); |
| 35 |
$texp[$i]->expect(15,' -re ',[ 'Remove test database and access to it?' => sub { |
| 36 |
$texp[$i]->send("n\n");}]); |
| 37 |
$texp[$i]->expect(15,' -re ',[ 'Reload privilege tables now?' => sub { $texp[$i]->send("n\n");}]); |
| 38 |
print "Execution number $i was successful\n"; |
| 39 |
} |
| 40 |
|
| 41 |
# Defining a new Expect object and invoking mysql_secure_installation |
| 42 |
sub initial_commands() |
| 43 |
{ |
| 44 |
$texp[$i] = new Expect(); |
| 45 |
$texp[$i]->raw_pty(1); |
| 46 |
} |
| 47 |
|
| 48 |
# Aggregating the commands which are executed post the password is input to |
| 49 |
# mysql_secure_installation into a function with the values yes. |
| 50 |
sub after_effects() |
| 51 |
{ |
| 52 |
$texp[$i]->expect(15,' -re ',[ 'Remove anonymous users?' => sub { |
| 53 |
$texp[$i]->send("y\n");}]); |
| 54 |
$texp[$i]->expect(15,' -re ',[ 'Disallow root login remotely?' => sub { |
| 55 |
$texp[$i]->send("y\n");}]); |
| 56 |
$texp[$i]->expect(15,' -re ',[ 'Remove test database and access to it?' => sub { |
| 57 |
$texp[$i]->send("y\n");}]); |
| 58 |
$texp[$i]->expect(15,' -re ',[ 'Reload privilege tables now?' => sub { $texp[$i]->send("y\n");}]); |
| 59 |
print "Execution number $i was successful\n"; |
| 60 |
} |
| 61 |
|
| 62 |
$i = 1; |
| 63 |
|
| 64 |
# Invoking mysql_secure_installation. |
| 65 |
initial_commands(); |
| 66 |
if (-e $ENV{MASTER_MYSOCK} ){ |
| 67 |
$texp[$i]->spawn("$ENV{MYSQL_SECURE_INSTALLATION} -S $ENV{MASTER_MYSOCK }"); |
| 68 |
} |
| 69 |
$texp[$i]->expect(15,' -re ',[ 'any other key for No' => sub { |
| 70 |
$texp[$i]->send("n\n");}]); |
| 71 |
$texp[$i]->expect(15,' -re ',[ 'New password' => sub { |
| 72 |
$texp[$i]->send("1\n");}]); |
| 73 |
$texp[$i]->expect(15,' -re ',[ 'Re-enter' => sub { $texp[$i]->send("1\n");}]); |
| 74 |
after_commands(); |
| 75 |
$i++; |
| 76 |
|
| 77 |
# Invoking mysql_secure_installation with different password values. |
| 78 |
|
| 79 |
initial_commands(); |
| 80 |
if (-e $ENV{MASTER_MYSOCK} ){ |
| 81 |
$texp[$i]->spawn("$ENV{MYSQL_SECURE_INSTALLATION} -S $ENV{MASTER_MYSOCK } -p"); |
| 82 |
} |
| 83 |
$texp[$i]->expect(15,' -re ',[ 'password' => sub { |
| 84 |
$texp[$i]->send("1\n");}]); |
| 85 |
$texp[$i]->expect(15,' -re ',[ 'any other key for No' => sub { |
| 86 |
$texp[$i]->send("n\n");}]); |
| 87 |
$texp[$i]->expect(15,' -re ',[ 'Change the password for root' => sub { |
| 88 |
$texp[$i]->send("y\n");}]); |
| 89 |
$texp[$i]->expect(15,' -re ',[ 'New password' => sub { |
| 90 |
$texp[$i]->send("null\n");}]); |
| 91 |
$texp[$i]->expect(15,' -re ',[ 'Re-enter' => sub { $texp[$i]->send("null\n");}]); |
| 92 |
after_effects(); |
| 93 |
$i++; |
| 94 |
|
| 95 |
# Invoking mysql_secure_installation and installing the validate_password plugin. |
| 96 |
initial_commands(); |
| 97 |
if (-e $ENV{MASTER_MYSOCK} ){ |
| 98 |
$texp[$i]->spawn("$ENV{MYSQL_SECURE_INSTALLATION} -S $ENV{MASTER_MYSOCK } -p"); |
| 99 |
} |
| 100 |
$texp[$i]->expect(15,' -re ',[ 'password' => sub { |
| 101 |
$texp[$i]->send("null\n");}]); |
| 102 |
$texp[$i]->expect(15,' -re ',[ 'any other key for No' => sub { |
| 103 |
$texp[$i]->send("y\n");}]); |
| 104 |
$texp[$i]->expect(15,' -re ',[ 'Please enter' => sub { |
| 105 |
$texp[$i]->send("1\n");}]); |
| 106 |
$texp[$i]->expect(15,' -re ',[ 'Change the password for root' => sub { |
| 107 |
$texp[$i]->send("y\n");}]); |
| 108 |
$texp[$i]->expect(15,' -re ',[ 'New password' => sub { |
| 109 |
$texp[$i]->send("passPASS1234!@#\n");}]); |
| 110 |
$texp[$i]->expect(15,' -re ',[ 'Re-enter' => sub { |
| 111 |
$texp[$i]->send("passPASS1234!@#\n");}]); |
| 112 |
$texp[$i]->expect(15,' -re ',[ 'Do you' => sub { $texp[$i]->send("y\n");}]); |
| 113 |
after_effects(); |
| 114 |
$i++; |
| 115 |
|
| 116 |
initial_commands(); |
| 117 |
if (-e $ENV{MASTER_MYSOCK} ){ |
| 118 |
$texp[$i]->spawn("$ENV{MYSQL_SECURE_INSTALLATION} -S $ENV{MASTER_MYSOCK } -p"); |
| 119 |
} |
| 120 |
$texp[$i]->expect(15,' -re ',[ 'password' => sub { |
| 121 |
$texp[$i]->send("passPASS1234!@#\n");}]); |
| 122 |
$texp[$i]->expect(15,' -re ',[ 'any other key for No' => sub { |
| 123 |
$texp[$i]->send("y\n");}]); |
| 124 |
$texp[$i]->expect(15,' -re ',[ 'New password' => sub { |
| 125 |
$texp[$i]->send("secure\n");}]); |
| 126 |
$texp[$i]->expect(15,' -re ',[ 'Re-enter new password' => sub { |
| 127 |
$texp[$i]->send("secure\n");}]); |
| 128 |
$texp[$i]->expect(15,' -re ',[ 'Do you' => sub { $texp[$i]->send("y\n");}]); |
| 129 |
$texp[$i]->expect(15,' -re ',[ 'New password' => sub { |
| 130 |
$texp[$i]->send("secureINSTALL09#)(\n");}]); |
| 131 |
$texp[$i]->expect(15,' -re ',[ 'Re-enter new password' => sub { |
| 132 |
$texp[$i]->send("secureINSTALL09#)(\n");}]); |
| 133 |
$texp[$i]->expect(15,' -re ',[ 'Do you' => sub { $texp[$i]->send("y\n");}]); |
| 134 |
after_effects(); |
| 135 |
$i++; |
| 136 |
|
| 137 |
initial_commands(); |
| 138 |
if (-e $ENV{MASTER_MYSOCK} ){ |
| 139 |
$texp[$i]->spawn("$ENV{MYSQL_SECURE_INSTALLATION} -S $ENV{MASTER_MYSOCK } -D -p"); |
| 140 |
} |
| 141 |
$texp[$i]->expect(15,' -re ',[ 'password' => sub { |
| 142 |
$texp[$i]->send("secureINSTALL09#)(\n");}]); |
| 143 |
print("Execution ".$i." was successful\n"); |
| 144 |
$i++; |
| 145 |
|
| 146 |
EOF |
| 147 |
|
| 148 |
# Uninstalling validate_password plugin |
| 149 |
UNINSTALL COMPONENT "file://component_validate_password"; |
| 150 |
|
| 151 |
# Restoring the server to the state prior to this test. |
| 152 |
SET PASSWORD for root@localhost = ''; |
| 153 |
CREATE DATABASE test; |
| 154 |
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); |
| 155 |
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); |
| 156 |
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'); |
| 157 |
UPDATE mysql.user SET password_last_changed=@plc, authentication_string=@auth_str, plugin= @plugin, user_attributes=@user_attrib where user='root'; |
| 158 |
UPDATE mysql.user SET password_last_changed=@sys_plc, authentication_string=@sys_auth_str, plugin= @sys_plugin where user='mysql.sys'; |
| 159 |
FLUSH PRIVILEGES; |