-
Notifications
You must be signed in to change notification settings - Fork 9
feat(devtools-connect): make dns lookup configurable COMPASS-9793 #602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,7 @@ | |
| "depcheck": "depcheck", | ||
| "check": "npm run typecheck && npm run lint && npm run depcheck", | ||
| "check-ci": "npm run check", | ||
| "testonly": "nyc mocha --colors -r ts-node/register src/**/*.spec.ts", | ||
| "testonly": "nyc mocha --colors --register ts-node/register src/**/*.spec.ts", | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assertions were not pointing to the correct line in the tests without this change and the debugger would not stop on the breakpoint lines. |
||
| "test": "npm run lint && npm run compile && npm run testonly", | ||
| "test-cov": "nyc -x \"**/*.spec.*\" --reporter=lcov --reporter=text --reporter=html npm run test", | ||
| "test-watch": "npm run test -- --watch", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -412,6 +412,30 @@ describe('devtools connect', function () { | |
| expect(result.client).to.equal(mClient); | ||
| }); | ||
|
|
||
| it('allows lookup to be configured', async function () { | ||
| const uri = 'localhost:27017'; | ||
| const mClient = stubConstructor(FakeMongoClient); | ||
| const mClientType = sinon.stub().returns(mClient); | ||
| mClient.connect.onFirstCall().resolves(mClient); | ||
| const lookupSpy = sinon.spy(); | ||
| await connectMongoClient( | ||
| uri, | ||
| { ...defaultOpts, useSystemCA: false, lookup: lookupSpy }, | ||
| bus, | ||
| mClientType as any, | ||
| ); | ||
|
|
||
| // get options passed to mongo client | ||
| const finalClientOptions = mClientType.getCalls()[0].args[1]; | ||
| expect(finalClientOptions.lookup).to.not.equal(lookupSpy); // lookup is always wrapped | ||
| finalClientOptions.lookup('localhost', 27017, () => {}); // invoke it the way it would be by net/tls | ||
| expect(lookupSpy.getCalls()).to.have.lengthOf(1); // verify our input lookup was called instead of the dns package | ||
|
Comment on lines
+431
to
+432
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bit of an odd test but since we're mocking things we don't actually get to the point where the driver would cause lookup to be invoked, by calling it here I'm checking that our input is wrapped rather than used directly. |
||
| expect(lookupSpy.getCalls()[0].args[1]).to.have.property( | ||
| 'verbatim', | ||
| false, | ||
| ); // but we still always set verbatim to false | ||
| }); | ||
|
|
||
| describe('retryable TLS errors', function () { | ||
| it('retries TLS errors without system CA integration enabled -- MongoClient error', async function () { | ||
| const uri = 'localhost:27017'; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -588,10 +588,15 @@ async function connectMongoClientImpl({ | |||||||||||||||||||||||||||||
| ca ? { ca } : {}, | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| const customLookup = mongoClientOptions.lookup; | ||||||||||||||||||||||||||||||
| // Adopt dns result order changes with Node v18 that affected the VSCode extension VSCODE-458. | ||||||||||||||||||||||||||||||
| // Refs https://github.com/microsoft/vscode/issues/189805 | ||||||||||||||||||||||||||||||
| mongoClientOptions.lookup = (hostname, options, callback) => { | ||||||||||||||||||||||||||||||
| return dns.lookup(hostname, { verbatim: false, ...options }, callback); | ||||||||||||||||||||||||||||||
| return (customLookup ?? dns.lookup)( | ||||||||||||||||||||||||||||||
| hostname, | ||||||||||||||||||||||||||||||
| { verbatim: false, ...options }, | ||||||||||||||||||||||||||||||
| callback, | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
|
Comment on lines
+591
to
+599
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This could also just be
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe also link to NODE-6437 given that passing the flag is a way to work around shortcomings of the driver, not something we should be doing here |
||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| delete (mongoClientOptions as any).useSystemCA; // can be removed once no product uses this anymore | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this relates to the -r change, but not sure how.