]> git.mxchange.org Git - friendica.git/commitdiff
Bugfixing wrong typed password setting
authorPhilipp Holzer <admin+github@philipp.info>
Mon, 10 Jun 2019 13:46:34 +0000 (15:46 +0200)
committerPhilipp Holzer <admin+github@philipp.info>
Mon, 10 Jun 2019 13:46:51 +0000 (15:46 +0200)
src/Core/Config/Cache/ConfigCache.php
tests/src/Core/Config/Cache/ConfigCacheTest.php

index c3cec19e26ee940418fec6c954263bff7e5ed5d8..441cdee811cc550c3e0bb748c8fdb26887b0dc59 100644 (file)
@@ -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;
                }
index 11845379d6b56dfb3c4e5c3142b037c69539b154..f8f81f9ee721c8193bfbe656d3ad9279efb2bdbf 100644 (file)
@@ -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'));
        }
 }