Skip to content

Commit a7065e9

Browse files
test and fix
1 parent 72f049b commit a7065e9

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

addon/mongocrypt.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,10 @@ Value MongoCrypt::MakeExplicitEncryptionContext(const CallbackInfo& info) {
565565

566566
Object options = info.Length() > 1 ? info[1].ToObject() : Object::New(info.Env());
567567

568+
if (!options.Has("expressionMode") || !options.Get("expressionMode").IsBoolean()) {
569+
throw TypeError::New(Env(), "option `expressionMode` is required.");
570+
}
571+
568572
if (!options.Get("keyId").IsUndefined()) {
569573
Uint8Array keyId = Uint8ArrayFromValue(options["keyId"], "keyId");
570574

@@ -627,9 +631,6 @@ Value MongoCrypt::MakeExplicitEncryptionContext(const CallbackInfo& info) {
627631
std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> binaryValue(
628632
Uint8ArrayToBinary(valueBuffer));
629633

630-
if (!options.Has("expressionMode") || !options.Get("expressionMode").IsBoolean()) {
631-
throw TypeError::New(Env(), "`rangeOptions` must be provided if `algorithm` is set to Range");
632-
}
633634
const bool isExpressionMode = options.Get("expressionMode").ToBoolean();
634635

635636
const bool status =

test/bindings.test.ts

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ describe('MongoCryptConstructor', () => {
1919
const mc = new MongoCrypt({
2020
kmsProviders: serialize({ aws: {} }),
2121
cryptoCallbacks: {
22-
aes256CbcEncryptHook: () => {},
23-
aes256CbcDecryptHook: () => {},
24-
aes256CtrEncryptHook: () => {},
25-
aes256CtrDecryptHook: () => {},
22+
aes256CbcEncryptHook: () => { },
23+
aes256CbcDecryptHook: () => { },
24+
aes256CtrEncryptHook: () => { },
25+
aes256CtrDecryptHook: () => { },
2626
randomHook,
27-
hmacSha512Hook: () => {},
28-
hmacSha256Hook: () => {},
29-
sha256Hook: () => {},
30-
signRsaSha256Hook: () => {}
27+
hmacSha512Hook: () => { },
28+
hmacSha256Hook: () => { },
29+
sha256Hook: () => { },
30+
signRsaSha256Hook: () => { }
3131
}
3232
});
3333

@@ -41,17 +41,17 @@ describe('MongoCryptConstructor', () => {
4141
kmsProviders: serialize({ aws: {} }),
4242
schemaMap: serialize({}),
4343
encryptedFieldsMap: serialize({}),
44-
logger: () => {},
44+
logger: () => { },
4545
cryptoCallbacks: {
46-
aes256CbcEncryptHook: () => {},
47-
aes256CbcDecryptHook: () => {},
48-
aes256CtrEncryptHook: () => {},
49-
aes256CtrDecryptHook: () => {},
46+
aes256CbcEncryptHook: () => { },
47+
aes256CbcDecryptHook: () => { },
48+
aes256CtrEncryptHook: () => { },
49+
aes256CtrDecryptHook: () => { },
5050
randomHook,
51-
hmacSha512Hook: () => {},
52-
hmacSha256Hook: () => {},
53-
sha256Hook: () => {},
54-
signRsaSha256Hook: () => {}
51+
hmacSha512Hook: () => { },
52+
hmacSha256Hook: () => { },
53+
sha256Hook: () => { },
54+
signRsaSha256Hook: () => { }
5555
},
5656

5757
bypassQueryAnalysis: false
@@ -387,6 +387,21 @@ describe('MongoCryptConstructor', () => {
387387
).to.be.instanceOf(MongoCryptContextCtor);
388388
});
389389
});
390+
391+
392+
describe('options.expressionMode', function () {
393+
it('throws if `expressionMode` is not defined', function () {
394+
expect(() =>
395+
mc.makeExplicitEncryptionContext(value, {
396+
// minimum required arguments from libmongocrypt
397+
keyId: keyId.buffer,
398+
algorithm: 'Unindexed'
399+
})
400+
)
401+
.to.throw(/option `expressionMode` is required./)
402+
.to.be.instanceOf(TypeError);
403+
});
404+
})
390405
});
391406
});
392407

0 commit comments

Comments
 (0)