Skip to content

Commit

Permalink
Hide db credentials
Browse files Browse the repository at this point in the history
To protect users who have publically accessible installs with debug
turned on - *** out db login credentials
  • Loading branch information
AD7six committed Jun 24, 2011
1 parent 08f1afe commit fcd0505
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lib/Cake/Test/Case/Utility/DebuggerTest.php
Expand Up @@ -326,4 +326,40 @@ public function testGetInstance() {
$result = Debugger::getInstance('Debugger');
$this->assertIsA($result, 'Debugger');
}

/**
* testNoDbCredentials
*
* If a connection error occurs, the config variable is passed through exportVar
* *** our database login credentials such that they are never visible
*
* @access public
* @return void
*/
function testNoDbCredentials() {
$config = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'void.cakephp.org',
'login' => 'cakephp-user',
'password' => 'cakephp-password',
'database' => 'cakephp-database',
'prefix' => ''
);

$output = Debugger::exportVar($config);

$expectedArray = array(
'driver' => 'mysql',
'persistent' => false,
'host' => '*****',
'login' => '*****',
'password' => '*****',
'database' => '*****',
'prefix' => ''
);
$expected = Debugger::exportVar($expectedArray);

$this->assertEqual($expected, $output);
}
}
10 changes: 10 additions & 0 deletions lib/Cake/Utility/Debugger.php
Expand Up @@ -464,6 +464,16 @@ public static function exportVar($var, $recursion = 0) {
case 'object':
return get_class($var) . "\n" . self::_object($var);
case 'array':
$var = array_merge($var, array_intersect_key(array(
'password' => '*****',
'login' => '*****',
'host' => '*****',
'database' => '*****',
'port' => '*****',
'prefix' => '*****',
'schema' => '*****'
), $var));

$out = "array(";
$vars = array();
foreach ($var as $key => $val) {
Expand Down

0 comments on commit fcd0505

Please sign in to comment.