Skip to content

Commit 4f987f1

Browse files
committed
refactor: don't use admin database in CSFLE tests
NODE-2571
1 parent a9d3965 commit 4f987f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+248
-178
lines changed

test/functional/client_side_encryption/corpus.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('Client Side Encryption Corpus', function() {
5959
const dataDbName = 'db';
6060
const dataCollName = 'coll';
6161
const dataNamespace = `${dataDbName}.${dataCollName}`;
62-
const keyVaultDbName = 'admin';
62+
const keyVaultDbName = 'keyvault';
6363
const keyVaultCollName = 'datakeys';
6464
const keyVaultNamespace = `${keyVaultDbName}.${keyVaultCollName}`;
6565

@@ -136,7 +136,7 @@ describe('Client Side Encryption Corpus', function() {
136136
return Promise.resolve()
137137
.then(() => client.connect())
138138
.then(() => {
139-
// 3. Using ``client``, drop the collection ``admin.datakeys``. Insert the documents `corpus/corpus-key-local.json <../corpus/corpus-key-local.json>`_ and `corpus/corpus-key-aws.json <../corpus/corpus-key-aws.json>`_.
139+
// 3. Using ``client``, drop the collection ``keyvault.datakeys``. Insert the documents `corpus/corpus-key-local.json <../corpus/corpus-key-local.json>`_ and `corpus/corpus-key-aws.json <../corpus/corpus-key-aws.json>`_.
140140
const keyDb = client.db(keyVaultDbName);
141141
return Promise.resolve()
142142
.then(() => keyDb.dropCollection(keyVaultCollName))
@@ -182,7 +182,7 @@ describe('Client Side Encryption Corpus', function() {
182182
// Where LOCAL_MASTERKEY is the following base64:
183183
// .. code:: javascript
184184
// Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk
185-
// Configure both objects with ``keyVaultNamespace`` set to ``admin.datakeys``.
185+
// Configure both objects with ``keyVaultNamespace`` set to ``keyvault.datakeys``.
186186
const autoEncryption = {
187187
keyVaultNamespace,
188188
kmsProviders: this.configuration.kmsProviders(null, localKey)

test/functional/client_side_encryption/driver.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ chai.use(require('chai-subset'));
1313
describe('Client Side Encryption Functional', function() {
1414
const dataDbName = 'db';
1515
const dataCollName = 'coll';
16-
const keyVaultDbName = 'admin';
16+
const keyVaultDbName = 'keyvault';
1717
const keyVaultCollName = 'datakeys';
1818
const keyVaultNamespace = `${keyVaultDbName}.${keyVaultCollName}`;
1919

test/functional/client_side_encryption/prose.test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('Client Side Encryption Prose Tests', function() {
1717
const dataDbName = 'db';
1818
const dataCollName = 'coll';
1919
const dataNamespace = `${dataDbName}.${dataCollName}`;
20-
const keyVaultDbName = 'admin';
20+
const keyVaultDbName = 'keyvault';
2121
const keyVaultCollName = 'datakeys';
2222
const keyVaultNamespace = `${keyVaultDbName}.${keyVaultCollName}`;
2323

@@ -65,7 +65,7 @@ describe('Client Side Encryption Prose Tests', function() {
6565
return (
6666
Promise.resolve()
6767
.then(() => this.client.connect())
68-
// #. Using ``client``, drop the collections ``admin.datakeys`` and ``db.coll``.
68+
// #. Using ``client``, drop the collections ``keyvault.datakeys`` and ``db.coll``.
6969
.then(() => dropCollection(this.client.db(dataDbName), dataCollName))
7070
.then(() => dropCollection(this.client.db(keyVaultDbName), keyVaultCollName))
7171
// #. Create the following:
@@ -77,7 +77,7 @@ describe('Client Side Encryption Prose Tests', function() {
7777
// "aws": { <AWS credentials> },
7878
// "local": { "key": <base64 decoding of LOCAL_MASTERKEY> }
7979
// }
80-
// Configure both objects with ``keyVaultNamespace`` set to ``admin.datakeys``.
80+
// Configure both objects with ``keyVaultNamespace`` set to ``keyvault.datakeys``.
8181
// Configure the ``MongoClient`` with the following ``schema_map``:
8282
// .. code:: javascript
8383
// {
@@ -136,7 +136,7 @@ describe('Client Side Encryption Prose Tests', function() {
136136
.then(() => {
137137
// #. Call ``client_encryption.createDataKey()`` with the ``local`` KMS provider and keyAltNames set to ``["local_altname"]``.
138138
// - Expect a BSON binary with subtype 4 to be returned, referred to as ``local_datakey_id``.
139-
// - Use ``client`` to run a ``find`` on ``admin.datakeys`` by querying with the ``_id`` set to the ``local_datakey_id``.
139+
// - Use ``client`` to run a ``find`` on ``keyvault.datakeys`` by querying with the ``_id`` set to the ``local_datakey_id``.
140140
// - Expect that exactly one document is returned with the "masterKey.provider" equal to "local".
141141
// - Check that ``client`` captured a command_started event for the ``insert`` command containing a majority writeConcern.
142142
this.commandStartedEvents.clear();
@@ -210,7 +210,7 @@ describe('Client Side Encryption Prose Tests', function() {
210210
// key: "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0"
211211
// }
212212
// - Expect a BSON binary with subtype 4 to be returned, referred to as ``aws_datakey_id``.
213-
// - Use ``client`` to run a ``find`` on ``admin.datakeys`` by querying with the ``_id`` set to the ``aws_datakey_id``.
213+
// - Use ``client`` to run a ``find`` on ``keyvault.datakeys`` by querying with the ``_id`` set to the ``aws_datakey_id``.
214214
// - Expect that exactly one document is returned with the "masterKey.provider" equal to "aws".
215215
// - Check that ``client`` captured a command_started event for the ``insert`` command containing a majority writeConcern.
216216
this.commandStartedEvents.clear();
@@ -315,7 +315,7 @@ describe('Client Side Encryption Prose Tests', function() {
315315
// {
316316
// "aws": { <AWS credentials> }
317317
// }
318-
// Configure with ``keyVaultNamespace`` set to ``admin.datakeys``, and a default MongoClient as the ``keyVaultClient``.
318+
// Configure with ``keyVaultNamespace`` set to ``keyvault.datakeys``, and a default MongoClient as the ``keyVaultClient``.
319319
this.client = this.configuration.newClient(
320320
{},
321321
{ useNewUrlParser: true, useUnifiedTopology: true }
@@ -481,7 +481,7 @@ describe('Client Side Encryption Prose Tests', function() {
481481
validator: { $jsonSchema: limitsSchema }
482482
});
483483
})
484-
// #. Using ``client``, drop the collection ``admin.datakeys``. Insert the document `limits/limits-key.json <../limits/limits-key.json>`_
484+
// #. Using ``client``, drop the collection ``keyvault.datakeys``. Insert the document `limits/limits-key.json <../limits/limits-key.json>`_
485485
.then(() => dropCollection(this.client.db(keyVaultDbName), keyVaultCollName))
486486
.then(() => {
487487
return this.client
@@ -497,7 +497,7 @@ describe('Client Side Encryption Prose Tests', function() {
497497
// Configure with the ``local`` KMS provider as follows:
498498
// .. code:: javascript
499499
// { "local": { "key": <base64 decoding of LOCAL_MASTERKEY> } }
500-
// Configure with the ``keyVaultNamespace`` set to ``admin.datakeys``.
500+
// Configure with the ``keyVaultNamespace`` set to ``keyvault.datakeys``.
501501
this.clientEncrypted = this.configuration.newClient(
502502
{},
503503
{
@@ -746,8 +746,8 @@ describe('Client Side Encryption Prose Tests', function() {
746746
return (
747747
this.client
748748
.connect()
749-
// #. Using ``client``, drop the collections ``admin.datakeys`` and ``db.coll``.
750-
// Insert the document `external/external-key.json <../external/external-key.json>`_ into ``admin.datakeys``.
749+
// #. Using ``client``, drop the collections ``keyvault.datakeys`` and ``db.coll``.
750+
// Insert the document `external/external-key.json <../external/external-key.json>`_ into ``keyvault.datakeys``.
751751
.then(() => dropCollection(this.client.db(dataDbName), dataCollName))
752752
.then(() => dropCollection(this.client.db(keyVaultDbName), keyVaultCollName))
753753
.then(() => {
@@ -803,7 +803,7 @@ describe('Client Side Encryption Prose Tests', function() {
803803
// Configure both objects with the ``local`` KMS providers as follows:
804804
// .. code:: javascript
805805
// { "local": { "key": <base64 decoding of LOCAL_MASTERKEY> } }
806-
// Configure both objects with ``keyVaultNamespace`` set to ``admin.datakeys``.
806+
// Configure both objects with ``keyVaultNamespace`` set to ``keyvault.datakeys``.
807807
// Configure ``client_encrypted`` to use the schema `external/external-schema.json <../external/external-schema.json>`_ for ``db.coll`` by setting a schema map like: ``{ "db.coll": <contents of external-schema.json>}``
808808
.then(() => {
809809
const options = {

test/functional/spec-runner/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ function translateClientOptions(options) {
4141
} else if (key === 'autoEncryptOpts') {
4242
options.autoEncryption = Object.assign({}, options.autoEncryptOpts);
4343

44+
if (options.autoEncryptOpts.keyVaultNamespace == null) {
45+
options.autoEncryption.keyVaultNamespace = 'keyvault.datakeys';
46+
}
47+
4448
if (options.autoEncryptOpts.kmsProviders) {
4549
delete options.kmsProviders;
4650
options.autoEncryption.kmsProviders = options.autoEncryptOpts.kmsProviders;
@@ -165,7 +169,7 @@ function prepareDatabaseForSuite(suite, context) {
165169
.admin()
166170
.command({ killAllSessions: [] })
167171
.catch(err => {
168-
if (err.code === 11601) {
172+
if (err.message.match(/no such command/) || err.code === 11601) {
169173
return;
170174
}
171175

@@ -184,7 +188,7 @@ function prepareDatabaseForSuite(suite, context) {
184188
})
185189
.then(() => {
186190
if (suite.key_vault_data) {
187-
const dataKeysCollection = context.sharedClient.db('admin').collection('datakeys');
191+
const dataKeysCollection = context.sharedClient.db('keyvault').collection('datakeys');
188192
return dataKeysCollection
189193
.drop({ w: 'majority' })
190194
.catch(err => {

0 commit comments

Comments
 (0)