Skip to content

Commit

Permalink
feat(NODE-5844): add iscryptd to ServerDescription
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Sep 13, 2024
1 parent 3ed4a14 commit 55a7d55
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/sdam/server_description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export class ServerDescription {
setVersion: number | null;
electionId: ObjectId | null;
logicalSessionTimeoutMinutes: number | null;
/** Indicates server is a mongocryptd instance. */
iscryptd: boolean;

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

get hostAddress(): HostAddress {
Expand Down Expand Up @@ -167,6 +170,7 @@ export class ServerDescription {

return (
other != null &&
other.iscryptd === this.iscryptd &&
errorStrictEqual(this.error, other.error) &&
this.type === other.type &&
this.minWireVersion === other.minWireVersion &&
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { type ChildProcess, spawn } from 'node:child_process';

import { expect } from 'chai';

import { MongoClient } from '../../mongodb';

describe('ServerDescription xxx', function () {
let client: MongoClient;
const mongocryptdTestPort = '27022';
let childProcess: ChildProcess;

beforeEach(async () => {
childProcess = spawn('mongocryptd', ['--port', mongocryptdTestPort, '--ipv6'], {
stdio: 'ignore',
detached: true
});

childProcess.on('error', err => {
console.warn('Sessions prose mongocryptd error:', err);
});
client = new MongoClient(`mongodb://localhost:${mongocryptdTestPort}`);
});

afterEach(async () => {
await client?.close();
childProcess.kill('SIGKILL');
});

it('iscryptd is set to true when connecting to mongocryptd', async function () {
const descriptions = [];
client.on('serverDescriptionChanged', description => descriptions.push(description));
const hello = await client.db().command({ hello: true });
expect(hello).to.have.property('iscryptd', true); // sanity check
expect(hello).to.not.have.property('logicalSessionTimeoutMinutes');
expect(descriptions.at(-1)).to.have.nested.property('newDescription.iscryptd', true);
});
});

0 comments on commit 55a7d55

Please sign in to comment.