Skip to content

Commit 4d0ae3d

Browse files
Pooja.ManralPooja.Manral
authored andcommitted
AC-11729::Magento_GraphQl execute headers processing even if the header value does not pass validation
1 parent 83a12d6 commit 4d0ae3d

File tree

2 files changed

+128
-3
lines changed
  • app/code/Magento/GraphQlCache/Controller/Plugin
  • dev/tests/api-functional/testsuite/Magento/GraphQl/GraphQlCache

2 files changed

+128
-3
lines changed

app/code/Magento/GraphQlCache/Controller/Plugin/GraphQl.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ public function beforeDispatch(
9898
): void {
9999
try {
100100
$this->requestProcessor->validateRequest($request);
101+
/** @var \Magento\Framework\App\Request\Http $request */
102+
$this->requestProcessor->processHeaders($request);
103+
$this->request = $request;
101104
} catch (\Exception $error) {
102105
$this->logger->critical($error->getMessage());
103106
}
104-
/** @var \Magento\Framework\App\Request\Http $request */
105-
$this->requestProcessor->processHeaders($request);
106-
$this->request = $request;
107107
}
108108

109109
/**

dev/tests/api-functional/testsuite/Magento/GraphQl/GraphQlCache/GraphQlTest.php

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,106 @@
88
namespace Magento\GraphQl\GraphQlCache;
99

1010
use Magento\Customer\Test\Fixture\Customer;
11+
use Magento\Framework\App\RequestInterface;
12+
use Magento\Framework\Registry;
1113
use Magento\TestFramework\Fixture\DataFixture;
1214
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
1315
use Magento\TestFramework\TestCase\GraphQlAbstract;
16+
use Magento\Framework\App\FrontControllerInterface;
17+
use Magento\Framework\App\Request\Http;
18+
use Magento\Framework\App\Response\Http as ResponseHttp;
19+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
20+
use Magento\GraphQl\Controller\HttpRequestProcessor;
21+
use Magento\GraphQlCache\Controller\Plugin\GraphQl;
22+
use Magento\GraphQlCache\Model\CacheableQuery;
23+
use Magento\GraphQlCache\Model\CacheId\CacheIdCalculator;
24+
use Magento\PageCache\Model\Config;
25+
use PHPUnit\Framework\MockObject\MockObject;
26+
use PHPUnit\Framework\TestCase;
27+
use Psr\Log\LoggerInterface;
28+
1429

1530
class GraphQlTest extends GraphQlAbstract
1631
{
32+
33+
/**
34+
* @var GraphQl
35+
*/
36+
private $graphql;
37+
38+
/**
39+
* @var CacheableQuery|MockObject
40+
*/
41+
private $cacheableQueryMock;
42+
43+
/**
44+
* @var Config|MockObject
45+
*/
46+
private $configMock;
47+
48+
/**
49+
* @var ResponseHttp|MockObject
50+
*/
51+
private $responseMock;
52+
53+
/**
54+
* @var HttpRequestProcessor|MockObject
55+
*/
56+
private $requestProcessorMock;
57+
58+
/**
59+
* @var CacheIdCalculator|MockObject
60+
*/
61+
private $cacheIdCalculatorMock;
62+
63+
/**
64+
* @var LoggerInterface|MockObject
65+
*/
66+
private $loggerMock;
67+
68+
/**
69+
* @var FrontControllerInterface|MockObject
70+
*/
71+
private $subjectMock;
72+
73+
/**
74+
* @var Http|MockObject
75+
*/
76+
private $requestMock;
77+
78+
/**
79+
* @var Registry
80+
*/
81+
private $registryMock;
82+
83+
protected function setUp(): void
84+
{
85+
$this->cacheableQueryMock = $this->createMock(CacheableQuery::class);
86+
$this->cacheIdCalculatorMock = $this->createMock(CacheIdCalculator::class);
87+
$this->configMock = $this->createMock(Config::class);
88+
$this->loggerMock = $this->getMockBuilder(LoggerInterface::class)
89+
->onlyMethods(['critical'])
90+
->disableOriginalConstructor()
91+
->getMockForAbstractClass();
92+
$this->requestProcessorMock = $this->getMockBuilder(HttpRequestProcessor::class)
93+
->onlyMethods(['validateRequest','processHeaders'])
94+
->disableOriginalConstructor()
95+
->getMockForAbstractClass();
96+
$this->registryMock = $this->createMock(Registry::class);
97+
$this->subjectMock = $this->createMock(FrontControllerInterface::class);
98+
$this->requestMock = $this
99+
->getMockBuilder(Http::class)
100+
->disableOriginalConstructor()
101+
->getMockForAbstractClass();
102+
$this->graphql = new GraphQl(
103+
$this->cacheableQueryMock,
104+
$this->cacheIdCalculatorMock,
105+
$this->configMock,
106+
$this->loggerMock,
107+
$this->requestProcessorMock,
108+
$this->registryMock
109+
);
110+
}
17111
#[
18112
DataFixture(Customer::class, as: 'customer'),
19113
]
@@ -40,4 +134,35 @@ public function testMutation(): void
40134
$tokenResponse['headers']['Cache-Control']
41135
);
42136
}
137+
138+
public function testBeforeDispatch(): void
139+
{
140+
$this->requestProcessorMock
141+
->expects($this->once())
142+
->method('validateRequest');
143+
$this->requestProcessorMock
144+
->expects($this->once())
145+
->method('processHeaders');
146+
$this->loggerMock
147+
->expects($this->never())
148+
->method('critical');
149+
$this->assertNull($this->graphql->beforeDispatch($this->subjectMock, $this->requestMock));
150+
}
151+
152+
public function testBeforeDispatchForException(): void
153+
{
154+
$this->requestProcessorMock
155+
->expects($this->once())
156+
->method('validateRequest')
157+
->willThrowException(new \Exception('Invalid Headers'));
158+
$this->requestProcessorMock
159+
->expects($this->never())
160+
->method('processHeaders');
161+
$this->loggerMock
162+
->expects($this->once())
163+
->method('critical');
164+
$this->assertNull($this->graphql->beforeDispatch($this->subjectMock, $this->requestMock));
165+
}
166+
167+
43168
}

0 commit comments

Comments
 (0)