Skip to content
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

feat(NODE-5908): support range v2 protocol #13

Merged
merged 3 commits into from
Jun 12, 2024
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
8 changes: 3 additions & 5 deletions addon/mongocrypt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,7 @@ MongoCrypt::MongoCrypt(const CallbackInfo& info)
mongocrypt_setopt_bypass_query_analysis(_mongo_crypt.get());
}

if (options.Get("rangeV2").ToBoolean()) {
mongocrypt_setopt_use_range_v2(_mongo_crypt.get());
}
mongocrypt_setopt_use_range_v2(_mongo_crypt.get());

mongocrypt_setopt_use_need_kms_credentials_state(_mongo_crypt.get());

Expand Down Expand Up @@ -596,10 +594,10 @@ Value MongoCrypt::MakeExplicitEncryptionContext(const CallbackInfo& info) {
throw TypeError::New(Env(), errorStringFromStatus(context.get()));
}

if (strcasecmp(algorithm.c_str(), "rangepreview") == 0) {
if (strcasecmp(algorithm.c_str(), "range") == 0) {
if (!options.Has("rangeOptions")) {
throw TypeError::New(
Env(), "`rangeOptions` must be provided if `algorithm` is set to RangePreview");
Env(), "`rangeOptions` must be provided if `algorithm` is set to Range");
}

Uint8Array rangeOptions = Uint8ArrayFromValue(options["rangeOptions"], "rangeOptions");
Expand Down
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ export interface MongoCryptConstructor {
cryptSharedLibSearchPaths?: string[];
cryptSharedLibPath?: string;
bypassQueryAnalysis?: boolean;
/** @experimental */
rangeV2?: boolean;
}): MongoCrypt;
libmongocryptVersion: string;
}
Expand Down
14 changes: 7 additions & 7 deletions test/bindings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,17 +341,17 @@ describe('MongoCryptConstructor', () => {
});
});

context('when algorithm is `rangePreview', () => {
context('when algorithm is `Range', () => {
it('throws a TypeError if rangeOptions is not provided', () => {
expect(() =>
mc.makeExplicitEncryptionContext(value, {
// minimum required arguments from libmongocrypt
keyId: keyId.buffer,
expressionMode: false,
algorithm: 'rangePreview'
algorithm: 'Range'
})
)
.to.throw(/`rangeOptions` must be provided if `algorithm` is set to RangePreview/)
.to.throw(/`rangeOptions` must be provided if `algorithm` is set to Range/)
.to.be.instanceOf(TypeError);
});

Expand All @@ -361,26 +361,26 @@ describe('MongoCryptConstructor', () => {
// minimum required arguments from libmongocrypt
keyId: keyId.buffer,
expressionMode: false,
algorithm: 'rangePreview',
algorithm: 'Range',
rangeOptions: 'non-buffer'
})
)
.to.throw(/Parameter `rangeOptions` must be a Uint8Array./)
.to.be.instanceOf(TypeError);
});

it('checks if `rangePreview` is set case-insensitive', () => {
it('checks if `Range` is set case-insensitive', () => {
expect(
mc.makeExplicitEncryptionContext(value, {
// minimum required arguments from libmongocrypt
keyId: keyId.buffer,
expressionMode: false,
algorithm: 'RANGEPREVIEW',
algorithm: 'RANGE',
rangeOptions: serialize({
sparsity: new Long(42)
}),

// contention factor is required for `rangePreview` but
// contention factor is required for `Range` but
// is enforced in libmongocrypt, not our bindings
contentionFactor: 2
})
Expand Down
Loading