From 50d8dbb12388dbb16af5f31aea420ab94c03cc57 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Mon, 10 Jun 2019 15:46:34 +0200 Subject: [PATCH] Bugfixing wrong typed password setting --- src/Core/Config/Cache/ConfigCache.php | 4 +-- .../src/Core/Config/Cache/ConfigCacheTest.php | 29 +++++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/Core/Config/Cache/ConfigCache.php b/src/Core/Config/Cache/ConfigCache.php index c3cec19e26..441cdee811 100644 --- a/src/Core/Config/Cache/ConfigCache.php +++ b/src/Core/Config/Cache/ConfigCache.php @@ -95,8 +95,8 @@ class ConfigCache implements IConfigCache, IPConfigCache if ($this->hidePasswordOutput && $key == 'password' && - !empty($value)) { - $this->config[$cat][$key] = new HiddenString($value); + !empty($value) && is_string($value)) { + $this->config[$cat][$key] = new HiddenString((string) $value); } else { $this->config[$cat][$key] = $value; } diff --git a/tests/src/Core/Config/Cache/ConfigCacheTest.php b/tests/src/Core/Config/Cache/ConfigCacheTest.php index 11845379d6..f8f81f9ee7 100644 --- a/tests/src/Core/Config/Cache/ConfigCacheTest.php +++ b/tests/src/Core/Config/Cache/ConfigCacheTest.php @@ -315,14 +315,37 @@ class ConfigCacheTest extends MockedTest */ public function testEmptyPassword() { - $confiCache = new ConfigCache([ + $configCache = new ConfigCache([ 'database' => [ 'password' => '', 'username' => '', ] ]); - $this->assertEmpty($confiCache->get('database', 'password')); - $this->assertEmpty($confiCache->get('database', 'username')); + $this->assertEmpty($configCache->get('database', 'password')); + $this->assertEmpty($configCache->get('database', 'username')); + } + + public function testWrongTypePassword() + { + $configCache = new ConfigCache([ + 'database' => [ + 'password' => new \stdClass(), + 'username' => '', + ] + ]); + + $this->assertNotEmpty($configCache->get('database', 'password')); + $this->assertEmpty($configCache->get('database', 'username')); + + $configCache = new ConfigCache([ + 'database' => [ + 'password' => 23, + 'username' => '', + ] + ]); + + $this->assertEquals(23, $configCache->get('database', 'password')); + $this->assertEmpty($configCache->get('database', 'username')); } } -- 2.39.5