diff --git a/app/code/Magento/Backend/App/BackendAppList.php b/app/code/Magento/Backend/App/BackendAppList.php index 224ce9893100c6b416da0362ca9a0e3af569bf1e..afb812b823488b29898a2027afa87b6980d9974c 100644 --- a/app/code/Magento/Backend/App/BackendAppList.php +++ b/app/code/Magento/Backend/App/BackendAppList.php @@ -44,6 +44,7 @@ class BackendAppList if ($appName && isset($this->backendApps[$appName])) { return $this->backendApps[$appName]; } + return null; } /** diff --git a/app/code/Magento/Webapi/Model/Soap/Wsdl/Generator.php b/app/code/Magento/Webapi/Model/Soap/Wsdl/Generator.php index d5c0bcc678f6a4af813fe88d6f2419f9561a5134..038f5cdcfc444802259049eac10e371fba17edec 100644 --- a/app/code/Magento/Webapi/Model/Soap/Wsdl/Generator.php +++ b/app/code/Magento/Webapi/Model/Soap/Wsdl/Generator.php @@ -12,6 +12,7 @@ use Magento\Webapi\Model\Soap\Wsdl; use Magento\Webapi\Model\Soap\WsdlFactory; use Magento\Framework\Webapi\Authorization; use Magento\Webapi\Model\ServiceMetadata; +use Magento\Framework\Exception\AuthorizationException; /** * WSDL generator. @@ -364,4 +365,21 @@ class Generator extends AbstractSchemaGenerator { return $this->serviceMetadata->getServiceMetadata($serviceName); } + + /** + * {@inheritdoc} + */ + protected function getAllowedServicesMetadata($requestedServices) + { + $allowedServicesMetadata = parent::getAllowedServicesMetadata($requestedServices); + if (!$allowedServicesMetadata) { + throw new AuthorizationException( + __( + AuthorizationException::NOT_AUTHORIZED, + ['resources' => implode(', ', $requestedServices)] + ) + ); + } + return $allowedServicesMetadata; + } } diff --git a/composer.json b/composer.json index 73115b15a9f32a8af1a49a14a7658cd5daf9804c..e9880765b172e765285b516db117e85a829b562b 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,25 @@ "OSL-3.0", "AFL-3.0" ], + "repositories": [ + { + "type": "package", + "package": { + "name": "colinmollenhour/php-redis-session-abstract", + "version": "1.0.100", + "source": { + "url": "https://github.com/colinmollenhour/php-redis-session-abstract.git", + "type": "git", + "reference": "95330b7f29663dab81f53d1a438e4d927b6c5f66" + }, + "autoload": { + "psr-0": { + "Cm\\RedisSession\\": "src/" + } + } + } + } + ], "require": { "php": "~5.5.22|~5.6.0|~7.0.0", "zendframework/zend-stdlib": "~2.4.6", @@ -33,7 +52,7 @@ "zendframework/zend-http": "~2.4.6", "magento/zendframework1": "1.12.16", "colinmollenhour/credis": "1.6", - "colinmollenhour/php-redis-session-abstract": "1.0", + "colinmollenhour/php-redis-session-abstract": "1.0.100", "composer/composer": "1.0.0-beta1", "monolog/monolog": "1.16.0", "oyejorge/less.php": "1.7.0.3", diff --git a/composer.lock b/composer.lock index 4aaae63b403d43bf5ce7a75886dc6c8cedb6adb0..ab35246723931cd1c3add2bc0197f89c12676e2f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "d81a16c234a62403d9b5b06057393d9d", - "content-hash": "cd415001aebab7eb87bb62e2223509fc", + "hash": "5a52eec976eea4fade155b472365d805", + "content-hash": "2116af7fe8db4568fecdd0d554db22c3", "packages": [ { "name": "braintree/braintree_php", @@ -95,41 +95,18 @@ }, { "name": "colinmollenhour/php-redis-session-abstract", - "version": "v1.0", + "version": "1.0.100", "source": { "type": "git", "url": "https://github.com/colinmollenhour/php-redis-session-abstract.git", - "reference": "1308ddc08e2adbe303f7f8b8ead9beb5f2f2adf9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/colinmollenhour/php-redis-session-abstract/zipball/1308ddc08e2adbe303f7f8b8ead9beb5f2f2adf9", - "reference": "1308ddc08e2adbe303f7f8b8ead9beb5f2f2adf9", - "shasum": "" - }, - "require": { - "colinmollenhour/credis": "1.6", - "magento/zendframework1": "1.12.16", - "php": "~5.5.0|~5.6.0|~7.0.0" + "reference": "95330b7f29663dab81f53d1a438e4d927b6c5f66" }, "type": "library", "autoload": { "psr-0": { "Cm\\RedisSession\\": "src/" } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Colin Mollenhour" - } - ], - "description": "A Redis-based session handler with optimistic locking", - "homepage": "https://github.com/colinmollenhour/php-redis-session-abstract", - "time": "2016-01-14 16:04:27" + } }, { "name": "composer/composer", @@ -208,16 +185,16 @@ }, { "name": "composer/semver", - "version": "1.3.0", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/composer/semver.git", - "reference": "df4463baa9f44fe6cf0a6da4fde2934d4c0a2747" + "reference": "84c47f3d8901440403217afc120683c7385aecb8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/semver/zipball/df4463baa9f44fe6cf0a6da4fde2934d4c0a2747", - "reference": "df4463baa9f44fe6cf0a6da4fde2934d4c0a2747", + "url": "https://api.github.com/repos/composer/semver/zipball/84c47f3d8901440403217afc120683c7385aecb8", + "reference": "84c47f3d8901440403217afc120683c7385aecb8", "shasum": "" }, "require": { @@ -266,28 +243,28 @@ "validation", "versioning" ], - "time": "2016-02-25 22:23:39" + "time": "2016-03-30 13:16:03" }, { "name": "composer/spdx-licenses", - "version": "1.1.2", + "version": "1.1.3", "source": { "type": "git", "url": "https://github.com/composer/spdx-licenses.git", - "reference": "9e1c3926bb0842812967213d7c92827bc5883671" + "reference": "547659c3cacd3ccfe1b4714c2ff88cafc6b6793b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/spdx-licenses/zipball/9e1c3926bb0842812967213d7c92827bc5883671", - "reference": "9e1c3926bb0842812967213d7c92827bc5883671", + "url": "https://api.github.com/repos/composer/spdx-licenses/zipball/547659c3cacd3ccfe1b4714c2ff88cafc6b6793b", + "reference": "547659c3cacd3ccfe1b4714c2ff88cafc6b6793b", "shasum": "" }, "require": { - "php": ">=5.3.2" + "php": "^5.3.2 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.5", - "phpunit/phpunit-mock-objects": "~2.3" + "phpunit/phpunit": "^4.5 || ^5.0.5", + "phpunit/phpunit-mock-objects": "2.3.0 || ^3.0" }, "type": "library", "extra": { @@ -327,7 +304,7 @@ "spdx", "validator" ], - "time": "2015-10-05 11:27:42" + "time": "2016-03-25 10:57:10" }, { "name": "justinrainbow/json-schema", @@ -1181,16 +1158,16 @@ }, { "name": "symfony/event-dispatcher", - "version": "v2.8.3", + "version": "v2.8.4", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "78c468665c9568c3faaa9c416a7134308f2d85c3" + "reference": "47d2d8cade9b1c3987573d2943bb9352536cdb87" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/78c468665c9568c3faaa9c416a7134308f2d85c3", - "reference": "78c468665c9568c3faaa9c416a7134308f2d85c3", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/47d2d8cade9b1c3987573d2943bb9352536cdb87", + "reference": "47d2d8cade9b1c3987573d2943bb9352536cdb87", "shasum": "" }, "require": { @@ -1237,20 +1214,20 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2016-01-27 05:14:19" + "time": "2016-03-07 14:04:32" }, { "name": "symfony/filesystem", - "version": "v2.8.3", + "version": "v2.8.4", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "65cb36b6539b1d446527d60457248f30d045464d" + "reference": "f08ffdf229252cd2745558cb2112df43903bcae4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/65cb36b6539b1d446527d60457248f30d045464d", - "reference": "65cb36b6539b1d446527d60457248f30d045464d", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/f08ffdf229252cd2745558cb2112df43903bcae4", + "reference": "f08ffdf229252cd2745558cb2112df43903bcae4", "shasum": "" }, "require": { @@ -1286,20 +1263,20 @@ ], "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", - "time": "2016-02-22 15:02:30" + "time": "2016-03-27 10:20:16" }, { "name": "symfony/finder", - "version": "v3.0.3", + "version": "v3.0.4", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "623bda0abd9aa29e529c8e9c08b3b84171914723" + "reference": "c54e407b35bc098916704e9fd090da21da4c4f52" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/623bda0abd9aa29e529c8e9c08b3b84171914723", - "reference": "623bda0abd9aa29e529c8e9c08b3b84171914723", + "url": "https://api.github.com/repos/symfony/finder/zipball/c54e407b35bc098916704e9fd090da21da4c4f52", + "reference": "c54e407b35bc098916704e9fd090da21da4c4f52", "shasum": "" }, "require": { @@ -1335,20 +1312,20 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2016-01-27 05:14:46" + "time": "2016-03-10 11:13:05" }, { "name": "symfony/process", - "version": "v2.8.3", + "version": "v2.8.4", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "7dedd5b60550f33dca16dd7e94ef8aca8b67bbfe" + "reference": "fb467471952ef5cf8497c029980e556b47545333" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/7dedd5b60550f33dca16dd7e94ef8aca8b67bbfe", - "reference": "7dedd5b60550f33dca16dd7e94ef8aca8b67bbfe", + "url": "https://api.github.com/repos/symfony/process/zipball/fb467471952ef5cf8497c029980e556b47545333", + "reference": "fb467471952ef5cf8497c029980e556b47545333", "shasum": "" }, "require": { @@ -1384,7 +1361,7 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2016-02-02 13:33:15" + "time": "2016-03-23 13:11:46" }, { "name": "tedivm/jshrink", @@ -4112,16 +4089,16 @@ }, { "name": "symfony/config", - "version": "v2.8.3", + "version": "v2.8.4", "source": { "type": "git", "url": "https://github.com/symfony/config.git", - "reference": "0f8f94e6a32b5c480024eed5fa5cbd2790d0ad19" + "reference": "5273f4724dc5288fe7a33cb08077ab9852621f2c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/config/zipball/0f8f94e6a32b5c480024eed5fa5cbd2790d0ad19", - "reference": "0f8f94e6a32b5c480024eed5fa5cbd2790d0ad19", + "url": "https://api.github.com/repos/symfony/config/zipball/5273f4724dc5288fe7a33cb08077ab9852621f2c", + "reference": "5273f4724dc5288fe7a33cb08077ab9852621f2c", "shasum": "" }, "require": { @@ -4161,20 +4138,20 @@ ], "description": "Symfony Config Component", "homepage": "https://symfony.com", - "time": "2016-02-22 16:12:45" + "time": "2016-03-04 07:54:35" }, { "name": "symfony/dependency-injection", - "version": "v2.8.3", + "version": "v2.8.4", "source": { "type": "git", "url": "https://github.com/symfony/dependency-injection.git", - "reference": "62251761a7615435b22ccf562384c588b431be44" + "reference": "f7b4a498e679fa440b16facb934680a1527ed48c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/62251761a7615435b22ccf562384c588b431be44", - "reference": "62251761a7615435b22ccf562384c588b431be44", + "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/f7b4a498e679fa440b16facb934680a1527ed48c", + "reference": "f7b4a498e679fa440b16facb934680a1527ed48c", "shasum": "" }, "require": { @@ -4223,20 +4200,20 @@ ], "description": "Symfony DependencyInjection Component", "homepage": "https://symfony.com", - "time": "2016-02-28 16:34:46" + "time": "2016-03-21 07:27:21" }, { "name": "symfony/stopwatch", - "version": "v3.0.3", + "version": "v3.0.4", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "4a204804952ff267ace88cf499e0b4bb302a475e" + "reference": "6015187088421e9499d8f8316bdb396f8b806c06" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/4a204804952ff267ace88cf499e0b4bb302a475e", - "reference": "4a204804952ff267ace88cf499e0b4bb302a475e", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/6015187088421e9499d8f8316bdb396f8b806c06", + "reference": "6015187088421e9499d8f8316bdb396f8b806c06", "shasum": "" }, "require": { @@ -4272,20 +4249,20 @@ ], "description": "Symfony Stopwatch Component", "homepage": "https://symfony.com", - "time": "2016-01-03 15:35:16" + "time": "2016-03-04 07:55:57" }, { "name": "symfony/yaml", - "version": "v2.8.3", + "version": "v2.8.4", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "2a4ee40acb880c56f29fb1b8886e7ffe94f3b995" + "reference": "584e52cb8f788a887553ba82db6caacb1d6260bb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/2a4ee40acb880c56f29fb1b8886e7ffe94f3b995", - "reference": "2a4ee40acb880c56f29fb1b8886e7ffe94f3b995", + "url": "https://api.github.com/repos/symfony/yaml/zipball/584e52cb8f788a887553ba82db6caacb1d6260bb", + "reference": "584e52cb8f788a887553ba82db6caacb1d6260bb", "shasum": "" }, "require": { @@ -4321,7 +4298,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2016-02-23 07:41:20" + "time": "2016-03-04 07:54:35" }, { "name": "theseer/fdomdocument", diff --git a/dev/tests/api-functional/testsuite/Magento/Webapi/Routing/BaseService.php b/dev/tests/api-functional/testsuite/Magento/Webapi/Routing/BaseService.php index eff0dbba735f6295e4084f10bb8228f56ee04539..88d4e559e16d52967f1d452bfd95791765cd1255 100644 --- a/dev/tests/api-functional/testsuite/Magento/Webapi/Routing/BaseService.php +++ b/dev/tests/api-functional/testsuite/Magento/Webapi/Routing/BaseService.php @@ -25,7 +25,7 @@ abstract class BaseService extends \Magento\TestFramework\TestCase\WebapiAbstrac $this->_assertSoapException( $serviceInfo, $requestData, - 'SOAP-ERROR: Parsing WSDL: Couldn\'t bind to service' + 'Consumer is not authorized to access %resources' ); } elseif (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) { $this->_assertRestUnauthorizedException($serviceInfo, $requestData); @@ -111,7 +111,7 @@ abstract class BaseService extends \Magento\TestFramework\TestCase\WebapiAbstrac } if ($expectedMessage) { - $this->assertEquals($expectedMessage, $e->getMessage()); + $this->assertContains($expectedMessage, $e->getMessage()); } } } diff --git a/dev/tests/api-functional/testsuite/Magento/Webapi/Routing/SoapErrorHandlingTest.php b/dev/tests/api-functional/testsuite/Magento/Webapi/Routing/SoapErrorHandlingTest.php index c7ef1d00e02fad6a9311240065b3c32a247e2065..8cd95ef23a47e75b7915e7c114c1968833d81125 100644 --- a/dev/tests/api-functional/testsuite/Magento/Webapi/Routing/SoapErrorHandlingTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Webapi/Routing/SoapErrorHandlingTest.php @@ -110,8 +110,8 @@ class SoapErrorHandlingTest extends \Magento\TestFramework\TestCase\WebapiAbstra } catch (\SoapFault $e) { $this->checkSoapFault( $e, - 'SOAP-ERROR: Parsing WSDL: Couldn\'t bind to service', - 'WSDL' + 'Consumer is not authorized to access %resources', + 'env:Sender' ); } } diff --git a/dev/tests/api-functional/testsuite/Magento/Webapi/WsdlGenerationFromDataObjectTest.php b/dev/tests/api-functional/testsuite/Magento/Webapi/WsdlGenerationFromDataObjectTest.php index 2593e9d12f5f94c4e18f12e3f9720747994e1b56..9afdb1f26067a769726fd4d44f235d3c5958ba48 100644 --- a/dev/tests/api-functional/testsuite/Magento/Webapi/WsdlGenerationFromDataObjectTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Webapi/WsdlGenerationFromDataObjectTest.php @@ -65,6 +65,16 @@ class WsdlGenerationFromDataObjectTest extends \Magento\TestFramework\TestCase\W $this->_checkFaultsDeclaration($wsdlContent); } + public function testNoAuthorizedServices() + { + $wsdlUrl = $this->_getBaseWsdlUrl() . 'testModule5AllSoapAndRestV2'; + $connection = curl_init($wsdlUrl); + curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1); + $responseContent = curl_exec($connection); + $this->assertEquals(curl_getinfo($connection, CURLINFO_HTTP_CODE), 401); + $this->assertContains("Consumer is not authorized to access %resources", $responseContent); + } + public function testInvalidWsdlUrlNoServices() { $responseContent = $this->_getWsdlContent($this->_getBaseWsdlUrl()); diff --git a/lib/internal/Magento/Framework/Session/SaveHandler/Redis/Config.php b/lib/internal/Magento/Framework/Session/SaveHandler/Redis/Config.php index d4dce686583b060b6e98a8335bf96d9c04608598..1a23e2974f568d90c33d49067cc228f8666d6705 100644 --- a/lib/internal/Magento/Framework/Session/SaveHandler/Redis/Config.php +++ b/lib/internal/Magento/Framework/Session/SaveHandler/Redis/Config.php @@ -5,9 +5,14 @@ */ namespace Magento\Framework\Session\SaveHandler\Redis; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Store\Model\ScopeInterface as StoreScopeInterface; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\State; +/** + * Redis session save handler + */ class Config implements \Cm\RedisSession\Handler\ConfigInterface { /** @@ -95,6 +100,21 @@ class Config implements \Cm\RedisSession\Handler\ConfigInterface */ const PARAM_BREAK_AFTER = 'session/redis/break_after'; + /** + * Cookie lifetime config path + */ + const XML_PATH_COOKIE_LIFETIME = 'web/cookie/cookie_lifetime'; + + /** + * Admin session lifetime config path + */ + const XML_PATH_ADMIN_SESSION_LIFETIME = 'admin/security/session_lifetime'; + + /** + * Session max lifetime + */ + const SESSION_MAX_LIFETIME = 31536000; + /** * Deployment config * @@ -102,14 +122,24 @@ class Config implements \Cm\RedisSession\Handler\ConfigInterface */ private $deploymentConfig; + /** + * @var ScopeConfigInterface + */ + private $scopeConfig; + /** * @param DeploymentConfig $deploymentConfig * @param State $appState + * @param ScopeConfigInterface $scopeConfig */ - public function __construct(DeploymentConfig $deploymentConfig, State $appState) - { + public function __construct( + DeploymentConfig $deploymentConfig, + State $appState, + ScopeConfigInterface $scopeConfig + ) { $this->deploymentConfig = $deploymentConfig; $this->appState = $appState; + $this->scopeConfig = $scopeConfig; } /** @@ -197,7 +227,7 @@ class Config implements \Cm\RedisSession\Handler\ConfigInterface */ public function getMaxLifetime() { - return $this->deploymentConfig->get(self::PARAM_MAX_LIFETIME); + return self::SESSION_MAX_LIFETIME; } /** @@ -247,4 +277,15 @@ class Config implements \Cm\RedisSession\Handler\ConfigInterface { return $this->deploymentConfig->get(self::PARAM_BREAK_AFTER . '_' . $this->appState->getAreaCode()); } + + /** + * {@inheritdoc} + */ + public function getLifetime() + { + if ($this->appState->getAreaCode() == \Magento\Framework\App\Area::AREA_ADMINHTML) { + return (int)$this->scopeConfig->getValue(self::XML_PATH_ADMIN_SESSION_LIFETIME); + } + return (int)$this->scopeConfig->getValue(self::XML_PATH_COOKIE_LIFETIME, StoreScopeInterface::SCOPE_STORE); + } } diff --git a/lib/internal/Magento/Framework/Session/Test/Unit/SaveHandler/Redis/ConfigTest.php b/lib/internal/Magento/Framework/Session/Test/Unit/SaveHandler/Redis/ConfigTest.php index f34ef8b756d3343620ce736529a089032ca0a403..c66c31d2fcdff67dcf11b21f35cb3a26c45950db 100644 --- a/lib/internal/Magento/Framework/Session/Test/Unit/SaveHandler/Redis/ConfigTest.php +++ b/lib/internal/Magento/Framework/Session/Test/Unit/SaveHandler/Redis/ConfigTest.php @@ -5,35 +5,44 @@ */ namespace Magento\Framework\Session\Test\Unit\SaveHandler\Redis; +use Magento\Store\Model\ScopeInterface; use Magento\Framework\Session\SaveHandler\Redis\Config; class ConfigTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Framework\App\DeploymentConfig + * @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject */ - protected $deploymentConfig; + private $deploymentConfigMock; /** - * @var \Magento\Framework\App\State + * @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject */ - protected $appState; + private $appStateMock; /** - * @var \Magento\Framework\Session\SaveHandler\Redis\Config + * @var \Magento\Framework\App\Config|\PHPUnit_Framework_MockObject_MockObject */ - protected $config; + private $scopeConfigMock; + + /** + * @var Config + */ + private $config; public function setUp() { - $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); - $this->appState = $this->getMock('Magento\Framework\App\State', [], [], '', false); + $this->deploymentConfigMock = $this->getMock(\Magento\Framework\App\DeploymentConfig::class, [], [], '', false); + $this->appStateMock = $this->getMock(\Magento\Framework\App\State::class, [], [], '', false); + $this->scopeConfigMock = $this->getMock(\Magento\Framework\App\Config::class, [], [], '', false); + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->config = $objectManager->getObject( - 'Magento\Framework\Session\SaveHandler\Redis\Config', + Config::class, [ - 'deploymentConfig' => $this->deploymentConfig, - 'appState' => $this->appState + 'deploymentConfig' => $this->deploymentConfigMock, + 'appState' => $this->appStateMock, + 'scopeConfig' => $this->scopeConfigMock ] ); } @@ -41,7 +50,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase public function testGetLogLevel() { $expected = 2; - $this->deploymentConfig->expects($this->once()) + $this->deploymentConfigMock->expects($this->once()) ->method('get') ->with(Config::PARAM_LOG_LEVEL) ->willReturn($expected); @@ -51,7 +60,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase public function testGetHost() { $expected = '127.0.0.1'; - $this->deploymentConfig->expects($this->once()) + $this->deploymentConfigMock->expects($this->once()) ->method('get') ->with(Config::PARAM_HOST) ->willReturn($expected); @@ -61,7 +70,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase public function testGetPort() { $expected = 1234; - $this->deploymentConfig->expects($this->once()) + $this->deploymentConfigMock->expects($this->once()) ->method('get') ->with(Config::PARAM_PORT) ->willReturn($expected); @@ -71,7 +80,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase public function testGetDatabase() { $expected = 2; - $this->deploymentConfig->expects($this->once()) + $this->deploymentConfigMock->expects($this->once()) ->method('get') ->with(Config::PARAM_DATABASE) ->willReturn($expected); @@ -81,7 +90,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase public function testGetPassword() { $expected = 'password'; - $this->deploymentConfig->expects($this->once()) + $this->deploymentConfigMock->expects($this->once()) ->method('get') ->with(Config::PARAM_PASSWORD) ->willReturn($expected); @@ -91,7 +100,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase public function testGetTimeout() { $expected = 10; - $this->deploymentConfig->expects($this->once()) + $this->deploymentConfigMock->expects($this->once()) ->method('get') ->with(Config::PARAM_TIMEOUT) ->willReturn($expected); @@ -101,7 +110,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase public function testGetPersistentIdentifier() { $expected = 'sess01'; - $this->deploymentConfig->expects($this->once()) + $this->deploymentConfigMock->expects($this->once()) ->method('get') ->with(Config::PARAM_PERSISTENT_IDENTIFIER) ->willReturn($expected); @@ -111,7 +120,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase public function testGetCompressionThreshold() { $expected = 2; - $this->deploymentConfig->expects($this->once()) + $this->deploymentConfigMock->expects($this->once()) ->method('get') ->with(Config::PARAM_COMPRESSION_THRESHOLD) ->willReturn($expected); @@ -121,7 +130,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase public function testGetCompressionLibrary() { $expected = 'gzip'; - $this->deploymentConfig->expects($this->once()) + $this->deploymentConfigMock->expects($this->once()) ->method('get') ->with(Config::PARAM_COMPRESSION_LIBRARY) ->willReturn($expected); @@ -131,7 +140,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase public function testGetMaxConcurrency() { $expected = 6; - $this->deploymentConfig->expects($this->once()) + $this->deploymentConfigMock->expects($this->once()) ->method('get') ->with(Config::PARAM_MAX_CONCURRENCY) ->willReturn($expected); @@ -140,18 +149,13 @@ class ConfigTest extends \PHPUnit_Framework_TestCase public function testGetMaxLifetime() { - $expected = 30; - $this->deploymentConfig->expects($this->once()) - ->method('get') - ->with(Config::PARAM_MAX_LIFETIME) - ->willReturn($expected); - $this->assertEquals($this->config->getMaxLifetime(), $expected); + $this->assertEquals($this->config->getMaxLifetime(), Config::SESSION_MAX_LIFETIME); } public function testGetMinLifetime() { $expected = 30; - $this->deploymentConfig->expects($this->once()) + $this->deploymentConfigMock->expects($this->once()) ->method('get') ->with(Config::PARAM_MIN_LIFETIME) ->willReturn($expected); @@ -161,7 +165,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase public function testGetDisableLocking() { $expected = false; - $this->deploymentConfig->expects($this->once()) + $this->deploymentConfigMock->expects($this->once()) ->method('get') ->with(Config::PARAM_DISABLE_LOCKING) ->willReturn($expected); @@ -171,7 +175,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase public function testGetBotLifetime() { $expected = 30; - $this->deploymentConfig->expects($this->once()) + $this->deploymentConfigMock->expects($this->once()) ->method('get') ->with(Config::PARAM_BOT_LIFETIME) ->willReturn($expected); @@ -181,7 +185,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase public function testGetBotFirstLifetime() { $expected = 30; - $this->deploymentConfig->expects($this->once()) + $this->deploymentConfigMock->expects($this->once()) ->method('get') ->with(Config::PARAM_BOT_FIRST_LIFETIME) ->willReturn($expected); @@ -191,7 +195,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase public function testGetFirstLifetime() { $expected = 30; - $this->deploymentConfig->expects($this->once()) + $this->deploymentConfigMock->expects($this->once()) ->method('get') ->with(Config::PARAM_FIRST_LIFETIME) ->willReturn($expected); @@ -202,13 +206,44 @@ class ConfigTest extends \PHPUnit_Framework_TestCase { $areaCode = 'frontend'; $breakAfter = 5; - $this->deploymentConfig->expects($this->once()) + $this->deploymentConfigMock->expects($this->once()) ->method('get') ->with(Config::PARAM_BREAK_AFTER . '_' . $areaCode) ->willReturn($breakAfter); - $this->appState->expects($this->once()) + $this->appStateMock->expects($this->once()) ->method('getAreaCode') ->willReturn($areaCode); $this->assertEquals($this->config->getBreakAfter(), $breakAfter); } + + public function testGetLifetimeAdmin() + { + $areaCode = 'adminhtml'; + $expectedLifetime = 123; + $this->appStateMock->expects($this->once()) + ->method('getAreaCode') + ->willReturn($areaCode); + $this->scopeConfigMock->expects($this->once()) + ->method('getValue') + ->with(Config::XML_PATH_ADMIN_SESSION_LIFETIME) + ->willReturn($expectedLifetime); + $this->assertEquals($this->config->getLifetime(), $expectedLifetime); + } + + public function testGetLifetimeFrontend() + { + $areaCode = 'frontend'; + $expectedLifetime = 234; + $this->appStateMock->expects($this->once()) + ->method('getAreaCode') + ->willReturn($areaCode); + $this->scopeConfigMock->expects($this->once()) + ->method('getValue') + ->with( + Config::XML_PATH_COOKIE_LIFETIME, + ScopeInterface::SCOPE_STORE + ) + ->willReturn($expectedLifetime); + $this->assertEquals($this->config->getLifetime(), $expectedLifetime); + } } diff --git a/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php b/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php index bad169e114754ee24dd850c636b2f27b3e9e76d0..ee5a42069fb0cca56c7bac2065ec7f3ac6607182 100644 --- a/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php +++ b/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php @@ -6,7 +6,7 @@ namespace Magento\Setup\Module\Di\Code\Reader; use Magento\Framework\Exception\FileSystemException; -use Zend\Code\Scanner\FileScanner; +use Magento\Setup\Module\Di\Code\Reader\FileScanner; class ClassesScanner implements ClassesScannerInterface { diff --git a/setup/src/Magento/Setup/Module/Di/Code/Reader/FileScanner.php b/setup/src/Magento/Setup/Module/Di/Code/Reader/FileScanner.php new file mode 100644 index 0000000000000000000000000000000000000000..5293b782064242a571cb7580835abb6586d2a454 --- /dev/null +++ b/setup/src/Magento/Setup/Module/Di/Code/Reader/FileScanner.php @@ -0,0 +1,367 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +// @codingStandardsIgnoreFile + +namespace Magento\Setup\Module\Di\Code\Reader; + +/** + * @SuppressWarnings(PHPMD) + */ +class FileScanner extends \Zend\Code\Scanner\FileScanner +{ + /** + * @var int + */ + private $tokenType; + + /** + * {@inheritdoc} + */ + protected function scan() + { + if ($this->isScanned) { + return; + } + + if (!$this->tokens) { + throw new \Zend\Code\Exception\RuntimeException('No tokens were provided'); + } + + /** + * Define PHP 5.4 'trait' token constant. + */ + if (!defined('T_TRAIT')) { + define('T_TRAIT', 42001); + } + + /** + * Variables & Setup + */ + + $tokens = &$this->tokens; // localize + $infos = &$this->infos; // localize + $tokenIndex = null; + $token = null; + $this->tokenType = null; + $tokenContent = null; + $tokenLine = null; + $namespace = null; + $docCommentIndex = false; + $infoIndex = 0; + + /* + * MACRO creation + */ + $MACRO_TOKEN_ADVANCE = function () use (&$tokens, &$tokenIndex, &$token, &$tokenContent, &$tokenLine) { + $tokenIndex = ($tokenIndex === null) ? 0 : $tokenIndex + 1; + if (!isset($tokens[$tokenIndex])) { + $token = false; + $tokenContent = false; + $this->tokenType = false; + $tokenLine = false; + + return false; + } + if (is_string($tokens[$tokenIndex]) && $tokens[$tokenIndex] === '"') { + do { + $tokenIndex++; + } while (!(is_string($tokens[$tokenIndex]) && $tokens[$tokenIndex] === '"')); + } + $token = $tokens[$tokenIndex]; + if (is_array($token)) { + list($this->tokenType, $tokenContent, $tokenLine) = $token; + } else { + $this->tokenType = null; + $tokenContent = $token; + } + + return $tokenIndex; + }; + $MACRO_TOKEN_LOGICAL_START_INDEX = function () use (&$tokenIndex, &$docCommentIndex) { + return ($docCommentIndex === false) ? $tokenIndex : $docCommentIndex; + }; + $MACRO_DOC_COMMENT_START = function () use (&$tokenIndex, &$docCommentIndex) { + $docCommentIndex = $tokenIndex; + + return $docCommentIndex; + }; + $MACRO_DOC_COMMENT_VALIDATE = function () use (&$docCommentIndex) { + static $validTrailingTokens = null; + if ($validTrailingTokens === null) { + $validTrailingTokens = array(T_WHITESPACE, T_FINAL, T_ABSTRACT, T_INTERFACE, T_CLASS, T_FUNCTION); + } + if ($docCommentIndex !== false && !in_array($this->tokenType, $validTrailingTokens)) { + $docCommentIndex = false; + } + + return $docCommentIndex; + }; + $MACRO_INFO_ADVANCE = function () use (&$infoIndex, &$infos, &$tokenIndex, &$tokenLine) { + $infos[$infoIndex]['tokenEnd'] = $tokenIndex; + $infos[$infoIndex]['lineEnd'] = $tokenLine; + $infoIndex++; + + return $infoIndex; + }; + + /** + * START FINITE STATE MACHINE FOR SCANNING TOKENS + */ + + // Initialize token + $MACRO_TOKEN_ADVANCE(); + + SCANNER_TOP: + + if ($token === false) { + goto SCANNER_END; + } + + // Validate current doc comment index + $MACRO_DOC_COMMENT_VALIDATE(); + + switch ($this->tokenType) { + + case T_DOC_COMMENT: + + $MACRO_DOC_COMMENT_START(); + goto SCANNER_CONTINUE; + //goto no break needed + + case T_NAMESPACE: + + $infos[$infoIndex] = array( + 'type' => 'namespace', + 'tokenStart' => $MACRO_TOKEN_LOGICAL_START_INDEX(), + 'tokenEnd' => null, + 'lineStart' => $token[2], + 'lineEnd' => null, + 'namespace' => null, + ); + + // start processing with next token + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + + SCANNER_NAMESPACE_TOP: + + if ($this->tokenType === null && $tokenContent === ';' || $tokenContent === '{') { + goto SCANNER_NAMESPACE_END; + } + + if ($this->tokenType === T_WHITESPACE) { + goto SCANNER_NAMESPACE_CONTINUE; + } + + if ($this->tokenType === T_NS_SEPARATOR || $this->tokenType === T_STRING) { + $infos[$infoIndex]['namespace'] .= $tokenContent; + } + + SCANNER_NAMESPACE_CONTINUE: + + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + goto SCANNER_NAMESPACE_TOP; + + SCANNER_NAMESPACE_END: + + $namespace = $infos[$infoIndex]['namespace']; + + $MACRO_INFO_ADVANCE(); + goto SCANNER_CONTINUE; + //goto no break needed + + case T_USE: + + $infos[$infoIndex] = array( + 'type' => 'use', + 'tokenStart' => $MACRO_TOKEN_LOGICAL_START_INDEX(), + 'tokenEnd' => null, + 'lineStart' => $tokens[$tokenIndex][2], + 'lineEnd' => null, + 'namespace' => $namespace, + 'statements' => array(0 => array('use' => null, + 'as' => null)), + ); + + $useStatementIndex = 0; + $useAsContext = false; + + // start processing with next token + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + + SCANNER_USE_TOP: + + if ($this->tokenType === null) { + if ($tokenContent === ';') { + goto SCANNER_USE_END; + } elseif ($tokenContent === ',') { + $useAsContext = false; + $useStatementIndex++; + $infos[$infoIndex]['statements'][$useStatementIndex] = array('use' => null, + 'as' => null); + } + } + + // ANALYZE + if ($this->tokenType !== null) { + if ($this->tokenType == T_AS) { + $useAsContext = true; + goto SCANNER_USE_CONTINUE; + } + + if ($this->tokenType == T_NS_SEPARATOR || $this->tokenType == T_STRING) { + if ($useAsContext == false) { + $infos[$infoIndex]['statements'][$useStatementIndex]['use'] .= $tokenContent; + } else { + $infos[$infoIndex]['statements'][$useStatementIndex]['as'] = $tokenContent; + } + } + } + + SCANNER_USE_CONTINUE: + + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + goto SCANNER_USE_TOP; + + SCANNER_USE_END: + + $MACRO_INFO_ADVANCE(); + goto SCANNER_CONTINUE; + //goto no break needed + + case T_INCLUDE: + case T_INCLUDE_ONCE: + case T_REQUIRE: + case T_REQUIRE_ONCE: + + // Static for performance + static $includeTypes = array( + T_INCLUDE => 'include', + T_INCLUDE_ONCE => 'include_once', + T_REQUIRE => 'require', + T_REQUIRE_ONCE => 'require_once' + ); + + $infos[$infoIndex] = array( + 'type' => 'include', + 'tokenStart' => $MACRO_TOKEN_LOGICAL_START_INDEX(), + 'tokenEnd' => null, + 'lineStart' => $tokens[$tokenIndex][2], + 'lineEnd' => null, + 'includeType' => $includeTypes[$tokens[$tokenIndex][0]], + 'path' => '', + ); + + // start processing with next token + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + + SCANNER_INCLUDE_TOP: + + if ($this->tokenType === null && $tokenContent === ';') { + goto SCANNER_INCLUDE_END; + } + + $infos[$infoIndex]['path'] .= $tokenContent; + + SCANNER_INCLUDE_CONTINUE: + + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + goto SCANNER_INCLUDE_TOP; + + SCANNER_INCLUDE_END: + + $MACRO_INFO_ADVANCE(); + goto SCANNER_CONTINUE; + //goto no break needed + + case T_FUNCTION: + case T_FINAL: + case T_ABSTRACT: + case T_CLASS: + case T_INTERFACE: + case T_TRAIT: + + $infos[$infoIndex] = array( + 'type' => ($this->tokenType === T_FUNCTION) ? 'function' : 'class', + 'tokenStart' => $MACRO_TOKEN_LOGICAL_START_INDEX(), + 'tokenEnd' => null, + 'lineStart' => $tokens[$tokenIndex][2], + 'lineEnd' => null, + 'namespace' => $namespace, + 'uses' => $this->getUsesNoScan($namespace), + 'name' => null, + 'shortName' => null, + ); + + $classBraceCount = 0; + + // start processing with current token + + SCANNER_CLASS_TOP: + + // process the name + if ($infos[$infoIndex]['shortName'] == '' + && (($this->tokenType === T_CLASS || $this->tokenType === T_INTERFACE || $this->tokenType === T_TRAIT) && $infos[$infoIndex]['type'] === 'class' + || ($this->tokenType === T_FUNCTION && $infos[$infoIndex]['type'] === 'function')) + ) { + $infos[$infoIndex]['shortName'] = $tokens[$tokenIndex + 2][1]; + $infos[$infoIndex]['name'] = (($namespace !== null) ? $namespace . '\\' : '') . $infos[$infoIndex]['shortName']; + } + + if ($this->tokenType === null) { + if ($tokenContent == '{') { + $classBraceCount++; + } + if ($tokenContent == '}') { + $classBraceCount--; + if ($classBraceCount === 0) { + goto SCANNER_CLASS_END; + } + } + } + + SCANNER_CLASS_CONTINUE: + + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + goto SCANNER_CLASS_TOP; + + SCANNER_CLASS_END: + + $MACRO_INFO_ADVANCE(); + goto SCANNER_CONTINUE; + + } + + SCANNER_CONTINUE: + + if ($MACRO_TOKEN_ADVANCE() === false) { + goto SCANNER_END; + } + goto SCANNER_TOP; + + SCANNER_END: + + /** + * END FINITE STATE MACHINE FOR SCANNING TOKENS + */ + + $this->isScanned = true; + } +} \ No newline at end of file diff --git a/setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php b/setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php index 135e03ae69b800d593bf6c0592f7454c7b9f1da2..2d98bc58f789ad4b8476fa057e615c27d7093253 100644 --- a/setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php +++ b/setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php @@ -123,16 +123,20 @@ class InitParamListener implements ListenerAggregateInterface, FactoryInterface /** @var \Magento\Framework\App\State $adminAppState */ $adminAppState = $objectManager->get('Magento\Framework\App\State'); $adminAppState->setAreaCode(\Magento\Framework\App\Area::AREA_ADMIN); + /** @var \Magento\Backend\Model\Session\AdminConfig $sessionConfig */ + $sessionConfig = $objectManager->get(\Magento\Backend\Model\Session\AdminConfig::class); + $cookiePath = $this->getSetupCookiePath($objectManager); + $sessionConfig->setCookiePath($cookiePath); /** @var \Magento\Backend\Model\Auth\Session $adminSession */ $adminSession = $objectManager->create( \Magento\Backend\Model\Auth\Session::class, [ - 'sessionConfig' => $objectManager->get(\Magento\Backend\Model\Session\AdminConfig::class), + 'sessionConfig' => $sessionConfig, 'appState' => $adminAppState ] ); if (!$objectManager->get(\Magento\Backend\Model\Auth::class)->isLoggedIn()) { - $adminSession->expireSessionCookie(); + $adminSession->destroy(); $response = $event->getResponse(); $response->getHeaders()->addHeaderLine('Location', 'index.php/session/unlogin'); $response->setStatusCode(302); @@ -145,6 +149,25 @@ class InitParamListener implements ListenerAggregateInterface, FactoryInterface return false; } + /** + * Get cookie path + * + * @param \Magento\Framework\ObjectManagerInterface $objectManager + * @return string + */ + private function getSetupCookiePath(\Magento\Framework\ObjectManagerInterface $objectManager) + { + /** @var \Magento\Backend\App\BackendAppList $backendAppList */ + $backendAppList = $objectManager->get(\Magento\Backend\App\BackendAppList::class); + $backendApp = $backendAppList->getBackendApp('setup'); + /** @var \Magento\Backend\Model\UrlFactory $backendUrlFactory */ + $backendUrlFactory = $objectManager->get(\Magento\Backend\Model\UrlFactory::class); + $baseUrl = parse_url($backendUrlFactory->create()->getBaseUrl(), PHP_URL_PATH); + $baseUrl = \Magento\Framework\App\Request\Http::getUrlNoScript($baseUrl); + $cookiePath = $baseUrl . $backendApp->getCookiePath(); + return $cookiePath; + } + /** * {@inheritdoc} */