Skip to content

Commit d1124d9

Browse files
ENGCOM-7611: #7213 prevent pointless session start in webapi scope #26032
- Merge Pull Request #26032 from maqlec/magento2:issue-7213 - Merged commits: 1. 859307b 2. 8aed39f 3. 4a05e78 4. cfa889e 5. b219c4e 6. c5ad40b 7. fe0bd17 8. ac0dea5 9. ea10595 10. b4a02dd 11. 4f20656 12. 192bc7e 13. f149763 14. ac0f4e6 15. 3e833b3 16. c1f5509 17. edd0ccd 18. 4dac67d 19. 97b235d 20. 16797c3
2 parents 2219289 + 16797c3 commit d1124d9

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)