Skip to content

Commit 781281d

Browse files
MAGETWO-54255: Full Path Disclosure in cache management
1 parent 1ea57c2 commit 781281d

File tree

3 files changed

+49
-34
lines changed

3 files changed

+49
-34
lines changed

app/code/Magento/Backend/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,3 +456,4 @@ Pagination,Pagination
456456
"Anchor Text for Next","Anchor Text for Next"
457457
"Alternative text for the next pages link in the pagination menu. If empty, default arrow image is used.","Alternative text for the next pages link in the pagination menu. If empty, default arrow image is used."
458458
"Theme Name","Theme Name"
459+
"Deployment config file %1 is not writable.","Deployment config file %1 is not writable."

lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88

99
use Magento\Framework\App\DeploymentConfig;
1010
use Magento\Framework\App\Filesystem\DirectoryList;
11+
use Magento\Framework\Exception\FileSystemException;
1112
use Magento\Framework\Filesystem;
1213
use Magento\Framework\Config\File\ConfigFilePool;
14+
use Magento\Framework\Phrase;
1315

1416
/**
1517
* Deployment configuration writer
@@ -110,7 +112,13 @@ public function saveConfig(array $data, $override = false)
110112
}
111113

112114
$contents = $this->formatter->format($config);
113-
$this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile($paths[$fileKey], $contents);
115+
try {
116+
$this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile($paths[$fileKey], $contents);
117+
} catch (FileSystemException $e) {
118+
throw new FileSystemException(
119+
new Phrase('Deployment config file %1 is not writable.', [$paths[$fileKey]])
120+
);
121+
}
114122
if (function_exists('opcache_invalidate')) {
115123
opcache_invalidate(
116124
$this->filesystem->getDirectoryRead(DirectoryList::CONFIG)->getAbsolutePath($paths[$fileKey])

lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,73 +7,67 @@
77
namespace Magento\Framework\App\Test\Unit\DeploymentConfig;
88

99
use Magento\Framework\App\DeploymentConfig;
10+
use Magento\Framework\App\DeploymentConfig\Reader;
1011
use Magento\Framework\App\DeploymentConfig\Writer;
12+
use Magento\Framework\App\DeploymentConfig\Writer\FormatterInterface;
1113
use Magento\Framework\App\Filesystem\DirectoryList;
1214
use Magento\Framework\Config\File\ConfigFilePool;
15+
use Magento\Framework\Exception\FileSystemException;
16+
use Magento\Framework\Filesystem;
17+
use Magento\Framework\Filesystem\Directory\ReadInterface;
18+
use Magento\Framework\Filesystem\Directory\WriteInterface;
19+
use Magento\Framework\Phrase;
1320

1421
class WriterTest extends \PHPUnit_Framework_TestCase
1522
{
16-
/**
17-
* @var Writer
18-
*/
23+
/** @var Writer */
1924
private $object;
2025

21-
/**
22-
* @var \PHPUnit_Framework_MockObject_MockObject
23-
*/
26+
/** @var \PHPUnit_Framework_MockObject_MockObject */
2427
private $reader;
2528

26-
/**
27-
* @var \PHPUnit_Framework_MockObject_MockObject
28-
*/
29+
/** @var \PHPUnit_Framework_MockObject_MockObject */
2930
private $dirWrite;
3031

31-
/**
32-
* @var \PHPUnit_Framework_MockObject_MockObject
33-
*/
32+
/** @var \PHPUnit_Framework_MockObject_MockObject */
3433
private $dirRead;
3534

36-
/**
37-
* @var \PHPUnit_Framework_MockObject_MockObject
38-
*/
35+
/** @var \PHPUnit_Framework_MockObject_MockObject */
3936
protected $formatter;
4037

41-
/**
42-
* @var ConfigFilePool
43-
*/
38+
/** @var ConfigFilePool */
4439
private $configFilePool;
4540

46-
/**
47-
* @var DeploymentConfig
48-
*/
41+
/** @var DeploymentConfig */
4942
private $deploymentConfig;
5043

44+
/** @var Filesystem */
45+
private $filesystem;
46+
5147
protected function setUp()
5248
{
53-
$this->reader = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false);
54-
$filesystem = $this->getMock('Magento\Framework\Filesystem', [], [], '', false);
55-
$this->formatter = $this->getMockForAbstractClass(
56-
'Magento\Framework\App\DeploymentConfig\Writer\FormatterInterface'
57-
);
58-
$this->configFilePool = $this->getMock('Magento\Framework\Config\File\ConfigFilePool', [], [], '', false);
59-
$this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
49+
$this->reader = $this->getMock(Reader::class, [], [], '', false);
50+
$this->filesystem = $this->getMock(Filesystem::class, [], [], '', false);
51+
$this->formatter = $this->getMockForAbstractClass(FormatterInterface::class);
52+
$this->configFilePool = $this->getMock(ConfigFilePool::class, [], [], '', false);
53+
$this->deploymentConfig = $this->getMock(DeploymentConfig::class, [], [], '', false);
6054
$this->object = new Writer(
6155
$this->reader,
62-
$filesystem,
56+
$this->filesystem,
6357
$this->configFilePool,
6458
$this->deploymentConfig,
6559
$this->formatter
6660
);
6761
$this->reader->expects($this->any())->method('getFiles')->willReturn('test.php');
68-
$this->dirWrite = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface');
69-
$this->dirRead = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\ReadInterface');
62+
$this->dirWrite = $this->getMockForAbstractClass(WriteInterface::class);
63+
$this->dirRead = $this->getMockForAbstractClass(ReadInterface::class);
7064
$this->dirRead->expects($this->any())
7165
->method('getAbsolutePath');
72-
$filesystem->expects($this->any())
66+
$this->filesystem->expects($this->any())
7367
->method('getDirectoryWrite')
7468
->with(DirectoryList::CONFIG)
7569
->willReturn($this->dirWrite);
76-
$filesystem->expects($this->any())
70+
$this->filesystem->expects($this->any())
7771
->method('getDirectoryRead')
7872
->with(DirectoryList::CONFIG)
7973
->willReturn($this->dirRead);
@@ -179,4 +173,16 @@ public function testSaveConfigOverride()
179173

180174
$this->object->saveConfig($testSetUpdate, true);
181175
}
176+
177+
/**
178+
* @expectedException \Magento\Framework\Exception\FileSystemException
179+
* @expectedExceptionMessage Deployment config file env.php is not writable.
180+
*/
181+
public function testSaveConfigException()
182+
{
183+
$this->configFilePool->method('getPaths')->willReturn([ConfigFilePool::APP_ENV => 'env.php']);
184+
$exception = new FileSystemException(new Phrase('error when writing file config file'));
185+
$this->dirWrite->method('writeFile')->willThrowException($exception);
186+
$this->object->saveConfig([ConfigFilePool::APP_ENV => ['key' => 'value']]);
187+
}
182188
}

0 commit comments

Comments
 (0)