-
Notifications
You must be signed in to change notification settings - Fork 1.8k
test(NODE-7561): Skip QE "prefixPreview" and "suffixPreview" tests on server 9.0.0+ #4934
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
base: main
Are you sure you want to change the base?
Changes from 12 commits
286e8ef
2e65a50
5b84994
abd126d
48671d0
f7d4dd5
d6d6570
178b0dc
06b6ce5
eb1a16d
8886a4a
574dd90
72a6c9c
339dde7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,14 @@ | ||
| import * as path from 'path'; | ||
| import { gte } from 'semver'; | ||
|
|
||
| import { loadSpecTests } from '../../spec'; | ||
| import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner'; | ||
|
|
||
| // TODO: NODE-7559 - remove once spec tests are compatible with MongoDB 9.0 | ||
| describe('Change Streams Spec - Unified', function () { | ||
| runUnifiedSuite(loadSpecTests(path.join('change-streams', 'unified'))); | ||
| runUnifiedSuite(loadSpecTests(path.join('change-streams', 'unified')), (_test, ctx) => | ||
| gte(ctx.version, '9.0.0') | ||
| ? 'TODO(NODE-7559): change stream spec tests not yet compatible with MongoDB >= 9.0' | ||
| : false | ||
| ); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ import { join } from 'node:path'; | |||||||||
|
|
||||||||||
| import { type Binary, type Document, EJSON } from 'bson'; | ||||||||||
| import { expect } from 'chai'; | ||||||||||
| import * as semver from 'semver'; | ||||||||||
|
|
||||||||||
| import { getCSFLEKMSProviders } from '../../csfle-kms-providers'; | ||||||||||
| import { ClientEncryption, type MongoClient, MongoDBCollectionNamespace } from '../../mongodb'; | ||||||||||
|
|
@@ -14,6 +15,15 @@ const metadata: MongoDBMetadataUI = { | |||||||||
| libmongocrypt: '>=1.15.1' | ||||||||||
| } | ||||||||||
| }; | ||||||||||
| // # Server 9.0.0-rc0 removes support for "prefixPreview" and "suffixPreview": SERVER-123416 | ||||||||||
| const metadataWithoutPreview: MongoDBMetadataUI = { | ||||||||||
| requires: { | ||||||||||
| clientSideEncryption: '>=6.4.0', | ||||||||||
| mongodb: '>=8.2.0 <9.0.0', | ||||||||||
| topology: '!single', | ||||||||||
| libmongocrypt: '>=1.15.1' | ||||||||||
| } | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| const loadFLEDataFile = async (filename: string) => | ||||||||||
| EJSON.parse( | ||||||||||
|
|
@@ -33,9 +43,15 @@ describe('27. Text Explicit Encryption', function () { | |||||||||
|
|
||||||||||
| beforeEach(async function () { | ||||||||||
| utilClient = this.configuration.newClient(); | ||||||||||
| const isServer9OrAbove = semver.satisfies(this.configuration.version, '>=9.0.0'); | ||||||||||
| const shouldRunPrefixSuffixTests = !isServer9OrAbove; | ||||||||||
| console.log( | ||||||||||
| `Running tests for MongoDB version ${this.configuration.version}. Prefix/suffix tests should ${shouldRunPrefixSuffixTests ? '' : 'not'} run.` | ||||||||||
| ); | ||||||||||
|
Member
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.
Suggested change
I guess this is leftover and can be removed?
Contributor
Author
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. Removing. |
||||||||||
|
|
||||||||||
| // Using QE CreateCollection() and Collection.Drop(), drop and create the following collections with majority write concern: | ||||||||||
| // - db.prefix-suffix using the encryptedFields option set to the contents of encryptedFields-prefix-suffix.json | ||||||||||
| // Skip this step if testing server 9.0.0+. | ||||||||||
| // - db.substring using the encryptedFields option set to the contents of encryptedFields-substring.json | ||||||||||
| async function dropAndCreateCollection(ns: string, encryptedFields?: Document) { | ||||||||||
| const { db, collection } = MongoDBCollectionNamespace.fromString(ns); | ||||||||||
|
|
@@ -49,10 +65,12 @@ describe('27. Text Explicit Encryption', function () { | |||||||||
| }); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| await dropAndCreateCollection( | ||||||||||
| 'db.prefix-suffix', | ||||||||||
| await loadFLEDataFile('encryptedFields-prefix-suffix.json') | ||||||||||
| ); | ||||||||||
| if (shouldRunPrefixSuffixTests) { | ||||||||||
| await dropAndCreateCollection( | ||||||||||
| 'db.prefix-suffix', | ||||||||||
| await loadFLEDataFile('encryptedFields-prefix-suffix.json') | ||||||||||
| ); | ||||||||||
| } | ||||||||||
| await dropAndCreateCollection( | ||||||||||
| 'db.substring', | ||||||||||
| await loadFLEDataFile('encryptedFields-substring.json') | ||||||||||
|
|
@@ -144,18 +162,20 @@ describe('27. Text Explicit Encryption', function () { | |||||||||
| } | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| // Use `encryptedClient` to insert the following document into `db.prefix-suffix` with majority write concern: | ||||||||||
| // { "_id": 0, "encryptedText": <encrypted 'foobarbaz'> } | ||||||||||
| await encryptedClient | ||||||||||
| .db('db') | ||||||||||
| .collection<{ _id: number; encryptedText: Binary }>('prefix-suffix') | ||||||||||
| .insertOne( | ||||||||||
| { | ||||||||||
| _id: 0, | ||||||||||
| encryptedText | ||||||||||
| }, | ||||||||||
| { writeConcern: { w: 'majority' } } | ||||||||||
| ); | ||||||||||
| if (shouldRunPrefixSuffixTests) { | ||||||||||
| // Use `encryptedClient` to insert the following document into `db.prefix-suffix` with majority write concern: | ||||||||||
| // { "_id": 0, "encryptedText": <encrypted 'foobarbaz'> } | ||||||||||
| await encryptedClient | ||||||||||
| .db('db') | ||||||||||
| .collection<{ _id: number; encryptedText: Binary }>('prefix-suffix') | ||||||||||
| .insertOne( | ||||||||||
| { | ||||||||||
| _id: 0, | ||||||||||
| encryptedText | ||||||||||
| }, | ||||||||||
| { writeConcern: { w: 'majority' } } | ||||||||||
| ); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| { | ||||||||||
|
|
@@ -208,7 +228,8 @@ describe('27. Text Explicit Encryption', function () { | |||||||||
| await Promise.allSettled([utilClient.close(), encryptedClient.close(), keyVaultClient.close()]); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| it('Case 1: can find a document by prefix', metadata, async function () { | ||||||||||
| it('Case 1: can find a document by prefix', metadataWithoutPreview, async function () { | ||||||||||
| // Skip this test case if testing MongoDB server 9.0.0+. | ||||||||||
| // Use clientEncryption.encrypt() to encrypt the string "foo" with the following EncryptOpts: | ||||||||||
| // class EncryptOpts { | ||||||||||
| // keyId : <key1ID>, | ||||||||||
|
|
@@ -260,7 +281,8 @@ describe('27. Text Explicit Encryption', function () { | |||||||||
| expect(result).to.deep.equal({ _id: 0, encryptedText: 'foobarbaz' }); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| it('Case 2: can find a document by suffix', metadata, async function () { | ||||||||||
| it('Case 2: can find a document by suffix', metadataWithoutPreview, async function () { | ||||||||||
| // Skip this test case if testing MongoDB server 9.0.0+. | ||||||||||
| // Use clientEncryption.encrypt() to encrypt the string "baz" with the following EncryptOpts: | ||||||||||
| // class EncryptOpts { | ||||||||||
| // keyId : <key1ID>, | ||||||||||
|
|
@@ -311,7 +333,8 @@ describe('27. Text Explicit Encryption', function () { | |||||||||
| expect(result).to.deep.equal({ _id: 0, encryptedText: 'foobarbaz' }); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| it('Case 3: assert no document found by prefix', metadata, async function () { | ||||||||||
| it('Case 3: assert no document found by prefix', metadataWithoutPreview, async function () { | ||||||||||
| // Skip this test case if testing MongoDB server 9.0.0+. | ||||||||||
| // Use clientEncryption.encrypt() to encrypt the string "baz" with the following EncryptOpts: | ||||||||||
| // class EncryptOpts { | ||||||||||
| // keyId : <key1ID>, | ||||||||||
|
|
@@ -351,7 +374,8 @@ describe('27. Text Explicit Encryption', function () { | |||||||||
| expect(await encryptedClient.db('db').collection('prefix-suffix').findOne(filter)).to.be.null; | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| it('Case 4: assert no document found by suffix', metadata, async function () { | ||||||||||
| it('Case 4: assert no document found by suffix', metadataWithoutPreview, async function () { | ||||||||||
| // Skip this test case if testing MongoDB server 9.0.0+. | ||||||||||
| // Use clientEncryption.encrypt() to encrypt the string "foo" with the following EncryptOpts: | ||||||||||
| // class EncryptOpts { | ||||||||||
| // keyId : <key1ID>, | ||||||||||
|
|
@@ -497,7 +521,8 @@ describe('27. Text Explicit Encryption', function () { | |||||||||
| expect(result).to.be.null; | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| it('Case 7: assert contentionFactor is required', metadata, async function () { | ||||||||||
| it('Case 7: assert contentionFactor is required', metadataWithoutPreview, async function () { | ||||||||||
| // Skip this test case if testing MongoDB server 9.0.0+. | ||||||||||
| // Use clientEncryption.encrypt() to encrypt the string "foo" with the following EncryptOpts: | ||||||||||
| // class EncryptOpts { | ||||||||||
| // keyId : <key1ID>, | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ export class MongoDBVersionFilter extends Filter { | |
| if (!test.metadata.requires) return true; | ||
| if (!test.metadata.requires.mongodb) return true; | ||
| if (typeof this.version !== 'string') throw new Error('expected version string!'); | ||
| return semver.satisfies(this.version, test.metadata.requires.mongodb); | ||
| const isVersionCompatible = semver.satisfies(this.version, test.metadata.requires.mongodb); | ||
| return isVersionCompatible; | ||
|
Member
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. What is the purpose of this change?
Contributor
Author
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. Testing. Removing. |
||
| } | ||
| } | ||
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.
Sorry for the confusion - we actually don't need this anymore as we are 2nd implementer and there is already PR into spec to remove those tests. You can drop it in favor of #4935
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.
Removing.