Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion test/integration/change-streams/change_streams.spec.test.ts
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
);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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
);
describe('Change Streams Spec - Unified', function () {
runUnifiedSuite(loadSpecTests(path.join('change-streams', 'unified')));

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing.

});
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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(
Expand All @@ -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.`
);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log(
`Running tests for MongoDB version ${this.configuration.version}. Prefix/suffix tests should ${shouldRunPrefixSuffixTests ? '' : 'not'} run.`
);

I guess this is leftover and can be removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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);
Expand All @@ -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')
Expand Down Expand Up @@ -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' } }
);
}
}

{
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"runOnRequirements": [
{
"minServerVersion": "8.2.0",
"maxServerVersion": "8.99.99",
"topologies": [
"replicaset",
"sharded",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ description: QE-Text-cleanupStructuredEncryptionData
schemaVersion: "1.25"
runOnRequirements:
- minServerVersion: "8.2.0" # Server 8.2.0 adds preview support for QE text queries.
maxServerVersion: "8.99.99" # Server 9.0.0-rc0 removes support for "prefixPreview" and "suffixPreview": SERVER-123416
topologies: ["replicaset", "sharded", "load-balanced"] # QE does not support standalone.
csfle:
minLibmongocryptVersion: 1.15.0 # For SPM-4158.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"runOnRequirements": [
{
"minServerVersion": "8.2.0",
"maxServerVersion": "8.99.99",
"topologies": [
"replicaset",
"sharded",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ description: QE-Text-compactStructuredEncryptionData
schemaVersion: "1.25"
runOnRequirements:
- minServerVersion: "8.2.0" # Server 8.2.0 adds preview support for QE text queries.
maxServerVersion: "8.99.99" # Server 9.0.0-rc0 removes support for "prefixPreview" and "suffixPreview": SERVER-123416
topologies: ["replicaset", "sharded", "load-balanced"] # QE does not support standalone.
csfle:
minLibmongocryptVersion: 1.15.0 # For SPM-4158.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"runOnRequirements": [
{
"minServerVersion": "8.2.0",
"maxServerVersion": "8.99.99",
"topologies": [
"replicaset",
"sharded",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ description: QE-Text-prefixPreview
schemaVersion: "1.25"
runOnRequirements:
- minServerVersion: "8.2.0" # Server 8.2.0 adds preview support for QE text queries.
maxServerVersion: "8.99.99" # Server 9.0.0-rc0 removes support for "prefixPreview" and "suffixPreview": SERVER-123416
topologies: ["replicaset", "sharded", "load-balanced"] # QE does not support standalone.
csfle:
minLibmongocryptVersion: 1.15.0 # For SPM-4158.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
],
"tests": [
{
"description": "Insert QE suffixPreview",
"description": "Insert QE substringPreview",
"operations": [
{
"name": "insertOne",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ initialData:
],
}
tests:
- description: "Insert QE suffixPreview"
- description: "Insert QE substringPreview"
operations:
- name: insertOne
arguments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"runOnRequirements": [
{
"minServerVersion": "8.2.0",
"maxServerVersion": "8.99.99",
"topologies": [
"replicaset",
"sharded",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ description: QE-Text-suffixPreview
schemaVersion: "1.25"
runOnRequirements:
- minServerVersion: "8.2.0" # Server 8.2.0 adds preview support for QE text queries.
maxServerVersion: "8.99.99" # Server 9.0.0-rc0 removes support for "prefixPreview" and "suffixPreview": SERVER-123416
topologies: ["replicaset", "sharded", "load-balanced"] # QE does not support standalone.
csfle:
minLibmongocryptVersion: 1.15.0 # For SPM-4158.
Expand Down
3 changes: 2 additions & 1 deletion test/tools/runner/filters/mongodb_version_filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing. Removing.

}
}
Loading