Skip to content

Commit bc618c5

Browse files
committed
Prose test 22.4 and 22.5
1 parent b9262b9 commit bc618c5

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

tests/SpecTests/ClientSideEncryption/Prose22_RangeExplicitEncryptionTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,67 @@ public function testCase3_CanFindEncryptedRangeAndReturnTheMinimum(string $type,
285285
$this->assertMultipleDocumentsMatch($expectedDocuments, $cursor);
286286
}
287287

288+
/**
289+
* @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.rst#case-4-can-find-encrypted-range-with-an-open-range-query
290+
* @dataProvider provideTypeAndRangeOpts
291+
*/
292+
public function testCase4_CanFindEncryptedRangeWithAnOpenRangeQuery(string $type, array $rangeOpts): void
293+
{
294+
$this->setUpWithTypeAndRangeOpts($type, $rangeOpts);
295+
296+
$encryptOpts = [
297+
'keyId' => $this->key1Id,
298+
'algorithm' => ClientEncryption::ALGORITHM_RANGE_PREVIEW,
299+
'queryType' => ClientEncryption::QUERY_TYPE_RANGE_PREVIEW,
300+
'contentionFactor' => 0,
301+
'rangeOpts' => $rangeOpts,
302+
];
303+
304+
$cast = self::getCastCallableForType($type);
305+
$fieldName = 'encrypted' . $type;
306+
307+
$expr = ['$and' => [[$fieldName => ['$gt' => $cast(30)]]]];
308+
309+
$encryptedExpr = $this->clientEncryption->encryptExpression($expr, $encryptOpts);
310+
$cursor = $this->collection->find($encryptedExpr, ['sort' => ['_id' => 1]]);
311+
$expectedDocuments = [['_id' => 3, $fieldName => $cast(200)]];
312+
313+
$this->assertMultipleDocumentsMatch($expectedDocuments, $cursor);
314+
}
315+
316+
/**
317+
* @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.rst#case-5-can-run-an-aggregation-expression-inside-expr
318+
* @dataProvider provideTypeAndRangeOpts
319+
*/
320+
public function testCase5_CanRunAnAggregationExpressionInsideExpr(string $type, array $rangeOpts): void
321+
{
322+
$this->setUpWithTypeAndRangeOpts($type, $rangeOpts);
323+
324+
$encryptOpts = [
325+
'keyId' => $this->key1Id,
326+
'algorithm' => ClientEncryption::ALGORITHM_RANGE_PREVIEW,
327+
'queryType' => ClientEncryption::QUERY_TYPE_RANGE_PREVIEW,
328+
'contentionFactor' => 0,
329+
'rangeOpts' => $rangeOpts,
330+
];
331+
332+
$cast = self::getCastCallableForType($type);
333+
$fieldName = 'encrypted' . $type;
334+
$fieldPath = '$' . $fieldName;
335+
336+
$expr = ['$and' => [['$lt' => [$fieldPath, $cast(30)]]]];
337+
338+
$encryptedExpr = $this->clientEncryption->encryptExpression($expr, $encryptOpts);
339+
$cursor = $this->collection->find(['$expr' => $encryptedExpr], ['sort' => ['_id' => 1]]);
340+
341+
$expectedDocuments = [
342+
['_id' => 0, $fieldName => $cast(0)],
343+
['_id' => 1, $fieldName => $cast(6)],
344+
];
345+
346+
$this->assertMultipleDocumentsMatch($expectedDocuments, $cursor);
347+
}
348+
288349
private function assertMultipleDocumentsMatch(array $expectedDocuments, Iterator $actualDocuments): void
289350
{
290351
$mi = new MultipleIterator(MultipleIterator::MIT_NEED_ANY);

0 commit comments

Comments
 (0)