Filter the objectstore password from the config list as well

This commit is contained in:
Joas Schilling 2015-08-19 14:06:05 +02:00
parent 0b37004808
commit 6231bbdde3
2 changed files with 52 additions and 10 deletions

View File

@ -34,15 +34,18 @@ class ListConfigs extends Base {
/** @var array */
protected $sensitiveValues = [
'dbpassword',
'dbuser',
'mail_smtpname',
'mail_smtppassword',
'passwordsalt',
'secret',
'ldap_agent_password',
'dbpassword' => true,
'dbuser' => true,
'mail_smtpname' => true,
'mail_smtppassword' => true,
'passwordsalt' => true,
'secret' => true,
'ldap_agent_password' => true,
'objectstore' => ['arguments' => ['password' => true]],
];
const SENSITIVE_VALUE = '***REMOVED SENSITIVE VALUE***';
/** * @var SystemConfig */
protected $systemConfig;
@ -124,11 +127,12 @@ class ListConfigs extends Base {
$configs = [];
foreach ($keys as $key) {
if ($noSensitiveValues && in_array($key, $this->sensitiveValues)) {
continue;
$value = $this->systemConfig->getValue($key, serialize(null));
if ($noSensitiveValues && isset($this->sensitiveValues[$key])) {
$value = $this->removeSensitiveValue($this->sensitiveValues[$key], $value);
}
$value = $this->systemConfig->getValue($key, serialize(null));
if ($value !== 'N;') {
$configs[$key] = $value;
}
@ -136,4 +140,25 @@ class ListConfigs extends Base {
return $configs;
}
/**
* @param bool|array $keysToRemove
* @param mixed $value
* @return mixed
*/
protected function removeSensitiveValue($keysToRemove, $value) {
if ($keysToRemove === true) {
return self::SENSITIVE_VALUE;
}
if (is_array($value)) {
foreach ($keysToRemove as $keyToRemove => $valueToRemove) {
if (isset($value[$keyToRemove])) {
$value[$keyToRemove] = $this->removeSensitiveValue($valueToRemove, $value[$keyToRemove]);
}
}
}
return $value;
}
}

View File

@ -81,6 +81,7 @@ class ListConfigsTest extends TestCase {
false,
json_encode([
'system' => [
'secret' => ListConfigs::SENSITIVE_VALUE,
'overwrite.cli.url' => 'http://localhost',
],
'apps' => [
@ -134,10 +135,18 @@ class ListConfigsTest extends TestCase {
// config.php
[
'secret',
'objectstore',
'overwrite.cli.url',
],
[
['secret', 'N;', 'my secret'],
['objectstore', 'N;', [
'class' => 'OC\\Files\\ObjectStore\\Swift',
'arguments' => [
'username' => 'facebook100000123456789',
'password' => 'Secr3tPaSSWoRdt7',
],
]],
['overwrite.cli.url', 'N;', 'http://localhost'],
],
// app config
@ -152,6 +161,14 @@ class ListConfigsTest extends TestCase {
false,
json_encode([
'system' => [
'secret' => ListConfigs::SENSITIVE_VALUE,
'objectstore' => [
'class' => 'OC\\Files\\ObjectStore\\Swift',
'arguments' => [
'username' => 'facebook100000123456789',
'password' => ListConfigs::SENSITIVE_VALUE,
],
],
'overwrite.cli.url' => 'http://localhost',
],
]),