Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion packages/build/src/compile/signable-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export class SignableCompiler {
path: await findModulePath('service-provider-server', 'mongodb-client-encryption'),
requireRegexp: /\bmongocrypt\.node$/
};
const osDnsAddon = {
path: await findModulePath('service-provider-server', 'os-dns-native'),
requireRegexp: /\bos_dns_native\.node$/
};
const winCAAddon = process.platform === 'win32' ? {
path: await findModulePath('cli-repl', 'win-export-certificate-and-key'),
requireRegexp: /\bwin_export_cert\.node$/
Expand Down Expand Up @@ -93,7 +97,8 @@ export class SignableCompiler {
AWS_SECRET_ACCESS_KEY: process.env.DEVTOOLS_CI_AWS_SECRET
},
addons: [
fleAddon
fleAddon,
osDnsAddon
].concat(winCAAddon ? [
winCAAddon
] : []).concat(macKeychainAddon ? [
Expand Down
13 changes: 13 additions & 0 deletions packages/connectivity-tests/test/atlas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,24 @@ function test_data_lake() {
check_failed
}

function test_srv_without_nodejs_dns() {
printf "test_srv_without_nodejs_dns ... "

CONNECTION_STRING="mongodb+srv://${ATLAS_USERNAME}:${ATLAS_PASSWORD}@${ATLAS_HOSTNAME}/admin"

echo "${CONNECTION_STATUS_COMMAND}" | NODE_OPTIONS="-r ${MONGOSH_ROOT_DIR}/testing/disable-dns-srv.js" mongosh "${CONNECTION_STRING}" |
grep -Fq "${CONNECTION_STATUS_CHECK_STRING}" ||
FAILED="Can't connect to Atlas using connection string without Node.js SRV/TXT DNS support"

check_failed
}

test_connection_string
test_atlas_in_logs
test_credentials_masking
test_cli_args
test_password_prompt
test_data_lake
test_srv_without_nodejs_dns

echo "All Atlas tests are passing"
70 changes: 70 additions & 0 deletions packages/service-provider-server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/service-provider-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
"@types/bl": "^2.1.0"
},
"optionalDependencies": {
"mongodb-client-encryption": "^1.2.3"
"mongodb-client-encryption": "^1.2.3",
"os-dns-native": "^1.0.3",
"resolve-mongodb-srv": "^1.0.1"
}
}
23 changes: 23 additions & 0 deletions packages/service-provider-server/src/cli-service-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,28 @@ async function connectWithFailFast(client: MongoClient): Promise<void> {
}
}

let resolveDnsHelpers: {
resolve: typeof import('resolve-mongodb-srv'),
osDns: typeof import('os-dns-native')
} | undefined = undefined;

async function resolveMongodbSrv(uri: string): Promise<string> {
if (uri.startsWith('mongodb+srv://')) {
try {
resolveDnsHelpers ??= {
resolve: require('resolve-mongodb-srv'),
osDns: require('os-dns-native')
};
} catch { /* ignore */ }
if (resolveDnsHelpers !== undefined) {
return await resolveDnsHelpers.resolve(uri, {
dns: resolveDnsHelpers.osDns.withNodeFallback
});
}
}
return uri;
}

/**
* Connect a MongoClient. If AutoEncryption is requested, first connect without the encryption options and verify that
* the connection is to an enterprise cluster. If not, then error, otherwise close the connection and reconnect with the
Expand All @@ -182,6 +204,7 @@ export async function connectMongoClient(uri: string, clientOptions: MongoClient
}
await client.close();
}
uri = await resolveMongodbSrv(uri);
const client = new MClient(uri, clientOptions);
await connectWithFailFast(client);
return client;
Expand Down
26 changes: 26 additions & 0 deletions testing/disable-dns-srv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';
const dns = require('dns');
console.log('!!! Disabling SRV and TXT DNS queries through the Node.js API !!!');

const origResolve = dns.resolve;
const origPromiseResolve = dns.promises.resolve;
const err = Object.assign(new Error('SRV and TXT not available'), { code: 'ENODATA' });

dns.resolve = (hostname, type, cb) => {
if (type === 'SRV' || type === 'TXT')
return process.nextTick(cb, err);
return origResolve(hostname, type, cb);
};
dns.resolveSrv = (hostname, cb) => {
return process.nextTick(cb, err);
};
dns.resolveTxt = (hostname, cb) => {
return process.nextTick(cb, err);
};
dns.promises.resolve = async(hostname, type) => {
if (type === 'SRV' || type === 'TXT')
throw err;
await origPromiseResolve;
};
dns.promises.resolveSrv = () => Promise.reject(err);
dns.promises.resolveTxt = () => Promise.reject(err);