Skip to content

Commit fe3c54b

Browse files
committed
feat(NODE-5844): add iscryptd to ServerDescription
1 parent 3ed4a14 commit fe3c54b

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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', 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 =>
20+
console.warn('class ServerDescription when connecting to mongocryptd:', error)
21+
);
22+
client = new MongoClient(`mongodb://localhost:${mongocryptdTestPort}`);
23+
});
24+
25+
afterEach(async function () {
26+
await client?.close();
27+
childProcess.kill('SIGKILL');
28+
});
29+
30+
it('iscryptd is set to true ', async function () {
31+
const descriptions = [];
32+
client.on('serverDescriptionChanged', description => descriptions.push(description));
33+
const hello = await client.db().command({ hello: true });
34+
expect(hello).to.have.property('iscryptd', true);
35+
expect(descriptions.at(-1)).to.have.nested.property('newDescription.iscryptd', true);
36+
});
37+
});
38+
39+
describe('when connecting to anything other than mongocryptd', function () {
40+
let client: MongoClient;
41+
42+
beforeEach(async function () {
43+
client = this.configuration.newClient();
44+
});
45+
46+
afterEach(async function () {
47+
await client?.close();
48+
});
49+
50+
it('iscryptd is set to false ', async function () {
51+
const descriptions = [];
52+
client.on('serverDescriptionChanged', description => descriptions.push(description));
53+
const hello = await client.db().command({ hello: true });
54+
expect(hello).to.not.have.property('iscryptd');
55+
expect(descriptions.at(-1)).to.have.nested.property('newDescription.iscryptd', false);
56+
});
57+
});
58+
});

0 commit comments

Comments
 (0)