diff --git a/app/code/Magento/Backup/Model/Fs/Collection.php b/app/code/Magento/Backup/Model/Fs/Collection.php index 289a1434e716f..d6f569f38ba15 100644 --- a/app/code/Magento/Backup/Model/Fs/Collection.php +++ b/app/code/Magento/Backup/Model/Fs/Collection.php @@ -91,7 +91,7 @@ protected function _hideBackupsForApache() $filename = '.htaccess'; if (!$this->_varDirectory->isFile($filename)) { $this->_varDirectory->writeFile($filename, 'deny from all'); - $this->_varDirectory->changePermissions($filename, 0644); + $this->_varDirectory->changePermissions($filename, 0640); } } diff --git a/app/code/Magento/CacheInvalidate/Model/PurgeCache.php b/app/code/Magento/CacheInvalidate/Model/PurgeCache.php index 2cde853240db4..d60e442ac7022 100644 --- a/app/code/Magento/CacheInvalidate/Model/PurgeCache.php +++ b/app/code/Magento/CacheInvalidate/Model/PurgeCache.php @@ -5,40 +5,64 @@ */ namespace Magento\CacheInvalidate\Model; +use Symfony\Component\Config\Definition\Exception\Exception; +use Zend\Uri\Uri; +use Zend\Http\Client\Adapter\Socket; use Magento\Framework\Cache\InvalidateLogger; +use Magento\Framework\App\DeploymentConfig; +use Magento\Framework\Config\ConfigOptionsListConstants; +use Magento\Framework\App\RequestInterface; class PurgeCache { /** - * @var \Magento\PageCache\Helper\Data + * @var Uri */ - protected $helper; + protected $uri; /** - * @var \Magento\Framework\HTTP\Adapter\Curl + * @var Socket */ - protected $curlAdapter; + protected $socketAdapter; /** * @var InvalidateLogger */ private $logger; + /** + * @var DeploymentConfig + */ + private $config; + + /** + * @var RequestInterface + */ + private $request; + + const DEFAULT_PORT = 80; + /** * Constructor * - * @param \Magento\PageCache\Helper\Data $helper - * @param \Magento\Framework\HTTP\Adapter\Curl $curlAdapter + * @param Uri $uri + * @param Socket $socketAdapter * @param InvalidateLogger $logger + * @param Reader $configReader + * @param RequestInterface $request */ public function __construct( - \Magento\PageCache\Helper\Data $helper, - \Magento\Framework\HTTP\Adapter\Curl $curlAdapter, - InvalidateLogger $logger + Uri $uri, + Socket $socketAdapter, + InvalidateLogger $logger, + DeploymentConfig $config, + RequestInterface $request ) { - $this->helper = $helper; - $this->curlAdapter = $curlAdapter; + $this->uri = $uri; + $this->socketAdapter = $socketAdapter; $this->logger = $logger; + $this->config = $config; + $this->request = $request; } /** @@ -50,12 +74,29 @@ public function __construct( */ public function sendPurgeRequest($tagsPattern) { - $headers = ["X-Magento-Tags-Pattern: {$tagsPattern}"]; - $this->curlAdapter->setOptions([CURLOPT_CUSTOMREQUEST => 'PURGE']); - $this->curlAdapter->write('', $this->helper->getUrl('*'), '1.1', $headers); - $this->curlAdapter->read(); - $this->curlAdapter->close(); + $servers = $this->config->get(ConfigOptionsListConstants::CONFIG_PATH_CACHE_HOSTS) + ?: [['host' => $this->request->getHttpHost()]]; + $headers = ['X-Magento-Tags-Pattern' => $tagsPattern]; + $this->socketAdapter->setOptions(['timeout' => 10]); + foreach ($servers as $server) { + $port = isset($server['port']) ? $server['port'] : self::DEFAULT_PORT; + $this->uri->setScheme('http') + ->setHost($server['host']) + ->setPort($port); + try { + $this->socketAdapter->connect($server['host'], $port); + $this->socketAdapter->write( + 'PURGE', + $this->uri, + '1.1', + $headers + ); + $this->socketAdapter->close(); + } catch (Exception $e) { + $this->logger->critical($e->getMessage(), compact('server', 'tagsPattern')); + } + } - $this->logger->execute(compact('tagsPattern')); + $this->logger->execute(compact('servers', 'tagsPattern')); } } diff --git a/app/code/Magento/CacheInvalidate/Test/Unit/Model/PurgeCacheTest.php b/app/code/Magento/CacheInvalidate/Test/Unit/Model/PurgeCacheTest.php index 93146a33e90b4..b0500dadc7284 100644 --- a/app/code/Magento/CacheInvalidate/Test/Unit/Model/PurgeCacheTest.php +++ b/app/code/Magento/CacheInvalidate/Test/Unit/Model/PurgeCacheTest.php @@ -5,70 +5,138 @@ */ namespace Magento\CacheInvalidate\Test\Unit\Model; +use \Magento\Framework\Config\ConfigOptionsListConstants; + class PurgeCacheTest extends \PHPUnit_Framework_TestCase { /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\CacheInvalidate\Model\PurgeCache */ protected $model; - /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\HTTP\Adapter\Curl */ - protected $curlMock; + /** @var \PHPUnit_Framework_MockObject_MockObject | \Zend\Uri\Uri */ + protected $uriMock; + + /** @var \PHPUnit_Framework_MockObject_MockObject | \Zend\Http\Client\Adapter\Socket */ + protected $socketAdapterMock; + + /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Cache\InvalidateLogger */ + protected $loggerMock; - /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\PageCache\Helper\Data */ - protected $helperMock; + /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\DeploymentConfig\Reader */ + protected $configReaderMock; - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $logger; + /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\RequestInterface */ + protected $requestMock; /** * Set up all mocks and data for test */ public function setUp() { - $this->helperMock = $this->getMock('Magento\PageCache\Helper\Data', ['getUrl'], [], '', false); - $this->curlMock = $this->getMock( - '\Magento\Framework\HTTP\Adapter\Curl', - ['setOptions', 'write', 'read', 'close'], - [], - '', - false - ); - $this->logger = $this->getMock('Magento\Framework\Cache\InvalidateLogger', [], [], '', false); + $this->uriMock = $this->getMock('\Zend\Uri\Uri', [], [], '', false); + $this->socketAdapterMock = $this->getMock('\Zend\Http\Client\Adapter\Socket', [], [], '', false); + $this->configMock = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); + $this->loggerMock = $this->getMock('Magento\Framework\Cache\InvalidateLogger', [], [], '', false); + $this->requestMock = $this->getMock('Magento\Framework\App\Request\Http', [], [], '', false); + $this->socketAdapterMock->expects($this->once()) + ->method('setOptions') + ->with(['timeout' => 10]); $this->model = new \Magento\CacheInvalidate\Model\PurgeCache( - $this->helperMock, - $this->curlMock, - $this->logger + $this->uriMock, + $this->socketAdapterMock, + $this->loggerMock, + $this->configMock, + $this->requestMock ); } - public function testSendPurgeRequest() + public function testSendPurgeRequestEmptyConfig() { - $tags = 'tags'; - $url = 'http://mangento.index.php'; - $httpVersion = '1.1'; - $headers = ["X-Magento-Tags-Pattern: {$tags}"]; - $this->helperMock->expects( - $this->any() - )->method( - 'getUrl' - )->with( - $this->equalTo('*'), - [] - )->will( - $this->returnValue($url) - ); - $this->curlMock->expects($this->once())->method('setOptions')->with([CURLOPT_CUSTOMREQUEST => 'PURGE']); - $this->curlMock->expects( - $this->once() - )->method( - 'write' - )->with( - $this->equalTo(''), - $this->equalTo($url), - $httpVersion, - $this->equalTo($headers) - ); - $this->curlMock->expects($this->once())->method('read'); - $this->curlMock->expects($this->once())->method('close'); - $this->model->sendPurgeRequest($tags); + $this->socketAdapterMock->expects($this->once()) + ->method('write') + ->with('PURGE', $this->uriMock, '1.1', $this->equalTo(['X-Magento-Tags-Pattern' => 'tags'])); + $this->socketAdapterMock->expects($this->once()) + ->method('close'); + $this->configMock->expects($this->once()) + ->method('get') + ->willReturn(''); + $this->requestMock->expects($this->any()) + ->method('getHttpHost') + ->willReturn('127.0.0.1'); + $this->uriMock->expects($this->once()) + ->method('setScheme') + ->with('http') + ->willReturnSelf(); + $this->uriMock->expects($this->once()) + ->method('setHost') + ->with('127.0.0.1') + ->willReturnSelf(); + $this->uriMock->expects($this->once()) + ->method('setPort') + ->with(\Magento\CacheInvalidate\Model\PurgeCache::DEFAULT_PORT); + $this->model->sendPurgeRequest('tags'); + } + + public function testSendPurgeRequestOneServer() + { + $this->socketAdapterMock->expects($this->once()) + ->method('write') + ->with('PURGE', $this->uriMock, '1.1', $this->equalTo(['X-Magento-Tags-Pattern' => 'tags'])); + $this->socketAdapterMock->expects($this->once()) + ->method('close'); + $this->configMock->expects($this->once()) + ->method('get') + ->willReturn([['host' => '127.0.0.2', 'port' => 1234]]); + $this->uriMock->expects($this->once()) + ->method('setScheme') + ->with('http') + ->willReturnSelf(); + $this->uriMock->expects($this->once()) + ->method('setHost') + ->with('127.0.0.2') + ->willReturnSelf(); + $this->uriMock->expects($this->once()) + ->method('setPort') + ->with(1234); + $this->model->sendPurgeRequest('tags'); + } + + public function testSendPurgeRequestMultipleServers() + { + $this->socketAdapterMock->expects($this->exactly(2)) + ->method('write') + ->with('PURGE', $this->uriMock, '1.1', $this->equalTo(['X-Magento-Tags-Pattern' => 'tags'])); + $this->socketAdapterMock->expects($this->exactly(2)) + ->method('close'); + $this->configMock->expects($this->once()) + ->method('get') + ->willReturn( + [ + ['host' => '127.0.0.1', 'port' => 8080], + ['host' => '127.0.0.2', 'port' => 1234] + ] + ); + $this->uriMock->expects($this->at(0)) + ->method('setScheme') + ->with('http') + ->willReturnSelf(); + $this->uriMock->expects($this->at(1)) + ->method('setHost') + ->with('127.0.0.1') + ->willReturnSelf(); + $this->uriMock->expects($this->at(2)) + ->method('setPort') + ->with(8080); + $this->uriMock->expects($this->at(3)) + ->method('setScheme') + ->with('http') + ->willReturnSelf(); + $this->uriMock->expects($this->at(4)) + ->method('setHost') + ->with('127.0.0.2') + ->willReturnSelf(); + $this->uriMock->expects($this->at(5)) + ->method('setPort') + ->with(1234); + $this->model->sendPurgeRequest('tags'); } } diff --git a/app/code/Magento/Captcha/Helper/Data.php b/app/code/Magento/Captcha/Helper/Data.php index 183e371328b82..f7956740411d4 100644 --- a/app/code/Magento/Captcha/Helper/Data.php +++ b/app/code/Magento/Captcha/Helper/Data.php @@ -7,6 +7,7 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem; +use Magento\Framework\Filesystem\DriverInterface; /** * Captcha image model @@ -149,7 +150,7 @@ public function getImgDir($website = null) $mediaDir = $this->_filesystem->getDirectoryWrite(DirectoryList::MEDIA); $captchaDir = '/captcha/' . $this->_getWebsiteCode($website); $mediaDir->create($captchaDir); - $mediaDir->changePermissions($captchaDir, 0775); + $mediaDir->changePermissions($captchaDir, DriverInterface::WRITEABLE_DIRECTORY_MODE); return $mediaDir->getAbsolutePath($captchaDir) . '/'; } diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Media.php b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Media.php index be2df526aaa8b..b227df7cb1b8f 100644 --- a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Media.php +++ b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Media.php @@ -13,6 +13,7 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Filesystem\DriverInterface; /** * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) @@ -396,7 +397,7 @@ public function addImage( $this->_mediaDirectory->copyFile($file, $destinationFile); $storageHelper->saveFile($this->_mediaConfig->getTmpMediaShortUrl($fileName)); - $this->_mediaDirectory->changePermissions($destinationFile, 0777); + $this->_mediaDirectory->changePermissions($destinationFile, DriverInterface::WRITEABLE_FILE_MODE); } } catch (\Exception $e) { throw new LocalizedException(__('We couldn\'t move this file: %1.', $e->getMessage())); diff --git a/app/code/Magento/Cms/Model/Block.php b/app/code/Magento/Cms/Model/Block.php index e8605a682cd9b..d2a367784ced2 100644 --- a/app/code/Magento/Cms/Model/Block.php +++ b/app/code/Magento/Cms/Model/Block.php @@ -65,7 +65,7 @@ public function beforeSave() */ public function getIdentities() { - return [self::CACHE_TAG . '_' . $this->getId()]; + return [self::CACHE_TAG . '_' . $this->getId(), self::CACHE_TAG . '_' . $this->getIdentifier()]; } /** diff --git a/app/code/Magento/Developer/Model/Config/Backend/AllowedIps.php b/app/code/Magento/Developer/Model/Config/Backend/AllowedIps.php index 49be834c93dfd..234d2e6707f0b 100644 --- a/app/code/Magento/Developer/Model/Config/Backend/AllowedIps.php +++ b/app/code/Magento/Developer/Model/Config/Backend/AllowedIps.php @@ -17,6 +17,13 @@ class AllowedIps extends \Magento\Framework\App\Config\Value */ private $messageManager; + /** + * Escaper + * + * @var \Magento\Framework\Escaper + */ + protected $escaper; + /** * Constructor * @@ -24,6 +31,7 @@ class AllowedIps extends \Magento\Framework\App\Config\Value * @param \Magento\Framework\Registry $registry * @param \Magento\Framework\App\Config\ScopeConfigInterface $config * @param \Magento\Framework\Message\ManagerInterface $messageManager + * @param \Magento\Framework\Escaper $escaper * @param \Magento\Framework\Model\Resource\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data @@ -33,11 +41,13 @@ public function __construct( \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\Message\ManagerInterface $messageManager, + \Magento\Framework\Escaper $escaper, \Magento\Framework\Model\Resource\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [] ) { $this->messageManager = $messageManager; + $this->escaper = $escaper; parent::__construct($context, $registry, $config, $resource, $resourceCollection, $data); } @@ -48,7 +58,7 @@ public function __construct( */ public function beforeSave() { - $allowedIpsRaw = $this->getValue(); + $allowedIpsRaw = $this->escaper->escapeHtml($this->getValue()); $noticeMsgArray = []; $allowedIpsArray = []; diff --git a/app/code/Magento/Developer/Test/Unit/Model/Config/Backend/AllowedIpsTest.php b/app/code/Magento/Developer/Test/Unit/Model/Config/Backend/AllowedIpsTest.php index bd6b0714c0cb4..e42646559a77b 100644 --- a/app/code/Magento/Developer/Test/Unit/Model/Config/Backend/AllowedIpsTest.php +++ b/app/code/Magento/Developer/Test/Unit/Model/Config/Backend/AllowedIpsTest.php @@ -30,11 +30,12 @@ protected function setUp() ->willReturn($eventMangerMock); $objectManagerHelper = new ObjectManagerHelper($this); - + $escaper = $objectManagerHelper->getObject('\Magento\Framework\Escaper'); $this->model = $objectManagerHelper->getObject( 'Magento\Developer\Model\Config\Backend\AllowedIps', [ 'context' => $contextMock, + 'escaper' => $escaper, ] ); } diff --git a/app/code/Magento/Directory/Test/Unit/Block/CurrencyTest.php b/app/code/Magento/Directory/Test/Unit/Block/CurrencyTest.php index 598dfb6777f5f..b20375ee93740 100644 --- a/app/code/Magento/Directory/Test/Unit/Block/CurrencyTest.php +++ b/app/code/Magento/Directory/Test/Unit/Block/CurrencyTest.php @@ -26,8 +26,8 @@ class CurrencyTest extends \PHPUnit_Framework_TestCase public function setUp() { $this->urlBuilder = $this->getMock( - '\Magento\Framework\UrlInterface\Proxy', - ['getUrl'], + '\Magento\Framework\UrlInterface', + [], [], '', false diff --git a/app/code/Magento/Directory/etc/zip_codes.xml b/app/code/Magento/Directory/etc/zip_codes.xml index dfca9b740fa03..1c9a840a69633 100644 --- a/app/code/Magento/Directory/etc/zip_codes.xml +++ b/app/code/Magento/Directory/etc/zip_codes.xml @@ -455,12 +455,12 @@ - ^[a-zA-Z]{2}[0-9]{2}\s[0-9]{1}[a-zA-Z]{2}$ - ^[a-zA-Z]{1}[0-9]{1}[a-zA-Z]{1}\s[0-9]{1}[a-zA-Z]{2}$ - ^[a-zA-Z]{2}[0-9]{1}\s[0-9]{1}[a-zA-Z]{2}$ - ^[a-zA-Z]{2}[0-9]{1}[a-zA-Z]{1}\s[0-9]{1}[a-zA-Z]{2}$ - ^[a-zA-Z]{1}[0-9]{2}\s[0-9]{1}[a-zA-Z]{2}$ - ^[a-zA-Z]{1}[0-9]{1}\s[0-9]{1}[a-zA-Z]{2}$ + ^[a-zA-Z]{2}[0-9]{2}\s?[0-9]{1}[a-zA-Z]{2}$ + ^[a-zA-Z]{1}[0-9]{1}[a-zA-Z]{1}\s?[0-9]{1}[a-zA-Z]{2}$ + ^[a-zA-Z]{2}[0-9]{1}\s?[0-9]{1}[a-zA-Z]{2}$ + ^[a-zA-Z]{2}[0-9]{1}[a-zA-Z]{1}\s?[0-9]{1}[a-zA-Z]{2}$ + ^[a-zA-Z]{1}[0-9]{2}\s?[0-9]{1}[a-zA-Z]{2}$ + ^[a-zA-Z]{1}[0-9]{1}\s?[0-9]{1}[a-zA-Z]{2}$ diff --git a/app/code/Magento/PageCache/etc/varnish3.vcl b/app/code/Magento/PageCache/etc/varnish3.vcl index 0b6651fbc0cd4..678244bb6f790 100644 --- a/app/code/Magento/PageCache/etc/varnish3.vcl +++ b/app/code/Magento/PageCache/etc/varnish3.vcl @@ -80,8 +80,8 @@ sub vcl_fetch { set beresp.do_gzip = true; } - # cache only successfully responses - if (beresp.status != 200) { + # cache only successfully responses and 404s + if (beresp.status != 200 && beresp.status != 404) { set beresp.ttl = 0s; return (hit_for_pass); } elsif (beresp.http.Cache-Control ~ "private") { diff --git a/app/code/Magento/PageCache/etc/varnish4.vcl b/app/code/Magento/PageCache/etc/varnish4.vcl index 2a3db0b42339d..d9ff63e5e9fa2 100644 --- a/app/code/Magento/PageCache/etc/varnish4.vcl +++ b/app/code/Magento/PageCache/etc/varnish4.vcl @@ -71,8 +71,8 @@ sub vcl_backend_response { set beresp.do_gzip = true; } - # cache only successfully responses - if (beresp.status != 200) { + # cache only successfully responses and 404s + if (beresp.status != 200 && beresp.status != 404) { set beresp.ttl = 0s; set beresp.uncacheable = true; return (deliver); diff --git a/app/code/Magento/Store/etc/di.xml b/app/code/Magento/Store/etc/di.xml index 57d4d9f65d15a..d5d09df39b262 100644 --- a/app/code/Magento/Store/etc/di.xml +++ b/app/code/Magento/Store/etc/di.xml @@ -102,7 +102,7 @@ Magento\Framework\Session\Generic\Proxy Magento\Store\Model\Store::CUSTOM_ENTRY_POINT_PARAM - Magento\Framework\UrlInterface\Proxy + Magento\Framework\UrlInterface @@ -266,7 +266,7 @@ - Magento\Framework\UrlInterface\Proxy + Magento\Framework\UrlInterface Magento\Framework\App\Request\Http\Proxy diff --git a/app/code/Magento/Wishlist/Test/Unit/Helper/DataTest.php b/app/code/Magento/Wishlist/Test/Unit/Helper/DataTest.php index afe0a833e84b3..e1f76f56e8203 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Helper/DataTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Helper/DataTest.php @@ -9,7 +9,7 @@ use Magento\Framework\App\Helper\Context; use Magento\Framework\Data\Helper\PostHelper; use Magento\Framework\Registry; -use Magento\Framework\UrlInterface\Proxy as UrlInterface; +use Magento\Framework\UrlInterface; use Magento\Store\Model\Store; use Magento\Store\Model\StoreManagerInterface; use Magento\Wishlist\Controller\WishlistProviderInterface; @@ -69,9 +69,8 @@ public function setUp() ->method('getStore') ->willReturn($this->store); - $this->urlBuilder = $this->getMockBuilder('Magento\Framework\UrlInterface\Proxy') + $this->urlBuilder = $this->getMockBuilder('Magento\Framework\UrlInterface') ->disableOriginalConstructor() - ->setMethods(['getUrl']) ->getMock(); $this->context = $this->getMockBuilder('Magento\Framework\App\Helper\Context') diff --git a/app/etc/di.xml b/app/etc/di.xml index ae1df3af1fba0..fbb7c6946ce3c 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -1050,7 +1050,7 @@ - Magento\Framework\UrlInterface\Proxy + Magento\Framework\UrlInterface diff --git a/dev/tests/functional/lib/Magento/Mtf/Util/Generate/Factory/AbstractFactory.php b/dev/tests/functional/lib/Magento/Mtf/Util/Generate/Factory/AbstractFactory.php index f9a85bef1fca7..0a3bc1d10f2dc 100644 --- a/dev/tests/functional/lib/Magento/Mtf/Util/Generate/Factory/AbstractFactory.php +++ b/dev/tests/functional/lib/Magento/Mtf/Util/Generate/Factory/AbstractFactory.php @@ -7,6 +7,8 @@ namespace Magento\Mtf\Util\Generate\Factory; +use Magento\Framework\Filesystem\DriverInterface; + /** * Class AbstractFactory * @@ -103,7 +105,7 @@ protected function endFactory($type) * @return bool * @throws \Exception */ - protected function checkAndCreateFolder($folder, $mode = 0777) + protected function checkAndCreateFolder($folder, $mode = DriverInterface::WRITEABLE_DIRECTORY_MODE) { if (is_dir($folder)) { return true; @@ -125,7 +127,7 @@ protected function checkAndCreateFolder($folder, $mode = 0777) * @param bool $recursive * @return bool */ - protected function mkDir($dir, $mode = 0777, $recursive = true) + protected function mkDir($dir, $mode = 0770, $recursive = true) { return @mkdir($dir, $mode, $recursive); } diff --git a/dev/tests/integration/framework/Magento/TestFramework/Application.php b/dev/tests/integration/framework/Magento/TestFramework/Application.php index 3aa2826ead126..18024e723b34d 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Application.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Application.php @@ -7,6 +7,7 @@ use Magento\Framework\Autoload\AutoloaderInterface; use Magento\Framework\Filesystem; +use Magento\Framework\Filesystem\DriverInterface; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\Config\ConfigOptionsListConstants; @@ -566,7 +567,7 @@ protected function _ensureDirExists($dir) { if (!file_exists($dir)) { $old = umask(0); - mkdir($dir, 0777); + mkdir($dir, DriverInterface::WRITEABLE_DIRECTORY_MODE); umask($old); } elseif (!is_dir($dir)) { throw new \Magento\Framework\Exception\LocalizedException(__("'%1' is not a directory.", $dir)); diff --git a/dev/tests/integration/framework/Magento/TestFramework/Db/Mysql.php b/dev/tests/integration/framework/Magento/TestFramework/Db/Mysql.php index f823efc6e1b09..d34d3cefe212b 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Db/Mysql.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Db/Mysql.php @@ -126,7 +126,7 @@ private function ensureDefaultsExtraFile() $this->assertVarPathWritable(); $extraConfig = ['[client]', 'user=' . $this->_user, 'password="' . $this->_password . '"']; file_put_contents($this->_defaultsExtraFile, implode(PHP_EOL, $extraConfig)); - chmod($this->_defaultsExtraFile, 0644); + chmod($this->_defaultsExtraFile, 0640); } } } diff --git a/dev/tests/integration/testsuite/Magento/Cms/Model/Wysiwyg/Images/StorageTest.php b/dev/tests/integration/testsuite/Magento/Cms/Model/Wysiwyg/Images/StorageTest.php index fc753a98ceb3e..9c057a86693cb 100644 --- a/dev/tests/integration/testsuite/Magento/Cms/Model/Wysiwyg/Images/StorageTest.php +++ b/dev/tests/integration/testsuite/Magento/Cms/Model/Wysiwyg/Images/StorageTest.php @@ -25,7 +25,7 @@ public static function setUpBeforeClass() 'Magento\Cms\Helper\Wysiwyg\Images' )->getCurrentPath() . 'MagentoCmsModelWysiwygImagesStorageTest'; if (!file_exists(self::$_baseDir)) { - mkdir(self::$_baseDir, 0777); + mkdir(self::$_baseDir, 0770); } touch(self::$_baseDir . '/1.swf'); } diff --git a/dev/tests/integration/testsuite/Magento/Developer/Model/Config/Backend/AllowedIpsTest.php b/dev/tests/integration/testsuite/Magento/Developer/Model/Config/Backend/AllowedIpsTest.php new file mode 100644 index 0000000000000..d34c64a96dc82 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Developer/Model/Config/Backend/AllowedIpsTest.php @@ -0,0 +1,40 @@ +create( + 'Magento\Developer\Model\Config\Backend\AllowedIps' + ); + $model->setValue($value); + $model->beforeSave(); + $model->save(); + $this->assertEquals($expected, $model->getValue()); + } + + /** + * @return array + */ + public function fieldDataProvider() + { + return [ + ['<'.'script>alert(\'XSS\')', '' ], + ['10.64.202.22, <'.'script>alert(\'XSS\')', '10.64.202.22' ] + ]; + } +} diff --git a/dev/tests/integration/testsuite/Magento/Framework/Filesystem/Directory/WriteTest.php b/dev/tests/integration/testsuite/Magento/Framework/Filesystem/Directory/WriteTest.php index 0388ee4f06385..54086e2990872 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Filesystem/Directory/WriteTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Filesystem/Directory/WriteTest.php @@ -28,7 +28,7 @@ class WriteTest extends \PHPUnit_Framework_TestCase */ public function testInstance() { - $dir = $this->getDirectoryInstance('newDir1', 0777); + $dir = $this->getDirectoryInstance('newDir1', 0770); $this->assertTrue($dir instanceof ReadInterface); $this->assertTrue($dir instanceof WriteInterface); } @@ -56,10 +56,10 @@ public function testCreate($basePath, $permissions, $path) public function createProvider() { return [ - ['newDir1', 0777, "newDir1"], - ['newDir1', 0777, "root_dir1/subdir1/subdir2"], - ['newDir2', 0755, "root_dir2/subdir"], - ['newDir1', 0777, "."] + ['newDir1', 0770, "newDir1"], + ['newDir1', 0770, "root_dir1/subdir1/subdir2"], + ['newDir2', 0750, "root_dir2/subdir"], + ['newDir1', 0770, "."] ]; } @@ -71,7 +71,7 @@ public function createProvider() */ public function testDelete($path) { - $directory = $this->getDirectoryInstance('newDir', 0777); + $directory = $this->getDirectoryInstance('newDir', 0770); $directory->create($path); $this->assertTrue($directory->isExist($path)); $directory->delete($path); @@ -116,7 +116,7 @@ public function testRename($basePath, $permissions, $name, $newName) */ public function renameProvider() { - return [['newDir1', 0777, 'first_name.txt', 'second_name.txt']]; + return [['newDir1', 0770, 'first_name.txt', 'second_name.txt']]; } /** @@ -150,7 +150,7 @@ public function testRenameTargetDir($firstDir, $secondDir, $permission, $name, $ */ public function renameTargetDirProvider() { - return [['dir1', 'dir2', 0777, 'first_name.txt', 'second_name.txt']]; + return [['dir1', 'dir2', 0770, 'first_name.txt', 'second_name.txt']]; } /** @@ -180,8 +180,8 @@ public function testCopy($basePath, $permissions, $name, $newName) public function copyProvider() { return [ - ['newDir1', 0777, 'first_name.txt', 'second_name.txt'], - ['newDir1', 0777, 'subdir/first_name.txt', 'subdir/second_name.txt'] + ['newDir1', 0770, 'first_name.txt', 'second_name.txt'], + ['newDir1', 0770, 'subdir/first_name.txt', 'subdir/second_name.txt'] ]; } @@ -216,8 +216,8 @@ public function testCopyTargetDir($firstDir, $secondDir, $permission, $name, $ne public function copyTargetDirProvider() { return [ - ['dir1', 'dir2', 0777, 'first_name.txt', 'second_name.txt'], - ['dir1', 'dir2', 0777, 'subdir/first_name.txt', 'subdir/second_name.txt'] + ['dir1', 'dir2', 0770, 'first_name.txt', 'second_name.txt'], + ['dir1', 'dir2', 0770, 'subdir/first_name.txt', 'subdir/second_name.txt'] ]; } @@ -226,9 +226,9 @@ public function copyTargetDirProvider() */ public function testChangePermissions() { - $directory = $this->getDirectoryInstance('newDir1', 0777); + $directory = $this->getDirectoryInstance('newDir1', 0770); $directory->create('test_directory'); - $this->assertTrue($directory->changePermissions('test_directory', 0644)); + $this->assertTrue($directory->changePermissions('test_directory', 0640)); } /** @@ -269,8 +269,8 @@ public function testTouch($basePath, $permissions, $path, $time) public function touchProvider() { return [ - ['test_directory', 0777, 'touch_file.txt', time() - 3600], - ['test_directory', 0777, 'subdirectory/touch_file.txt', time() - 3600] + ['test_directory', 0770, 'touch_file.txt', time() - 3600], + ['test_directory', 0770, 'subdirectory/touch_file.txt', time() - 3600] ]; } @@ -279,7 +279,7 @@ public function touchProvider() */ public function testIsWritable() { - $directory = $this->getDirectoryInstance('newDir1', 0777); + $directory = $this->getDirectoryInstance('newDir1', 0770); $directory->create('bar'); $this->assertFalse($directory->isWritable('not_existing_dir')); $this->assertTrue($directory->isWritable('bar')); @@ -310,8 +310,8 @@ public function testOpenFile($basePath, $permissions, $path, $mode) public function openFileProvider() { return [ - ['newDir1', 0777, 'newFile.txt', 'w+'], - ['newDir1', 0777, 'subdirectory/newFile.txt', 'w+'] + ['newDir1', 0770, 'newFile.txt', 'w+'], + ['newDir1', 0770, 'subdirectory/newFile.txt', 'w+'] ]; } @@ -325,7 +325,7 @@ public function openFileProvider() */ public function testWriteFile($path, $content, $extraContent) { - $directory = $this->getDirectoryInstance('writeFileDir', 0777); + $directory = $this->getDirectoryInstance('writeFileDir', 0770); $directory->writeFile($path, $content); $this->assertEquals($content, $directory->readFile($path)); $directory->writeFile($path, $extraContent); @@ -342,7 +342,7 @@ public function testWriteFile($path, $content, $extraContent) */ public function testWriteFileAppend($path, $content, $extraContent) { - $directory = $this->getDirectoryInstance('writeFileDir', 0777); + $directory = $this->getDirectoryInstance('writeFileDir', 0770); $directory->writeFile($path, $content, 'a+'); $this->assertEquals($content, $directory->readFile($path)); $directory->writeFile($path, $extraContent, 'a+'); diff --git a/dev/tests/performance/framework/Magento/TestFramework/Application.php b/dev/tests/performance/framework/Magento/TestFramework/Application.php index 8ce9836bbb244..f0e072b54ca3f 100644 --- a/dev/tests/performance/framework/Magento/TestFramework/Application.php +++ b/dev/tests/performance/framework/Magento/TestFramework/Application.php @@ -10,6 +10,7 @@ namespace Magento\TestFramework; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Filesystem\DriverInterface; class Application { @@ -184,7 +185,7 @@ protected function _updateFilesystemPermissions() )->getDirectoryWrite( DirectoryList::VAR_DIR ); - $varDirectory->changePermissions('', 0777); + $varDirectory->changePermissions('', DriverInterface::WRITEABLE_DIRECTORY_MODE); } /** diff --git a/dev/tests/performance/framework/Magento/TestFramework/Performance/Bootstrap.php b/dev/tests/performance/framework/Magento/TestFramework/Performance/Bootstrap.php index f13126d189a49..9cc810f84829a 100644 --- a/dev/tests/performance/framework/Magento/TestFramework/Performance/Bootstrap.php +++ b/dev/tests/performance/framework/Magento/TestFramework/Performance/Bootstrap.php @@ -9,6 +9,8 @@ */ namespace Magento\TestFramework\Performance; +use Magento\Framework\Filesystem\DriverInterface; + class Bootstrap { /** @@ -64,7 +66,7 @@ public function cleanupReports() ); } } - mkdir($reportDir, 0777, true); + mkdir($reportDir, DriverInterface::WRITEABLE_DIRECTORY_MODE, true); } /** diff --git a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/BootstrapTest.php b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/BootstrapTest.php index 29a617952d587..a6b1efadac81b 100644 --- a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/BootstrapTest.php +++ b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/BootstrapTest.php @@ -93,7 +93,7 @@ public function testCleanupReportsRemovesFiles() $bootstrap = new \Magento\TestFramework\Performance\Bootstrap($this->appBootstrap, $fixtureDir); $reportDir = $fixtureDir . '/tmp/subdirectory/report'; - mkdir($reportDir, 0777, true); + mkdir($reportDir, 0770, true); $reportFile = $reportDir . '/a.jtl'; touch($reportFile); diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Di/CompilerTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Di/CompilerTest.php index 70fc9300695d3..273295098e3af 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Di/CompilerTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Di/CompilerTest.php @@ -72,11 +72,11 @@ protected function setUp() $this->_tmpDir = realpath(__DIR__) . '/tmp'; $this->_generationDir = $this->_tmpDir . '/generation'; if (!file_exists($this->_generationDir)) { - mkdir($this->_generationDir, 0777, true); + mkdir($this->_generationDir, 0770, true); } $this->_compilationDir = $this->_tmpDir . '/di'; if (!file_exists($this->_compilationDir)) { - mkdir($this->_compilationDir, 0777, true); + mkdir($this->_compilationDir, 0770, true); } $this->_command = 'php ' . $basePath . '/bin/magento setup:di:compile-multi-tenant --generation=%s --di=%s'; diff --git a/dev/tests/static/testsuite/Magento/Test/Js/Exemplar/JsHintTest.php b/dev/tests/static/testsuite/Magento/Test/Js/Exemplar/JsHintTest.php index d02432bdb789f..48fbceed561ab 100644 --- a/dev/tests/static/testsuite/Magento/Test/Js/Exemplar/JsHintTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Js/Exemplar/JsHintTest.php @@ -29,7 +29,7 @@ protected function setUp() { $reportFile = self::$_cmd->getReportFile(); if (!is_dir(dirname($reportFile))) { - mkdir(dirname($reportFile), 0777); + mkdir(dirname($reportFile), 0770); } } diff --git a/dev/tests/static/testsuite/Magento/Test/Js/LiveCodeTest.php b/dev/tests/static/testsuite/Magento/Test/Js/LiveCodeTest.php index 3e05589de50b7..f51c544a10996 100644 --- a/dev/tests/static/testsuite/Magento/Test/Js/LiveCodeTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Js/LiveCodeTest.php @@ -60,7 +60,7 @@ public static function setUpBeforeClass() { $reportDir = Files::init()->getPathToSource() . '/dev/tests/static/report'; if (!is_dir($reportDir)) { - mkdir($reportDir, 0777); + mkdir($reportDir, 0770); } self::$_reportFile = $reportDir . '/js_report.txt'; @unlink(self::$_reportFile); diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_constants.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_constants.php index 38151b5a8b8d2..353b7bef2f399 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_constants.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_constants.php @@ -73,6 +73,7 @@ ['DEFAULT_THEME_NAME', 'Magento\Core\Model\Design\Package'], ['DEFAULT_STORE_ID', 'Magento\Catalog\Model\AbstractModel', 'Magento\Store\Model\Store::DEFAULT_STORE_ID'], ['DEFAULT_VALUE_TABLE_PREFIX'], + ['DIRECTORY_PERMISSION', 'Magento\Framework\Code\Generator\Io'], ['DIVIDE_EPSILON', 'Magento\Core\Helper\Data'], ['ENTITY_PRODUCT', 'Magento\Review\Model\Review'], ['EXCEPTION_CODE_IS_GROUPED_PRODUCT'], @@ -935,5 +936,4 @@ 'Magento\Setup\Model\ConfigOptionsList', 'Magento\Framework\Config\ConfigOptionsListConstants::KEY_MODULES' ], - ['CONFIG_PATH_RESOURCE_DEFAULT_SETUP', 'Magento\Framework\Config\ConfigOptionsListConstants'], ]; diff --git a/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php b/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php index 03153c58c0ff3..b7ee29706dcbf 100644 --- a/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php @@ -42,7 +42,7 @@ public static function setUpBeforeClass() self::$pathToSource = Utility\Files::init()->getPathToSource(); self::$reportDir = self::$pathToSource . '/dev/tests/static/report'; if (!is_dir(self::$reportDir)) { - mkdir(self::$reportDir, 0777); + mkdir(self::$reportDir, 0770); } } diff --git a/dev/tools/Magento/Tools/Migration/Acl/Db/Logger/File.php b/dev/tools/Magento/Tools/Migration/Acl/Db/Logger/File.php index 8a48285b5ce94..77761c7a1dfb9 100644 --- a/dev/tools/Magento/Tools/Migration/Acl/Db/Logger/File.php +++ b/dev/tools/Magento/Tools/Migration/Acl/Db/Logger/File.php @@ -6,6 +6,7 @@ namespace Magento\Tools\Migration\Acl\Db\Logger; use InvalidArgumentException; +use Magento\Framework\Filesystem\DriverInterface; /** * Db migration logger. Output result put to file @@ -27,7 +28,7 @@ public function __construct($file) { $logDir = realpath(__DIR__ . '/../../') . '/log/'; if (false == is_dir($logDir)) { - mkdir($logDir, 0777, true); + mkdir($logDir, DriverInterface::WRITEABLE_DIRECTORY_MODE, true); } if (false == is_writeable($logDir)) { throw new InvalidArgumentException('Directory ' . dirname($logDir) . ' is not writeable'); diff --git a/dev/tools/Magento/Tools/Migration/Acl/FileManager.php b/dev/tools/Magento/Tools/Migration/Acl/FileManager.php index a3ea9412217cc..25c7403a9b566 100644 --- a/dev/tools/Magento/Tools/Migration/Acl/FileManager.php +++ b/dev/tools/Magento/Tools/Migration/Acl/FileManager.php @@ -5,6 +5,8 @@ */ namespace Magento\Tools\Migration\Acl; +use Magento\Framework\Filesystem\DriverInterface; + class FileManager { /** @@ -15,7 +17,7 @@ class FileManager public function write($fileName, $contents) { if (false == is_dir(dirname($fileName))) { - mkdir(dirname($fileName), 0777, true); + mkdir(dirname($fileName), DriverInterface::WRITEABLE_DIRECTORY_MODE, true); } file_put_contents($fileName, $contents); } diff --git a/dev/tools/Magento/Tools/Migration/System/Writer/FileSystem.php b/dev/tools/Magento/Tools/Migration/System/Writer/FileSystem.php index 4ece101c043ca..9d13f68a94f2d 100644 --- a/dev/tools/Magento/Tools/Migration/System/Writer/FileSystem.php +++ b/dev/tools/Magento/Tools/Migration/System/Writer/FileSystem.php @@ -5,6 +5,8 @@ */ namespace Magento\Tools\Migration\System\Writer; +use Magento\Framework\Filesystem\DriverInterface; + class FileSystem implements \Magento\Tools\Migration\System\WriterInterface { /** @@ -15,7 +17,7 @@ class FileSystem implements \Magento\Tools\Migration\System\WriterInterface public function write($fileName, $contents) { if (false == is_dir(dirname($fileName))) { - mkdir(dirname($fileName), 0777, true); + mkdir(dirname($fileName), DriverInterface::WRITEABLE_DIRECTORY_MODE, true); } file_put_contents($fileName, $contents); } diff --git a/lib/internal/Magento/Framework/App/Cache/Frontend/Factory.php b/lib/internal/Magento/Framework/App/Cache/Frontend/Factory.php index af5075ec5b566..5f48c269ec9a8 100644 --- a/lib/internal/Magento/Framework/App/Cache/Frontend/Factory.php +++ b/lib/internal/Magento/Framework/App/Cache/Frontend/Factory.php @@ -12,6 +12,7 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\Resource; use Magento\Framework\Filesystem; +use Magento\Framework\Filesystem\DriverInterface; class Factory { @@ -66,7 +67,7 @@ class Factory */ protected $_backendOptions = [ 'hashed_directory_level' => 1, - 'hashed_directory_umask' => 0777, + 'hashed_directory_umask' => DriverInterface::WRITEABLE_DIRECTORY_MODE, 'file_name_prefix' => 'mage', ]; diff --git a/lib/internal/Magento/Framework/App/PageCache/Kernel.php b/lib/internal/Magento/Framework/App/PageCache/Kernel.php index fa5ea418572cf..b065336108b9a 100644 --- a/lib/internal/Magento/Framework/App/PageCache/Kernel.php +++ b/lib/internal/Magento/Framework/App/PageCache/Kernel.php @@ -64,7 +64,9 @@ public function process(\Magento\Framework\App\Response\Http $response) if (preg_match('/public.*s-maxage=(\d+)/', $response->getHeader('Cache-Control')->getFieldValue(), $matches)) { $maxAge = $matches[1]; $response->setNoCacheHeaders(); - if ($response->getHttpResponseCode() == 200 && ($this->request->isGet() || $this->request->isHead())) { + if (($response->getHttpResponseCode() == 200 || $response->getHttpResponseCode() == 404) + && ($this->request->isGet() || $this->request->isHead()) + ) { $tagsHeader = $response->getHeader('X-Magento-Tags'); $tags = $tagsHeader ? explode(',', $tagsHeader->getFieldValue()) : []; diff --git a/lib/internal/Magento/Framework/App/Test/Unit/PageCache/KernelTest.php b/lib/internal/Magento/Framework/App/Test/Unit/PageCache/KernelTest.php index 874f847ca90ce..1028112e36aef 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/PageCache/KernelTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/PageCache/KernelTest.php @@ -98,10 +98,12 @@ public function loadProvider() ]; } - public function testProcessSaveCache() + /** + * @param $httpCode + * @dataProvider testProcessSaveCacheDataProvider + */ + public function testProcessSaveCache($httpCode, $at) { - $httpCode = 200; - $cacheControlHeader = \Zend\Http\Header\CacheControl::fromString( 'Cache-Control: public, max-age=100, s-maxage=100' ); @@ -116,21 +118,37 @@ public function testProcessSaveCache() $this->returnValue($cacheControlHeader) ); $this->responseMock->expects( - $this->once() + $this->any() )->method( 'getHttpResponseCode' - )->will( - $this->returnValue($httpCode) - ); - $this->requestMock->expects($this->once())->method('isGet')->will($this->returnValue(true)); - $this->responseMock->expects($this->once())->method('setNoCacheHeaders'); - $this->responseMock->expects($this->at(3))->method('getHeader')->with('X-Magento-Tags'); - $this->responseMock->expects($this->at(4))->method('clearHeader')->with($this->equalTo('Set-Cookie')); - $this->responseMock->expects($this->at(5))->method('clearHeader')->with($this->equalTo('X-Magento-Tags')); - $this->cacheMock->expects($this->once())->method('save'); + )->willReturn($httpCode); + $this->requestMock->expects($this->once()) + ->method('isGet') + ->willReturn(true); + $this->responseMock->expects($this->once()) + ->method('setNoCacheHeaders'); + $this->responseMock->expects($this->at($at[0])) + ->method('getHeader') + ->with('X-Magento-Tags'); + $this->responseMock->expects($this->at($at[1])) + ->method('clearHeader') + ->with($this->equalTo('Set-Cookie')); + $this->responseMock->expects($this->at($at[2])) + ->method('clearHeader') + ->with($this->equalTo('X-Magento-Tags')); + $this->cacheMock->expects($this->once()) + ->method('save'); $this->kernel->process($this->responseMock); } + public function testProcessSaveCacheDataProvider() + { + return [ + [200, [3, 4, 5]], + [404, [4, 5, 6]] + ]; + } + /** * @dataProvider processNotSaveCacheProvider * @param string $cacheControlHeader @@ -167,13 +185,11 @@ public function processNotSaveCacheProvider() return [ ['private, max-age=100', 200, true, false], ['private, max-age=100', 200, false, false], - ['private, max-age=100', 404, true, false], ['private, max-age=100', 500, true, false], ['no-store, no-cache, must-revalidate, max-age=0', 200, true, false], ['no-store, no-cache, must-revalidate, max-age=0', 200, false, false], ['no-store, no-cache, must-revalidate, max-age=0', 404, true, false], ['no-store, no-cache, must-revalidate, max-age=0', 500, true, false], - ['public, max-age=100, s-maxage=100', 404, true, true], ['public, max-age=100, s-maxage=100', 500, true, true], ['public, max-age=100, s-maxage=100', 200, false, true] ]; diff --git a/lib/internal/Magento/Framework/Archive/Helper/File.php b/lib/internal/Magento/Framework/Archive/Helper/File.php index eab51af7b2c87..ec2f846f5f34c 100644 --- a/lib/internal/Magento/Framework/Archive/Helper/File.php +++ b/lib/internal/Magento/Framework/Archive/Helper/File.php @@ -12,6 +12,7 @@ namespace Magento\Framework\Archive\Helper; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Filesystem\DriverInterface; class File { @@ -90,7 +91,7 @@ public function __destruct() * @throws LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ - public function open($mode = 'w+', $chmod = 0666) + public function open($mode = 'w+', $chmod = DriverInterface::WRITEABLE_FILE_MODE) { $this->_isInWriteMode = $this->_isWritableMode($mode); diff --git a/lib/internal/Magento/Framework/Archive/Tar.php b/lib/internal/Magento/Framework/Archive/Tar.php index c9e5fe5eebe9a..2f4b6f3f41a2a 100644 --- a/lib/internal/Magento/Framework/Archive/Tar.php +++ b/lib/internal/Magento/Framework/Archive/Tar.php @@ -12,6 +12,7 @@ namespace Magento\Framework\Archive; use Magento\Framework\Archive\Helper\File; +use Magento\Framework\Filesystem\DriverInterface; class Tar extends \Magento\Framework\Archive\AbstractArchive implements \Magento\Framework\Archive\ArchiveInterface { @@ -378,7 +379,7 @@ protected function _composeHeader($long = false) /** * Read TAR string from file, and unpacked it. - * Create files and directories information about discribed + * Create files and directories information about described * in the string. * * @param string $destination path to file is unpacked @@ -403,7 +404,7 @@ protected function _unpackCurrentTar($destination) if (in_array($header['type'], ["0", chr(0), ''])) { if (!file_exists($dirname)) { - $mkdirResult = @mkdir($dirname, 0777, true); + $mkdirResult = @mkdir($dirname, DriverInterface::WRITEABLE_DIRECTORY_MODE, true); if (false === $mkdirResult) { throw new \Magento\Framework\Exception\LocalizedException( diff --git a/lib/internal/Magento/Framework/Backup/Filesystem.php b/lib/internal/Magento/Framework/Backup/Filesystem.php index 4cd031d5a7f92..1157ed153736b 100644 --- a/lib/internal/Magento/Framework/Backup/Filesystem.php +++ b/lib/internal/Magento/Framework/Backup/Filesystem.php @@ -7,6 +7,7 @@ // @codingStandardsIgnoreFile namespace Magento\Framework\Backup; +use Magento\Framework\Filesystem\DriverInterface; /** * Class to work with filesystem backups @@ -278,7 +279,7 @@ protected function _checkBackupsDir() } mkdir($backupsDir); - chmod($backupsDir, 0777); + chmod($backupsDir, DriverInterface::WRITEABLE_DIRECTORY_MODE); } if (!is_writable($backupsDir)) { diff --git a/lib/internal/Magento/Framework/Backup/Filesystem/Rollback/Ftp.php b/lib/internal/Magento/Framework/Backup/Filesystem/Rollback/Ftp.php index 395700ab0bb4e..d69f89ed13e61 100644 --- a/lib/internal/Magento/Framework/Backup/Filesystem/Rollback/Ftp.php +++ b/lib/internal/Magento/Framework/Backup/Filesystem/Rollback/Ftp.php @@ -5,6 +5,8 @@ */ namespace Magento\Framework\Backup\Filesystem\Rollback; +use Magento\Framework\Filesystem\DriverInterface; + /** * Rollback worker for rolling back via ftp * @@ -124,7 +126,7 @@ protected function _createTmpDir() { $tmpDir = $this->_snapshot->getBackupsDir() . '/~tmp-' . microtime(true); - $result = @mkdir($tmpDir); + $result = @mkdir($tmpDir, DriverInterface::WRITEABLE_DIRECTORY_MODE); if (false === $result) { throw new \Magento\Framework\Backup\Exception\NotEnoughPermissions( diff --git a/lib/internal/Magento/Framework/Cache/InvalidateLogger.php b/lib/internal/Magento/Framework/Cache/InvalidateLogger.php index 41c26d5370e04..42d4330b3c99c 100644 --- a/lib/internal/Magento/Framework/Cache/InvalidateLogger.php +++ b/lib/internal/Magento/Framework/Cache/InvalidateLogger.php @@ -53,4 +53,16 @@ private function makeParams($invalidateInfo) $url = $this->request->getUriString(); return compact('method', 'url', 'invalidateInfo'); } + + /** + * Log critical + * + * @param string $message + * @param mixed $params + * @return void + */ + public function critical($message, $params) + { + $this->logger->critical($message, $this->makeParams($params)); + } } diff --git a/lib/internal/Magento/Framework/Cache/Test/Unit/InvalidateLoggerTest.php b/lib/internal/Magento/Framework/Cache/Test/Unit/InvalidateLoggerTest.php new file mode 100644 index 0000000000000..6c2b12725f3fd --- /dev/null +++ b/lib/internal/Magento/Framework/Cache/Test/Unit/InvalidateLoggerTest.php @@ -0,0 +1,85 @@ +requestMock = $this->getMock('Magento\Framework\App\Request\Http', [], [], '', false); + $this->loggerMock = $this->getMock('Psr\Log\LoggerInterface', [], [], '', false); + $this->invalidateLogger = new \Magento\Framework\Cache\InvalidateLogger( + $this->requestMock, + $this->loggerMock + ); + $this->requestMock->expects($this->once()) + ->method('getMethod') + ->willReturn($this->method); + $this->requestMock->expects($this->once()) + ->method('getUriString') + ->willReturn($this->url); + } + + public function testCritical() + { + $this->loggerMock->expects($this->once()) + ->method('critical') + ->with('message', ['method' => $this->method, 'url' => $this->url, 'invalidateInfo' => $this->params]); + $this->invalidateLogger->critical('message', $this->params); + } + + public function testExecute() + { + $this->loggerMock->expects($this->once()) + ->method('debug') + ->with( + 'cache_invalidate: ', + ['method' => $this->method, 'url' => $this->url, 'invalidateInfo' => $this->params] + ); + $this->invalidateLogger->execute($this->params); + } + + public function testMakeParams() + { + $expected = ['method' => $this->method, 'url' => $this->url, 'invalidateInfo' => $this->params];; + $method = new \ReflectionMethod($this->invalidateLogger, 'makeParams'); + $method->setAccessible(true); + $this->assertEquals( + $expected, + $method->invoke($this->invalidateLogger, $this->params) + ); + } + + protected function tearDown() + { + unset($this->requestMock); + unset($this->loggerMock); + } +} diff --git a/lib/internal/Magento/Framework/Code/Generator/Io.php b/lib/internal/Magento/Framework/Code/Generator/Io.php index 945f1879afc3b..eb6cabeebf911 100644 --- a/lib/internal/Magento/Framework/Code/Generator/Io.php +++ b/lib/internal/Magento/Framework/Code/Generator/Io.php @@ -6,6 +6,7 @@ namespace Magento\Framework\Code\Generator; use Magento\Framework\Exception\FileSystemException; +use Magento\Framework\Filesystem\DriverInterface; class Io { @@ -15,11 +16,6 @@ class Io */ const DEFAULT_DIRECTORY = 'var/generation'; - /** - * \Directory permission for created directories - */ - const DIRECTORY_PERMISSION = 0777; - /** * Path to directory where new file must be created * @@ -161,7 +157,7 @@ private function _makeDirectory($directory) } try { if (!$this->filesystemDriver->isDirectory($directory)) { - $this->filesystemDriver->createDirectory($directory, self::DIRECTORY_PERMISSION); + $this->filesystemDriver->createDirectory($directory, DriverInterface::WRITEABLE_DIRECTORY_MODE); } return true; } catch (FileSystemException $e) { diff --git a/lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php b/lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php index 2951d806750fb..16bb120e24707 100644 --- a/lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php +++ b/lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php @@ -22,6 +22,7 @@ class ConfigOptionsListConstants const CONFIG_PATH_DB_CONNECTIONS = 'db/connection'; const CONFIG_PATH_DB_PREFIX = 'db/table_prefix'; const CONFIG_PATH_X_FRAME_OPT = 'x-frame-options'; + const CONFIG_PATH_CACHE_HOSTS = 'http_cache_hosts'; /**#@-*/ /**#@+ @@ -40,6 +41,7 @@ class ConfigOptionsListConstants const INPUT_KEY_DB_ENGINE = 'db-engine'; const INPUT_KEY_RESOURCE = 'resource'; const INPUT_KEY_SKIP_DB_VALIDATION = 'skip-db-validation'; + const INPUT_KEY_CACHE_HOSTS = 'http-cache-hosts'; /**#@-*/ /**#@+ diff --git a/lib/internal/Magento/Framework/File/Uploader.php b/lib/internal/Magento/Framework/File/Uploader.php index b5a0dedbbdf5b..9d41363799e1a 100644 --- a/lib/internal/Magento/Framework/File/Uploader.php +++ b/lib/internal/Magento/Framework/File/Uploader.php @@ -5,6 +5,8 @@ */ namespace Magento\Framework\File; +use Magento\Framework\Filesystem\DriverInterface; + /** * File upload class * @@ -221,7 +223,7 @@ public function save($destinationFolder, $newFileName = null) $this->_result = $this->_moveFile($this->_file['tmp_name'], $destinationFile); if ($this->_result) { - chmod($destinationFile, 0777); + chmod($destinationFile, DriverInterface::WRITEABLE_DIRECTORY_MODE); if ($this->_enableFilesDispersion) { $fileName = str_replace('\\', '/', self::_addDirSeparator($this->_dispretionPath)) . $fileName; } @@ -542,7 +544,9 @@ private function _createDestinationFolder($destinationFolder) $destinationFolder = substr($destinationFolder, 0, -1); } - if (!(@is_dir($destinationFolder) || @mkdir($destinationFolder, 0777, true))) { + if (!(@is_dir($destinationFolder) + || @mkdir($destinationFolder, DriverInterface::WRITEABLE_DIRECTORY_MODE, true) + )) { throw new \Exception("Unable to create directory '{$destinationFolder}'."); } return $this; diff --git a/lib/internal/Magento/Framework/Filesystem/Directory/Write.php b/lib/internal/Magento/Framework/Filesystem/Directory/Write.php index 2ec2a9d3c32f7..a74447f2a91ea 100644 --- a/lib/internal/Magento/Framework/Filesystem/Directory/Write.php +++ b/lib/internal/Magento/Framework/Filesystem/Directory/Write.php @@ -6,6 +6,7 @@ namespace Magento\Framework\Filesystem\Directory; use Magento\Framework\Exception\FileSystemException; +use Magento\Framework\Filesystem\DriverInterface; class Write extends Read implements WriteInterface { @@ -14,7 +15,7 @@ class Write extends Read implements WriteInterface * * @var int */ - protected $permissions = 0777; + protected $permissions = DriverInterface::WRITEABLE_DIRECTORY_MODE; /** * Constructor diff --git a/lib/internal/Magento/Framework/Filesystem/DriverInterface.php b/lib/internal/Magento/Framework/Filesystem/DriverInterface.php index ac1ff792e33b3..5122787f7b046 100644 --- a/lib/internal/Magento/Framework/Filesystem/DriverInterface.php +++ b/lib/internal/Magento/Framework/Filesystem/DriverInterface.php @@ -14,6 +14,16 @@ */ interface DriverInterface { + /** + * Permissions to give read/write/execute access to owner and owning group, but not to all users + */ + const WRITEABLE_DIRECTORY_MODE = 0770; + + /** + * Permissions to give read/write access to owner and owning group, but not to all users + */ + const WRITEABLE_FILE_MODE = 0660; + /** * * @param string $path diff --git a/lib/internal/Magento/Framework/Filesystem/Io/File.php b/lib/internal/Magento/Framework/Filesystem/Io/File.php index 4f754db62250e..b504f54b173be 100644 --- a/lib/internal/Magento/Framework/Filesystem/Io/File.php +++ b/lib/internal/Magento/Framework/Filesystem/Io/File.php @@ -5,6 +5,9 @@ */ namespace Magento\Framework\Filesystem\Io; +use Magento\Framework\Filesystem\DriverInterface; +use Symfony\Component\Finder\Tests\Iterator\DateRangeFilterIteratorTest; + /** * Filesystem client * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) @@ -298,7 +301,7 @@ public function close() * @param bool $recursive * @return bool */ - public function mkdir($dir, $mode = 0777, $recursive = true) + public function mkdir($dir, $mode = DriverInterface::WRITEABLE_DIRECTORY_MODE, $recursive = true) { $this->_cwd(); $result = @mkdir($dir, $mode, $recursive); @@ -550,7 +553,7 @@ public function createDestinationDir($path) * @return true * @throws \Exception */ - public function checkAndCreateFolder($folder, $mode = 0777) + public function checkAndCreateFolder($folder, $mode = DriverInterface::WRITEABLE_DIRECTORY_MODE) { if (is_dir($folder)) { return true; diff --git a/lib/internal/Magento/Framework/Filesystem/Io/Ftp.php b/lib/internal/Magento/Framework/Filesystem/Io/Ftp.php index 1f897eee69f01..f909f2cf39fdb 100644 --- a/lib/internal/Magento/Framework/Filesystem/Io/Ftp.php +++ b/lib/internal/Magento/Framework/Filesystem/Io/Ftp.php @@ -5,6 +5,7 @@ */ namespace Magento\Framework\Filesystem\Io; +use Magento\Framework\Filesystem\DriverInterface; use Magento\Framework\Phrase; use Magento\Framework\Exception\LocalizedException; @@ -158,7 +159,7 @@ public function close() * @return bool * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function mkdir($dir, $mode = 0777, $recursive = true) + public function mkdir($dir, $mode = DriverInterface::WRITEABLE_DIRECTORY_MODE, $recursive = true) { return @ftp_mkdir($this->_conn, $dir); } diff --git a/lib/internal/Magento/Framework/Filesystem/Io/IoInterface.php b/lib/internal/Magento/Framework/Filesystem/Io/IoInterface.php index 8466b51ca3728..3fd0883171139 100644 --- a/lib/internal/Magento/Framework/Filesystem/Io/IoInterface.php +++ b/lib/internal/Magento/Framework/Filesystem/Io/IoInterface.php @@ -5,6 +5,8 @@ */ namespace Magento\Framework\Filesystem\Io; +use Magento\Framework\Filesystem\DriverInterface; + /** * Input/output client interface */ @@ -33,7 +35,7 @@ public function close(); * @param bool $recursive * @return bool */ - public function mkdir($dir, $mode = 0777, $recursive = true); + public function mkdir($dir, $mode = DriverInterface::WRITEABLE_DIRECTORY_MODE, $recursive = true); /** * Delete a directory diff --git a/lib/internal/Magento/Framework/Filesystem/Io/Sftp.php b/lib/internal/Magento/Framework/Filesystem/Io/Sftp.php index 69365d9885b33..9082dfd268c34 100644 --- a/lib/internal/Magento/Framework/Filesystem/Io/Sftp.php +++ b/lib/internal/Magento/Framework/Filesystem/Io/Sftp.php @@ -8,6 +8,8 @@ namespace Magento\Framework\Filesystem\Io; +use Magento\Framework\Filesystem\DriverInterface; + /** * Sftp client interface * @@ -76,7 +78,7 @@ public function close() * @return bool * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function mkdir($dir, $mode = 0777, $recursive = true) + public function mkdir($dir, $mode = DriverInterface::WRITEABLE_DIRECTORY_MODE, $recursive = true) { if ($recursive) { $no_errors = true; diff --git a/lib/internal/Magento/Framework/Logger/Handler/Base.php b/lib/internal/Magento/Framework/Logger/Handler/Base.php index 66037768a062d..3ce02081fb651 100644 --- a/lib/internal/Magento/Framework/Logger/Handler/Base.php +++ b/lib/internal/Magento/Framework/Logger/Handler/Base.php @@ -54,7 +54,7 @@ public function write(array $record) { $logDir = $this->filesystem->getParentDirectory($this->url); if (!$this->filesystem->isDirectory($logDir)) { - $this->filesystem->createDirectory($logDir, 0777); + $this->filesystem->createDirectory($logDir, DriverInterface::WRITEABLE_DIRECTORY_MODE); } parent::write($record); diff --git a/lib/internal/Magento/Framework/Setup/BackupRollback.php b/lib/internal/Magento/Framework/Setup/BackupRollback.php index ae3464ae3ca9f..b992827bff9b5 100644 --- a/lib/internal/Magento/Framework/Setup/BackupRollback.php +++ b/lib/internal/Magento/Framework/Setup/BackupRollback.php @@ -13,6 +13,7 @@ use Magento\Framework\Backup\Filesystem\Helper; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Filesystem\Driver\File; +use Magento\Framework\Filesystem\DriverInterface; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Phrase; @@ -120,7 +121,7 @@ public function codeBackup($time, $type = Factory::TYPE_FILESYSTEM) throw new LocalizedException(new Phrase("This backup type \'$type\' is not supported.")); } if (!$this->file->isExists($this->backupsDir)) { - $this->file->createDirectory($this->backupsDir, 0777); + $this->file->createDirectory($this->backupsDir, DriverInterface::WRITEABLE_DIRECTORY_MODE); } $fsBackup->setBackupsDir($this->backupsDir); $fsBackup->setBackupExtension('tgz'); @@ -201,7 +202,7 @@ public function dbBackup($time) $dbBackup = $this->objectManager->create('Magento\Framework\Backup\Db'); $dbBackup->setRootDir($this->directoryList->getRoot()); if (!$this->file->isExists($this->backupsDir)) { - $this->file->createDirectory($this->backupsDir, 0777); + $this->file->createDirectory($this->backupsDir, DriverInterface::WRITEABLE_DIRECTORY_MODE); } $dbBackup->setBackupsDir($this->backupsDir); $dbBackup->setBackupExtension('gz'); diff --git a/lib/internal/Magento/Framework/Setup/Test/Unit/BackupRollbackTest.php b/lib/internal/Magento/Framework/Setup/Test/Unit/BackupRollbackTest.php index dbcd9a28a90b7..3a5a6b838b0f0 100644 --- a/lib/internal/Magento/Framework/Setup/Test/Unit/BackupRollbackTest.php +++ b/lib/internal/Magento/Framework/Setup/Test/Unit/BackupRollbackTest.php @@ -107,7 +107,7 @@ public function testCodeBackup() $this->filesystem->expects($this->once()) ->method('create'); $this->file->expects($this->once())->method('isExists')->with($this->path . '/backups')->willReturn(false); - $this->file->expects($this->once())->method('createDirectory')->with($this->path . '/backups', 0777); + $this->file->expects($this->once())->method('createDirectory')->with($this->path . '/backups', 0770); $this->model->codeBackup(time()); } @@ -158,7 +158,7 @@ public function testMediaBackup() $this->filesystem->expects($this->once()) ->method('create'); $this->file->expects($this->once())->method('isExists')->with($this->path . '/backups')->willReturn(false); - $this->file->expects($this->once())->method('createDirectory')->with($this->path . '/backups', 0777); + $this->file->expects($this->once())->method('createDirectory')->with($this->path . '/backups', 0770); $this->model->codeBackup(time(), Factory::TYPE_MEDIA); } diff --git a/lib/internal/Magento/Framework/System/Dirs.php b/lib/internal/Magento/Framework/System/Dirs.php index aa8731c6fce2f..3585b2f72a2cf 100644 --- a/lib/internal/Magento/Framework/System/Dirs.php +++ b/lib/internal/Magento/Framework/System/Dirs.php @@ -5,6 +5,8 @@ */ namespace Magento\Framework\System; +use Magento\Framework\Filesystem\DriverInterface; + class Dirs { /** @@ -73,7 +75,7 @@ public static function rm($dirname) * @return true * @throws \Exception */ - public static function mkdirStrict($path, $recursive = true, $mode = 0777) + public static function mkdirStrict($path, $recursive = true, $mode = DriverInterface::WRITEABLE_DIRECTORY_MODE) { $exists = file_exists($path); if ($exists && is_dir($path)) { diff --git a/lib/internal/Magento/Framework/System/Ftp.php b/lib/internal/Magento/Framework/System/Ftp.php index b36bd07f8f5d2..3aa7a858f6b96 100644 --- a/lib/internal/Magento/Framework/System/Ftp.php +++ b/lib/internal/Magento/Framework/System/Ftp.php @@ -6,6 +6,8 @@ namespace Magento\Framework\System; +use Magento\Framework\Filesystem\DriverInterface; + /** * Class to work with remote FTP server */ @@ -50,7 +52,7 @@ public function mdkir($name) * @param int $mode * @return bool */ - public function mkdirRecursive($path, $mode = 0777) + public function mkdirRecursive($path, $mode = DriverInterface::WRITEABLE_DIRECTORY_MODE) { $this->checkConnected(); $dir = explode("/", $path); @@ -217,7 +219,7 @@ public function raw($cmd) * @return bool * @throws \Exception */ - public function upload($remote, $local, $dirMode = 0777, $ftpMode = FTP_BINARY) + public function upload($remote, $local, $dirMode = DriverInterface::WRITEABLE_DIRECTORY_MODE, $ftpMode = FTP_BINARY) { $this->checkConnected(); diff --git a/lib/internal/Magento/Framework/UrlInterface/Proxy.php b/lib/internal/Magento/Framework/UrlInterface/Proxy.php deleted file mode 100644 index 7ed1a1bbc7bff..0000000000000 --- a/lib/internal/Magento/Framework/UrlInterface/Proxy.php +++ /dev/null @@ -1,212 +0,0 @@ -_objectManager = $objectManager; - $this->_instanceName = $instanceName; - $this->_isShared = $shared; - } - - /** - * @return array - */ - public function __sleep() - { - return ['_subject', '_isShared']; - } - - /** - * Retrieve ObjectManager from global scope - * - * @return void - */ - public function __wakeup() - { - $this->_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); - } - - /** - * Clone proxied instance - * - * @return void - */ - public function __clone() - { - $this->_subject = clone $this->_getSubject(); - } - - /** - * Get proxied instance - * - * @return \Magento\Framework\UrlInterface - */ - protected function _getSubject() - { - if (!$this->_subject) { - $this->_subject = true === $this->_isShared - ? $this->_objectManager->get($this->_instanceName) - : $this->_objectManager->create($this->_instanceName); - } - return $this->_subject; - } - - /** - * {@inheritdoc} - */ - public function getUseSession() - { - return $this->_getSubject()->getUseSession(); - } - - /** - * {@inheritdoc} - */ - public function getBaseUrl($params = []) - { - return $this->_getSubject()->getBaseUrl($params); - } - - /** - * {@inheritdoc} - */ - public function getCurrentUrl() - { - return $this->_getSubject()->getCurrentUrl(); - } - - /** - * {@inheritdoc} - */ - public function getRouteUrl($routePath = null, $routeParams = null) - { - return $this->_getSubject()->getRouteUrl($routePath, $routeParams); - } - - /** - * {@inheritdoc} - */ - public function addSessionParam() - { - return $this->_getSubject()->addSessionParam(); - } - - /** - * {@inheritdoc} - */ - public function addQueryParams(array $data) - { - return $this->_getSubject()->addQueryParams($data); - } - - /** - * {@inheritdoc} - */ - public function setQueryParam($key, $data) - { - return $this->_getSubject()->setQueryParam($key, $data); - } - - /** - * {@inheritdoc} - */ - public function getUrl($routePath = null, $routeParams = null) - { - return $this->_getSubject()->getUrl($routePath, $routeParams); - } - - /** - * {@inheritdoc} - */ - public function escape($value) - { - return $this->_getSubject()->escape($value); - } - - /** - * {@inheritdoc} - */ - public function getDirectUrl($url, $params = []) - { - return $this->_getSubject()->getDirectUrl($url, $params); - } - - /** - * {@inheritdoc} - */ - public function sessionUrlVar($html) - { - return $this->_getSubject()->sessionUrlVar($html); - } - - /** - * {@inheritdoc} - */ - public function isOwnOriginUrl() - { - return $this->_getSubject()->isOwnOriginUrl(); - } - - /** - * {@inheritdoc} - */ - public function getRedirectUrl($url) - { - return $this->_getSubject()->getRedirectUrl($url); - } - - /** - * {@inheritdoc} - */ - public function setScope($params) - { - return $this->_getSubject()->setScope($params); - } -} diff --git a/pub/errors/processor.php b/pub/errors/processor.php index edbbb4dd60204..81b797f62f310 100644 --- a/pub/errors/processor.php +++ b/pub/errors/processor.php @@ -4,6 +4,7 @@ * See COPYING.txt for license details. */ namespace Magento\Framework\Error; +use Magento\Framework\Filesystem\DriverInterface; /** * Error processor @@ -453,11 +454,11 @@ public function saveReport($reportData) $this->_setReportData($reportData); if (!file_exists($this->_reportDir)) { - @mkdir($this->_reportDir, 0777, true); + @mkdir($this->_reportDir, DriverInterface::WRITEABLE_DIRECTORY_MODE, true); } @file_put_contents($this->_reportFile, serialize($reportData)); - @chmod($this->_reportFile, 0777); + @chmod($this->_reportFile, DriverInterface::WRITEABLE_FILE_MODE); if (isset($reportData['skin']) && self::DEFAULT_SKIN != $reportData['skin']) { $this->_setSkin($reportData['skin']); diff --git a/setup/src/Magento/Setup/Console/Command/DiCompileMultiTenantCommand.php b/setup/src/Magento/Setup/Console/Command/DiCompileMultiTenantCommand.php index 941d21c21a712..95cac1be21853 100644 --- a/setup/src/Magento/Setup/Console/Command/DiCompileMultiTenantCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DiCompileMultiTenantCommand.php @@ -5,6 +5,7 @@ */ namespace Magento\Setup\Console\Command; +use Magento\Framework\Filesystem\DriverInterface; use Magento\Setup\Model\ObjectManagerProvider; use Magento\Framework\App\ObjectManager; use Symfony\Component\Console\Input\InputInterface; @@ -350,8 +351,9 @@ private function compileCode($generationDir, $fileExcludePatterns, $input) $directoryInstancesNamesList->getList($generationDir); $relations = $directoryInstancesNamesList->getRelations(); // 2.2 Compression - if (!file_exists(dirname($relationsFile))) { - mkdir(dirname($relationsFile), 0777, true); + $relationsFileDir = dirname($relationsFile); + if (!file_exists($relationsFileDir)) { + mkdir($relationsFileDir, DriverInterface::WRITEABLE_DIRECTORY_MODE, true); } $relations = array_filter($relations); file_put_contents($relationsFile, $serializer->serialize($relations)); @@ -367,8 +369,9 @@ private function compileCode($generationDir, $fileExcludePatterns, $input) } } $outputContent = $serializer->serialize($pluginDefinitions); - if (!file_exists(dirname($pluginDefFile))) { - mkdir(dirname($pluginDefFile), 0777, true); + $pluginDefFileDir = dirname($pluginDefFile); + if (!file_exists($pluginDefFileDir)) { + mkdir($pluginDefFileDir, DriverInterface::WRITEABLE_DIRECTORY_MODE, true); } file_put_contents($pluginDefFile, $outputContent); } diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index 491f60d9d2643..db1e6727b703f 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -238,4 +238,30 @@ public function createModeConfig() $configData->set(State::PARAM_MODE, State::MODE_DEFAULT); return $configData; } + + /** + * Creates cache hosts config data + * + * @param array $data + * @return ConfigData + */ + public function createCacheHostsConfig(array $data) + { + $configData = new ConfigData(ConfigFilePool::APP_ENV); + if (isset($data[ConfigOptionsListConstants::INPUT_KEY_CACHE_HOSTS])) { + $hostData = explode(',', $data[ConfigOptionsListConstants::INPUT_KEY_CACHE_HOSTS]); + $hosts = []; + foreach ($hostData as $data) { + $dataArray = explode(':', trim($data)); + $host = []; + $host['host'] = $dataArray[0]; + if (isset($dataArray[1])) { + $host['port'] = $dataArray[1]; + } + $hosts[] = $host; + } + $configData->set(ConfigOptionsListConstants::CONFIG_PATH_CACHE_HOSTS, $hosts); + } + return $configData; + } } diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index 5f481a0f5db80..8a4a82ef416f0 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -119,7 +119,7 @@ public function process($inputOptions) } - $this->writer->saveConfig($fileConfigStorage); + $this->writer->saveConfig($fileConfigStorage, true); } /** diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList.php b/setup/src/Magento/Setup/Model/ConfigOptionsList.php index 18d89da6394cb..1011731e112dc 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList.php @@ -47,6 +47,7 @@ public function __construct(ConfigGenerator $configGenerator, DbValidator $dbVal /** * {@inheritdoc} + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function getOptions() { @@ -141,6 +142,12 @@ public function getOptions() 'If specified, then db connection validation will be skipped', '-s' ), + new TextConfigOption( + ConfigOptionsListConstants::INPUT_KEY_CACHE_HOSTS, + TextConfigOption::FRONTEND_WIZARD_TEXT, + ConfigOptionsListConstants::CONFIG_PATH_CACHE_HOSTS, + 'http Cache hosts' + ), ]; } @@ -161,6 +168,7 @@ public function createConfig(array $data, DeploymentConfig $deploymentConfig) $configData[] = $this->configGenerator->createResourceConfig(); $configData[] = $this->configGenerator->createXFrameConfig(); $configData[] = $this->configGenerator->createModeConfig(); + $configData[] = $this->configGenerator->createCacheHostsConfig($data); return $configData; } @@ -171,35 +179,22 @@ public function validate(array $options, DeploymentConfig $deploymentConfig) { $errors = []; - if (isset($options[ConfigOptionsListConstants::INPUT_KEY_DB_PREFIX])) { - try { - $this->dbValidator->checkDatabaseTablePrefix($options[ConfigOptionsListConstants::INPUT_KEY_DB_PREFIX]); - } catch (\InvalidArgumentException $exception) { - $errors[] = $exception->getMessage(); - } + if (isset($options[ConfigOptionsListConstants::INPUT_KEY_CACHE_HOSTS])) { + $errors = array_merge( + $errors, + $this->validateHttpCacheHosts($options[ConfigOptionsListConstants::INPUT_KEY_CACHE_HOSTS]) + ); } - if (!$options[ConfigOptionsListConstants::INPUT_KEY_SKIP_DB_VALIDATION] && - ( - $options[ConfigOptionsListConstants::INPUT_KEY_DB_NAME] !== null - || $options[ConfigOptionsListConstants::INPUT_KEY_DB_HOST] !== null - || $options[ConfigOptionsListConstants::INPUT_KEY_DB_USER] !== null - || $options[ConfigOptionsListConstants::INPUT_KEY_DB_PASSWORD] !== null - ) - ) { - try { - - $options = $this->getDbSettings($options, $deploymentConfig); + if (isset($options[ConfigOptionsListConstants::INPUT_KEY_DB_PREFIX])) { + $errors = array_merge( + $errors, + $this->validateDbPrefix($options[ConfigOptionsListConstants::INPUT_KEY_DB_PREFIX]) + ); + } - $this->dbValidator->checkDatabaseConnection( - $options[ConfigOptionsListConstants::INPUT_KEY_DB_NAME], - $options[ConfigOptionsListConstants::INPUT_KEY_DB_HOST], - $options[ConfigOptionsListConstants::INPUT_KEY_DB_USER], - $options[ConfigOptionsListConstants::INPUT_KEY_DB_PASSWORD] - ); - } catch (\Exception $exception) { - $errors[] = $exception->getMessage(); - } + if (!$options[ConfigOptionsListConstants::INPUT_KEY_SKIP_DB_VALIDATION]) { + $errors = array_merge($errors, $this->validateDbSettings($options, $deploymentConfig)); } $errors = array_merge( @@ -296,4 +291,70 @@ private function validateEncryptionKey(array $options) return $errors; } + + /** + * Validate http cache hosts + * + * @param string $option + * @return string[] + */ + private function validateHttpCacheHosts($option) + { + $errors = []; + if (!preg_match('/^[a-zA-Z0-9_:,.]+$/', $option) + ) { + $errors[] = "Invalid http cache hosts '{$option}'"; + } + return $errors; + } + + /** + * Validate Db table prefix + * + * @param string $option + * @return string[] + */ + private function validateDbPrefix($option) + { + $errors = []; + try { + $this->dbValidator->checkDatabaseTablePrefix($option); + } catch (\InvalidArgumentException $exception) { + $errors[] = $exception->getMessage(); + } + return $errors; + } + + /** + * Validate Db settings + * + * @param array $options + * @param DeploymentConfig $deploymentConfig + * @return string[] + */ + private function validateDbSettings(array $options, DeploymentConfig $deploymentConfig) + { + $errors = []; + + if ($options[ConfigOptionsListConstants::INPUT_KEY_DB_NAME] !== null + || $options[ConfigOptionsListConstants::INPUT_KEY_DB_HOST] !== null + || $options[ConfigOptionsListConstants::INPUT_KEY_DB_USER] !== null + || $options[ConfigOptionsListConstants::INPUT_KEY_DB_PASSWORD] !== null + ) { + try { + + $options = $this->getDbSettings($options, $deploymentConfig); + + $this->dbValidator->checkDatabaseConnection( + $options[ConfigOptionsListConstants::INPUT_KEY_DB_NAME], + $options[ConfigOptionsListConstants::INPUT_KEY_DB_HOST], + $options[ConfigOptionsListConstants::INPUT_KEY_DB_USER], + $options[ConfigOptionsListConstants::INPUT_KEY_DB_PASSWORD] + ); + } catch (\Exception $exception) { + $errors[] = $exception->getMessage(); + } + } + return $errors; + } } diff --git a/setup/src/Magento/Setup/Module/I18n/Pack/Writer/File/AbstractFile.php b/setup/src/Magento/Setup/Module/I18n/Pack/Writer/File/AbstractFile.php index 599b806f09930..e5909fb68296f 100644 --- a/setup/src/Magento/Setup/Module/I18n/Pack/Writer/File/AbstractFile.php +++ b/setup/src/Magento/Setup/Module/I18n/Pack/Writer/File/AbstractFile.php @@ -143,7 +143,7 @@ abstract protected function _getFileExtension(); * @param bool $recursive Allows the creation of nested directories specified in the $destinationPath * @return void */ - protected function _createDirectoryIfNotExist($destinationPath, $mode = 0755, $recursive = true) + protected function _createDirectoryIfNotExist($destinationPath, $mode = 0750, $recursive = true) { if (!is_dir($destinationPath)) { mkdir($destinationPath, $mode, $recursive); diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php index 12ce5af79e7dc..65df905990221 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php @@ -38,4 +38,24 @@ public function testCreateXFrameConfig() $configData = $this->model->createXFrameConfig(); $this->assertSame('SAMEORIGIN', $configData->getData()[ConfigOptionsListConstants::CONFIG_PATH_X_FRAME_OPT]); } + + public function testCreateCacheHostsConfig() + { + $data = [ConfigOptionsListConstants::INPUT_KEY_CACHE_HOSTS => 'localhost:8080, website.com, 120.0.0.1:90']; + $expectedData = [ + 0 => [ + 'host' => 'localhost', + 'port' => '8080', + ], + 1 => [ + 'host' => 'website.com', + ], + 2 => [ + 'host' => '120.0.0.1', + 'port' => '90', + ], + ]; + $configData = $this->model->createCacheHostsConfig($data); + $this->assertEquals($expectedData, $configData->getData()[ConfigOptionsListConstants::CONFIG_PATH_CACHE_HOSTS]); + } } diff --git a/setup/src/Magento/Setup/Test/Unit/Module/ConfigOptionsListTest.php b/setup/src/Magento/Setup/Test/Unit/Module/ConfigOptionsListTest.php index e2952dd17327c..15c6de640bc60 100644 --- a/setup/src/Magento/Setup/Test/Unit/Module/ConfigOptionsListTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Module/ConfigOptionsListTest.php @@ -71,7 +71,9 @@ public function testGetOptions() 'If specified, then db connection validation will be skipped', $options[11]->getDescription() ); - $this->assertEquals(12, count($options)); + $this->assertInstanceOf('Magento\Framework\Setup\Option\TextConfigOption', $options[12]); + $this->assertSame('http Cache hosts', $options[12]->getDescription()); + $this->assertEquals(13, count($options)); } public function testCreateOptions() @@ -84,8 +86,9 @@ public function testCreateOptions() $this->generator->expects($this->once())->method('createDbConfig')->willReturn($configDataMock); $this->generator->expects($this->once())->method('createResourceConfig')->willReturn($configDataMock); $this->generator->expects($this->once())->method('createXFrameConfig')->willReturn($configDataMock); + $this->generator->expects($this->once())->method('createCacheHostsConfig')->willReturn($configDataMock); $configData = $this->object->createConfig([], $this->deploymentConfig); - $this->assertEquals(8, count($configData)); + $this->assertEquals(9, count($configData)); } public function testCreateOptionsWithOptionalNull() @@ -98,8 +101,9 @@ public function testCreateOptionsWithOptionalNull() $this->generator->expects($this->once())->method('createDbConfig')->willReturn($configDataMock); $this->generator->expects($this->once())->method('createResourceConfig')->willReturn($configDataMock); $this->generator->expects($this->once())->method('createXFrameConfig')->willReturn($configDataMock); + $this->generator->expects($this->once())->method('createCacheHostsConfig')->willReturn($configDataMock); $configData = $this->object->createConfig([], $this->deploymentConfig); - $this->assertEquals(7, count($configData)); + $this->assertEquals(8, count($configData)); } public function testValidate() @@ -118,4 +122,37 @@ public function testValidate() $result = $this->object->validate($options, $this->deploymentConfig); $this->assertEquals([], $result); } + + /** + * @param string $hosts + * @param bool $expectedError + * @dataProvider validateCacheHostsDataProvider + */ + public function testValidateCacheHosts($hosts, $expectedError) + { + $options = [ + ConfigOptionsListConstants::INPUT_KEY_SKIP_DB_VALIDATION => true, + ConfigOptionsListConstants::INPUT_KEY_CACHE_HOSTS => $hosts + ]; + $result = $this->object->validate($options, $this->deploymentConfig); + if ($expectedError) { + $this->assertCount(1, $result); + $this->assertEquals("Invalid http cache hosts '$hosts'", $result[0]); + } else { + $this->assertCount(0, $result); + } + + } + + public function validateCacheHostsDataProvider() + { + return [ + ['localhost', false], + ['122.11.2.34:800', false], + ['122.11.2.34:800,localhost', false], + ['website.com:9000', false], + ['website.com/m2ce:9000', true], + ['website.com+:9000', true], + ]; + } }