Skip to content

Commit 34d111b

Browse files
* changed the location of check encrypt in filters
* changed the collection name for testing the encrypt checking in e2e tests
1 parent c77d1f4 commit 34d111b

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/Database/Validator/Query/Filter.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ public function __construct(
4141
*/
4242
protected function isValidAttribute(string $attribute): bool
4343
{
44+
if (
45+
\in_array('encrypt', $this->schema[$attribute]['filters'] ?? [])
46+
) {
47+
$this->message = 'Cannot query encrypted attribute: ' . $attribute;
48+
return false;
49+
}
50+
4451
if (\str_contains($attribute, '.')) {
4552
// Check for special symbol `.`
4653
if (isset($this->schema[$attribute])) {
@@ -74,13 +81,6 @@ protected function isValidAttribute(string $attribute): bool
7481
*/
7582
protected function isValidAttributeAndValues(string $attribute, array $values, string $method): bool
7683
{
77-
if (
78-
isset($this->schema[$attribute]['filters'])
79-
&& in_array('encrypt', $this->schema[$attribute]['filters'])
80-
) {
81-
$this->message = 'Cannot select encrypted attribute: ' . $attribute;
82-
return false;
83-
}
8484
if (!$this->isValidAttribute($attribute)) {
8585
return false;
8686
}

tests/e2e/Adapter/Base.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,7 +2069,6 @@ public function testCreateCollectionValidator(): void
20692069

20702070
public function testCreateDocument(): Document
20712071
{
2072-
20732072
static::getDatabase()->createCollection('documents');
20742073

20752074
$this->assertEquals(true, static::getDatabase()->createAttribute('documents', 'string', Database::VAR_STRING, 128, true));
@@ -2836,27 +2835,28 @@ function (mixed $value) {
28362835
}
28372836
);
28382837

2839-
static::getDatabase()->createCollection('test_documents');
2838+
$col = static::getDatabase()->createCollection(__FUNCTION__);
2839+
$this->assertNotNull($col->getId());
28402840

2841-
static::getDatabase()->createAttribute('test_documents', 'title', Database::VAR_STRING, 255, true);
2842-
static::getDatabase()->createAttribute('test_documents', 'encrypt', Database::VAR_STRING, 128, true, filters: ['encrypt']);
2841+
static::getDatabase()->createAttribute($col->getId(), 'title', Database::VAR_STRING, 255, true);
2842+
static::getDatabase()->createAttribute($col->getId(), 'encrypt', Database::VAR_STRING, 128, true, filters: ['encrypt']);
28432843

2844-
static::getDatabase()->createDocument('test_documents', new Document([
2844+
static::getDatabase()->createDocument($col->getId(), new Document([
28452845
'title' => 'Sample Title',
28462846
'encrypt' => 'secret',
28472847
]));
28482848
// query against encrypt
28492849
try {
28502850
$queries = [Query::equal('encrypt', ['test'])];
2851-
$doc = static::getDatabase()->find('test_documents', $queries);
2851+
$doc = static::getDatabase()->find($col->getId(), $queries);
28522852
$this->fail('Queried against encrypt field. Failed to throw exeception.');
28532853
} catch (Throwable $e) {
28542854
$this->assertTrue($e instanceof QueryException);
28552855
}
28562856

28572857
try {
28582858
$queries = [Query::equal('title', ['test'])];
2859-
static::getDatabase()->find('test_documents', $queries);
2859+
static::getDatabase()->find($col->getId(), $queries);
28602860
} catch (Throwable $e) {
28612861
$this->fail('Should not have thrown error');
28622862
}

0 commit comments

Comments
 (0)