Skip to content

Commit 7036647

Browse files
committed
ACP2E-4191: [B2B] Webapi requests go infinite loop for logged-in customers when 'eav' cache disabled
1 parent 9bc23cc commit 7036647

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

app/code/Magento/Customer/Test/Unit/Model/SessionTest.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
use Magento\Customer\Model\Context as CustomerContext;
1313
use Magento\Customer\Model\Customer;
1414
use Magento\Customer\Model\CustomerFactory;
15+
use Magento\Customer\Model\CustomerRegistry;
1516
use Magento\Customer\Model\ResourceModel\Customer as ResourceCustomer;
1617
use Magento\Customer\Model\Session;
1718
use Magento\Customer\Model\Session\Storage;
1819
use Magento\Framework\App\Http\Context;
1920
use Magento\Framework\App\Response\Http;
2021
use Magento\Framework\Event\ManagerInterface;
22+
use Magento\Framework\Exception\NoSuchEntityException;
2123
use Magento\Framework\Session\SessionStartChecker;
2224
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
2325
use Magento\Framework\Url;
@@ -70,6 +72,11 @@ class SessionTest extends TestCase
7072
*/
7173
protected $responseMock;
7274

75+
/**
76+
* @var CustomerRegistry|MockObject
77+
*/
78+
private $customerRegistryMock;
79+
7380
/**
7481
* @var Session
7582
*/
@@ -105,6 +112,7 @@ protected function setUp(): void
105112
];
106113
$helper->prepareObjectManager($objects);
107114
$this->responseMock = $this->createMock(Http::class);
115+
$this->customerRegistryMock = $this->createMock(CustomerRegistry::class);
108116
$this->_model = $helper->getObject(
109117
Session::class,
110118
[
@@ -115,7 +123,8 @@ protected function setUp(): void
115123
'urlFactory' => $this->urlFactoryMock,
116124
'customerRepository' => $this->customerRepositoryMock,
117125
'response' => $this->responseMock,
118-
'_customerResource' => $this->_customerResourceMock
126+
'_customerResource' => $this->_customerResourceMock,
127+
'customerRegistry' => $this->customerRegistryMock,
119128
]
120129
);
121130
}
@@ -342,4 +351,27 @@ public function testSetCustomer(): void
342351

343352
$this->_model->setCustomer($customer);
344353
}
354+
355+
public function testCheckCustomerId(): void
356+
{
357+
$customerId = 123;
358+
$customer = $this->createMock(Customer::class);
359+
$this->customerRegistryMock->expects($this->once())
360+
->method('retrieve')
361+
->with($customerId)
362+
->willReturn($customer);
363+
$result = $this->_model->checkCustomerId($customerId);
364+
$this->assertTrue($result);
365+
}
366+
367+
public function testCheckCustomerIdInvalid(): void
368+
{
369+
$customerId = 123;
370+
$this->customerRegistryMock->expects($this->once())
371+
->method('retrieve')
372+
->with($customerId)
373+
->willThrowException(new NoSuchEntityException());
374+
$result = $this->_model->checkCustomerId($customerId);
375+
$this->assertFalse($result);
376+
}
345377
}

dev/tests/integration/testsuite/Magento/Customer/Model/SessionTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2013 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\Customer\Model;
77

8+
use Magento\Eav\Model\Cache\Type as EavCacheType;
89
use Magento\Framework\App\PageCache\FormKey;
910
use Magento\Framework\App\Response\Http as HttpResponse;
1011
use Magento\Framework\App\ResponseInterface;
1112
use Magento\Framework\Session\SidResolverInterface;
1213
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
1314
use Magento\Framework\Stdlib\Cookie\PublicCookieMetadata;
15+
use Magento\TestFramework\Fixture\Cache as CacheAlias;
1416
use Magento\TestFramework\Helper\Bootstrap;
1517

1618
/**
@@ -167,4 +169,13 @@ public function testNoSid(): void
167169
$this->assertNotEmpty($location);
168170
$this->assertStringNotContainsString(SidResolverInterface::SESSION_ID_QUERY_PARAM . '=', $location);
169171
}
172+
173+
#[
174+
CacheAlias(EavCacheType::TYPE_IDENTIFIER, false),
175+
]
176+
public function testCheckCustomerId(): void
177+
{
178+
$result = $this->_customerSession->checkCustomerId(1);
179+
$this->assertTrue($result);
180+
}
170181
}

0 commit comments

Comments
 (0)