@@ -990,11 +990,11 @@ describe('FLE tests', function () {
990
990
} ) ;
991
991
992
992
after ( async function ( ) {
993
- await shell . executeLine ( `${ testCollection } .drop()` ) ;
993
+ await shell . executeLine ( `ecoll. ${ testCollection } .drop()` ) ;
994
994
} ) ;
995
995
996
996
afterEach ( async function ( ) {
997
- await shell . executeLine ( `${ testCollection } .deleteMany({})` ) ;
997
+ await shell . executeLine ( `ecoll. ${ testCollection } .deleteMany({})` ) ;
998
998
} ) ;
999
999
1000
1000
it ( 'allows queryable encryption with prefix searches' , async function ( ) {
@@ -1009,12 +1009,22 @@ describe('FLE tests', function () {
1009
1009
ecoll.insertOne({ data: ce.encrypt(keyId, 'admin_explicit_test.pdf', explicitOpts) });
1010
1010
}` ) ;
1011
1011
const prefixResults = await shell . executeLine (
1012
- 'coll.find({$expr: { $and: [{$encStrContains : {substring : "admin_", input: "$data"}}] }}, { __safeContent__: 0 }).toArray()'
1012
+ 'coll.find({$expr: { $and: [{$encStrStartsWith : {prefix : "admin_", input: "$data"}}] }}, { __safeContent__: 0 }).toArray()'
1013
1013
) ;
1014
- expect ( prefixResults ) . to . have . length ( 2 ) ;
1014
+ expect ( prefixResults ) . to . have . length ( 3 ) ;
1015
1015
expect ( prefixResults ) . to . include ( 'admin_user_123.txt' ) ;
1016
1016
expect ( prefixResults ) . to . include ( 'admin_super_456.pdf' ) ;
1017
1017
expect ( prefixResults ) . to . include ( 'admin_explicit_test.pdf' ) ;
1018
+
1019
+ const explicitPrefixResult = await shell . executeLine ( `
1020
+ ecoll.findOne({$expr: { $and: [{$encStrStartsWith: {prefix:
1021
+ ce.encrypt(keyId, 'admin_', { ...explicitOpts, queryType: 'prefixPreview' }), input: '$data'}}] }},
1022
+ { __safeContent__: 0 })
1023
+ ` ) ;
1024
+ expect ( explicitPrefixResult ) . to . have . length ( 3 ) ;
1025
+ expect ( explicitPrefixResult ) . to . include ( 'admin_user_123.txt' ) ;
1026
+ expect ( explicitPrefixResult ) . to . include ( 'admin_super_456.pdf' ) ;
1027
+ expect ( explicitPrefixResult ) . to . include ( 'admin_explicit_test.pdf' ) ;
1018
1028
} ) ;
1019
1029
1020
1030
it ( 'allows queryable encryption with suffix searches' , async function ( ) {
@@ -1030,12 +1040,22 @@ describe('FLE tests', function () {
1030
1040
}` ) ;
1031
1041
1032
1042
const suffixResults = await shell . executeLine (
1033
- 'coll.find({$expr: { $and: [{$encStrContains : {substring : ".pdf", input: "$data"}}] }}, { __safeContent__: 0 }).toArray()'
1043
+ 'coll.find({$expr: { $and: [{$encStrEndsWith : { suffix : ".pdf", input: "$data"}}] }}, { __safeContent__: 0 }).toArray()'
1034
1044
) ;
1035
1045
expect ( suffixResults ) . to . have . length ( 3 ) ;
1036
1046
expect ( suffixResults ) . to . include ( 'admin_super_456.pdf' ) ;
1037
1047
expect ( suffixResults ) . to . include ( 'user_regular_789.pdf' ) ;
1038
1048
expect ( suffixResults ) . to . include ( 'admin_explicit_test.pdf' ) ;
1049
+
1050
+ const explicitSuffixResult = await shell . executeLine ( `
1051
+ ecoll.find({$expr: { $and: [{$encStrEndsWith: {suffix:
1052
+ ce.encrypt(keyId, '.pdf', { ...explicitOpts, queryType: 'suffixPreview' }), input: '$data'}}] }},
1053
+ { __safeContent__: 0 })
1054
+ ` ) ;
1055
+ expect ( explicitSuffixResult ) . to . have . length ( 3 ) ;
1056
+ expect ( explicitSuffixResult ) . to . include ( 'admin_super_456.pdf' ) ;
1057
+ expect ( explicitSuffixResult ) . to . include ( 'user_regular_789.pdf' ) ;
1058
+ expect ( explicitSuffixResult ) . to . include ( 'admin_explicit_test.pdf' ) ;
1039
1059
} ) ;
1040
1060
1041
1061
it ( 'allows queryable encryption with substring searches' , async function ( ) {
@@ -1050,13 +1070,6 @@ describe('FLE tests', function () {
1050
1070
// Add explicit encryption data
1051
1071
ecoll.insertOne({ data: ce.encrypt(keyId, 'explicit_user', explicitOpts) });
1052
1072
}` ) ;
1053
- // Test substring search returning multiple documents
1054
- const substringResults = await shell . executeLine (
1055
- 'coll.find({$expr: { $and: [{$encStrContains: {substring: "user", input: "$data"}}] }}, { __safeContent__: 0 }).toArray()'
1056
- ) ;
1057
- expect ( substringResults ) . to . have . length ( 2 ) ;
1058
- expect ( substringResults ) . to . include ( 'user_regular_789.pdf' ) ;
1059
- expect ( substringResults ) . to . include ( 'admin_user_123.txt' ) ;
1060
1073
1061
1074
const testingSubstringResult = await shell . executeLine (
1062
1075
'coll.find({$expr: { $and: [{$encStrContains: {substring: "user", input: "$data"}}] }}, { __safeContent__: 0 }).toArray()'
@@ -1068,7 +1081,7 @@ describe('FLE tests', function () {
1068
1081
1069
1082
// Test explicit encryption substring search
1070
1083
const explicitSubstringResult = await shell . executeLine ( `
1071
- ecoll.findOne ({$expr: { $and: [{$encStrContains: {substring:
1084
+ ecoll.find ({$expr: { $and: [{$encStrContains: {substring:
1072
1085
ce.encrypt(keyId, 'user', { ...explicitOpts, queryType: 'substringPreview' }), input: '$data'}}] }},
1073
1086
{ __safeContent__: 0 })
1074
1087
` ) ;
0 commit comments