public function testSessionUrlVarWithoutMatchedHostsAndBaseUrl() { $requestMock = $this->getRequestMock(); $model = $this->getUrlModel( [ 'session' => $this->sessionMock, 'request' => $requestMock, 'sidResolver' => $this->sidResolverMock, 'scopeResolver' => $this->scopeResolverMock, 'routeParamsResolverFactory' => $this->getRouteParamsResolverFactory(), ] ); $requestMock->expects($this->once())->method('getHttpHost')->will($this->returnValue('localhost')); $this->scopeMock->expects($this->once()) ->method('getBaseUrl') ->will($this->returnValue('http://example.com')); $this->scopeResolverMock->expects($this->any()) ->method('getScope') ->will($this->returnValue($this->scopeMock)); $this->sidResolverMock->expects($this->once())->method('getSessionIdQueryParam') ->will($this->returnValue('SID')); $this->sessionMock->expects($this->once())->method('getSessionId') ->will($this->returnValue('session-id')); $this->assertEquals( '<a href="http://example.com/?SID=session-id">www.example.com</a>', $model->sessionUrlVar('<a href="http://example.com/?___SID=U">www.example.com</a>') ); }
/** * Init merge model * * @param \Magento\Framework\View\DesignInterface $design * @param \Magento\Framework\Url\ScopeResolverInterface $scopeResolver * @param \Magento\Framework\View\File\CollectorInterface $fileSource * @param \Magento\Framework\View\File\CollectorInterface $pageLayoutFileSource * @param \Magento\Framework\App\State $appState * @param \Magento\Framework\Cache\FrontendInterface $cache * @param \Magento\Framework\View\Model\Layout\Update\Validator $validator * @param \Psr\Log\LoggerInterface $logger * @param \Magento\Framework\Filesystem $filesystem * @param \Magento\Framework\View\Design\ThemeInterface $theme Non-injectable theme instance * @param string $cacheSuffix * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct(\Magento\Framework\View\DesignInterface $design, \Magento\Framework\Url\ScopeResolverInterface $scopeResolver, \Magento\Framework\View\File\CollectorInterface $fileSource, \Magento\Framework\View\File\CollectorInterface $pageLayoutFileSource, \Magento\Framework\App\State $appState, \Magento\Framework\Cache\FrontendInterface $cache, \Magento\Framework\View\Model\Layout\Update\Validator $validator, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\View\Design\ThemeInterface $theme = null, $cacheSuffix = '') { $this->theme = $theme ?: $design->getDesignTheme(); $this->scope = $scopeResolver->getScope(); $this->fileSource = $fileSource; $this->pageLayoutFileSource = $pageLayoutFileSource; $this->appState = $appState; $this->cache = $cache; $this->layoutValidator = $validator; $this->logger = $logger; $this->filesystem = $filesystem; $this->cacheSuffix = $cacheSuffix; }
/** * Check if users originated URL is one of the domain URLs assigned to scopes * * @return boolean */ public function isOwnOriginUrl() { $scopeDomains = []; $referer = parse_url($this->_request->getServer('HTTP_REFERER'), PHP_URL_HOST); foreach ($this->_scopeResolver->getScopes() as $scope) { $scopeDomains[] = parse_url($scope->getBaseUrl(), PHP_URL_HOST); $scopeDomains[] = parse_url($scope->getBaseUrl(UrlInterface::URL_TYPE_LINK, true), PHP_URL_HOST); } $scopeDomains = array_unique($scopeDomains); if (empty($referer) || in_array($referer, $scopeDomains)) { return true; } return false; }