-
Notifications
You must be signed in to change notification settings - Fork 1.8k
test(NODE-4663): add csfle prose test 20 #4585
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 all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
732b009
add csfle prose test 20
baileympearson 2e06e53
comment test
baileympearson e5e6b2a
add dbName to cmd events
baileympearson 904ded1
sync invalid tests
baileympearson 0a36b57
unless -> if
baileympearson 09856aa
add cyrpt_shared filter
baileympearson 07de741
make ClientSideEncryptionFilter use instance fields, not static fields
baileympearson a4e3638
Merge branch 'main' into NODE-4663
baileympearson 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
75 changes: 75 additions & 0 deletions
75
...gration/client-side-encryption/client_side_encryption.prose.20.mongocryptd_client.test.ts
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,75 @@ | ||
import { expect } from 'chai'; | ||
import { once } from 'events'; | ||
import { createServer, type Server } from 'net'; | ||
|
||
import { getCSFLEKMSProviders } from '../../csfle-kms-providers'; | ||
import { type MongoClient } from '../../mongodb'; | ||
import { getEncryptExtraOptions } from '../../tools/utils'; | ||
|
||
describe('20. Bypass creating mongocryptd client when shared library is loaded', function () { | ||
let server: Server; | ||
let hasConnection = false; | ||
let client: MongoClient; | ||
|
||
beforeEach(function () { | ||
// Start a new thread (referred to as listenerThread) | ||
// On listenerThread, create a TcpListener on 127.0.0.1 endpoint and port 27021. Start the listener and wait for establishing connections. If any connection is established, then signal about this to the main thread. | ||
// Drivers MAY pass a different port if they expect their testing infrastructure to be using port 27021. Pass a port that should be free. | ||
// In Node, we don't need to create a separate thread for the server. | ||
server = createServer({}); | ||
server.listen(27021); | ||
server.on('connection', () => (hasConnection = true)); | ||
|
||
// Create a MongoClient configured with auto encryption (referred to as client_encrypted) | ||
// Configure the required options. Use the local KMS provider as follows: | ||
// { "local": { "key": <base64 decoding of LOCAL_MASTERKEY> } } | ||
// Configure with the keyVaultNamespace set to keyvault.datakeys. | ||
// Configure the following extraOptions: | ||
// { | ||
// "mongocryptdURI": "mongodb://localhost:27021/?serverSelectionTimeoutMS=1000" | ||
// } | ||
client = this.configuration.newClient( | ||
{}, | ||
{ | ||
autoEncryption: { | ||
kmsProviders: { local: getCSFLEKMSProviders().local }, | ||
keyVaultNamespace: 'keyvault.datakeys', | ||
extraOptions: { | ||
cryptSharedLibPath: getEncryptExtraOptions().cryptSharedLibPath, | ||
mongocryptdURI: 'mongodb://localhost:27021' | ||
} | ||
} | ||
} | ||
); | ||
}); | ||
|
||
afterEach(async function () { | ||
server && (await once(server.close(), 'close')); | ||
await client?.close(); | ||
}); | ||
|
||
it( | ||
'does not create or use a mongocryptd client when the shared library is loaded', | ||
{ | ||
requires: { | ||
clientSideEncryption: true, | ||
crypt_shared: 'enabled' | ||
} | ||
}, | ||
async function () { | ||
// Use client_encrypted to insert the document {"unencrypted": "test"} into db.coll. | ||
await client.db('db').collection('coll').insertOne({ unencrypted: 'test' }); | ||
|
||
// Expect no signal from listenerThread. | ||
expect(hasConnection).to.be.false; | ||
|
||
// Note: this assertion is not in the spec test. However, unlike other drivers, Node's client | ||
// does not connect when instantiated. So, we won't receive any TCP connections to the | ||
// server if the mongocryptd client is only instantiated. This assertion captures the | ||
// spirit of this test, causing it to fail if we do instantiate a client. I left the | ||
// TCP server in, although it isn't necessary for Node's test, just because its nice to have | ||
// in case Node's client behavior ever changes. | ||
expect(client.autoEncrypter._mongocryptdClient).to.be.undefined; | ||
} | ||
); | ||
}); |
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
Oops, something went wrong.
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.