Skip to content

Commit 3619cdf

Browse files
clean up existing state machine tests
1 parent 32b3e34 commit 3619cdf

4 files changed

Lines changed: 38 additions & 66 deletions

File tree

.evergreen/config.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2752,7 +2752,6 @@ tasks:
27522752
- {key: VERSION, value: latest}
27532753
- {key: TOPOLOGY, value: sharded_cluster}
27542754
- {key: AUTH, value: auth}
2755-
- {key: TEST_NPM_SCRIPT, value: check:csfle}
27562755
- func: install dependencies
27572756
- func: bootstrap mongo-orchestration
27582757
- func: run tests
@@ -2768,7 +2767,6 @@ tasks:
27682767
- {key: VERSION, value: rapid}
27692768
- {key: TOPOLOGY, value: sharded_cluster}
27702769
- {key: AUTH, value: auth}
2771-
- {key: TEST_NPM_SCRIPT, value: check:csfle}
27722770
- func: install dependencies
27732771
- func: bootstrap mongo-orchestration
27742772
- func: run tests
@@ -2784,7 +2782,6 @@ tasks:
27842782
- {key: VERSION, value: '8.0'}
27852783
- {key: TOPOLOGY, value: sharded_cluster}
27862784
- {key: AUTH, value: auth}
2787-
- {key: TEST_NPM_SCRIPT, value: check:csfle}
27882785
- func: install dependencies
27892786
- func: bootstrap mongo-orchestration
27902787
- func: run tests
@@ -2800,7 +2797,6 @@ tasks:
28002797
- {key: VERSION, value: '7.0'}
28012798
- {key: TOPOLOGY, value: sharded_cluster}
28022799
- {key: AUTH, value: auth}
2803-
- {key: TEST_NPM_SCRIPT, value: check:csfle}
28042800
- func: install dependencies
28052801
- func: bootstrap mongo-orchestration
28062802
- func: run tests
@@ -2816,7 +2812,6 @@ tasks:
28162812
- {key: VERSION, value: '6.0'}
28172813
- {key: TOPOLOGY, value: sharded_cluster}
28182814
- {key: AUTH, value: auth}
2819-
- {key: TEST_NPM_SCRIPT, value: check:csfle}
28202815
- func: install dependencies
28212816
- func: bootstrap mongo-orchestration
28222817
- func: run tests
@@ -2832,7 +2827,6 @@ tasks:
28322827
- {key: VERSION, value: '5.0'}
28332828
- {key: TOPOLOGY, value: sharded_cluster}
28342829
- {key: AUTH, value: auth}
2835-
- {key: TEST_NPM_SCRIPT, value: check:csfle}
28362830
- func: install dependencies
28372831
- func: bootstrap mongo-orchestration
28382832
- func: run tests
@@ -2848,7 +2842,6 @@ tasks:
28482842
- {key: VERSION, value: '4.4'}
28492843
- {key: TOPOLOGY, value: sharded_cluster}
28502844
- {key: AUTH, value: auth}
2851-
- {key: TEST_NPM_SCRIPT, value: check:csfle}
28522845
- func: install dependencies
28532846
- func: bootstrap mongo-orchestration
28542847
- func: run tests
@@ -2864,7 +2857,6 @@ tasks:
28642857
- {key: VERSION, value: '4.2'}
28652858
- {key: TOPOLOGY, value: sharded_cluster}
28662859
- {key: AUTH, value: auth}
2867-
- {key: TEST_NPM_SCRIPT, value: check:csfle}
28682860
- func: install dependencies
28692861
- func: bootstrap mongo-orchestration
28702862
- func: run tests

.evergreen/generate_evergreen_tasks.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,7 @@ const MONGOCRYPTD_CSFLE_TASKS = MONGODB_VERSIONS.filter(
464464
updateExpansions({
465465
VERSION: mongoVersion,
466466
TOPOLOGY: 'sharded_cluster',
467-
AUTH: 'auth',
468-
TEST_NPM_SCRIPT: 'check:csfle'
467+
AUTH: 'auth'
469468
}),
470469
{ func: 'install dependencies' },
471470
{ func: 'bootstrap mongo-orchestration' },

.evergreen/run-tests.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
#!/bin/bash
22
# set -o xtrace # Write all commands first to stderr
3-
set -o errexit # Exit the script with error if any of the commands fail
3+
set -o errexit # Exit the script with error if any of the commands fail
44

55
# Supported/used environment variables:
66
# AUTH Set to enable authentication. Defaults to "noauth"
77
# SSL Set to enable SSL. Defaults to "nossl"
88
# MONGODB_URI Set the suggested connection MONGODB_URI (including credentials and topology info)
99
# MARCH Machine Architecture. Defaults to lowercase uname -m
10-
# TEST_NPM_SCRIPT Script to npm run. Defaults to "integration-coverage"
1110
# SKIP_DEPS Skip installing dependencies
1211
# TEST_CSFLE Set to enforce running csfle tests
1312

1413
AUTH=${AUTH:-noauth}
1514
MONGODB_URI=${MONGODB_URI:-}
16-
TEST_NPM_SCRIPT=${TEST_NPM_SCRIPT:-check:integration-coverage}
1715
COMPRESSOR=${COMPRESSOR:-}
1816
SKIP_DEPS=${SKIP_DEPS:-true}
1917

@@ -28,8 +26,8 @@ fi
2826
# ssl setup
2927
SSL=${SSL:-nossl}
3028
if [ "$SSL" != "nossl" ]; then
31-
export SSL_KEY_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/client.pem"
32-
export SSL_CA_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/ca.pem"
29+
export SSL_KEY_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/client.pem"
30+
export SSL_CA_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/ca.pem"
3331
fi
3432

3533
# run tests
@@ -60,4 +58,4 @@ export MONGODB_URI=${MONGODB_URI}
6058
export LOAD_BALANCER=${LOAD_BALANCER}
6159
export TEST_CSFLE=${TEST_CSFLE}
6260
export COMPRESSOR=${COMPRESSOR}
63-
npm run "${TEST_NPM_SCRIPT}"
61+
npm run check:integration-coverage

test/integration/node-specific/auto_encrypter.test.ts

Lines changed: 33 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,31 @@ import * as fs from 'fs';
44
import { dirname, resolve } from 'path';
55
import * as sinon from 'sinon';
66

7-
/* eslint-disable @typescript-eslint/no-restricted-imports */
8-
import { AutoEncrypter } from '../../../src/client-side-encryption/auto_encrypter';
9-
/* eslint-disable @typescript-eslint/no-restricted-imports */
10-
import { MongocryptdManager } from '../../../src/client-side-encryption/mongocryptd_manager';
11-
/* eslint-disable @typescript-eslint/no-restricted-imports */
12-
import { StateMachine } from '../../../src/client-side-encryption/state_machine';
137
import {
8+
AutoEncrypter,
149
BSON,
10+
type CollectionInfo,
11+
type DataKey,
1512
deserialize,
1613
type MongoClient,
14+
MongocryptdManager,
1715
MongoError,
1816
MongoNetworkTimeoutError,
19-
serialize
17+
serialize,
18+
StateMachine
2019
} from '../../mongodb';
20+
import { ClientSideEncryptionFilter } from '../../tools/runner/filters/client_encryption_filter';
2121
import { getEncryptExtraOptions } from '../../tools/utils';
2222

2323
const { EJSON } = BSON;
2424
const cryptShared = (status: 'enabled' | 'disabled') => () => {
25-
const isPathPresent = (getEncryptExtraOptions().cryptSharedLibPath ?? '').length > 0;
25+
const isCryptSharedLoaded = ClientSideEncryptionFilter.cryptShared != null;
2626

2727
if (status === 'enabled') {
28-
return isPathPresent ? true : 'Test requires the shared library.';
28+
return isCryptSharedLoaded ? true : 'Test requires the shared library.';
2929
}
3030

31-
return isPathPresent ? 'Test requires that the crypt shared library NOT be present' : true;
31+
return isCryptSharedLoaded ? 'Test requires that the crypt shared library NOT be present' : true;
3232
};
3333

3434
const dataPath = (fileName: string) =>
@@ -51,7 +51,7 @@ const MOCK_MONGOCRYPTD_RESPONSE = readExtendedJsonToBuffer(dataPath(`mongocryptd
5151
const MOCK_KEYDOCUMENT_RESPONSE = readExtendedJsonToBuffer(dataPath(`key-document.json`));
5252
const MOCK_KMS_DECRYPT_REPLY = readHttpResponse(dataPath(`kms-decrypt-reply.txt`));
5353

54-
describe('crypt_shared library', function () {
54+
describe.only('crypt_shared library', function () {
5555
let client: MongoClient;
5656
let autoEncrypter: AutoEncrypter | undefined;
5757

@@ -68,37 +68,24 @@ describe('crypt_shared library', function () {
6868

6969
beforeEach(() => {
7070
sandbox.restore();
71-
sandbox.stub(StateMachine.prototype, 'kmsRequest').callsFake(request => {
71+
sandbox.stub(StateMachine.prototype, 'kmsRequest').callsFake(async request => {
7272
request.addResponse(MOCK_KMS_DECRYPT_REPLY);
73-
return Promise.resolve();
7473
});
7574

7675
sandbox
7776
.stub(StateMachine.prototype, 'fetchCollectionInfo')
78-
.callsFake((client, ns, filter, callback) => {
79-
callback(null, MOCK_COLLINFO_RESPONSE);
80-
});
81-
82-
sandbox
83-
.stub(StateMachine.prototype, 'markCommand')
84-
.callsFake((client, ns, command, callback) => {
85-
if (ENABLE_LOG_TEST) {
86-
const response = bson.deserialize(MOCK_MONGOCRYPTD_RESPONSE);
87-
response.schemaRequiresEncryption = false;
88-
89-
ENABLE_LOG_TEST = false; // disable test after run
90-
callback(null, bson.serialize(response));
91-
return;
77+
.callsFake(function (_client, __ns, ___filter) {
78+
async function* iterator() {
79+
yield deserialize(MOCK_COLLINFO_RESPONSE) as CollectionInfo;
9280
}
93-
94-
callback(null, MOCK_MONGOCRYPTD_RESPONSE);
81+
return iterator();
9582
});
9683

97-
sandbox.stub(StateMachine.prototype, 'fetchKeys').callsFake((client, ns, filter, callback) => {
98-
// mock data is already serialized, our action deals with the result of a cursor
99-
const deserializedKey = deserialize(MOCK_KEYDOCUMENT_RESPONSE);
100-
callback(null, [deserializedKey]);
101-
});
84+
sandbox.stub(StateMachine.prototype, 'markCommand').resolves(MOCK_MONGOCRYPTD_RESPONSE);
85+
86+
sandbox
87+
.stub(StateMachine.prototype, 'fetchKeys')
88+
.resolves([deserialize(MOCK_KEYDOCUMENT_RESPONSE) as DataKey]);
10289
});
10390

10491
afterEach(() => {
@@ -134,14 +121,13 @@ describe('crypt_shared library', function () {
134121
{ requires: { clientSideEncryption: true, predicate: cryptShared('disabled') } },
135122
async function () {
136123
let called = false;
137-
StateMachine.prototype.markCommand.callsFake((client, ns, filter, callback) => {
124+
StateMachine.prototype.markCommand.callsFake(async (_client, _ns, _filter) => {
138125
if (!called) {
139126
called = true;
140-
callback(new Error('msg'));
141-
return;
127+
throw new Error('msg');
142128
}
143129

144-
callback(null, MOCK_MONGOCRYPTD_RESPONSE);
130+
return MOCK_MONGOCRYPTD_RESPONSE;
145131
});
146132

147133
autoEncrypter = new AutoEncrypter(client, {
@@ -169,14 +155,13 @@ describe('crypt_shared library', function () {
169155
{ requires: { clientSideEncryption: true, predicate: cryptShared('disabled') } },
170156
async function () {
171157
let called = false;
172-
StateMachine.prototype.markCommand.callsFake((client, ns, filter, callback) => {
158+
StateMachine.prototype.markCommand.callsFake(async (_client, _ns, _filter) => {
173159
if (!called) {
174160
called = true;
175-
callback(new MongoNetworkTimeoutError('msg'));
176-
return;
161+
throw new MongoNetworkTimeoutError('msg');
177162
}
178163

179-
callback(null, MOCK_MONGOCRYPTD_RESPONSE);
164+
return MOCK_MONGOCRYPTD_RESPONSE;
180165
});
181166

182167
autoEncrypter = new AutoEncrypter(client, {
@@ -203,14 +188,13 @@ describe('crypt_shared library', function () {
203188
{ requires: { clientSideEncryption: true, predicate: cryptShared('disabled') } },
204189
async function () {
205190
let counter = 2;
206-
StateMachine.prototype.markCommand.callsFake((client, ns, filter, callback) => {
191+
StateMachine.prototype.markCommand.callsFake(async (_client, _ns, _filter) => {
207192
if (counter) {
208193
counter -= 1;
209-
callback(new MongoNetworkTimeoutError('msg'));
210-
return;
194+
throw new MongoNetworkTimeoutError('msg');
211195
}
212196

213-
callback(null, MOCK_MONGOCRYPTD_RESPONSE);
197+
return MOCK_MONGOCRYPTD_RESPONSE;
214198
});
215199

216200
autoEncrypter = new AutoEncrypter(client, {
@@ -298,14 +282,13 @@ describe('crypt_shared library', function () {
298282
async function () {
299283
let called = false;
300284
const timeoutError = new MongoNetworkTimeoutError('msg');
301-
StateMachine.prototype.markCommand.callsFake((client, ns, filter, callback) => {
285+
StateMachine.prototype.markCommand.callsFake(async (_client, _ns, _filter) => {
302286
if (!called) {
303287
called = true;
304-
callback(timeoutError);
305-
return;
288+
throw timeoutError;
306289
}
307290

308-
callback(null, MOCK_MONGOCRYPTD_RESPONSE);
291+
return MOCK_MONGOCRYPTD_RESPONSE;
309292
});
310293

311294
autoEncrypter = new AutoEncrypter(client, {

0 commit comments

Comments
 (0)