Browse Source

Fixes #15850: check basePath is writable on publish in AssetManager

tags/2.0.16
Andrew 6 years ago committed by Alexander Makarov
parent
commit
572e5f6655
  1. 2
      framework/CHANGELOG.md
  2. 9
      framework/web/AssetManager.php
  3. 17
      tests/framework/web/AssetBundleTest.php

2
framework/CHANGELOG.md

@ -3,6 +3,8 @@ Yii Framework 2 Change Log
2.0.16 under development
------------------------
- Bug #15850: check basePath is writable on publish in AssetManager (Groonya)
- Bug #16910: Fix messages sorting on extract (Groonya)
- Bug #16969: Fix `yii\filters\PageCache` incorrectly storing empty data in some cases (sammousa)
- Bug #15683: Fixed file as array uploading in MultipartFormDataParser (Groonya)

9
framework/web/AssetManager.php

@ -211,8 +211,6 @@ class AssetManager extends Component
$this->basePath = Yii::getAlias($this->basePath);
if (!is_dir($this->basePath)) {
throw new InvalidConfigException("The directory does not exist: {$this->basePath}");
} elseif (!is_writable($this->basePath)) {
throw new InvalidConfigException("The directory is not writable by the Web process: {$this->basePath}");
}
$this->basePath = realpath($this->basePath);
@ -427,7 +425,7 @@ class AssetManager extends Component
* discussion: http://code.google.com/p/yii/issues/detail?id=2579
*
* @param string $path the asset (file or directory) to be published
* @param array $options the options to be applied when publishing a directory.
* @param array $options the options to be applied when publishing a directory.
* The following options are supported:
*
* - only: array, list of patterns that the file paths should match if they want to be copied.
@ -443,6 +441,7 @@ class AssetManager extends Component
*
* @return array the path (directory or file path) and the URL that the asset is published as.
* @throws InvalidArgumentException if the asset to be published does not exist.
* @throws InvalidConfigException
*/
public function publish($path, $options = [])
{
@ -456,6 +455,10 @@ class AssetManager extends Component
throw new InvalidArgumentException("The file or directory to be published does not exist: $path");
}
if (!is_writable($this->basePath)) {
throw new InvalidConfigException("The directory is not writable by the Web process: {$this->basePath}");
}
if (is_file($src)) {
return $this->_published[$path] = $this->publishFile($src);
}

17
tests/framework/web/AssetBundleTest.php

@ -28,6 +28,9 @@ class AssetBundleTest extends \yiiunit\TestCase
Yii::setAlias('@testAssetsPath', '@webroot/assets');
Yii::setAlias('@testAssetsUrl', '@web/assets');
Yii::setAlias('@testSourcePath', '@webroot/assetSources');
Yii::setAlias('@testReadOnlyAssetPath', '@webroot/readOnlyAssets');
mkdir(Yii::getAlias('@testReadOnlyAssetPath'), 0555);
// clean up assets directory
$handle = opendir($dir = Yii::getAlias('@testAssetsPath'));
@ -48,6 +51,11 @@ class AssetBundleTest extends \yiiunit\TestCase
closedir($handle);
}
protected function tearDown()
{
rmdir(Yii::getAlias('@testReadOnlyAssetPath'));
}
/**
* Returns View with configured AssetManager.
*
@ -173,6 +181,15 @@ class AssetBundleTest extends \yiiunit\TestCase
$this->assertTrue(is_dir($bundle->basePath));
}
public function testBasePathIsWritableOnPublish()
{
$view = $this->getView(['basePath' => '@testReadOnlyAssetPath']);
$bundle = new TestSourceAsset();
$this->setExpectedException('yii\base\InvalidConfigException', 'The directory is not writable by the Web process');
$bundle->publish($view->getAssetManager());
}
/**
* @param View $view
* @return AssetBundle

Loading…
Cancel
Save