Skip to content

Commit f14bb30

Browse files
glo23503o-dubovyk
authored andcommitted
ACP2E-3246: Customer API - Login Failures Number Not Able To Reset To 0 After Successful Login
1 parent 9f6f3cb commit f14bb30

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

app/code/Magento/Customer/Model/Customer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,5 +1415,9 @@ public function getPassword()
14151415
public function _resetState(): void
14161416
{
14171417
$this->_errors = [];
1418+
$this->_origData = null;
1419+
$this->storedData = [];
1420+
$this->_data = [];
1421+
14181422
}
14191423
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
2020
use Magento\TestFramework\Helper\Bootstrap;
2121
use Magento\TestFramework\TestCase\GraphQlAbstract;
22+
use Magento\Customer\Model\CustomerFactory;
2223

2324
/**
2425
* API-functional tests cases for generateCustomerToken mutation
@@ -30,13 +31,19 @@ class GenerateCustomerTokenTest extends GraphQlAbstract
3031
*/
3132
private $logger;
3233

34+
/**
35+
* @var CustomerFactory
36+
*/
37+
private $customerFactory;
38+
3339
/**
3440
* @inheritdoc
3541
*/
3642
protected function setUp(): void
3743
{
3844
parent::setUp();
3945
$this->logger = Bootstrap::getObjectManager()->get(Logger::class);
46+
$this->customerFactory = Bootstrap::getObjectManager()->get(CustomerFactory::class);
4047
}
4148

4249
/**
@@ -46,9 +53,23 @@ protected function setUp(): void
4653
*/
4754
public function testGenerateCustomerValidToken(): void
4855
{
56+
$mutation = $this->getQuery('customer@example.com', 'wrongpassword');
57+
try {
58+
$response = $this->graphQlMutation($mutation);
59+
} catch (\Exception $e) {
60+
}
61+
$customer = $this->customerFactory->create()->setWebsiteId(1)
62+
->loadByEmail('customer@example.com');
63+
$this->assertEquals(1, $customer->getFailuresNum());
64+
$this->assertNotNull($customer->getFirstFailure());
65+
4966
$mutation = $this->getQuery();
5067

5168
$response = $this->graphQlMutation($mutation);
69+
$customer = $this->customerFactory->create()->setWebsiteId(1)
70+
->loadByEmail('customer@example.com');
71+
$this->assertEquals(0, $customer->getFailuresNum());
72+
$this->assertNull($customer->getFirstFailure());
5273
$this->assertArrayHasKey('generateCustomerToken', $response);
5374
$this->assertIsArray($response['generateCustomerToken']);
5475
}

dev/tests/api-functional/testsuite/Magento/Integration/Model/CustomerTokenServiceTest.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Integration\Model\ResourceModel\Oauth\Token\CollectionFactory;
1919
use Magento\Integration\Model\Oauth\Token\RequestLog\Config as TokenThrottlerConfig;
2020
use Magento\Integration\Api\CustomerTokenServiceInterface;
21+
use Magento\Customer\Model\CustomerFactory;
2122

2223
/**
2324
* api-functional test for \Magento\Integration\Model\CustomerTokenService.
@@ -26,9 +27,9 @@
2627
*/
2728
class CustomerTokenServiceTest extends WebapiAbstract
2829
{
29-
const SERVICE_NAME = "integrationCustomerTokenServiceV1";
30-
const SERVICE_VERSION = "V1";
31-
const RESOURCE_PATH_CUSTOMER_TOKEN = "/V1/integration/customer/token";
30+
private const SERVICE_NAME = "integrationCustomerTokenServiceV1";
31+
private const SERVICE_VERSION = "V1";
32+
private const RESOURCE_PATH_CUSTOMER_TOKEN = "/V1/integration/customer/token";
3233

3334
/**
3435
* @var CustomerTokenServiceInterface
@@ -60,6 +61,11 @@ class CustomerTokenServiceTest extends WebapiAbstract
6061
*/
6162
private $tokenReader;
6263

64+
/**
65+
* @var CustomerFactory
66+
*/
67+
private $customerFactory;
68+
6369
/**
6470
* Setup CustomerTokenService
6571
*/
@@ -81,6 +87,7 @@ protected function setUp(): void
8187
$tokenThrottlerConfig = Bootstrap::getObjectManager()->get(TokenThrottlerConfig::class);
8288
$this->attemptsCountToLockAccount = $tokenThrottlerConfig->getMaxFailuresCount();
8389
$this->tokenReader = Bootstrap::getObjectManager()->get(UserTokenReaderInterface::class);
90+
$this->customerFactory = Bootstrap::getObjectManager()->get(CustomerFactory::class);
8491
}
8592

8693
/**
@@ -103,9 +110,26 @@ public function testCreateCustomerAccessToken(?string $store): void
103110
'httpMethod' => Request::HTTP_METHOD_POST,
104111
],
105112
];
113+
114+
$invalidCredentials = [
115+
'username' => $userName,
116+
'password' => 'invalid',
117+
];
118+
try {
119+
$this->_webApiCall($serviceInfo, $invalidCredentials);
120+
} catch (\Exception $e) {
121+
}
122+
$customerData = $this->customerAccountManagement->authenticate($userName, $password);
123+
$customer = $this->customerFactory->create()->setWebsiteId($customerData->getWebsiteId())
124+
->loadByEmail($customerData->getEmail());
125+
$this->assertEquals(1, $customer->getFailuresNum());
126+
$this->assertNotNull($customer->getFirstFailure());
106127
$requestData = ['username' => $userName, 'password' => $password];
107128
$accessToken = $this->_webApiCall($serviceInfo, $requestData, null, $store);
108-
129+
$customer = $this->customerFactory->create()->setWebsiteId($customerData->getWebsiteId())
130+
->loadByEmail($customerData->getEmail());
131+
$this->assertEquals(0, $customer->getFailuresNum());
132+
$this->assertNull($customer->getFirstFailure());
109133
$this->assertToken($accessToken, $userName, $password);
110134
}
111135

0 commit comments

Comments
 (0)