Skip to content

Commit caf4ad4

Browse files
committed
AC-6049: Filtering inputs handler in page_cache/block controller
* Unit test fixes
1 parent 0925f36 commit caf4ad4

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

app/code/Magento/PageCache/Controller/Block.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private function validateHandleParam($handles): bool
125125
{
126126
$validator = $this->regexValidatorFactory->create(['pattern' => self::VALIDATION_RULE_PATTERN]);
127127
foreach ($handles as $handle) {
128-
if (!$validator->isValid($handle)) {
128+
if ($handle && !$validator->isValid($handle)) {
129129
return false;
130130
}
131131
}

app/code/Magento/PageCache/Test/Unit/Controller/Block/EsiTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Magento\Framework\View\Element\AbstractBlock;
1919
use Magento\Framework\View\Layout;
2020
use Magento\Framework\View\Layout\LayoutCacheKeyInterface;
21+
use Magento\Framework\Validator\Regex;
22+
use Magento\Framework\Validator\RegexFactory;
2123
use Magento\PageCache\Controller\Block;
2224
use Magento\PageCache\Controller\Block\Esi;
2325
use Magento\PageCache\Test\Unit\Block\Controller\StubBlock;
@@ -98,6 +100,16 @@ protected function setUp(): void
98100

99101
$this->translateInline = $this->getMockForAbstractClass(InlineInterface::class);
100102

103+
$regexFactoryMock = $this->getMockBuilder(RegexFactory::class)
104+
->disableOriginalConstructor()
105+
->setMethods(['create'])
106+
->getMock();
107+
108+
$regexObject = new Regex('/^[a-z]+[a-z0-9_]*$/i');
109+
110+
$regexFactoryMock->expects($this->any())->method('create')
111+
->willReturn($regexObject);
112+
101113
$helperObjectManager = new ObjectManager($this);
102114
$this->action = $helperObjectManager->getObject(
103115
Esi::class,
@@ -106,7 +118,8 @@ protected function setUp(): void
106118
'translateInline' => $this->translateInline,
107119
'jsonSerializer' => new Json(),
108120
'base64jsonSerializer' => new Base64Json(),
109-
'layoutCacheKey' => $this->layoutCacheKeyMock
121+
'layoutCacheKey' => $this->layoutCacheKeyMock,
122+
'regexValidatorFactory' => $regexFactoryMock
110123
]
111124
);
112125
}

app/code/Magento/PageCache/Test/Unit/Controller/Block/RenderTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Magento\Framework\View\Layout;
1919
use Magento\Framework\View\Layout\LayoutCacheKeyInterface;
2020
use Magento\Framework\View\Layout\ProcessorInterface;
21+
use Magento\Framework\Validator\Regex;
22+
use Magento\Framework\Validator\RegexFactory;
2123
use Magento\PageCache\Controller\Block;
2224
use Magento\PageCache\Controller\Block\Render;
2325
use Magento\PageCache\Test\Unit\Block\Controller\StubBlock;
@@ -111,6 +113,16 @@ protected function setUp(): void
111113

112114
$this->translateInline = $this->getMockForAbstractClass(InlineInterface::class);
113115

116+
$regexFactoryMock = $this->getMockBuilder(RegexFactory::class)
117+
->disableOriginalConstructor()
118+
->setMethods(['create'])
119+
->getMock();
120+
121+
$regexObject = new Regex('/^[a-z]+[a-z0-9_]*$/i');
122+
123+
$regexFactoryMock->expects($this->any())->method('create')
124+
->willReturn($regexObject);
125+
114126
$helperObjectManager = new ObjectManager($this);
115127
$this->action = $helperObjectManager->getObject(
116128
Render::class,
@@ -119,7 +131,8 @@ protected function setUp(): void
119131
'translateInline' => $this->translateInline,
120132
'jsonSerializer' => new Json(),
121133
'base64jsonSerializer' => new Base64Json(),
122-
'layoutCacheKey' => $this->layoutCacheKeyMock
134+
'layoutCacheKey' => $this->layoutCacheKeyMock,
135+
'regexValidatorFactory' => $regexFactoryMock
123136
]
124137
);
125138
}

0 commit comments

Comments
 (0)