Skip to content

Commit 5d6dd2a

Browse files
committed
MAGETWO-97947: Invalid action behavior
1 parent a998b71 commit 5d6dd2a

File tree

5 files changed

+36
-20
lines changed

5 files changed

+36
-20
lines changed

app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/DeleteFolder.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Cms\Controller\Adminhtml\Wysiwyg\Images;
88

99
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\Exception\NotFoundException;
1011

1112
/**
1213
* Delete image folder.
@@ -57,11 +58,11 @@ public function __construct(
5758
*/
5859
public function execute()
5960
{
60-
try {
61-
if (!$this->getRequest()->isPost()) {
62-
throw new \Exception('Wrong request.');
63-
}
61+
if (!$this->getRequest()->isPost()) {
62+
throw new NotFoundException(__('Page not found'));
63+
}
6464

65+
try {
6566
$path = $this->getStorage()->getCmsWysiwygImages()->getCurrentPath();
6667
if (!$this->directoryResolver->validatePath($path, DirectoryList::MEDIA)) {
6768
throw new \Magento\Framework\Exception\LocalizedException(

app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/NewFolder.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Cms\Controller\Adminhtml\Wysiwyg\Images;
88

99
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\Exception\NotFoundException;
1011

1112
/**
1213
* Creates new folder.
@@ -49,11 +50,11 @@ public function __construct(
4950
*/
5051
public function execute()
5152
{
52-
try {
53-
if (!$this->getRequest()->isPost()) {
54-
throw new \Exception('Wrong request.');
55-
}
53+
if (!$this->getRequest()->isPost()) {
54+
throw new NotFoundException(__('Page not found'));
55+
}
5656

57+
try {
5758
$this->_initAction();
5859
$name = $this->getRequest()->getPost('name');
5960
$path = $this->getStorage()->getSession()->getCurrentPath();

app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/CancelTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ protected function setUp()
103103
\Magento\Sales\Controller\Adminhtml\Order\Cancel::class,
104104
[
105105
'context' => $this->context,
106-
//'request' => $this->request,
107-
//'response' => $this->response,
108106
'orderRepository' => $this->orderRepositoryMock
109107
]
110108
);

app/code/Magento/Widget/Controller/Adminhtml/Widget/BuildWidget.php

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77
namespace Magento\Widget\Controller\Adminhtml\Widget;
88

9+
use Magento\Framework\App\ObjectManager;
10+
911
class BuildWidget extends \Magento\Backend\App\Action
1012
{
1113
/**
@@ -18,15 +20,25 @@ class BuildWidget extends \Magento\Backend\App\Action
1820
*/
1921
protected $_widget;
2022

23+
/**
24+
* @var \Magento\Framework\Serialize\SerializerInterface
25+
*/
26+
private $serializer;
27+
2128
/**
2229
* @param \Magento\Backend\App\Action\Context $context
2330
* @param \Magento\Widget\Model\Widget $widget
31+
* @param \Magento\Framework\Serialize\SerializerInterface|null $serializer
2432
*/
2533
public function __construct(
2634
\Magento\Backend\App\Action\Context $context,
27-
\Magento\Widget\Model\Widget $widget
35+
\Magento\Widget\Model\Widget $widget,
36+
\Magento\Framework\Serialize\SerializerInterface $serializer = null
2837
) {
2938
$this->_widget = $widget;
39+
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(
40+
\Magento\Framework\Serialize\SerializerInterface::class
41+
);
3042
parent::__construct($context);
3143
}
3244

@@ -37,13 +49,17 @@ public function __construct(
3749
*/
3850
public function execute()
3951
{
40-
$html = '';
41-
if ($this->getRequest()->isPost()) {
42-
$type = $this->getRequest()->getPost('widget_type');
43-
$params = $this->getRequest()->getPost('parameters', []);
44-
$asIs = $this->getRequest()->getPost('as_is');
45-
$html = $this->_widget->getWidgetDeclaration($type, $params, $asIs);
52+
if (!$this->getRequest()->isPost()) {
53+
$this->getResponse()->representJson(
54+
$this->serializer->serialize(['error' => true, 'message' => 'Invalid request'])
55+
);
56+
return;
4657
}
58+
59+
$type = $this->getRequest()->getPost('widget_type');
60+
$params = $this->getRequest()->getPost('parameters', []);
61+
$asIs = $this->getRequest()->getPost('as_is');
62+
$html = $this->_widget->getWidgetDeclaration($type, $params, $asIs);
4763
$this->getResponse()->setBody($html);
4864
}
4965
}

dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/GroupTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function testNewActionWithCustomerGroupDataInSession()
8686
*/
8787
public function testDeleteActionNoGroupId()
8888
{
89-
$this->getRequest()->setMethod(\Magento\Framework\App\Request\Http::METHOD_POST);
89+
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
9090
$this->dispatch('backend/customer/group/delete');
9191
$this->assertRedirect($this->stringStartsWith(self::BASE_CONTROLLER_URL));
9292
}
@@ -100,7 +100,7 @@ public function testDeleteActionExistingGroup()
100100
{
101101
$groupId = $this->findGroupIdWithCode(self::CUSTOMER_GROUP_CODE);
102102
$this->getRequest()->setParam('id', $groupId);
103-
$this->getRequest()->setMethod(\Magento\Framework\App\Request\Http::METHOD_POST);
103+
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
104104
$this->dispatch('backend/customer/group/delete');
105105

106106
/**
@@ -121,7 +121,7 @@ public function testDeleteActionExistingGroup()
121121
public function testDeleteActionNonExistingGroupId()
122122
{
123123
$this->getRequest()->setParam('id', 10000);
124-
$this->getRequest()->setMethod(\Magento\Framework\App\Request\Http::METHOD_POST);
124+
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
125125
$this->dispatch('backend/customer/group/delete');
126126

127127
/**

0 commit comments

Comments
 (0)