-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(NODE-3924)!: read tls files async #3776
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
Merged
Merged
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
9881228
chore(NODE-3924): update package-lock.json
W-A-James b7763ae
feat(NODE-3924)!: read tls files async
W-A-James 0fbb2f9
test(NODE-3924): add unit test
W-A-James 28a2ba5
test(NODE-3924): move tests to manual tests
W-A-James 8bc7296
style(NODE-3924): eslint
W-A-James ddb1e7f
test(NODE-3924): update assertions
W-A-James 32de88b
style(NODE-3924): remove unneeded import
W-A-James d69dd69
fix(NODE-3924): remove unused option
W-A-James b418f99
test(NODE-3924): update test name
W-A-James e571b80
test(NODE-3924): fix test setup and timeouts
W-A-James 84a3a89
test(NODE-3924): update existing unit test
W-A-James 8acfbb6
test(NODE-3924): update table
W-A-James 52bf930
docs(NODE-3924): update tls options API docs
W-A-James 694b4a7
style(NODE-3924): eslint
W-A-James 0dfac88
test(NODE-3924): fix spec test
W-A-James 135aadf
fix(NODE-3924): change option names to shadow spec tls option names
W-A-James 428aa6f
Merge branch 'main' into NODE-3924
W-A-James 1053452
ci(NODE-3924): revert unneeded ci change
W-A-James 1e6d240
fix(NODE-3924): throw error on parse
W-A-James 20d09ea
test(NODE-3924): update tests
W-A-James 702f6f8
docs(NODE-3924): revert table change and modify heading
W-A-James 7438df7
style(NODE-3924): eslint
W-A-James b1d4e51
fix(NODE-3924): address review comments
W-A-James 253aa6d
fix(NODE-3924): revert unintended change
W-A-James c454e37
Update test/unit/mongo_client.test.js
W-A-James 5352581
fix(NODE-3924): Change to throw at connect time
W-A-James a67d3a1
fix(NODE-3924): throw on non-string
W-A-James af14ffe
test(NODE-3924): add test to throw on non-string values
W-A-James 1550a94
revert validation
W-A-James File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { expect } from 'chai'; | ||
import { promises as fs } from 'fs'; | ||
|
||
import { LEGACY_HELLO_COMMAND, MongoClient, type MongoClientOptions } from '../mongodb'; | ||
|
||
const REQUIRED_ENV = ['MONGODB_URI', 'SSL_KEY_FILE', 'SSL_CA_FILE']; | ||
|
||
describe('TLS Support', function () { | ||
for (const key of REQUIRED_ENV) { | ||
if (process.env[key] == null) { | ||
throw new Error(`skipping SSL tests, ${key} environment variable is not defined`); | ||
} | ||
} | ||
|
||
const CONNECTION_STRING = process.env.MONGODB_URI as string; | ||
const TLS_CERT_KEY_FILE = process.env.SSL_KEY_FILE as string; | ||
const TLS_CA_FILE = process.env.SSL_CA_FILE as string; | ||
const tlsSettings = { | ||
tls: true, | ||
tlsCertificateKeyFile: TLS_CERT_KEY_FILE, | ||
tlsCAFile: TLS_CA_FILE | ||
}; | ||
|
||
it( | ||
'should connect with tls via client options', | ||
makeConnectionTest(CONNECTION_STRING, tlsSettings) | ||
); | ||
|
||
it( | ||
'should connect with tls via url options', | ||
makeConnectionTest( | ||
`${CONNECTION_STRING}?${Object.keys(tlsSettings) | ||
.map(key => `${key}=${tlsSettings[key]}`) | ||
.join('&')}` | ||
) | ||
); | ||
|
||
context('when tls filepaths are provided', () => { | ||
let client: MongoClient; | ||
context('when tls filepaths have length > 0', () => { | ||
beforeEach(async () => { | ||
client = new MongoClient(CONNECTION_STRING, tlsSettings); | ||
}); | ||
|
||
afterEach(async () => { | ||
if (client) await client.close(); | ||
}); | ||
|
||
it('should read in files async at connect time', async () => { | ||
expect(client.options).property('tlsCAFile', TLS_CA_FILE); | ||
expect(client.options).property('tlsCertificateKeyFile', TLS_CERT_KEY_FILE); | ||
expect(client.options).not.have.property('ca'); | ||
expect(client.options).not.have.property('key'); | ||
|
||
await client.connect(); | ||
|
||
expect(client.options).property('ca').to.exist; | ||
expect(client.options).property('key').to.exist; | ||
}); | ||
|
||
context('when client has been opened and closed more than once', function () { | ||
it('should only read files once', async () => { | ||
await client.connect(); | ||
await client.close(); | ||
|
||
const caFileAccessTime = (await fs.stat(TLS_CA_FILE)).atime; | ||
const certKeyFileAccessTime = (await fs.stat(TLS_CERT_KEY_FILE)).atime; | ||
|
||
await client.connect(); | ||
|
||
expect((await fs.stat(TLS_CA_FILE)).atime).to.deep.equal(caFileAccessTime); | ||
expect((await fs.stat(TLS_CERT_KEY_FILE)).atime).to.deep.equal(certKeyFileAccessTime); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
function makeConnectionTest(connectionString: string, clientOptions?: MongoClientOptions) { | ||
return async function () { | ||
const client = new MongoClient(connectionString, clientOptions); | ||
|
||
await client.connect(); | ||
await client.db('admin').command({ [LEGACY_HELLO_COMMAND]: 1 }); | ||
await client.db('test').collection('test').findOne({}); | ||
return await client.close(); | ||
}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.