Skip to content

Commit d3438ea

Browse files
authored
feat(NODE-5844): add iscryptd to ServerDescription (#4239)
1 parent 3ed4a14 commit d3438ea

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/sdam/server_description.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ export class ServerDescription {
6969
setVersion: number | null;
7070
electionId: ObjectId | null;
7171
logicalSessionTimeoutMinutes: number | null;
72+
/** Indicates server is a mongocryptd instance. */
73+
iscryptd: boolean;
7274

7375
// NOTE: does this belong here? It seems we should gossip the cluster time at the CMAP level
7476
$clusterTime?: ClusterTime;
@@ -114,6 +116,7 @@ export class ServerDescription {
114116
this.primary = hello?.primary ?? null;
115117
this.me = hello?.me?.toLowerCase() ?? null;
116118
this.$clusterTime = hello?.$clusterTime ?? null;
119+
this.iscryptd = Boolean(hello?.iscryptd);
117120
}
118121

119122
get hostAddress(): HostAddress {
@@ -167,6 +170,7 @@ export class ServerDescription {
167170

168171
return (
169172
other != null &&
173+
other.iscryptd === this.iscryptd &&
170174
errorStrictEqual(this.error, other.error) &&
171175
this.type === other.type &&
172176
this.minWireVersion === other.minWireVersion &&
Lines changed: 56 additions & 0 deletions
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)