-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(NODE-6284): make sparsity and trimFactor optional #4189
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 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b9d141e
add back install dir
baileympearson 4a975a7
use latest FLE
baileympearson e3f2f2b
fix
baileympearson aea5126
fix tests on serverless
baileympearson d5a8631
new todo cmment
baileympearson 92f9317
latest spec sync
baileympearson 9911a80
Merge branch 'main' into NODE-6284
W-A-James 7a4664f
import from EJSON
baileympearson 62ecd77
suppoort other numeric types
baileympearson a8c8e58
types and lint
baileympearson 4498947
add prose test
baileympearson 716ebb2
fix lint
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
144 changes: 144 additions & 0 deletions
144
.../client-side-encryption/client_side_encryption.prose.23.range_encryption_defaults.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,144 @@ | ||
import { type Binary, EJSON, Int32, Long } from 'bson'; | ||
nbbeeken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import { expect } from 'chai'; | ||
|
||
/* eslint-disable @typescript-eslint/no-restricted-imports */ | ||
import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption'; | ||
import { installNodeDNSWorkaroundHooks } from '../../tools/runner/hooks/configuration'; | ||
|
||
const metaData: MongoDBMetadataUI = { | ||
requires: { | ||
clientSideEncryption: '>=6.1.0', | ||
|
||
// The Range Explicit Encryption tests require MongoDB server 7.0+ for QE v2. | ||
// The tests must not run against a standalone. | ||
// | ||
// `range` is not supported on 8.0+ servers. | ||
mongodb: '>=8.0.0', | ||
topology: '!single' | ||
} | ||
}; | ||
|
||
const getKmsProviders = (): { local: { key: string } } => { | ||
const result = EJSON.parse(process.env.CSFLE_KMS_PROVIDERS || '{}') as unknown as { | ||
local: { key: string }; | ||
}; | ||
|
||
return { local: result.local }; | ||
}; | ||
|
||
describe('Range Explicit Encryption Defaults', function () { | ||
installNodeDNSWorkaroundHooks(); | ||
|
||
let clientEncryption: ClientEncryption; | ||
let keyId; | ||
let keyVaultClient; | ||
let payload_defaults: Binary; | ||
|
||
beforeEach(async function () { | ||
// Create a MongoClient named `keyVaultClient`. | ||
keyVaultClient = this.configuration.newClient(); | ||
|
||
// Create a ClientEncryption object named `clientEncryption` with these options: | ||
// ```typescript | ||
// class ClientEncryptionOpts { | ||
// keyVaultClient: keyVaultClient, | ||
// keyVaultNamespace: "keyvault.datakeys", | ||
// kmsProviders: { "local": { "key": "<base64 decoding of LOCAL_MASTERKEY>" } }, | ||
// } | ||
// ``` | ||
clientEncryption = new ClientEncryption(keyVaultClient, { | ||
keyVaultNamespace: 'keyvault.datakeys', | ||
kmsProviders: getKmsProviders() | ||
}); | ||
|
||
// Create a key with `clientEncryption.createDataKey`. Store the returned key ID in a variable named `keyId`. | ||
keyId = await clientEncryption.createDataKey('local'); | ||
|
||
// Call `clientEncryption.encrypt` to encrypt the int32 value `123` with these options: | ||
// ```typescript | ||
// class EncryptOpts { | ||
// keyId : keyId, | ||
// algorithm: "Range", | ||
// contentionFactor: 0, | ||
// rangeOpts: RangeOpts { | ||
// min: 0, | ||
// max: 1000 | ||
// } | ||
// } | ||
// ``` | ||
// Store the result in a variable named `payload_defaults`. | ||
payload_defaults = await clientEncryption.encrypt(new Int32(123), { | ||
keyId, | ||
algorithm: 'Range', | ||
contentionFactor: 0, | ||
rangeOptions: { | ||
min: 0, | ||
max: 1000 | ||
} | ||
}); | ||
}); | ||
|
||
afterEach(async function () { | ||
await keyVaultClient.close(); | ||
}); | ||
|
||
it('Case 1: Uses libmongocrypt defaults', metaData, async function () { | ||
// Call `clientEncryption.encrypt` to encrypt the int32 value `123` with these options: | ||
// ```typescript | ||
// class EncryptOpts { | ||
// keyId : keyId, | ||
// algorithm: "Range", | ||
// contentionFactor: 0, | ||
// rangeOpts: RangeOpts { | ||
// min: 0, | ||
// max: 1000, | ||
// sparsity: 2, | ||
// trimFactor: 6 | ||
// } | ||
// } | ||
// ``` | ||
const encrypted = await clientEncryption.encrypt(new Int32(123), { | ||
keyId: keyId, | ||
algorithm: 'Range', | ||
contentionFactor: 0, | ||
rangeOptions: { | ||
min: 0, | ||
max: 1000, | ||
sparsity: new Long(2), | ||
trimFactor: new Int32(6) | ||
} | ||
}); | ||
|
||
// Assert the returned payload size equals the size of `payload_defaults`. | ||
expect(encrypted.length()).to.equal(payload_defaults.length()); | ||
}); | ||
|
||
it('Case 2: can find encrypted range and return the maximum', metaData, async function () { | ||
// Call `clientEncryption.encrypt` to encrypt the int32 value `123` with these options: | ||
// ```typescript | ||
// class EncryptOpts { | ||
// keyId : keyId, | ||
// algorithm: "Range", | ||
// contentionFactor: 0, | ||
// rangeOpts: RangeOpts { | ||
// min: 0, | ||
// max: 1000, | ||
// trimFactor: 0 | ||
// } | ||
// } | ||
// ``` | ||
const encrypted = await clientEncryption.encrypt(new Int32(123), { | ||
keyId: keyId, | ||
algorithm: 'Range', | ||
contentionFactor: 0, | ||
rangeOptions: { | ||
min: 0, | ||
max: 1000, | ||
trimFactor: new Int32(0) | ||
} | ||
}); | ||
|
||
// Assert the returned payload size is greater than the size of `payload_defaults`. | ||
expect(encrypted.length()).to.be.greaterThan(payload_defaults.length()); | ||
}); | ||
}); |
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.