Skip to content

Commit 06f406e

Browse files
authored
ENGCOM-7611: #7213 prevent pointless session start in webapi scope #26032
2 parents 407f464 + d1124d9 commit 06f406e

File tree

6 files changed

+86
-5
lines changed

6 files changed

+86
-5
lines changed

app/code/Magento/Customer/etc/webapi_rest/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<arguments>
1414
<argument name="userContexts" xsi:type="array">
1515
<item name="customerSessionUserContext" xsi:type="array">
16-
<item name="type" xsi:type="object">Magento\Customer\Model\Authorization\CustomerSessionUserContext</item>
16+
<item name="type" xsi:type="object">Magento\Customer\Model\Authorization\CustomerSessionUserContext\Proxy</item>
1717
<item name="sortOrder" xsi:type="string">20</item>
1818
</item>
1919
</argument>

app/code/Magento/PageCache/etc/di.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737
<argument name="layoutCacheKey" xsi:type="object">Magento\Framework\View\Layout\LayoutCacheKeyInterface</argument>
3838
</arguments>
3939
</type>
40-
<type name="Magento\Framework\App\FrontControllerInterface">
41-
<plugin name="page_cache_from_key_from_cookie" type="Magento\PageCache\Plugin\RegisterFormKeyFromCookie" />
42-
</type>
4340
<type name="Magento\Framework\App\Cache\RuntimeStaleCacheStateModifier">
4441
<arguments>
4542
<argument name="cacheTypes" xsi:type="array">

app/code/Magento/PageCache/etc/frontend/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<type name="Magento\Framework\App\FrontControllerInterface">
1010
<plugin name="front-controller-builtin-cache" type="Magento\PageCache\Model\App\FrontController\BuiltinPlugin"/>
1111
<plugin name="front-controller-varnish-cache" type="Magento\PageCache\Model\App\FrontController\VarnishPlugin"/>
12+
<plugin name="page_cache_form_key_from_cookie" type="Magento\PageCache\Plugin\RegisterFormKeyFromCookie" />
1213
</type>
1314
<type name="Magento\Framework\Controller\ResultInterface">
1415
<plugin name="result-builtin-cache" type="Magento\PageCache\Model\Controller\Result\BuiltinPlugin"/>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\Framework\App\FrontControllerInterface">
10+
<plugin name="page_cache_form_key_from_cookie" type="Magento\PageCache\Plugin\RegisterFormKeyFromCookie" />
11+
</type>
12+
</config>

app/code/Magento/User/etc/webapi_rest/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<arguments>
1111
<argument name="userContexts" xsi:type="array">
1212
<item name="adminSessionUserContext" xsi:type="array">
13-
<item name="type" xsi:type="object">Magento\User\Model\Authorization\AdminSessionUserContext</item>
13+
<item name="type" xsi:type="object">Magento\User\Model\Authorization\AdminSessionUserContext\Proxy</item>
1414
<item name="sortOrder" xsi:type="string">30</item>
1515
</item>
1616
</argument>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Webapi;
8+
9+
use Magento\Framework\Module\Manager;
10+
use Magento\TestFramework\Helper\Bootstrap;
11+
12+
/**
13+
* Class for RestSessionCookieTest
14+
*/
15+
class RestSessionCookieTest extends \Magento\TestFramework\TestCase\WebapiAbstract
16+
{
17+
18+
private $moduleManager;
19+
private $objectManager;
20+
21+
/**
22+
* @inheritdoc
23+
*/
24+
protected function setUp(): void
25+
{
26+
$this->objectManager = Bootstrap::getObjectManager();
27+
$this->moduleManager = $this->objectManager->get(Manager::class);
28+
if ($this->moduleManager->isEnabled('Magento_B2b')) {
29+
$this->markTestSkipped('Skipped, because this logic is rewritten on B2B.');
30+
}
31+
}
32+
33+
/**
34+
* Check for non exist cookie PHPSESSID
35+
*/
36+
public function testRestSessionNoCookie()
37+
{
38+
$this->_markTestAsRestOnly();
39+
/** @var $curlClient CurlClientWithCookies */
40+
41+
$curlClient = $this->objectManager
42+
->get(\Magento\TestFramework\TestCase\HttpClient\CurlClientWithCookies::class);
43+
$phpSessionCookieName =
44+
[
45+
'cookie_name' => 'PHPSESSID',
46+
];
47+
48+
$response = $curlClient->get('/rest/V1/directory/countries', []);
49+
50+
$cookie = $this->findCookie($phpSessionCookieName['cookie_name'], $response['cookies']);
51+
$this->assertNull($cookie);
52+
}
53+
54+
/**
55+
* Find cookie with given name in the list of cookies
56+
*
57+
* @param string $cookieName
58+
* @param array $cookies
59+
* @return $cookie|null
60+
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
61+
*/
62+
private function findCookie($cookieName, $cookies)
63+
{
64+
foreach ($cookies as $cookieIndex => $cookie) {
65+
if ($cookie['name'] === $cookieName) {
66+
return $cookie;
67+
}
68+
}
69+
return null;
70+
}
71+
}

0 commit comments

Comments
 (0)