Skip to content

Commit 7e89e47

Browse files
authored
test: add tests for azure and GCP CSFLE (#2662)
This adds new tests, and modifies the test runner to account for the recent addition of Azure and GCP CSFLE support in the CSLFE specification. NODE-2825
1 parent 8daff7f commit 7e89e47

File tree

108 files changed

+12081
-4101
lines changed

Some content is hidden

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

108 files changed

+12081
-4101
lines changed

.evergreen/config.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ functions:
9393
if [ -n "${CLIENT_ENCRYPTION}" ]; then
9494
cat <<EOT > prepare_client_encryption.sh
9595
export CLIENT_ENCRYPTION=${CLIENT_ENCRYPTION}
96-
export AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}"
97-
export AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}"
96+
export CSFLE_KMS_PROVIDERS='${CSFLE_KMS_PROVIDERS}'
9897
EOT
9998
fi
10099
- command: shell.exec

.evergreen/config.yml.in

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ functions:
112112
if [ -n "${CLIENT_ENCRYPTION}" ]; then
113113
cat <<EOT > prepare_client_encryption.sh
114114
export CLIENT_ENCRYPTION=${CLIENT_ENCRYPTION}
115-
export AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}"
116-
export AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}"
115+
export CSFLE_KMS_PROVIDERS='${CSFLE_KMS_PROVIDERS}'
117116
EOT
118117
fi
119118
- command: shell.exec
@@ -239,7 +238,7 @@ functions:
239238
MONGODB_URI='${plain_auth_mongodb_uri}' NODE_LTS_NAME='${NODE_LTS_NAME}' \
240239
bash ${PROJECT_DIRECTORY}/.evergreen/run-ldap-tests.sh
241240

242-
"run tls tests":
241+
"run tls tests":
243242
- command: shell.exec
244243
type: test
245244
params:

.evergreen/run-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ if [[ -z "${CLIENT_ENCRYPTION}" ]]; then
5252
unset AWS_ACCESS_KEY_ID;
5353
unset AWS_SECRET_ACCESS_KEY;
5454
else
55-
npm install mongodb-client-encryption
55+
npm install mongodb-client-encryption@1.1.1-beta.0
5656
fi
5757

5858
MONGODB_UNIFIED_TOPOLOGY=${UNIFIED} MONGODB_URI=${MONGODB_URI} npm run ${TEST_NPM_SCRIPT}

test/functional/client_side_encryption/corpus.test.js

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,21 @@ describe('Client Side Encryption Corpus', function() {
2424
return EJSON.parse(fs.readFileSync(path.resolve(corpusDir, filename), { strict: true }));
2525
}
2626

27+
const CSFLE_KMS_PROVIDERS = process.env.CSFLE_KMS_PROVIDERS;
28+
const kmsProviders = CSFLE_KMS_PROVIDERS ? EJSON.parse(CSFLE_KMS_PROVIDERS) : {};
29+
kmsProviders.local = {
30+
key: Buffer.from(
31+
'Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk',
32+
'base64'
33+
)
34+
};
35+
2736
// TODO: build this into EJSON
2837
// TODO: make a custom chai assertion for this
2938
function toComparableExtendedJSON(value) {
3039
return JSON.parse(EJSON.stringify({ value }, { strict: true }));
3140
}
3241

33-
const localKey = Buffer.from(
34-
'Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk',
35-
'base64'
36-
);
37-
3842
// Filters out tests that have to do with dbPointer
3943
// TODO: fix dbpointer and get rid of this.
4044
function filterImportedObject(object) {
@@ -53,6 +57,8 @@ describe('Client Side Encryption Corpus', function() {
5357
const corpusSchema = loadCorpusData('corpus-schema.json');
5458
const corpusKeyLocal = loadCorpusData('corpus-key-local.json');
5559
const corpusKeyAws = loadCorpusData('corpus-key-aws.json');
60+
const corpusKeyAzure = loadCorpusData('corpus-key-azure.json');
61+
const corpusKeyGcp = loadCorpusData('corpus-key-gcp.json');
5662
const corpusAll = filterImportedObject(loadCorpusData('corpus.json'));
5763
const corpusEncryptedExpectedAll = filterImportedObject(loadCorpusData('corpus-encrypted.json'));
5864

@@ -69,13 +75,23 @@ describe('Client Side Encryption Corpus', function() {
6975
]);
7076
const identifierMap = new Map([
7177
['local', corpusKeyLocal._id],
72-
['aws', corpusKeyAws._id]
78+
['aws', corpusKeyAws._id],
79+
['azure', corpusKeyAzure._id],
80+
['gcp', corpusKeyGcp._id]
7381
]);
7482
const keyAltNameMap = new Map([
7583
['local', 'local'],
76-
['aws', 'aws']
84+
['aws', 'aws'],
85+
['azure', 'azure'],
86+
['gcp', 'gcp']
87+
]);
88+
const copyOverValues = new Set([
89+
'_id',
90+
'altname_aws',
91+
'altname_local',
92+
'altname_azure',
93+
'altname_gcp'
7794
]);
78-
const copyOverValues = new Set(['_id', 'altname_aws', 'altname_local']);
7995

8096
let client;
8197

@@ -102,7 +118,7 @@ describe('Client Side Encryption Corpus', function() {
102118
break;
103119
}
104120
default: {
105-
throw new Error('how did you get here?');
121+
throw new Error('Unexpected algorithm: ' + expected.algo);
106122
}
107123
}
108124

@@ -122,7 +138,7 @@ describe('Client Side Encryption Corpus', function() {
122138
} else if (expected.allowed === false) {
123139
expect(actualJSON).to.deep.equal(expectedJSON);
124140
} else {
125-
throw new Error('how did you get here?');
141+
throw new Error('Unexpected value for allowed: ' + expected.allowed);
126142
}
127143
}
128144

@@ -142,7 +158,9 @@ describe('Client Side Encryption Corpus', function() {
142158
.then(() => keyDb.dropCollection(keyVaultCollName))
143159
.catch(() => {})
144160
.then(() => keyDb.collection(keyVaultCollName))
145-
.then(keyColl => keyColl.insertMany([corpusKeyLocal, corpusKeyAws]));
161+
.then(keyColl =>
162+
keyColl.insertMany([corpusKeyLocal, corpusKeyAws, corpusKeyAzure, corpusKeyGcp])
163+
);
146164
});
147165
});
148166

@@ -185,7 +203,7 @@ describe('Client Side Encryption Corpus', function() {
185203
// Configure both objects with ``keyVaultNamespace`` set to ``keyvault.datakeys``.
186204
const autoEncryption = {
187205
keyVaultNamespace,
188-
kmsProviders: this.configuration.kmsProviders(null, localKey)
206+
kmsProviders
189207
};
190208
if (useClientSideSchema) {
191209
autoEncryption.schemaMap = {
@@ -204,7 +222,7 @@ describe('Client Side Encryption Corpus', function() {
204222
return clientEncrypted.connect().then(() => {
205223
clientEncryption = new mongodbClientEncryption.ClientEncryption(client, {
206224
keyVaultNamespace,
207-
kmsProviders: this.configuration.kmsProviders(null, localKey)
225+
kmsProviders
208226
});
209227
});
210228
});
@@ -269,7 +287,7 @@ describe('Client Side Encryption Corpus', function() {
269287
} else if (field.identifier === 'altname') {
270288
encryptOptions.keyAltName = keyAltNameMap.get(field.kms);
271289
} else {
272-
throw new Error('wtf how did u get here?');
290+
throw new Error('Unexpected identifier: ' + field.identifier);
273291
}
274292

275293
return Promise.resolve()
@@ -294,7 +312,7 @@ describe('Client Side Encryption Corpus', function() {
294312
);
295313
}
296314

297-
throw new Error('how did u get here?');
315+
throw new Error('Unexpected method: ' + field.method);
298316
});
299317
})
300318
.then(() => {

0 commit comments

Comments
 (0)