diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php index 9d9bbde00b..dffb1f6b48 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php @@ -91,7 +91,11 @@ class Base extends Queries new Limit(), new Offset(), new Cursor(), - new Filter($attributes, APP_DATABASE_QUERY_MAX_VALUES), + new Filter( + attributes: $attributes, + idAttributeType: Database::VAR_INTEGER, + maxValuesCount: APP_DATABASE_QUERY_MAX_VALUES + ), new Order($attributes), ]; diff --git a/tests/unit/Utopia/Database/Validator/Queries/BaseTest.php b/tests/unit/Utopia/Database/Validator/Queries/BaseTest.php new file mode 100644 index 0000000000..88223b7e4e --- /dev/null +++ b/tests/unit/Utopia/Database/Validator/Queries/BaseTest.php @@ -0,0 +1,53 @@ +assertTrue( + $validator->isValid([Query::equal('userId', $values)]), + $validator->getDescription() + ); + } + + public function testQueryOverMaxValuesIsInvalid(): void + { + $validator = new Presences(); + $values = \array_fill(0, APP_DATABASE_QUERY_MAX_VALUES + 1, 'user'); + + $this->assertFalse( + $validator->isValid([Query::equal('userId', $values)]), + 'Query with ' . \count($values) . ' values must exceed the ' . APP_DATABASE_QUERY_MAX_VALUES . ' value cap' + ); + $this->assertStringContainsString( + 'greater than ' . APP_DATABASE_QUERY_MAX_VALUES . ' values', + $validator->getDescription(), + 'Rejection must be reported against the configured cap, not the validator default' + ); + } + + public function testSequenceTypedAttributeIsValidated(): void + { + $validator = new Presences(); + + $this->assertTrue( + $validator->isValid([Query::equal('userInternalId', [1])]), + $validator->getDescription() + ); + $this->assertFalse( + $validator->isValid([Query::equal('userInternalId', [1.5])]), + 'Fractional value must not validate against a sequence attribute' + ); + } +}