Commit f5f64799 authored by alexpott's avatar alexpott

Issue #2669418 by pwolanin: Php Storage not defining secret index

parent 02ba883a
...@@ -34,6 +34,7 @@ class PhpStorageFactory { ...@@ -34,6 +34,7 @@ class PhpStorageFactory {
* An instantiated storage for the specified name. * An instantiated storage for the specified name.
*/ */
static function get($name) { static function get($name) {
$configuration = array();
$overrides = Settings::get('php_storage'); $overrides = Settings::get('php_storage');
if (isset($overrides[$name])) { if (isset($overrides[$name])) {
$configuration = $overrides[$name]; $configuration = $overrides[$name];
...@@ -41,13 +42,11 @@ static function get($name) { ...@@ -41,13 +42,11 @@ static function get($name) {
elseif (isset($overrides['default'])) { elseif (isset($overrides['default'])) {
$configuration = $overrides['default']; $configuration = $overrides['default'];
} }
else { // Make sure all the necessary configuration values are set.
$configuration = array(
'class' => 'Drupal\Component\PhpStorage\MTimeProtectedFileStorage',
'secret' => Settings::getHashSalt(),
);
}
$class = isset($configuration['class']) ? $configuration['class'] : 'Drupal\Component\PhpStorage\MTimeProtectedFileStorage'; $class = isset($configuration['class']) ? $configuration['class'] : 'Drupal\Component\PhpStorage\MTimeProtectedFileStorage';
if (!isset($configuration['secret'])) {
$configuration['secret'] = Settings::getHashSalt();
}
if (!isset($configuration['bin'])) { if (!isset($configuration['bin'])) {
$configuration['bin'] = $name; $configuration['bin'] = $name;
} }
......
...@@ -65,18 +65,28 @@ public function testGetOverride() { ...@@ -65,18 +65,28 @@ public function testGetOverride() {
$this->setSettings('test', array('bin' => NULL)); $this->setSettings('test', array('bin' => NULL));
$php = PhpStorageFactory::get('test'); $php = PhpStorageFactory::get('test');
$this->assertTrue($php instanceof MockPhpStorage, 'An MockPhpStorage instance was returned from overridden settings.'); $this->assertTrue($php instanceof MockPhpStorage, 'An MockPhpStorage instance was returned from overridden settings.');
$this->assertIdentical('test', $php->getConfigurationValue('bin'), 'Name value was used for bin.'); $this->assertSame('test', $php->getConfigurationValue('bin'), 'Name value was used for bin.');
// Test that a default directory is set if it's empty. // Test that a default directory is set if it's empty.
$this->setSettings('test', array('directory' => NULL)); $this->setSettings('test', array('directory' => NULL));
$php = PhpStorageFactory::get('test'); $php = PhpStorageFactory::get('test');
$this->assertTrue($php instanceof MockPhpStorage, 'An MockPhpStorage instance was returned from overridden settings.'); $this->assertTrue($php instanceof MockPhpStorage, 'An MockPhpStorage instance was returned from overridden settings.');
$this->assertIdentical(PublicStream::basePath() . '/php', $php->getConfigurationValue('directory'), 'Default file directory was used.'); $this->assertSame(PublicStream::basePath() . '/php', $php->getConfigurationValue('directory'), 'Default file directory was used.');
// Test that a default storage class is set if it's empty. // Test that a default storage class is set if it's empty.
$this->setSettings('test', array('class' => NULL)); $this->setSettings('test', array('class' => NULL));
$php = PhpStorageFactory::get('test'); $php = PhpStorageFactory::get('test');
$this->assertTrue($php instanceof MTimeProtectedFileStorage, 'An MTimeProtectedFileStorage instance was returned from overridden settings with no class.'); $this->assertTrue($php instanceof MTimeProtectedFileStorage, 'An MTimeProtectedFileStorage instance was returned from overridden settings with no class.');
// Test that a default secret is not returned if it's set in the override.
$this->setSettings('test');
$php = PhpStorageFactory::get('test');
$this->assertNotEquals('mock hash salt', $php->getConfigurationValue('secret'), 'The default secret is not used if a secret is set in the overridden settings.');
// Test that a default secret is set if it's empty.
$this->setSettings('test', array('secret' => NULL));
$php = PhpStorageFactory::get('test');
$this->assertSame('mock hash salt', $php->getConfigurationValue('secret'), 'The default secret is used if one is not set in the overridden settings.');
} }
/** /**
...@@ -94,6 +104,7 @@ protected function setSettings($name = 'default', array $configuration = array() ...@@ -94,6 +104,7 @@ protected function setSettings($name = 'default', array $configuration = array()
'secret' => $this->randomString(), 'secret' => $this->randomString(),
'bin' => 'test', 'bin' => 'test',
); );
$settings['hash_salt'] = 'mock hash salt';
new Settings($settings); new Settings($settings);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment