Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#7213 prevent pointless session start in webapi scope #26032

Merged
merged 20 commits into from
Aug 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/code/Magento/Customer/etc/webapi_rest/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<arguments>
<argument name="userContexts" xsi:type="array">
<item name="customerSessionUserContext" xsi:type="array">
<item name="type" xsi:type="object">Magento\Customer\Model\Authorization\CustomerSessionUserContext</item>
<item name="type" xsi:type="object">Magento\Customer\Model\Authorization\CustomerSessionUserContext\Proxy</item>
<item name="sortOrder" xsi:type="string">20</item>
</item>
</argument>
Expand Down
3 changes: 0 additions & 3 deletions app/code/Magento/PageCache/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
<argument name="layoutCacheKey" xsi:type="object">Magento\Framework\View\Layout\LayoutCacheKeyInterface</argument>
</arguments>
</type>
<type name="Magento\Framework\App\FrontControllerInterface">
<plugin name="page_cache_from_key_from_cookie" type="Magento\PageCache\Plugin\RegisterFormKeyFromCookie" />
</type>
<type name="Magento\Framework\App\Cache\RuntimeStaleCacheStateModifier">
<arguments>
<argument name="cacheTypes" xsi:type="array">
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/PageCache/etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<type name="Magento\Framework\App\FrontControllerInterface">
<plugin name="front-controller-builtin-cache" type="Magento\PageCache\Model\App\FrontController\BuiltinPlugin"/>
<plugin name="front-controller-varnish-cache" type="Magento\PageCache\Model\App\FrontController\VarnishPlugin"/>
<plugin name="page_cache_form_key_from_cookie" type="Magento\PageCache\Plugin\RegisterFormKeyFromCookie" />
</type>
<type name="Magento\Framework\Controller\ResultInterface">
<plugin name="result-builtin-cache" type="Magento\PageCache\Model\Controller\Result\BuiltinPlugin"/>
Expand Down
12 changes: 12 additions & 0 deletions app/code/Magento/PageCache/etc/graphql/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\App\FrontControllerInterface">
<plugin name="page_cache_form_key_from_cookie" type="Magento\PageCache\Plugin\RegisterFormKeyFromCookie" />
</type>
</config>
2 changes: 1 addition & 1 deletion app/code/Magento/User/etc/webapi_rest/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<arguments>
<argument name="userContexts" xsi:type="array">
<item name="adminSessionUserContext" xsi:type="array">
<item name="type" xsi:type="object">Magento\User\Model\Authorization\AdminSessionUserContext</item>
<item name="type" xsi:type="object">Magento\User\Model\Authorization\AdminSessionUserContext\Proxy</item>
<item name="sortOrder" xsi:type="string">30</item>
</item>
</argument>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Webapi;

use Magento\Framework\Module\Manager;
use Magento\TestFramework\Helper\Bootstrap;

/**
* Class for RestSessionCookieTest
*/
class RestSessionCookieTest extends \Magento\TestFramework\TestCase\WebapiAbstract
{

private $moduleManager;
private $objectManager;

/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->moduleManager = $this->objectManager->get(Manager::class);
if ($this->moduleManager->isEnabled('Magento_B2b')) {
$this->markTestSkipped('Skipped, because this logic is rewritten on B2B.');
}
}

/**
* Check for non exist cookie PHPSESSID
*/
public function testRestSessionNoCookie()
{
$this->_markTestAsRestOnly();
/** @var $curlClient CurlClientWithCookies */

$curlClient = $this->objectManager
->get(\Magento\TestFramework\TestCase\HttpClient\CurlClientWithCookies::class);
$phpSessionCookieName =
[
'cookie_name' => 'PHPSESSID',
];

$response = $curlClient->get('/rest/V1/directory/countries', []);

$cookie = $this->findCookie($phpSessionCookieName['cookie_name'], $response['cookies']);
$this->assertNull($cookie);
}

/**
* Find cookie with given name in the list of cookies
*
* @param string $cookieName
* @param array $cookies
* @return $cookie|null
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
private function findCookie($cookieName, $cookies)
{
foreach ($cookies as $cookieIndex => $cookie) {
if ($cookie['name'] === $cookieName) {
return $cookie;
}
}
return null;
}
}