From eef59d6c487102b8d78f4393096a448c9136bfa1 Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Wed, 12 Oct 2016 13:53:11 +0530 Subject: [PATCH 1/2] Fix order of testing DBConnection with different parameters in Config method In setup, try to follow what the docs say. 'Password login is still tried first, but as fallback, no password method is tried.' Fix #12472 Signed-off-by: Deven Bansod --- libraries/config/ConfigFile.php | 4 +++- libraries/config/Validator.php | 24 ++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/libraries/config/ConfigFile.php b/libraries/config/ConfigFile.php index c051d5b080..b74c1cc838 100644 --- a/libraries/config/ConfigFile.php +++ b/libraries/config/ConfigFile.php @@ -416,7 +416,9 @@ class ConfigFile $dsn = 'mysqli://'; if ($this->getValue("$path/auth_type") == 'config') { $dsn .= $this->getValue("$path/user"); - if (! $this->getValue("$path/nopassword")) { + if (! $this->getValue("$path/nopassword") + || ! empty($this->getValue("$path/password")) + ) { $dsn .= ':***'; } $dsn .= '@'; diff --git a/libraries/config/Validator.php b/libraries/config/Validator.php index 0825e24b2b..faa115e899 100644 --- a/libraries/config/Validator.php +++ b/libraries/config/Validator.php @@ -271,8 +271,10 @@ class Validator } if (! $error && $values['Servers/1/auth_type'] == 'config') { - $password = !empty($values['Servers/1/nopassword']) && $values['Servers/1/nopassword'] ? null - : (empty($values['Servers/1/password']) ? '' : $values['Servers/1/password']); + $password = ''; + if (! empty($values['Servers/1/password'])) { + $password = $values['Servers/1/password']; + } $test = static::testDBConnection( empty($values['Servers/1/connect_type']) ? '' : $values['Servers/1/connect_type'], empty($values['Servers/1/host']) ? '' : $values['Servers/1/host'], @@ -282,6 +284,24 @@ class Validator $password, 'Server' ); + + // If failed 'with' password, try 'without' password + if ($test !== true + && !empty($values['Servers/1/nopassword']) + && $values['Servers/1/nopassword'] + ) { + $password = ''; + $test = static::testDBConnection( + empty($values['Servers/1/connect_type']) ? '' : $values['Servers/1/connect_type'], + empty($values['Servers/1/host']) ? '' : $values['Servers/1/host'], + empty($values['Servers/1/port']) ? '' : $values['Servers/1/port'], + empty($values['Servers/1/socket']) ? '' : $values['Servers/1/socket'], + empty($values['Servers/1/user']) ? '' : $values['Servers/1/user'], + $password, + 'Server' + ); + } + if ($test !== true) { $result = array_merge($result, $test); } From 5a413ae6df0ad032be2532f2b668e299fd682479 Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Wed, 12 Oct 2016 14:01:53 +0530 Subject: [PATCH 2/2] Add tests Signed-off-by: Deven Bansod --- test/classes/config/ConfigFileTest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/classes/config/ConfigFileTest.php b/test/classes/config/ConfigFileTest.php index cb727e2de0..df77943322 100644 --- a/test/classes/config/ConfigFileTest.php +++ b/test/classes/config/ConfigFileTest.php @@ -529,6 +529,26 @@ class ConfigFileTest extends PMATestCase "mysqli://testUser@123", $this->object->getServerDSN(1) ); + + $this->object->updateWithGlobalConfig( + array( + 'Servers' => array( + 1 => array( + "auth_type" => "config", + "user" => "testUser", + "connect_type" => "tcp", + "host" => "example.com", + "port" => "21", + "nopassword" => "yes", + "password" => "testPass" + ) + ) + ) + ); + $this->assertEquals( + "mysqli://testUser:***@example.com:21", + $this->object->getServerDSN(1) + ); } /**