Skip to content

Commit 48cad97

Browse files
committed
AC-1271: Add rate limiting for payment information endpoint and mutation
1 parent 90cb13e commit 48cad97

File tree

4 files changed

+19
-38
lines changed

4 files changed

+19
-38
lines changed

app/code/Magento/Quote/Test/Unit/Model/Backpressure/OrderLimitConfigManagerTest.php

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
namespace Magento\Quote\Test\Unit\Model\Backpressure;
1010

11-
use Magento\Framework\App\DeploymentConfig;
12-
use Magento\Framework\Exception\FileSystemException;
1311
use Magento\Framework\Exception\RuntimeException;
1412
use Magento\Quote\Model\Backpressure\OrderLimitConfigManager;
1513
use Magento\Framework\App\Backpressure\ContextInterface;
@@ -24,11 +22,6 @@ class OrderLimitConfigManagerTest extends TestCase
2422
*/
2523
private $scopeConfigMock;
2624

27-
/**
28-
* @var DeploymentConfig|MockObject
29-
*/
30-
private $deploymentConfigMock;
31-
3225
/**
3326
* @var OrderLimitConfigManager
3427
*/
@@ -42,12 +35,8 @@ protected function setUp(): void
4235
parent::setUp();
4336

4437
$this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
45-
$this->deploymentConfigMock = $this->createMock(DeploymentConfig::class);
4638

47-
$this->model = new OrderLimitConfigManager(
48-
$this->scopeConfigMock,
49-
$this->deploymentConfigMock
50-
);
39+
$this->model = new OrderLimitConfigManager($this->scopeConfigMock);
5140
}
5241

5342
/**
@@ -106,20 +95,13 @@ public function testReadLimit(
10695
*
10796
* @param bool $enabled
10897
* @param bool $expected
109-
* @param string|null $requestLoggerType
11098
* @return void
111-
* @throws RuntimeException
112-
* @throws FileSystemException
11399
* @dataProvider getEnabledCases
114100
*/
115101
public function testIsEnforcementEnabled(
116102
bool $enabled,
117-
bool $expected,
118-
?string $requestLoggerType
103+
bool $expected
119104
): void {
120-
$this->deploymentConfigMock->method('get')
121-
->with('backpressure/logger/type')
122-
->willReturn($requestLoggerType);
123105
$this->scopeConfigMock->method('isSetFlag')
124106
->with('sales/backpressure/enabled')
125107
->willReturn($enabled);
@@ -135,10 +117,8 @@ public function testIsEnforcementEnabled(
135117
public function getEnabledCases(): array
136118
{
137119
return [
138-
'disabled' => [false, false, null],
139-
'disabled-request-logger-type-exists' => [false, false, 'requestLoggerType'],
140-
'enabled-request-logger-type-not-exist' => [true, false, null],
141-
'enabled' => [true, true, 'requestLoggerType'],
120+
'disabled' => [false, false],
121+
'enabled' => [true, true],
142122
];
143123
}
144124
}

dev/tests/integration/etc/install-config-mysql.php.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ return [
2424
'amqp-user' => 'guest',
2525
'amqp-password' => 'guest',
2626
'consumers-wait-for-messages' => '0',
27+
'backpressure-logger' => 'redis',
28+
'backpressure-logger-redis-timeout'=>10,
2729
];

lib/internal/Magento/Framework/App/Backpressure/SlidingWindow/RedisRequestLogger/RedisClient.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class RedisClient
6868
/**
6969
* @var Credis_Client
7070
*/
71-
private Credis_Client $pipeline;
71+
private $pipeline;
7272

7373
/**
7474
* @param DeploymentConfig $config
@@ -95,40 +95,35 @@ public function __construct(DeploymentConfig $config)
9595
*
9696
* @param string $key
9797
* @param int $decrement
98-
* @return $this
98+
* @return Credis_Client|int
9999
*/
100-
public function incrBy(string $key, int $decrement): RedisClient
100+
public function incrBy(string $key, int $decrement)
101101
{
102-
$this->pipeline->incrBy($key, $decrement);
102+
return $this->pipeline->incrBy($key, $decrement);
103103

104-
return $this;
105104
}
106105

107106
/**
108107
* Sets expiration date of the key
109108
*
110109
* @param string $key
111110
* @param int $timestamp
112-
* @return $this
111+
* @return Credis_Client|int
113112
*/
114-
public function expireAt(string $key, int $timestamp): RedisClient
113+
public function expireAt(string $key, int $timestamp)
115114
{
116-
$this->pipeline->expireAt($key, $timestamp);
117-
118-
return $this;
115+
return $this->pipeline->expireAt($key, $timestamp);
119116
}
120117

121118
/**
122119
* Returns value by key
123120
*
124121
* @param string $key
125-
* @return bool|RedisClient|string
122+
* @return bool|Credis_Client|string
126123
*/
127124
public function get(string $key)
128125
{
129-
$value = $this->pipeline->get($key);
130-
131-
return $value instanceof Credis_Client ? $this : $value;
126+
return $this->pipeline->get($key);
132127
}
133128

134129
/**

setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/BackpressureLoggerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ public function testCreateConfigCacheRedis(
9797
$this->assertEquals($expectedConfigData, $configData->getData());
9898
}
9999

100+
/**
101+
* @return array[]
102+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
103+
*/
100104
public function dataProviderCreateConfigCacheRedis(): array
101105
{
102106
return [

0 commit comments

Comments
 (0)