diff --git a/app/code/Magento/GraphQl/etc/di.xml b/app/code/Magento/GraphQl/etc/di.xml index 0b18d3c4cfdc..c04c3875787e 100644 --- a/app/code/Magento/GraphQl/etc/di.xml +++ b/app/code/Magento/GraphQl/etc/di.xml @@ -110,9 +110,8 @@ - - Magento\GraphQl\Model\Backpressure\BackpressureFieldValidator - + Magento\Framework\GraphQl\Query\Resolver\Argument\Validator\SearchCriteriaValidator + Magento\GraphQl\Model\Backpressure\BackpressureFieldValidator diff --git a/app/etc/di.xml b/app/etc/di.xml index bae85aa539ec..dc77b9551ac4 100644 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -1990,13 +1990,6 @@ - - - - Magento\Framework\GraphQl\Query\Resolver\Argument\Validator\SearchCriteriaValidator - - - 300 diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Query/SearchCriteriaValidatorTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Query/SearchCriteriaValidatorTest.php new file mode 100644 index 000000000000..f643079bdf36 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Query/SearchCriteriaValidatorTest.php @@ -0,0 +1,85 @@ +expectException(ResponseContainsErrorsException::class); + $this->expectExceptionMessage('Maximum pageSize is 5'); + $this->graphQlQuery($query); + } + + /** + * Verify that a pageSize argument within the configured maximum succeeds. + */ + #[ + Config('graphql/validation/input_limit_enabled', 1), + Config('graphql/validation/maximum_page_size', 5) + ] + public function testProductsQueryWithinPageSizeLimitSucceeds() + { + $query = <<graphQlQuery($query); + $this->assertArrayHasKey('products', $response); + } + + /** + * Verify that pageSize is not enforced when input limiting is disabled. + */ + #[ + Config('graphql/validation/input_limit_enabled', 0), + Config('graphql/validation/maximum_page_size', 5) + ] + public function testProductsQueryPageSizeNotEnforcedWhenLimitingDisabled() + { + $query = <<graphQlQuery($query); + $this->assertArrayHasKey('products', $response); + } +} diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/Query/CompositeValidatorTest.php b/dev/tests/integration/testsuite/Magento/GraphQl/Query/CompositeValidatorTest.php new file mode 100644 index 000000000000..bc7d7009ac4c --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Query/CompositeValidatorTest.php @@ -0,0 +1,98 @@ +compositeValidator = Bootstrap::getObjectManager()->get(CompositeValidator::class); + } + + /** + * Verify SearchCriteriaValidator in composite enforces pageSize when limiting is enabled. + */ + #[ + Config('graphql/validation/input_limit_enabled', 1, ScopeInterface::SCOPE_STORE, 'default'), + Config('graphql/validation/maximum_page_size', 5, ScopeInterface::SCOPE_STORE, 'default') + ] + public function testSearchCriteriaValidatorEnforcesPageSizeLimit(): void + { + $field = $this->createMock(Field::class); + + $this->expectException(GraphQlInputException::class); + $this->expectExceptionMessage('Maximum pageSize is 5'); + $this->compositeValidator->validate($field, ['pageSize' => 6]); + } + + /** + * Verify composite does not throw when pageSize is within the configured limit. + * + * @doesNotPerformAssertions + */ + #[ + Config('graphql/validation/input_limit_enabled', 1, ScopeInterface::SCOPE_STORE, 'default'), + Config('graphql/validation/maximum_page_size', 5, ScopeInterface::SCOPE_STORE, 'default') + ] + public function testCompositeAllowsPageSizeWithinLimit(): void + { + $field = $this->createMock(Field::class); + + $this->compositeValidator->validate($field, ['pageSize' => 5]); + } + + /** + * Verify composite does not throw when input limiting is disabled. + * + * @doesNotPerformAssertions + */ + #[ + Config('graphql/validation/input_limit_enabled', 0, ScopeInterface::SCOPE_STORE, 'default'), + Config('graphql/validation/maximum_page_size', 5, ScopeInterface::SCOPE_STORE, 'default') + ] + public function testSearchCriteriaValidatorSkipsEnforcementWhenDisabled(): void + { + $field = $this->createMock(Field::class); + + $this->compositeValidator->validate($field, ['pageSize' => 100]); + } +}