Skip to content

Commit 51e9768

Browse files
authored
test(NODE-3118): run CSFLE integration tests from libmongocrypt repo (#2833)
1 parent 70cace8 commit 51e9768

File tree

6 files changed

+98
-12
lines changed

6 files changed

+98
-12
lines changed

.evergreen/run-custom-csfle-tests.sh

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,27 @@ if [ -z ${AWS_ACCESS_KEY_ID+omitted} ]; then echo "AWS_ACCESS_KEY_ID is unset" &
55
if [ -z ${AWS_SECRET_ACCESS_KEY+omitted} ]; then echo "AWS_SECRET_ACCESS_KEY is unset" && exit 1; fi
66
if [ -z ${CSFLE_KMS_PROVIDERS+omitted} ]; then echo "CSFLE_KMS_PROVIDERS is unset" && exit 1; fi
77

8+
export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
9+
export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
10+
export CSFLE_KMS_PROVIDERS=${CSFLE_KMS_PROVIDERS}
11+
812
[ -s "$PROJECT_DIRECTORY/node-artifacts/nvm/nvm.sh" ] && source "$PROJECT_DIRECTORY"/node-artifacts/nvm/nvm.sh
913

1014
set -o xtrace # Write all commands first to stderr
1115
set -o errexit # Exit the script with error if any of the commands fail
1216

17+
ABS_PATH_TO_PATCH=$(pwd)
18+
1319
# Environment Variables:
1420
# CSFLE_GIT_REF - set the git reference to checkout for a custom CSFLE version
1521
# CDRIVER_GIT_REF - set the git reference to checkout for a custom CDRIVER version (this is for libbson)
1622

1723
CSFLE_GIT_REF=${CSFLE_GIT_REF:-master}
18-
CDRIVER_GIT_REF=${CDRIVER_GIT_REF:-1.17.4}
24+
CDRIVER_GIT_REF=${CDRIVER_GIT_REF:-1.17.6}
1925

20-
rm -rf csfle-deps-tmp
21-
mkdir -p csfle-deps-tmp
22-
pushd csfle-deps-tmp
26+
rm -rf ../csfle-deps-tmp
27+
mkdir -p ../csfle-deps-tmp
28+
pushd ../csfle-deps-tmp
2329

2430
rm -rf libmongocrypt mongo-c-driver
2531

@@ -37,15 +43,53 @@ popd # mongo-c-driver
3743

3844
pushd libmongocrypt/bindings/node
3945

46+
npm install --production --ignore-scripts
4047
source ./.evergreen/find_cmake.sh
4148
bash ./etc/build-static.sh
4249

4350
popd # libmongocrypt/bindings/node
44-
popd # csfle-deps-tmp
45-
46-
npm install
51+
popd # ../csfle-deps-tmp
4752

48-
cp -r csfle-deps-tmp/libmongocrypt/bindings/node node_modules/mongodb-client-encryption
53+
# copy mongodb-client-encryption into driver's node_modules
54+
cp -R ../csfle-deps-tmp/libmongocrypt/bindings/node node_modules/mongodb-client-encryption
4955

5056
export MONGODB_URI=${MONGODB_URI}
51-
npx mocha test/functional/client_side_encryption
57+
set +o errexit # We want to run both test suites even if the first fails
58+
npm run check:csfle
59+
DRIVER_CSFLE_TEST_RESULT=$?
60+
set -o errexit
61+
62+
# Great! our drivers tests ran
63+
# there are tests inside the bindings repo that we also want to check
64+
65+
pushd ../csfle-deps-tmp/libmongocrypt/bindings/node
66+
67+
# a mongocryptd was certainly started by the driver tests,
68+
# let us let the bindings tests start their own
69+
killall mongocryptd || true
70+
71+
# only prod deps were installed earlier, install devDependencies here (except for mongodb!)
72+
npm install --ignore-scripts
73+
74+
# copy mongodb into CSFLE's node_modules
75+
rm -rf node_modules/mongodb
76+
cp -R "$ABS_PATH_TO_PATCH" node_modules/mongodb
77+
pushd node_modules/mongodb
78+
# lets be sure we have compiled TS since driver tests don't need to compile
79+
npm run build:ts
80+
popd # node_modules/mongodb
81+
82+
# this variable needs to be empty
83+
export MONGODB_NODE_SKIP_LIVE_TESTS=""
84+
# all of the below must be defined (as well as AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY)
85+
export AWS_REGION="us-east-1"
86+
export AWS_CMK_ID="arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0"
87+
npm test -- --colors
88+
89+
popd # ../csfle-deps-tmp/libmongocrypt/bindings/node
90+
91+
# Exit the script in a way that will show evergreen a pass or fail
92+
if [ $DRIVER_CSFLE_TEST_RESULT -ne 0 ]; then
93+
echo "Driver tests failed, look above for results"
94+
exit 1
95+
fi

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
"check:kerberos": "mocha --config \"test/manual/mocharc.json\" test/manual/kerberos.test.js",
110110
"check:tls": "mocha --config \"test/manual/mocharc.json\" test/manual/tls_support.test.js",
111111
"check:ldap": "mocha --config \"test/manual/mocharc.json\" test/manual/ldap.test.js",
112+
"check:csfle": "mocha test/functional/client_side_encryption",
112113
"prepare": "node etc/prepare.js",
113114
"release": "standard-version -i HISTORY.md",
114115
"test": "npm run check:lint && npm run check:test"

src/error.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ export interface ErrorDescription {
7171
/**
7272
* @public
7373
* @category Error
74+
*
75+
* @privateRemarks
76+
* CSFLE has a dependency on this error, it uses the constructor with a string argument
7477
*/
7578
export class MongoError extends Error {
7679
/** @internal */
@@ -192,7 +195,8 @@ export class MongoNetworkError extends MongoError {
192195
}
193196
}
194197

195-
interface MongoNetworkTimeoutErrorOptions {
198+
/** @public */
199+
export interface MongoNetworkTimeoutErrorOptions {
196200
/** Indicates the timeout happened before a connection handshake completed */
197201
beforeHandshake: boolean;
198202
}
@@ -201,6 +205,9 @@ interface MongoNetworkTimeoutErrorOptions {
201205
* An error indicating a network timeout occurred
202206
* @public
203207
* @category Error
208+
*
209+
* @privateRemarks
210+
* CSFLE has a dependency on this error with an instanceof check
204211
*/
205212
export class MongoNetworkTimeoutError extends MongoNetworkError {
206213
constructor(message: string, options?: MongoNetworkTimeoutErrorOptions) {

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export {
3434
MongoServerError,
3535
MongoDriverError,
3636
MongoNetworkError,
37+
MongoNetworkTimeoutError,
3738
MongoSystemError,
3839
MongoServerSelectionError,
3940
MongoParseError,
@@ -186,7 +187,7 @@ export type {
186187
} from './cursor/abstract_cursor';
187188
export type { DbPrivate, DbOptions } from './db';
188189
export type { AutoEncryptionOptions, AutoEncrypter } from './deps';
189-
export type { AnyError, ErrorDescription } from './error';
190+
export type { AnyError, ErrorDescription, MongoNetworkTimeoutErrorOptions } from './error';
190191
export type { Explain, ExplainOptions, ExplainVerbosityLike } from './explain';
191192
export type {
192193
GridFSBucketReadStream,

test/functional/client_side_encryption/driver.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,38 @@ describe('Client Side Encryption Functional', function () {
2020
}
2121
};
2222

23+
it('CSFLE_KMS_PROVIDERS should be valid EJSON', function () {
24+
if (process.env.CSFLE_KMS_PROVIDERS) {
25+
/**
26+
* The shape of CSFLE_KMS_PROVIDERS is as follows:
27+
*
28+
* interface CSFLE_kms_providers {
29+
* aws: {
30+
* accessKeyId: string;
31+
* secretAccessKey: string;
32+
* };
33+
* azure: {
34+
* tenantId: string;
35+
* clientId: string;
36+
* clientSecret: string;
37+
* };
38+
* gcp: {
39+
* email: string;
40+
* privateKey: string;
41+
* };
42+
* local: {
43+
* // EJSON handle converting this, its actually the canonical -> { $binary: { base64: string; subType: string } }
44+
* // **NOTE**: The dollar sign has to be escaped when using this as an ENV variable
45+
* key: Binary;
46+
* }
47+
* }
48+
*/
49+
expect(() => BSON.EJSON.parse(process.env.CSFLE_KMS_PROVIDERS)).to.not.throw(SyntaxError);
50+
} else {
51+
this.skip();
52+
}
53+
});
54+
2355
describe('BSON Options', function () {
2456
beforeEach(function () {
2557
this.client = this.configuration.newClient();

test/functional/client_side_encryption/spec.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ describe('Client Side Encryption', function () {
3838
return (
3939
!spec.description.match(/type=regex/) &&
4040
!spec.description.match(/type=symbol/) &&
41-
!spec.description.match(/maxWireVersion < 8/)
41+
!spec.description.match(/maxWireVersion < 8/) &&
42+
!spec.description.match(/Count with deterministic encryption/) // TODO(NODE-3369): Unskip
4243
);
4344
});
4445
});

0 commit comments

Comments
 (0)