-
Notifications
You must be signed in to change notification settings - Fork 79
WIP chore(e2e-tests): add queryable encryption suffix/prefix/substring tests MONGOSH-1351 #2534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
gagik
wants to merge
3
commits into
main
Choose a base branch
from
gagik/qe-substring
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -914,6 +914,162 @@ describe('FLE tests', function () { | |||||
}); | ||||||
}); | ||||||
|
||||||
context('8.2+', function () { | ||||||
skipIfServerVersion(testServer, '< 8.2'); | ||||||
|
||||||
context( | ||||||
'Queryable Encryption Prefix/Suffix/Substring Support', | ||||||
function () { | ||||||
// Substring prefix support is enterprise-only 8.2+ | ||||||
skipIfCommunityServer(testServer); | ||||||
|
||||||
let shell: TestShell; | ||||||
let uri: string; | ||||||
|
||||||
const testCollection = 'qeSubstringTest'; | ||||||
|
||||||
before(async function () { | ||||||
shell = this.startTestShell({ | ||||||
args: ['--nodb', `--cryptSharedLibPath=${cryptLibrary}`], | ||||||
}); | ||||||
uri = JSON.stringify(await testServer.connectionString()); | ||||||
await shell.waitForPrompt(); | ||||||
|
||||||
// Shared setup for all substring search tests - create collection once | ||||||
await shell.executeLine(`{ | ||||||
opts = { | ||||||
keyVaultNamespace: '${dbname}.__keyVault', | ||||||
kmsProviders: { local: { key: 'A'.repeat(128) } }, | ||||||
bypassQueryAnalysis: false | ||||||
}; | ||||||
|
||||||
autoMongo = Mongo(${uri}, { ...opts }); | ||||||
autoMongo.getDB('${dbname}').test.drop(); | ||||||
|
||||||
keyId = autoMongo.getKeyVault().createKey('local'); | ||||||
|
||||||
substringOptions = { | ||||||
strMinQueryLength: 2, | ||||||
strMaxQueryLength: 10, | ||||||
strMaxLength: 60, | ||||||
}; | ||||||
|
||||||
autoMongo.getClientEncryption().createEncryptedCollection('${dbname}', '${testCollection}', { | ||||||
provider: 'local', | ||||||
createCollectionOptions: { | ||||||
encryptedFields: { | ||||||
fields: [{ | ||||||
keyId, | ||||||
path: 'data', | ||||||
bsonType: 'string', | ||||||
queries: [{ | ||||||
queryType: 'substringPreview', | ||||||
...substringOptions, | ||||||
caseSensitive: false, | ||||||
diacriticSensitive: false, | ||||||
contention: 4 | ||||||
}] | ||||||
}] | ||||||
} | ||||||
} | ||||||
}); | ||||||
|
||||||
coll = autoMongo.getDB('${dbname}').${testCollection}; | ||||||
|
||||||
// Setup explicit encryption client | ||||||
explicitMongo = Mongo(${uri}, { ...opts, bypassQueryAnalysis: true }); | ||||||
ce = explicitMongo.getClientEncryption(); | ||||||
ecoll = explicitMongo.getDB('${dbname}').${testCollection}; | ||||||
|
||||||
explicitOpts = { | ||||||
algorithm: 'TextPreview', | ||||||
contentionFactor: 4, | ||||||
textOptions: { caseSensitive: false, diacriticSensitive: false, substring: substringOptions } | ||||||
}; | ||||||
}`); | ||||||
}); | ||||||
|
||||||
after(async function () { | ||||||
await shell.executeLine(`ecoll.${testCollection}.drop()`); | ||||||
}); | ||||||
|
||||||
afterEach(async function () { | ||||||
await shell.executeLine(`ecoll.${testCollection}.deleteMany({})`); | ||||||
}); | ||||||
|
||||||
it.skip('allows queryable encryption with prefix searches', async function () { | ||||||
// Insert test data for prefix searches | ||||||
await shell.executeLine(`{ | ||||||
coll.insertOne({ data: 'admin_user_123.txt' }); | ||||||
coll.insertOne({ data: 'admin_super_456.pdf' }); | ||||||
coll.insertOne({ data: 'user_regular_789.pdf' }); | ||||||
coll.insertOne({ data: 'guest_access_000.txt' }); | ||||||
|
||||||
// Add explicit encryption data | ||||||
ecoll.insertOne({ data: ce.encrypt(keyId, 'admin_explicit_test.pdf', explicitOpts) }); | ||||||
}`); | ||||||
const prefixResults = await shell.executeLine( | ||||||
'coll.find({$expr: { $and: [{$encStrStartsWith: {prefix: "admin_", input: "$data"}}] }}, { __safeContent__: 0 }).toArray()' | ||||||
); | ||||||
expect(prefixResults).to.have.length(3); | ||||||
expect(prefixResults).to.include('admin_user_123.txt'); | ||||||
expect(prefixResults).to.include('admin_super_456.pdf'); | ||||||
expect(prefixResults).to.include('admin_explicit_test.pdf'); | ||||||
|
||||||
const explicitPrefixResult = await shell.executeLine(` | ||||||
ecoll.find({$expr: { $and: [{$encStrStartsWith: {prefix: "admin_", input: "$data"}}] }}, | ||||||
{ __safeContent__: 0 }) | ||||||
`); | ||||||
expect(explicitPrefixResult).to.include('admin_user_123.txt'); | ||||||
expect(explicitPrefixResult).to.include('admin_super_456.pdf'); | ||||||
expect(explicitPrefixResult).to.include('admin_explicit_test.pdf'); | ||||||
}); | ||||||
|
||||||
it.skip('allows queryable encryption with suffix searches', async function () { | ||||||
// Insert test data for suffix searches | ||||||
await shell.executeLine(`{ | ||||||
coll.insertOne({ data: 'admin_user_123.txt' }); | ||||||
coll.insertOne({ data: 'admin_super_456.pdf' }); | ||||||
coll.insertOne({ data: 'user_regular_789.pdf' }); | ||||||
coll.insertOne({ data: 'guest_access_000.txt' }); | ||||||
|
||||||
// Add explicit encryption data | ||||||
ecoll.insertOne({ data: ce.encrypt(keyId, 'admin_explicit_test.pdf', explicitOpts) }); | ||||||
}`); | ||||||
|
||||||
const explicitSuffixResult = await shell.executeLine(` | ||||||
ecoll.find({$expr: { $and: [{$encStrEndsWith: {suffix: ".pdf", input: "$data"}}] }}, { __safeContent__: 0 }).toArray() | ||||||
`); | ||||||
expect(explicitSuffixResult).to.include('admin_super_456.pdf'); | ||||||
expect(explicitSuffixResult).to.include('user_regular_789.pdf'); | ||||||
expect(explicitSuffixResult).to.include('admin_explicit_test.pdf'); | ||||||
}); | ||||||
|
||||||
it('allows queryable encryption with substring searches', async function () { | ||||||
// Insert test data for substring searches | ||||||
// Insert test data for prefix searches | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment 'Insert test data for prefix searches' is incorrect for a substring search test. It should be 'Insert test data for substring searches'.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
await shell.executeLine(`{ | ||||||
coll.insertOne({ data: 'admin_user_123.txt' }); | ||||||
coll.insertOne({ data: 'admin_super_456.pdf' }); | ||||||
coll.insertOne({ data: 'user_regular_789.pdf' }); | ||||||
coll.insertOne({ data: 'guest_access_000.txt' }); | ||||||
|
||||||
// Add explicit encryption data | ||||||
ecoll.insertOne({ data: ce.encrypt(keyId, 'explicit_user', explicitOpts) }); | ||||||
}`); | ||||||
|
||||||
const testingSubstringResult = await shell.executeLine( | ||||||
'ecoll.find({$expr: { $and: [{$encStrContains: {substring: "user", input: "$data"}}] }}, { __safeContent__: 0 }).toArray()' | ||||||
); | ||||||
|
||||||
expect(testingSubstringResult).to.include('user_regular_789.pdf'); | ||||||
expect(testingSubstringResult).to.include('admin_user_123.txt'); | ||||||
expect(testingSubstringResult).to.include('explicit_user'); | ||||||
}); | ||||||
} | ||||||
); | ||||||
}); | ||||||
|
||||||
context('pre-6.0', function () { | ||||||
skipIfServerVersion(testServer, '>= 6.0'); // FLE2 available on 6.0+ | ||||||
|
||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fwiw, I'd have a mild preference for testing this in a way that would be reflective of real user behavior, i.e. adding the ability to pass through a version of the crypt_shared library to download through this function, then downloading that file and using it for only the QE text search tests.
If not that, then I'd maybe spent a minute to think about whether there's an easy way to make sure that this branch here only is taken in tests, because setting this environment variable could be done quite easily on accident