Skip to content

Commit 2795656

Browse files
chore: updates fake mongodb deployment detection using [email protected] (#1530)
1 parent 5a6ec6c commit 2795656

File tree

6 files changed

+46
-104
lines changed

6 files changed

+46
-104
lines changed

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/service-provider-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"@mongosh/errors": "0.0.0-dev.0",
4646
"bson": "^5.3.0",
4747
"mongodb": "^5.6.0",
48-
"mongodb-build-info": "^1.5.0"
48+
"mongodb-build-info": "^1.6.2"
4949
},
5050
"optionalDependencies": {
5151
"mongodb-client-encryption": "^2.8.0"

packages/service-provider-core/src/connect-info.spec.ts

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,6 @@ describe('getConnectInfo', function () {
4141
ok: 1,
4242
};
4343

44-
const CMD_LINE_OPTS = {
45-
argv: [
46-
'/opt/mongodb-osx-x86_64-enterprise-3.6.3/bin/mongod',
47-
'--dbpath=/Users/user/testdata',
48-
],
49-
parsed: {
50-
storage: {
51-
dbPath: '/Users/user/testdata',
52-
},
53-
},
54-
ok: 1,
55-
};
56-
5744
const ATLAS_VERSION = {
5845
atlasVersion: '20210330.0.0.1617063608',
5946
gitVersion: '8f7e5bdde713391e8123a463895bb7fb660a5ffd',
@@ -98,7 +85,6 @@ describe('getConnectInfo', function () {
9885
ATLAS_URI,
9986
'0.0.6',
10087
BUILD_INFO,
101-
CMD_LINE_OPTS,
10288
ATLAS_VERSION,
10389
TOPOLOGY_WITH_CREDENTIALS
10490
)
@@ -129,7 +115,6 @@ describe('getConnectInfo', function () {
129115
ATLAS_URI,
130116
'0.0.6',
131117
BUILD_INFO,
132-
CMD_LINE_OPTS,
133118
ATLAS_VERSION,
134119
TOPOLOGY_NO_CREDENTIALS
135120
)
@@ -156,14 +141,7 @@ describe('getConnectInfo', function () {
156141
uri: '',
157142
};
158143
expect(
159-
getConnectInfo(
160-
'',
161-
'0.0.6',
162-
BUILD_INFO,
163-
CMD_LINE_OPTS,
164-
null,
165-
TOPOLOGY_WITH_CREDENTIALS
166-
)
144+
getConnectInfo('', '0.0.6', BUILD_INFO, null, TOPOLOGY_WITH_CREDENTIALS)
167145
).to.deep.equal(output);
168146
});
169147

@@ -187,14 +165,7 @@ describe('getConnectInfo', function () {
187165
uri: '',
188166
};
189167
expect(
190-
getConnectInfo(
191-
'',
192-
'0.0.6',
193-
null,
194-
CMD_LINE_OPTS,
195-
null,
196-
TOPOLOGY_WITH_CREDENTIALS
197-
)
168+
getConnectInfo('', '0.0.6', null, null, TOPOLOGY_WITH_CREDENTIALS)
198169
).to.deep.equal(output);
199170
});
200171
});

packages/service-provider-core/src/connect-info.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,16 @@ export default function getConnectInfo(
2525
uri: string,
2626
mongoshVersion: string,
2727
buildInfo: any,
28-
cmdLineOpts: any,
2928
atlasVersion: any,
3029
topology: any
3130
): ConnectInfo {
3231
buildInfo ??= {}; // We're currently not getting buildInfo with --apiStrict.
3332
const { isGenuine: is_genuine, serverName: non_genuine_server_name } =
34-
getBuildInfo.getGenuineMongoDB(buildInfo, cmdLineOpts);
33+
getBuildInfo.getGenuineMongoDB(uri);
3534
// Atlas Data Lake has been renamed to Atlas Data Federation
3635
const { isDataLake: is_data_federation, dlVersion: dl_version } =
3736
getBuildInfo.getDataLake(buildInfo);
3837

39-
// get this information from topology rather than cmdLineOpts, since not all
40-
// connections are able to run getCmdLineOpts command
4138
const auth_type = topology.s.credentials
4239
? topology.s.credentials.mechanism
4340
: null;

packages/service-provider-server/src/cli-service-provider.spec.ts

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -961,25 +961,18 @@ describe('CliServiceProvider', function () {
961961
expect(info.extraInfo.is_atlas).to.equal(false);
962962
expect(info.extraInfo.is_localhost).to.equal(true);
963963
expect(info.extraInfo.fcv).to.equal(undefined);
964-
expect(dbStub.command).to.have.callCount(4);
964+
expect(dbStub.command).to.have.callCount(3);
965965
});
966966

967967
context('when connected to a DocumentDB deployment', function () {
968968
it('correctly gathers info on the fake deployment', async function () {
969-
dbStub.command.callsFake(
970-
(params) =>
971-
new Promise((resolve, reject) => {
972-
if (params.getCmdLineOpts) {
973-
reject({
974-
ok: 0,
975-
code: 303,
976-
message: 'Feature not supported: getCmdLineOpts',
977-
operationTime: Date.now(),
978-
});
979-
} else {
980-
resolve({ ok: 1 });
981-
}
982-
})
969+
const serviceProvider = new CliServiceProvider(
970+
clientStub,
971+
bus,
972+
dummyOptions,
973+
new ConnectionString(
974+
'mongodb://elastic-docdb-123456789.eu-central-1.docdb-elastic.amazonaws.com:27017'
975+
)
983976
);
984977

985978
const info = await serviceProvider.getConnectionInfo();
@@ -990,13 +983,14 @@ describe('CliServiceProvider', function () {
990983

991984
context('when connected to a CosmosDB deployment', function () {
992985
it('correctly gathers info on the fake deployment', async function () {
993-
// eslint-disable-next-line @typescript-eslint/require-await
994-
dbStub.command.callsFake(async (params) => {
995-
if (params.buildInfo) {
996-
return { ok: 1, _t: 1 };
997-
}
998-
return { ok: 1 };
999-
});
986+
const serviceProvider = new CliServiceProvider(
987+
clientStub,
988+
bus,
989+
dummyOptions,
990+
new ConnectionString(
991+
'mongodb+srv://compass-vcore.mongocluster.cosmos.azure.com'
992+
)
993+
);
1000994

1001995
const info = await serviceProvider.getConnectionInfo();
1002996
expect(info.extraInfo.is_genuine).to.be.false;

packages/service-provider-server/src/cli-service-provider.ts

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -331,49 +331,29 @@ class CliServiceProvider
331331
async getConnectionInfo(): Promise<ConnectionInfo> {
332332
const topology = this.getTopology();
333333
const { version } = require('../package.json');
334-
const [
335-
buildInfo = null,
336-
cmdLineOptsOrServerError = null,
337-
atlasVersion = null,
338-
fcv = null,
339-
] = await Promise.all([
340-
this.runCommandWithCheck(
341-
'admin',
342-
{ buildInfo: 1 },
343-
this.baseCmdOptions
344-
).catch(() => {}),
345-
this.runCommandWithCheck(
346-
'admin',
347-
{ getCmdLineOpts: 1 },
348-
this.baseCmdOptions
349-
).catch((e) => {
350-
// mongodb-build-info.getGenuineMongoDB expects either
351-
// the successful or failure response from server
352-
// Ref: https://github.com/mongodb-js/mongodb-build-info/blob/9247eeba730a905397ad09fe5a377067edc49b34/index.js#L89
353-
return {
354-
ok: e.ok,
355-
code: e.code,
356-
errmsg: e.message,
357-
operationTime: e.operationTime,
358-
};
359-
}),
360-
this.runCommandWithCheck(
361-
'admin',
362-
{ atlasVersion: 1 },
363-
this.baseCmdOptions
364-
).catch(() => {}),
365-
this.runCommandWithCheck(
366-
'admin',
367-
{ getParameter: 1, featureCompatibilityVersion: 1 },
368-
this.baseCmdOptions
369-
).catch(() => {}),
370-
]);
334+
const [buildInfo = null, atlasVersion = null, fcv = null] =
335+
await Promise.all([
336+
this.runCommandWithCheck(
337+
'admin',
338+
{ buildInfo: 1 },
339+
this.baseCmdOptions
340+
).catch(() => {}),
341+
this.runCommandWithCheck(
342+
'admin',
343+
{ atlasVersion: 1 },
344+
this.baseCmdOptions
345+
).catch(() => {}),
346+
this.runCommandWithCheck(
347+
'admin',
348+
{ getParameter: 1, featureCompatibilityVersion: 1 },
349+
this.baseCmdOptions
350+
).catch(() => {}),
351+
]);
371352

372353
const extraConnectionInfo = getConnectInfo(
373354
this.uri?.toString() ?? '',
374355
version,
375356
buildInfo,
376-
cmdLineOptsOrServerError,
377357
atlasVersion,
378358
topology
379359
);

0 commit comments

Comments
 (0)