Skip to content

Commit 3d8ac8c

Browse files
committed
ACP2E-3992: Customer password reset through GraphQL doesn't honour the restrictions
1 parent dbde90c commit 3d8ac8c

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

dev/tests/integration/testsuite/Magento/GraphQl/App/GraphQlCustomerMutationsTest.php

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2023 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

88
namespace Magento\GraphQl\App;
99

10+
use Magento\TestFramework\Helper\Bootstrap;
11+
use Magento\Customer\Api\AccountManagementInterface;
12+
use Magento\Framework\App\Area;
13+
use Magento\Framework\App\State;
14+
use Magento\Framework\Exception\SecurityViolationException;
1015
use Magento\Customer\Api\CustomerRepositoryInterface;
1116
use Magento\Framework\Exception\NoSuchEntityException;
1217
use Magento\Framework\Registry;
@@ -118,7 +123,12 @@ public function testMergeCarts(): void
118123
}
119124

120125
/**
126+
* Test password reset email (security disabled)
127+
*
121128
* @magentoDataFixture Magento/Customer/_files/customer.php
129+
* @magentoConfigFixture current_store customer/password/password_reset_protection_type 0
130+
* @magentoConfigFixture current_store customer/password/max_number_password_reset_requests 0
131+
* @magentoConfigFixture current_store customer/password/min_time_between_password_reset_requests 0
122132
* @return void
123133
*/
124134
public function testRequestPasswordResetEmail(): void
@@ -136,7 +146,12 @@ public function testRequestPasswordResetEmail(): void
136146
}
137147

138148
/**
149+
* Test password reset (security disabled)
150+
*
139151
* @magentoDataFixture Magento/Customer/_files/customer.php
152+
* @magentoConfigFixture current_store customer/password/password_reset_protection_type 0
153+
* @magentoConfigFixture current_store customer/password/max_number_password_reset_requests 0
154+
* @magentoConfigFixture current_store customer/password/min_time_between_password_reset_requests 0
140155
* @return void
141156
*/
142157
public function testResetPassword(): void
@@ -155,6 +170,37 @@ public function testResetPassword(): void
155170
);
156171
}
157172

173+
/**
174+
* Test that GraphQL password reset requests are subject to security checks (rate limiting)
175+
* This test verifies our fix to include GraphQL area in security checks
176+
*
177+
* @magentoDataFixture Magento/Customer/_files/customer.php
178+
* @magentoConfigFixture current_store customer/password/password_reset_protection_type 1
179+
* @magentoConfigFixture current_store customer/password/max_number_password_reset_requests 1
180+
* @magentoConfigFixture current_store customer/password/min_time_between_password_reset_requests 10
181+
* @return void
182+
*/
183+
public function testGraphQlPasswordResetSecurityLimiting(): void
184+
{
185+
$email = '[email protected]';
186+
$query = $this->getRequestPasswordResetEmailMutation();
187+
$this->graphQlStateDiff->testState(
188+
$query,
189+
['email' => $email],
190+
[],
191+
[],
192+
'requestPasswordResetEmail',
193+
'"data":{"requestPasswordResetEmail":',
194+
$this
195+
);
196+
$this->expectException(SecurityViolationException::class);
197+
$objectManager = Bootstrap::getObjectManager();
198+
$accountManagement = $objectManager->get(AccountManagementInterface::class);
199+
$appState = $objectManager->get(State::class);
200+
$appState->setAreaCode(Area::AREA_GRAPHQL);
201+
$accountManagement->initiatePasswordReset($email, 'reset_password_template');
202+
}
203+
158204
/**
159205
* @magentoDataFixture Magento/Customer/_files/customer.php
160206
* @return void

0 commit comments

Comments
 (0)