Skip to content

Commit 55a7d55

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

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { type ChildProcess, spawn } from 'node:child_process';
2+
3+
import { expect } from 'chai';
4+
5+
import { MongoClient } from '../../mongodb';
6+
7+
describe('ServerDescription xxx', function () {
8+
let client: MongoClient;
9+
const mongocryptdTestPort = '27022';
10+
let childProcess: ChildProcess;
11+
12+
beforeEach(async () => {
13+
childProcess = spawn('mongocryptd', ['--port', mongocryptdTestPort, '--ipv6'], {
14+
stdio: 'ignore',
15+
detached: true
16+
});
17+
18+
childProcess.on('error', err => {
19+
console.warn('Sessions prose mongocryptd error:', err);
20+
});
21+
client = new MongoClient(`mongodb://localhost:${mongocryptdTestPort}`);
22+
});
23+
24+
afterEach(async () => {
25+
await client?.close();
26+
childProcess.kill('SIGKILL');
27+
});
28+
29+
it('iscryptd is set to true when connecting to mongocryptd', async function () {
30+
const descriptions = [];
31+
client.on('serverDescriptionChanged', description => descriptions.push(description));
32+
const hello = await client.db().command({ hello: true });
33+
expect(hello).to.have.property('iscryptd', true); // sanity check
34+
expect(hello).to.not.have.property('logicalSessionTimeoutMinutes');
35+
expect(descriptions.at(-1)).to.have.nested.property('newDescription.iscryptd', true);
36+
});
37+
});

0 commit comments

Comments
 (0)