| 1 |
############################################################################### |
| 2 |
# # |
| 3 |
# Create automated tests for mysql_config_editor --password # |
| 4 |
# Author : Pavan Naik # |
| 5 |
# # |
| 6 |
############################################################################### |
| 7 |
|
| 8 |
# Checking if perl Expect module is installed on the system. |
| 9 |
# If not, the test will be skipped. |
| 10 |
--source include/have_expect.inc |
| 11 |
--source include/not_windows.inc |
| 12 |
|
| 13 |
--echo ############################# |
| 14 |
--echo # Creating 3 users # |
| 15 |
--echo ############################# |
| 16 |
CREATE USER 'user_1'@'localhost' identified by 'pass_1'; |
| 17 |
CREATE USER 'user_2'@'localhost' identified by 'pass_2'; |
| 18 |
CREATE USER 'user_3'@'localhost' identified by 'pass_3'; |
| 19 |
|
| 20 |
|
| 21 |
# The execution of mysql_config_editor using perl which uses the |
| 22 |
# Expect module as mysql_config_editor is user interactive. |
| 23 |
--perl |
| 24 |
|
| 25 |
# Checking if perl Expect module is installed on the system. |
| 26 |
# If not, the test will be skipped. |
| 27 |
die "Please install the Expect module ." unless(eval{require Expect}); |
| 28 |
|
| 29 |
use strict; |
| 30 |
require Expect; |
| 31 |
|
| 32 |
# Declaring variables for Expect |
| 33 |
my @texp; |
| 34 |
my $i; |
| 35 |
my $n; |
| 36 |
|
| 37 |
# Defining a new Expect object for 3 users and invoking mysql_config_editor for each user |
| 38 |
sub initial_commands |
| 39 |
{ |
| 40 |
$texp[$i] = new Expect(); |
| 41 |
$texp[$i]->raw_pty(1); |
| 42 |
my $user = "user_$_[0]"; |
| 43 |
my $login_path = "login_path_$_[0]"; |
| 44 |
my $host = "localhost"; |
| 45 |
$texp[$i]->spawn("$ENV{MYSQL_CONFIG_EDITOR} set --login-path=$login_path --user=$user --host=$host --password"); |
| 46 |
} |
| 47 |
|
| 48 |
$i=1; |
| 49 |
print "\n"; |
| 50 |
system("echo Invoking mysql_config_editor for user1 with correct password"); |
| 51 |
$n = 1; |
| 52 |
initial_commands($n); |
| 53 |
$texp[$i]->expect(1,' -re ',[ 'Enter password:' => sub { |
| 54 |
$texp[$i]->send("pass_1\n");}]); |
| 55 |
$texp[$i]->expect(1,' -re ',[ 'any other key for No' => sub { |
| 56 |
$texp[$i]->send("y\n");}]); |
| 57 |
$texp[$i]->soft_close(); |
| 58 |
print "\n"; |
| 59 |
system("$ENV{MYSQL} --login-path='login_path_1' -S $ENV{MASTER_MYSOCK} -e \"SELECT USER(), CURRENT_USER()\""); |
| 60 |
print "\n"; |
| 61 |
$i++; |
| 62 |
|
| 63 |
system("echo Invoking mysql_config_editor for user2 with correct password"); |
| 64 |
$n = 2; |
| 65 |
initial_commands($n); |
| 66 |
$texp[$i]->expect(1,' -re ',[ 'Enter password:' => sub { |
| 67 |
$texp[$i]->send("pass_2\n");}]); |
| 68 |
$texp[$i]->expect(1,' -re ',[ 'any other key for No' => sub { |
| 69 |
$texp[$i]->send("y\n");}]); |
| 70 |
$texp[$i]->soft_close(); |
| 71 |
print "\n"; |
| 72 |
system("$ENV{MYSQL} --login-path='login_path_2' -S $ENV{MASTER_MYSOCK} -e \"SELECT USER(), CURRENT_USER()\""); |
| 73 |
print "\n"; |
| 74 |
$i++; |
| 75 |
|
| 76 |
system("echo Invoking mysql_config_editor for user3 with correct password"); |
| 77 |
$n = 3; |
| 78 |
initial_commands($n); |
| 79 |
$texp[$i]->expect(1,' -re ',[ 'Enter password:' => sub { |
| 80 |
$texp[$i]->send("pass_3\n");}]); |
| 81 |
$texp[$i]->expect(1,' -re ',[ 'any other key for No' => sub { |
| 82 |
$texp[$i]->send("y\n");}]); |
| 83 |
$texp[$i]->soft_close(); |
| 84 |
print "\n"; |
| 85 |
system("$ENV{MYSQL} --login-path='login_path_3' -S $ENV{MASTER_MYSOCK} -e \"SELECT USER(), CURRENT_USER()\""); |
| 86 |
print "\n"; |
| 87 |
$i++; |
| 88 |
|
| 89 |
system("echo Invoking mysql_config_editor for user3 with wrong password"); |
| 90 |
$n = 3; |
| 91 |
initial_commands($n); |
| 92 |
$texp[$i]->expect(1,' -re ',[ 'Enter password:' => sub { |
| 93 |
$texp[$i]->send("pass_4\n");}]); |
| 94 |
$texp[$i]->soft_close(); |
| 95 |
print "\n"; |
| 96 |
system("$ENV{MYSQL} --login-path='login_path_3' -S $ENV{MASTER_MYSOCK} -e \"SELECT USER(), CURRENT_USER()\""); |
| 97 |
print "\n"; |
| 98 |
$i++; |
| 99 |
|
| 100 |
system("echo Invoking mysql_config_editor for user2 and not changing the password"); |
| 101 |
$n = 2; |
| 102 |
initial_commands($n); |
| 103 |
$texp[$i]->expect(1,' -re ',[ 'Enter password:' => sub { |
| 104 |
$texp[$i]->send("pass_5\n");}]); |
| 105 |
$texp[$i]->expect(1,' -re ',[ 'any other key for No' => sub { |
| 106 |
$texp[$i]->send("N\n");}]); |
| 107 |
$texp[$i]->soft_close(); |
| 108 |
print "\n"; |
| 109 |
system("$ENV{MYSQL} --login-path='login_path_2' -S $ENV{MASTER_MYSOCK} -e \"SELECT USER(), CURRENT_USER()\""); |
| 110 |
print "\n"; |
| 111 |
$i++; |
| 112 |
|
| 113 |
system("echo invoking mysql_config_editor for user2 and changing the password to wrong value"); |
| 114 |
$n = 2; |
| 115 |
initial_commands($n); |
| 116 |
$texp[$i]->expect(1,' -re ',[ 'Enter password:' => sub { |
| 117 |
$texp[$i]->send("pass_5\n");}]); |
| 118 |
$texp[$i]->expect(1,' -re ',[ 'any other key for No' => sub { |
| 119 |
$texp[$i]->send("y\n");}]); |
| 120 |
$texp[$i]->soft_close(); |
| 121 |
print "\n"; |
| 122 |
system("$ENV{MYSQL} --login-path='login_path_2' -S $ENV{MASTER_MYSOCK} -e \"SELECT USER(), CURRENT_USER()\""); |
| 123 |
print "\n"; |
| 124 |
$i++; |
| 125 |
|
| 126 |
system("echo Invoking mysql_config_editor for user2 and changing the password to wrong value"); |
| 127 |
$n = 2; |
| 128 |
initial_commands($n); |
| 129 |
$texp[$i]->expect(1,' -re ',[ 'Enter password:' => sub { |
| 130 |
$texp[$i]->send("\n");}]); |
| 131 |
$texp[$i]->expect(1,' -re ',[ 'any other key for No' => sub { |
| 132 |
$texp[$i]->send("y\n");}]); |
| 133 |
$texp[$i]->soft_close(); |
| 134 |
print "\n"; |
| 135 |
system("$ENV{MYSQL} --login-path='login_path_2' -S $ENV{MASTER_MYSOCK} -e \"SELECT USER(), CURRENT_USER()\""); |
| 136 |
print "\n"; |
| 137 |
$i++; |
| 138 |
|
| 139 |
system("echo Invoking mysql_config_editor for user2 and changing the password to wrong value"); |
| 140 |
$n = 2; |
| 141 |
initial_commands($n); |
| 142 |
$texp[$i]->expect(1,' -re ',[ 'Enter password:' => sub { |
| 143 |
$texp[$i]->send(" \n");}]); |
| 144 |
$texp[$i]->expect(1,' -re ',[ 'any other key for No' => sub { |
| 145 |
$texp[$i]->send("y\n");}]); |
| 146 |
$texp[$i]->soft_close(); |
| 147 |
print "\n"; |
| 148 |
system("$ENV{MYSQL} --login-path='login_path_2' -S $ENV{MASTER_MYSOCK} -e \"SELECT USER(), CURRENT_USER()\""); |
| 149 |
print "\n"; |
| 150 |
$i++; |
| 151 |
|
| 152 |
system("echo Invoking mysql_config_editor for user2 and changing the password to wrong value"); |
| 153 |
$n = 2; |
| 154 |
initial_commands($n); |
| 155 |
$texp[$i]->expect(1,' -re ',[ 'Enter password:' => sub { |
| 156 |
$texp[$i]->send("1234\n");}]); |
| 157 |
$texp[$i]->expect(1,' -re ',[ 'any other key for No' => sub { |
| 158 |
$texp[$i]->send("y\n");}]); |
| 159 |
$texp[$i]->soft_close(); |
| 160 |
print "\n"; |
| 161 |
system("$ENV{MYSQL} --login-path='login_path_2' -S $ENV{MASTER_MYSOCK} -e \"SELECT USER(), CURRENT_USER()\""); |
| 162 |
print "\n"; |
| 163 |
$i++; |
| 164 |
|
| 165 |
system("echo Invoking mysql_config_editor for user2 and changing the password to wrong value"); |
| 166 |
$n = 2; |
| 167 |
initial_commands($n); |
| 168 |
$texp[$i]->expect(1,' -re ',[ 'Enter password:' => sub { |
| 169 |
$texp[$i]->send("abc123def456\n");}]); |
| 170 |
$texp[$i]->expect(1,' -re ',[ 'any other key for No' => sub { |
| 171 |
$texp[$i]->send("y\n");}]); |
| 172 |
$texp[$i]->soft_close(); |
| 173 |
print "\n"; |
| 174 |
system("$ENV{MYSQL} --login-path='login_path_2' -S $ENV{MASTER_MYSOCK} -e \"SELECT USER(), CURRENT_USER()\""); |
| 175 |
print "\n"; |
| 176 |
$i++; |
| 177 |
|
| 178 |
system("echo invoking mysql_config_editor for user2 and changing the password to wrong value"); |
| 179 |
$n = 2; |
| 180 |
initial_commands($n); |
| 181 |
$texp[$i]->expect(1,' -re ',[ 'Enter password:' => sub { |
| 182 |
$texp[$i]->send("asdasdasjiouuwqjeqwejkklqwelkqwjeqwkjelkqwjeqwkljeqwkljdklas\n");}]); |
| 183 |
$texp[$i]->expect(1,' -re ',[ 'any other key for No' => sub { |
| 184 |
$texp[$i]->send("y\n");}]); |
| 185 |
$texp[$i]->soft_close(); |
| 186 |
print "\n"; |
| 187 |
system("$ENV{MYSQL} --login-path='login_path_2' -S $ENV{MASTER_MYSOCK} -e \"SELECT USER(), CURRENT_USER()\""); |
| 188 |
print "\n"; |
| 189 |
$i++; |
| 190 |
|
| 191 |
system("echo Invoking mysql_config_editor for user2 and changing the password to wrong value"); |
| 192 |
$n = 2; |
| 193 |
initial_commands($n); |
| 194 |
$texp[$i]->expect(1,' -re ',[ 'Enter password:' => sub { |
| 195 |
$texp[$i]->send("NULL\n");}]); |
| 196 |
$texp[$i]->expect(1,' -re ',[ 'any other key for No' => sub { |
| 197 |
$texp[$i]->send("y\n");}]); |
| 198 |
$texp[$i]->soft_close(); |
| 199 |
print "\n"; |
| 200 |
system("$ENV{MYSQL} --login-path='login_path_2' -S $ENV{MASTER_MYSOCK} -e \"SELECT USER(), CURRENT_USER()\""); |
| 201 |
print "\n"; |
| 202 |
$i++; |
| 203 |
|
| 204 |
system("echo Invoking mysql_config_editor for user2 and changing the password to wrong value"); |
| 205 |
$n = 2; |
| 206 |
initial_commands($n); |
| 207 |
$texp[$i]->expect(1,' -re ',[ 'Enter password:' => sub { |
| 208 |
$texp[$i]->send("ABCud134*1##sfdsf!\n");}]); |
| 209 |
$texp[$i]->expect(1,' -re ',[ 'any other key for No' => sub { |
| 210 |
$texp[$i]->send("y\n");}]); |
| 211 |
$texp[$i]->soft_close(); |
| 212 |
print "\n"; |
| 213 |
system("$ENV{MYSQL} --login-path='login_path_2' -S $ENV{MASTER_MYSOCK} -e \"SELECT USER(), CURRENT_USER()\""); |
| 214 |
print "\n"; |
| 215 |
$i++; |
| 216 |
|
| 217 |
system("echo Invoking mysql_config_editor for user2 and changing the password to correct value"); |
| 218 |
$n = 2; |
| 219 |
initial_commands($n); |
| 220 |
$texp[$i]->expect(1,' -re ',[ 'Enter password:' => sub { |
| 221 |
$texp[$i]->send("pass_2\n");}]); |
| 222 |
$texp[$i]->expect(1,' -re ',[ 'any other key for No' => sub { |
| 223 |
$texp[$i]->send("y\n");}]); |
| 224 |
$texp[$i]->soft_close(); |
| 225 |
print "\n"; |
| 226 |
system("$ENV{MYSQL} --login-path='login_path_2' -S $ENV{MASTER_MYSOCK} -e \"SELECT USER(), CURRENT_USER()\""); |
| 227 |
print "\n"; |
| 228 |
$i++; |
| 229 |
|
| 230 |
EOF |
| 231 |
|
| 232 |
--echo ############################################ |
| 233 |
--echo # .mylogin.cnf file before cleanup # |
| 234 |
--echo ############################################ |
| 235 |
--exec $MYSQL_CONFIG_EDITOR print --all |
| 236 |
|
| 237 |
# Cleanup |
| 238 |
--exec $MYSQL_CONFIG_EDITOR reset |
| 239 |
--echo |
| 240 |
--echo ################################################# |
| 241 |
--echo # empty .mylogin.cnf file after cleanup # |
| 242 |
--echo ################################################# |
| 243 |
--exec $MYSQL_CONFIG_EDITOR print --all |
| 244 |
|
| 245 |
--echo |
| 246 |
--echo ################################################ |
| 247 |
--echo # Dropping users user1, user2 and user3 # |
| 248 |
--echo ################################################ |
| 249 |
DROP USER 'user_1'@'localhost'; |
| 250 |
DROP USER 'user_2'@'localhost'; |
| 251 |
DROP USER 'user_3'@'localhost'; |
| 252 |
--remove_file $MYSQL_TMP_DIR/.mylogin.cnf |