Skip to content

Commit 07b5efc

Browse files
committed
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 8ae3505 commit 07b5efc

File tree

108 files changed

+12081
-4102
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
-4102
lines changed

.evergreen/config.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ functions:
107107
if [ -n "${CLIENT_ENCRYPTION}" ]; then
108108
cat <<EOT > prepare_client_encryption.sh
109109
export CLIENT_ENCRYPTION=${CLIENT_ENCRYPTION}
110-
export AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}"
111-
export AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}"
110+
export CSFLE_KMS_PROVIDERS='${CSFLE_KMS_PROVIDERS}'
112111
EOT
113112
fi
114113
- command: shell.exec

.evergreen/config.yml.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ functions:
127127
if [ -n "${CLIENT_ENCRYPTION}" ]; then
128128
cat <<EOT > prepare_client_encryption.sh
129129
export CLIENT_ENCRYPTION=${CLIENT_ENCRYPTION}
130-
export AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}"
131-
export AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}"
130+
export CSFLE_KMS_PROVIDERS='${CSFLE_KMS_PROVIDERS}'
132131
EOT
133132
fi
134133
- command: shell.exec

.evergreen/run-tests.sh

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

5959
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
@@ -21,17 +21,21 @@ describe('Client Side Encryption Corpus', function () {
2121
return EJSON.parse(fs.readFileSync(path.resolve(corpusDir, filename)), { relaxed: false });
2222
}
2323

24+
const CSFLE_KMS_PROVIDERS = process.env.CSFLE_KMS_PROVIDERS;
25+
const kmsProviders = CSFLE_KMS_PROVIDERS ? EJSON.parse(CSFLE_KMS_PROVIDERS) : {};
26+
kmsProviders.local = {
27+
key: Buffer.from(
28+
'Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk',
29+
'base64'
30+
)
31+
};
32+
2433
// TODO: build this into EJSON
2534
// TODO: make a custom chai assertion for this
2635
function toComparableExtendedJSON(value) {
2736
return JSON.parse(EJSON.stringify({ value }, { relaxed: false }));
2837
}
2938

30-
const localKey = Buffer.from(
31-
'Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk',
32-
'base64'
33-
);
34-
3539
// Filters out tests that have to do with dbPointer
3640
// TODO: fix dbpointer and get rid of this.
3741
function filterImportedObject(object) {
@@ -50,6 +54,8 @@ describe('Client Side Encryption Corpus', function () {
5054
const corpusSchema = loadCorpusData('corpus-schema.json');
5155
const corpusKeyLocal = loadCorpusData('corpus-key-local.json');
5256
const corpusKeyAws = loadCorpusData('corpus-key-aws.json');
57+
const corpusKeyAzure = loadCorpusData('corpus-key-azure.json');
58+
const corpusKeyGcp = loadCorpusData('corpus-key-gcp.json');
5359
const corpusAll = filterImportedObject(loadCorpusData('corpus.json'));
5460
const corpusEncryptedExpectedAll = filterImportedObject(loadCorpusData('corpus-encrypted.json'));
5561

@@ -66,13 +72,23 @@ describe('Client Side Encryption Corpus', function () {
6672
]);
6773
const identifierMap = new Map([
6874
['local', corpusKeyLocal._id],
69-
['aws', corpusKeyAws._id]
75+
['aws', corpusKeyAws._id],
76+
['azure', corpusKeyAzure._id],
77+
['gcp', corpusKeyGcp._id]
7078
]);
7179
const keyAltNameMap = new Map([
7280
['local', 'local'],
73-
['aws', 'aws']
81+
['aws', 'aws'],
82+
['azure', 'azure'],
83+
['gcp', 'gcp']
84+
]);
85+
const copyOverValues = new Set([
86+
'_id',
87+
'altname_aws',
88+
'altname_local',
89+
'altname_azure',
90+
'altname_gcp'
7491
]);
75-
const copyOverValues = new Set(['_id', 'altname_aws', 'altname_local']);
7692

7793
let client;
7894

@@ -99,7 +115,7 @@ describe('Client Side Encryption Corpus', function () {
99115
break;
100116
}
101117
default: {
102-
throw new Error('how did you get here?');
118+
throw new Error('Unexpected algorithm: ' + expected.algo);
103119
}
104120
}
105121

@@ -119,7 +135,7 @@ describe('Client Side Encryption Corpus', function () {
119135
} else if (expected.allowed === false) {
120136
expect(actualJSON).to.deep.equal(expectedJSON);
121137
} else {
122-
throw new Error('how did you get here?');
138+
throw new Error('Unexpected value for allowed: ' + expected.allowed);
123139
}
124140
}
125141

@@ -136,7 +152,9 @@ describe('Client Side Encryption Corpus', function () {
136152
.then(() => keyDb.dropCollection(keyVaultCollName))
137153
.catch(() => {})
138154
.then(() => keyDb.collection(keyVaultCollName))
139-
.then(keyColl => keyColl.insertMany([corpusKeyLocal, corpusKeyAws]));
155+
.then(keyColl =>
156+
keyColl.insertMany([corpusKeyLocal, corpusKeyAws, corpusKeyAzure, corpusKeyGcp])
157+
);
140158
});
141159
});
142160

@@ -179,7 +197,7 @@ describe('Client Side Encryption Corpus', function () {
179197
// Configure both objects with ``keyVaultNamespace`` set to ``keyvault.datakeys``.
180198
const autoEncryption = {
181199
keyVaultNamespace,
182-
kmsProviders: this.configuration.kmsProviders(null, localKey)
200+
kmsProviders
183201
};
184202
if (useClientSideSchema) {
185203
autoEncryption.schemaMap = {
@@ -192,7 +210,7 @@ describe('Client Side Encryption Corpus', function () {
192210
clientEncryption = new mongodbClientEncryption.ClientEncryption(client, {
193211
bson: BSON,
194212
keyVaultNamespace,
195-
kmsProviders: this.configuration.kmsProviders(null, localKey)
213+
kmsProviders
196214
});
197215
});
198216
});
@@ -257,7 +275,7 @@ describe('Client Side Encryption Corpus', function () {
257275
} else if (field.identifier === 'altname') {
258276
encryptOptions.keyAltName = keyAltNameMap.get(field.kms);
259277
} else {
260-
throw new Error('wtf how did u get here?');
278+
throw new Error('Unexpected identifier: ' + field.identifier);
261279
}
262280

263281
return Promise.resolve()
@@ -282,7 +300,7 @@ describe('Client Side Encryption Corpus', function () {
282300
);
283301
}
284302

285-
throw new Error('how did u get here?');
303+
throw new Error('Unexpected method: ' + field.method);
286304
});
287305
})
288306
.then(() => {

0 commit comments

Comments
 (0)