Skip to content

Commit c39d443

Browse files
nbbeekendariakp
authored andcommitted
feat(NODE-5844): add iscryptd to ServerDescription (#4239)
1 parent e0db01b commit c39d443

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/sdam/server_description.ts

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export class ServerDescription {
7575
maxWriteBatchSize: number | null;
7676
/** The max bson object size. */
7777
maxBsonObjectSize: number | null;
78+
/** Indicates server is a mongocryptd instance. */
79+
iscryptd: boolean;
7880

7981
// NOTE: does this belong here? It seems we should gossip the cluster time at the CMAP level
8082
$clusterTime?: ClusterTime;
@@ -123,6 +125,7 @@ export class ServerDescription {
123125
this.primary = hello?.primary ?? null;
124126
this.me = hello?.me?.toLowerCase() ?? null;
125127
this.$clusterTime = hello?.$clusterTime ?? null;
128+
this.iscryptd = Boolean(hello?.iscryptd);
126129
}
127130

128131
get hostAddress(): HostAddress {
@@ -176,6 +179,7 @@ export class ServerDescription {
176179

177180
return (
178181
other != null &&
182+
other.iscryptd === this.iscryptd &&
179183
errorStrictEqual(this.error, other.error) &&
180184
this.type === other.type &&
181185
this.minWireVersion === other.minWireVersion &&
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { type ChildProcess, spawn } from 'node:child_process';
2+
3+
import { expect } from 'chai';
4+
5+
import { MongoClient } from '../../mongodb';
6+
7+
describe('class ServerDescription', function () {
8+
describe('when connecting to mongocryptd', { requires: { mongodb: '>=4.4' } }, function () {
9+
let client: MongoClient;
10+
const mongocryptdTestPort = '27022';
11+
let childProcess: ChildProcess;
12+
13+
beforeEach(async function () {
14+
childProcess = spawn('mongocryptd', ['--port', mongocryptdTestPort, '--ipv6'], {
15+
stdio: 'ignore',
16+
detached: true
17+
});
18+
19+
childProcess.on('error', error => console.warn(this.currentTest?.fullTitle(), error));
20+
client = new MongoClient(`mongodb://localhost:${mongocryptdTestPort}`);
21+
});
22+
23+
afterEach(async function () {
24+
await client?.close();
25+
childProcess.kill('SIGKILL');
26+
});
27+
28+
it('iscryptd is set to true ', async function () {
29+
const descriptions = [];
30+
client.on('serverDescriptionChanged', description => descriptions.push(description));
31+
const hello = await client.db().command({ hello: true });
32+
expect(hello).to.have.property('iscryptd', true);
33+
expect(descriptions.at(-1)).to.have.nested.property('newDescription.iscryptd', true);
34+
});
35+
});
36+
37+
describe('when connecting to anything other than mongocryptd', function () {
38+
let client: MongoClient;
39+
40+
beforeEach(async function () {
41+
client = this.configuration.newClient();
42+
});
43+
44+
afterEach(async function () {
45+
await client?.close();
46+
});
47+
48+
it('iscryptd is set to false ', async function () {
49+
const descriptions = [];
50+
client.on('serverDescriptionChanged', description => descriptions.push(description));
51+
const hello = await client.db().command({ hello: true });
52+
expect(hello).to.not.have.property('iscryptd');
53+
expect(descriptions.at(-1)).to.have.nested.property('newDescription.iscryptd', false);
54+
});
55+
});
56+
});

0 commit comments

Comments
 (0)