Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import * as path from 'path';
import { loadSpecTests } from '../../spec';
import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';

// TODO: NODE-7559 - remove the mongodb version requirement once the spec tests are updated to be compatible with MongoDB 9.0
describe('Change Streams Spec - Unified', function () {
runUnifiedSuite(loadSpecTests(path.join('change-streams', 'unified')));
it('should run, unless it should not', { requires: { mongodb: '<9.0' } }, function () {
runUnifiedSuite(loadSpecTests(path.join('change-streams', 'unified')));
});
Comment on lines +8 to +10
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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 +42,12 @@ describe('27. Text Explicit Encryption', function () {

beforeEach(async function () {
utilClient = this.configuration.newClient();
const isServer9OrAbove = this.configuration.version >= '9.0.0';
const shouldRunPrefixSuffixTests = !isServer9OrAbove;
Comment on lines +45 to +46

// 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 +61,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 +158,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 +224,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 +277,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 +329,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 +370,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 +517,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
Loading