Skip to content

Commit 4c1335b

Browse files
committed
AC-1271: Add rate limiting for payment information endpoint and mutation
1 parent 172a620 commit 4c1335b

File tree

5 files changed

+30
-16
lines changed

5 files changed

+30
-16
lines changed

app/code/Magento/Quote/Model/Backpressure/Config/PeriodValue.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,14 @@ public function beforeSave()
6060
{
6161
if ($this->isValueChanged()) {
6262
$value = (string)$this->getValue();
63-
if (!array_key_exists($value, $this->source->toOptionArray())) {
64-
throw new LocalizedException(__('Please select a valid rate limit period'));
63+
$availableValues = $this->source->toOptionArray();
64+
if (!array_key_exists($value, $availableValues)) {
65+
throw new LocalizedException(
66+
__(
67+
'Please select a valid speed limit period in seconds: %1',
68+
implode(', ', array_keys($availableValues))
69+
)
70+
);
6571
}
6672
}
6773

app/code/Magento/Quote/i18n/en_US.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ Carts,Carts
7070
"Validated Vat Number","Validated Vat Number"
7171
"Invalid Quote Item id %1","Invalid Quote Item id %1"
7272
"Number above 0 is required for the limit","Number above 0 is required for the limit"
73-
"Please select a valid rate limit period","Please select a valid rate limit period"
73+
"Please select a valid speed limit period in seconds: %1.","Please select a valid speed limit period in seconds: %1."
7474
"Identity type not found","Identity type not found"
7575
"Invalid order backpressure limit config","Invalid order backpressure limit config"

app/code/Magento/Webapi/Controller/Rest/RequestValidator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ private function checkBackpressure(Route $route)
145145
try {
146146
$this->backpressureEnforcer->enforce($context);
147147
} catch (BackpressureExceededException $exception) {
148-
throw new WebapiException(__('Something went wrong, please try again later'));
148+
throw new WebapiException(
149+
__('Something went wrong, please try again later'),
150+
0,
151+
WebapiException::HTTP_TOO_MANY_REQUESTS
152+
);
149153
}
150154
}
151155
}

app/code/Magento/Webapi/Controller/Soap/Request/Handler.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,11 @@ private function backpressureEnforcement(string $class, string $method, string $
299299
try {
300300
$this->backpressureEnforcer->enforce($context);
301301
} catch (BackpressureExceededException $exception) {
302-
throw new WebapiException(__('Something went wrong, please try again later'));
302+
throw new WebapiException(
303+
__('Something went wrong, please try again later'),
304+
0,
305+
WebapiException::HTTP_TOO_MANY_REQUESTS
306+
);
303307
}
304308
}
305309
}

lib/internal/Magento/Framework/Webapi/Exception.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,29 @@ class Exception extends LocalizedException
2727
/**#@+
2828
* Error HTTP response codes.
2929
*/
30-
const HTTP_BAD_REQUEST = 400;
30+
public const HTTP_BAD_REQUEST = 400;
3131

32-
const HTTP_UNAUTHORIZED = 401;
32+
public const HTTP_UNAUTHORIZED = 401;
3333

34-
const HTTP_FORBIDDEN = 403;
34+
public const HTTP_FORBIDDEN = 403;
3535

36-
const HTTP_NOT_FOUND = 404;
36+
public const HTTP_NOT_FOUND = 404;
3737

38-
const HTTP_METHOD_NOT_ALLOWED = 405;
38+
public const HTTP_METHOD_NOT_ALLOWED = 405;
3939

40-
const HTTP_NOT_ACCEPTABLE = 406;
40+
public const HTTP_NOT_ACCEPTABLE = 406;
4141

42-
const HTTP_INTERNAL_ERROR = 500;
42+
public const HTTP_TOO_MANY_REQUESTS = 429;
43+
44+
public const HTTP_INTERNAL_ERROR = 500;
4345

4446
/**#@-*/
4547

4648
/**#@+
4749
* Fault codes that are used in SOAP faults.
4850
*/
49-
const FAULT_CODE_SENDER = 'Sender';
50-
const FAULT_CODE_RECEIVER = 'Receiver';
51+
public const FAULT_CODE_SENDER = 'Sender';
52+
public const FAULT_CODE_RECEIVER = 'Receiver';
5153

5254
/**
5355
* Optional exception details.
@@ -71,8 +73,6 @@ class Exception extends LocalizedException
7173
protected $_name;
7274

7375
/**
74-
* Stacktrace
75-
*
7676
* @var string
7777
*/
7878
protected $_stackTrace;

0 commit comments

Comments
 (0)