libmongocrypt-helper 1.7.4.0.1002 → 1.8.0.0.1001
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +9 -7
- data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +17 -23
- data/ext/libmongocrypt/libmongocrypt/Earthfile +374 -0
- data/ext/libmongocrypt/libmongocrypt/README.md +7 -7
- data/ext/libmongocrypt/libmongocrypt/VERSION_CURRENT +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClient.cs +25 -6
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Library.cs +25 -3
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Example/MongoDB.Libmongocrypt.Example.csproj +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/BasicTests.cs +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.cake +3 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/cs.sln +79 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/build.gradle.kts +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/java/com/mongodb/crypt/capi/MongoCryptTest.java +6 -4
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/CHANGELOG.md +24 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/README.md +134 -5
- data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/build-static.sh +3 -6
- data/ext/libmongocrypt/libmongocrypt/bindings/node/index.d.ts +203 -77
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/autoEncrypter.js +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/clientEncryption.js +165 -43
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/common.js +12 -14
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/errors.js +75 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/index.js +34 -3
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/aws.js +26 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/azure.js +178 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/gcp.js +24 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/index.js +54 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/utils.js +39 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/stateMachine.js +9 -4
- data/ext/libmongocrypt/libmongocrypt/bindings/node/package-lock.json +4440 -5189
- data/ext/libmongocrypt/libmongocrypt/bindings/node/package.json +27 -8
- data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.cc +65 -38
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/autoEncrypter.test.js +4 -7
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/clientEncryption.test.js +434 -42
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/common.test.js +94 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/cryptoCallbacks.test.js +1 -45
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/index.test.js +45 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/mongocryptdManager.test.js +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/providers/credentialsProvider.test.js +551 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/release.test.js +10 -3
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/requirements.helper.js +23 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/stateMachine.test.js +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/chai-addons.js +8 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/types/index.test-d.ts +63 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +26 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/README.rst +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/python/build-manylinux-wheel.sh +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +128 -238
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/compat.py +0 -27
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/explicit_encrypter.py +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +5 -21
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/python/release.sh +5 -5
- data/ext/libmongocrypt/libmongocrypt/bindings/python/setup.py +14 -9
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/__init__.py +1 -10
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_mongocrypt.py +5 -5
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test-requirements.txt +4 -12
- data/ext/libmongocrypt/libmongocrypt/cmake/ImportBSON.cmake +8 -6
- data/ext/libmongocrypt/libmongocrypt/cmake/IntelDFP.cmake +2 -1
- data/ext/libmongocrypt/libmongocrypt/cmake/Platform.cmake +50 -0
- data/ext/libmongocrypt/libmongocrypt/cmake/mongocrypt-config.cmake +21 -0
- data/ext/libmongocrypt/libmongocrypt/debian/gbp.conf +2 -2
- data/ext/libmongocrypt/libmongocrypt/etc/c6-vault.repo +39 -0
- data/ext/libmongocrypt/libmongocrypt/etc/fle2_aead_generate_tests.py +15 -24
- data/ext/libmongocrypt/libmongocrypt/etc/fle2_crypto.py +66 -54
- data/ext/libmongocrypt/libmongocrypt/etc/fle2_generate_tests.py +14 -23
- data/ext/libmongocrypt/libmongocrypt/etc/fle2v2_aead_generate_tests.py +32 -0
- data/ext/libmongocrypt/libmongocrypt/etc/format-all.sh +12 -0
- data/ext/libmongocrypt/libmongocrypt/etc/format.sh +16 -0
- data/ext/libmongocrypt/libmongocrypt/etc/install-package.sh +48 -0
- data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-libmongocrypt-pr-625.patch +13 -0
- data/ext/libmongocrypt/libmongocrypt/src/crypto/cng.c +381 -436
- data/ext/libmongocrypt/libmongocrypt/src/crypto/commoncrypto.c +162 -227
- data/ext/libmongocrypt/libmongocrypt/src/crypto/libcrypto.c +180 -248
- data/ext/libmongocrypt/libmongocrypt/src/crypto/none.c +33 -55
- data/ext/libmongocrypt/libmongocrypt/src/csfle-markup.cpp +175 -205
- data/ext/libmongocrypt/libmongocrypt/src/mc-array-private.h +10 -21
- data/ext/libmongocrypt/libmongocrypt/src/mc-array.c +44 -56
- data/ext/libmongocrypt/libmongocrypt/src/mc-check-conversions-private.h +4 -8
- data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.h +351 -463
- data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.test.cpp +59 -66
- data/ext/libmongocrypt/libmongocrypt/src/mc-efc-private.h +7 -11
- data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +80 -92
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle-blob-subtype-private.h +18 -10
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +59 -70
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +384 -439
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private-v2.h +41 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private.h +11 -18
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-v2.c +135 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload.c +109 -126
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private-v2.h +88 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private.h +24 -27
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +137 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload.c +106 -125
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private-v2.h +117 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private.h +28 -36
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +294 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload.c +237 -278
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private-v2.h +133 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private.h +67 -56
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-v2.c +437 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev.c +476 -325
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common-private.h +69 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common.c +182 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-private.h +23 -31
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2-private.h +85 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2.c +142 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev.c +104 -231
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-range-operator-private.h +8 -7
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds-private.h +55 -56
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +517 -580
- data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +36 -66
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +57 -76
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +158 -189
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +36 -42
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +515 -558
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +155 -191
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +43 -53
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +170 -240
- data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +29 -34
- data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +289 -338
- data/ext/libmongocrypt/libmongocrypt/src/mc-reader-private.h +36 -71
- data/ext/libmongocrypt/libmongocrypt/src/mc-reader.c +111 -164
- data/ext/libmongocrypt/libmongocrypt/src/mc-tokens-private.h +55 -49
- data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +109 -125
- data/ext/libmongocrypt/libmongocrypt/src/mc-writer-private.h +66 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-writer.c +141 -0
- data/ext/libmongocrypt/libmongocrypt/src/mlib/check.hpp +37 -55
- data/ext/libmongocrypt/libmongocrypt/src/mlib/endian.h +11 -11
- data/ext/libmongocrypt/libmongocrypt/src/mlib/error.h +27 -32
- data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.h +444 -499
- data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +251 -334
- data/ext/libmongocrypt/libmongocrypt/src/mlib/macros.h +4 -5
- data/ext/libmongocrypt/libmongocrypt/src/mlib/path.h +196 -231
- data/ext/libmongocrypt/libmongocrypt/src/mlib/path.test.c +56 -79
- data/ext/libmongocrypt/libmongocrypt/src/mlib/str.h +411 -530
- data/ext/libmongocrypt/libmongocrypt/src/mlib/str.test.c +116 -131
- data/ext/libmongocrypt/libmongocrypt/src/mlib/thread.h +17 -26
- data/ext/libmongocrypt/libmongocrypt/src/mlib/user-check.h +2 -2
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary-private.h +3 -6
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary.c +31 -48
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer-private.h +55 -131
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer.c +444 -565
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo-private.h +1 -2
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo.c +28 -45
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key-private.h +11 -17
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key.c +103 -132
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth-private.h +8 -14
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth.c +78 -90
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-private.h +26 -45
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache.c +220 -273
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext-private.h +13 -25
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext.c +147 -166
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-compat.h +2 -2
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto-private.h +110 -204
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto.c +1137 -1565
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +425 -472
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +817 -694
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +2394 -2697
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-private.h +166 -186
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-rewrap-many-datakey.c +308 -351
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +921 -1138
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +16 -24
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endian-private.h +44 -58
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint-private.h +21 -25
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint.c +167 -181
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek-private.h +37 -43
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek.c +215 -253
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker-private.h +73 -108
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +889 -1034
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-private.h +27 -44
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key.c +349 -402
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx-private.h +92 -120
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx.c +1397 -1612
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log-private.h +35 -67
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log.c +49 -83
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking-private.h +30 -36
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +1821 -1470
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-mutex-private.h +7 -12
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +80 -108
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +354 -424
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +101 -117
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status-private.h +3 -8
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status.c +92 -119
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util-private.h +19 -29
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util.c +136 -176
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util-private.h +11 -21
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util.c +96 -135
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +1092 -1320
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.h +130 -295
- data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +66 -78
- data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_mutex.c +20 -28
- data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +60 -73
- data/ext/libmongocrypt/libmongocrypt/src/os_win/os_mutex.c +8 -16
- data/ext/libmongocrypt/libmongocrypt/test/crypt_shared-stub.cpp +57 -87
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/empty/encrypted-payload-v2.json +60 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/success/encrypted-payload-v2.json +67 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/encrypted-payload.json +2 -2
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-contentionFactor1-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-contentionFactor1-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-same-user-and-index-key-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/cmd.json +6 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-field-map.json +22 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-payload.json +40 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/mongocryptd-reply.json +19 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/cmd.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/cmd.json +6 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-payload.json +50 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/mongocryptd-reply.json +58 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/cmd.json +6 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-field-map.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double/encrypted-payload-v2.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double-precision/encrypted-payload-v2.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32/encrypted-payload-v2.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload-v2.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-openinterval/encrypted-payload-v2.json +16 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert/cmd.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date/RNG_DATA.h +65 -65
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/cmd.json +13 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128/RNG_DATA.h +132 -132
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision/RNG_DATA.h +71 -71
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-payload.json +53 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/mongocryptd-reply.json +61 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double/RNG_DATA.h +68 -68
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision/RNG_DATA.h +19 -19
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-field-map.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-payload.json +47 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/mongocryptd-reply.json +55 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32/RNG_DATA.h +25 -25
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64/RNG_DATA.h +65 -65
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/RNG_DATA.h +68 -68
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/RNG_DATA.h +19 -19
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/RNG_DATA.h +25 -25
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/RNG_DATA.h +15 -15
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-field-map.json +18 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-payload.json +14 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/mongocryptd-reply.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-field-map.json +22 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-payload.json +39 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneRangeV2.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneV2.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/README.md +17 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/aes-ctr.json +29 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-fixed.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-generated.json +38 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-decrypt.json +35 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-fixed.json +29 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-generated.json +122 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-fixed.json +29 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-generated.json +122 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/mcgrew.json +12 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/nist.json +20 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/tokens/README.md +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +21 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +21 -0
- data/ext/libmongocrypt/libmongocrypt/test/example-no-bson.c +4 -4
- data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +278 -323
- data/ext/libmongocrypt/libmongocrypt/test/fuzz_kms.c +8 -7
- data/ext/libmongocrypt/libmongocrypt/test/test-dll.cpp +6 -7
- data/ext/libmongocrypt/libmongocrypt/test/test-gcp-auth.c +221 -283
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-efc.c +58 -73
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-equality-payload-v2.c +78 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-range-payload-v2.c +89 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev-v2.c +248 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev.c +467 -414
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup-v2.c +172 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup.c +141 -159
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev-v2.c +338 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev.c +238 -176
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-rfds.c +373 -474
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-edge-generation.c +346 -388
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +708 -825
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +417 -481
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +110 -144
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-reader.c +124 -207
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +223 -213
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-writer.c +176 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +634 -807
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.h +1 -2
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert.h +168 -189
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-buffer.c +187 -211
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache-oauth.c +34 -36
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache.c +210 -233
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ciphertext.c +185 -220
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-compact.c +331 -445
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +670 -814
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +102 -135
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.h +54 -71
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto.c +394 -846
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-csfle-lib.c +159 -183
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-decrypt.c +867 -1045
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +4349 -4713
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +750 -964
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +991 -1178
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +342 -419
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-dll.c +23 -30
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-endpoint.c +98 -111
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kek.c +49 -52
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-broker.c +770 -920
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-cache.c +354 -407
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key.c +197 -245
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-ctx.c +286 -370
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-responses.c +147 -166
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-local-kms.c +50 -61
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-log.c +85 -100
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-marking.c +656 -692
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-status.c +46 -58
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-traverse-util.c +377 -451
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.c +48 -67
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.h +4 -10
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +827 -918
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +111 -172
- data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +508 -559
- data/ext/libmongocrypt/libmongocrypt/test/util/util.c +735 -881
- data/ext/libmongocrypt/libmongocrypt/test/util/util.h +33 -55
- data/lib/libmongocrypt_helper/version.rb +2 -2
- data.tar.gz.sig +0 -0
- metadata +154 -26
- metadata.gz.sig +0 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/key-document.json +0 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/credentialsProvider.js +0 -33
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/credentialsProvider.test.js +0 -163
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
- data/ext/libmongocrypt/libmongocrypt/test/data/aes-ctr.cstructs +0 -359
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-aead.cstructs +0 -109
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload.json +0 -26
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/rangeopts.json +0 -5
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/value-to-encrypt.json +0 -20
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/RNG_DATA.h +0 -70
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload.json +0 -8
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/rangeopts.json +0 -5
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/value-to-encrypt.json +0 -5
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2.cstructs +0 -33
- /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/key-filter.json +0 -0
- /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
- /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
- /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
- /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
'use strict';
|
2
2
|
const fs = require('fs');
|
3
|
-
const expect = require('chai')
|
3
|
+
const { expect } = require('chai');
|
4
4
|
const sinon = require('sinon');
|
5
5
|
const mongodb = require('mongodb');
|
6
6
|
const BSON = mongodb.BSON;
|
@@ -9,6 +9,10 @@ const cryptoCallbacks = require('../lib/cryptoCallbacks');
|
|
9
9
|
const stateMachine = require('../lib/stateMachine')({ mongodb });
|
10
10
|
const StateMachine = stateMachine.StateMachine;
|
11
11
|
const { Binary, EJSON, deserialize } = BSON;
|
12
|
+
const {
|
13
|
+
MongoCryptCreateEncryptedCollectionError,
|
14
|
+
MongoCryptCreateDataKeyError
|
15
|
+
} = require('../lib/errors');
|
12
16
|
|
13
17
|
function readHttpResponse(path) {
|
14
18
|
let data = fs.readFileSync(path, 'utf8').toString();
|
@@ -27,12 +31,20 @@ class MockClient {
|
|
27
31
|
bson: BSON
|
28
32
|
};
|
29
33
|
}
|
34
|
+
db(dbName) {
|
35
|
+
return {
|
36
|
+
async createCollection(name, options) {
|
37
|
+
return { namespace: `${dbName}.${name}`, options };
|
38
|
+
}
|
39
|
+
};
|
40
|
+
}
|
30
41
|
}
|
31
42
|
|
32
43
|
const requirements = require('./requirements.helper');
|
33
44
|
|
34
45
|
describe('ClientEncryption', function () {
|
35
46
|
this.timeout(12000);
|
47
|
+
/** @type {MongoClient} */
|
36
48
|
let client;
|
37
49
|
|
38
50
|
function throwIfNotNsNotFoundError(err) {
|
@@ -42,10 +54,7 @@ describe('ClientEncryption', function () {
|
|
42
54
|
}
|
43
55
|
|
44
56
|
async function setup() {
|
45
|
-
client = new MongoClient('mongodb://localhost:27017/test'
|
46
|
-
useNewUrlParser: true,
|
47
|
-
useUnifiedTopology: true
|
48
|
-
});
|
57
|
+
client = new MongoClient(process.env.MONGODB_URI || 'mongodb://localhost:27017/test');
|
49
58
|
await client.connect();
|
50
59
|
try {
|
51
60
|
await client.db('client').collection('encryption').drop();
|
@@ -202,7 +211,7 @@ describe('ClientEncryption', function () {
|
|
202
211
|
options: { masterKey: { region: 'region', key: 'cmk' } }
|
203
212
|
}
|
204
213
|
].forEach(providerTest => {
|
205
|
-
it(`should create a data key with the "${providerTest.name}" KMS provider`, function (
|
214
|
+
it(`should create a data key with the "${providerTest.name}" KMS provider`, async function () {
|
206
215
|
const providerName = providerTest.name;
|
207
216
|
const encryption = new ClientEncryption(client, {
|
208
217
|
keyVaultNamespace: 'client.encryption',
|
@@ -210,24 +219,16 @@ describe('ClientEncryption', function () {
|
|
210
219
|
});
|
211
220
|
|
212
221
|
const dataKeyOptions = providerTest.options || {};
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
.findOne({ _id: dataKey }, (err, doc) => {
|
221
|
-
expect(err).to.not.exist;
|
222
|
-
expect(doc).to.have.property('masterKey');
|
223
|
-
expect(doc.masterKey).to.have.property('provider');
|
224
|
-
expect(doc.masterKey.provider).to.eql(providerName);
|
225
|
-
done();
|
226
|
-
});
|
227
|
-
});
|
222
|
+
|
223
|
+
const dataKey = await encryption.createDataKey(providerName, dataKeyOptions);
|
224
|
+
expect(dataKey).property('_bsontype', 'Binary');
|
225
|
+
|
226
|
+
const doc = await client.db('client').collection('encryption').findOne({ _id: dataKey });
|
227
|
+
expect(doc).to.have.property('masterKey');
|
228
|
+
expect(doc.masterKey).property('provider', providerName);
|
228
229
|
});
|
229
230
|
|
230
|
-
it(`should create a data key with the "${providerTest.name}" KMS provider (fixed key material)`, function (
|
231
|
+
it(`should create a data key with the "${providerTest.name}" KMS provider (fixed key material)`, async function () {
|
231
232
|
const providerName = providerTest.name;
|
232
233
|
const encryption = new ClientEncryption(client, {
|
233
234
|
keyVaultNamespace: 'client.encryption',
|
@@ -238,21 +239,13 @@ describe('ClientEncryption', function () {
|
|
238
239
|
...providerTest.options,
|
239
240
|
keyMaterial: new BSON.Binary(Buffer.alloc(96))
|
240
241
|
};
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
.findOne({ _id: dataKey }, (err, doc) => {
|
249
|
-
expect(err).to.not.exist;
|
250
|
-
expect(doc).to.have.property('masterKey');
|
251
|
-
expect(doc.masterKey).to.have.property('provider');
|
252
|
-
expect(doc.masterKey.provider).to.eql(providerName);
|
253
|
-
done();
|
254
|
-
});
|
255
|
-
});
|
242
|
+
|
243
|
+
const dataKey = await encryption.createDataKey(providerName, dataKeyOptions);
|
244
|
+
expect(dataKey).property('_bsontype', 'Binary');
|
245
|
+
|
246
|
+
const doc = await client.db('client').collection('encryption').findOne({ _id: dataKey });
|
247
|
+
expect(doc).to.have.property('masterKey');
|
248
|
+
expect(doc.masterKey).property('provider', providerName);
|
256
249
|
});
|
257
250
|
});
|
258
251
|
|
@@ -514,7 +507,7 @@ describe('ClientEncryption', function () {
|
|
514
507
|
beforeEach(function () {
|
515
508
|
if (requirements.SKIP_AWS_TESTS) {
|
516
509
|
this.currentTest.skipReason = `requirements.SKIP_AWS_TESTS=${requirements.SKIP_AWS_TESTS}`;
|
517
|
-
this.skip();
|
510
|
+
this.currentTest.skip();
|
518
511
|
return;
|
519
512
|
}
|
520
513
|
|
@@ -683,10 +676,6 @@ describe('ClientEncryption', function () {
|
|
683
676
|
.then(encrypted => {
|
684
677
|
expect(encrypted._bsontype).to.equal('Binary');
|
685
678
|
expect(encrypted.sub_type).to.equal(6);
|
686
|
-
expect(encrypted.toString('base64')).to.equal(
|
687
|
-
'BqvN76sSNJh2EjQSNFZ4kBICTQaVZPWgXp41I7mPV1rLFTtw1tXzjcdSEyxpKKqujlko5TeizkB9hHQ009dVY1+fgIiDcefh+eQrm3CkhQ=='
|
688
|
-
);
|
689
|
-
|
690
679
|
return encryption.decrypt(encrypted);
|
691
680
|
})
|
692
681
|
.then(decrypted => {
|
@@ -695,7 +684,410 @@ describe('ClientEncryption', function () {
|
|
695
684
|
});
|
696
685
|
});
|
697
686
|
|
687
|
+
describe('encrypt()', function () {
|
688
|
+
let clientEncryption;
|
689
|
+
let completeOptions;
|
690
|
+
let dataKey;
|
691
|
+
|
692
|
+
beforeEach(async function () {
|
693
|
+
if (requirements.SKIP_LIVE_TESTS) {
|
694
|
+
this.currentTest.skipReason = `requirements.SKIP_LIVE_TESTS=${requirements.SKIP_LIVE_TESTS}`;
|
695
|
+
this.test.skip();
|
696
|
+
return;
|
697
|
+
}
|
698
|
+
|
699
|
+
await setup();
|
700
|
+
clientEncryption = new ClientEncryption(client, {
|
701
|
+
keyVaultNamespace: 'client.encryption',
|
702
|
+
kmsProviders: { local: { key: Buffer.alloc(96) } }
|
703
|
+
});
|
704
|
+
|
705
|
+
dataKey = await clientEncryption.createDataKey('local', {
|
706
|
+
name: 'local',
|
707
|
+
kmsProviders: { local: { key: Buffer.alloc(96) } }
|
708
|
+
});
|
709
|
+
|
710
|
+
completeOptions = {
|
711
|
+
algorithm: 'RangePreview',
|
712
|
+
contentionFactor: 0,
|
713
|
+
rangeOptions: {
|
714
|
+
min: new BSON.Long(0),
|
715
|
+
max: new BSON.Long(10),
|
716
|
+
sparsity: new BSON.Long(1)
|
717
|
+
},
|
718
|
+
keyId: dataKey
|
719
|
+
};
|
720
|
+
});
|
721
|
+
|
722
|
+
afterEach(() => teardown());
|
723
|
+
|
724
|
+
context('when expressionMode is incorrectly provided as an argument', function () {
|
725
|
+
it('overrides the provided option with the correct value for expression mode', async function () {
|
726
|
+
const optionsWithExpressionMode = { ...completeOptions, expressionMode: true };
|
727
|
+
const result = await clientEncryption.encrypt(
|
728
|
+
new mongodb.Long(0),
|
729
|
+
optionsWithExpressionMode
|
730
|
+
);
|
731
|
+
|
732
|
+
expect(result).to.be.instanceof(Binary);
|
733
|
+
});
|
734
|
+
});
|
735
|
+
});
|
736
|
+
|
737
|
+
describe('encryptExpression()', function () {
|
738
|
+
let clientEncryption;
|
739
|
+
let completeOptions;
|
740
|
+
let dataKey;
|
741
|
+
const expression = {
|
742
|
+
$and: [{ someField: { $gt: 1 } }]
|
743
|
+
};
|
744
|
+
|
745
|
+
beforeEach(async function () {
|
746
|
+
if (requirements.SKIP_LIVE_TESTS) {
|
747
|
+
this.currentTest.skipReason = `requirements.SKIP_LIVE_TESTS=${requirements.SKIP_LIVE_TESTS}`;
|
748
|
+
this.test.skip();
|
749
|
+
return;
|
750
|
+
}
|
751
|
+
|
752
|
+
await setup();
|
753
|
+
clientEncryption = new ClientEncryption(client, {
|
754
|
+
keyVaultNamespace: 'client.encryption',
|
755
|
+
kmsProviders: { local: { key: Buffer.alloc(96) } }
|
756
|
+
});
|
757
|
+
|
758
|
+
dataKey = await clientEncryption.createDataKey('local', {
|
759
|
+
name: 'local',
|
760
|
+
kmsProviders: { local: { key: Buffer.alloc(96) } }
|
761
|
+
});
|
762
|
+
|
763
|
+
completeOptions = {
|
764
|
+
algorithm: 'RangePreview',
|
765
|
+
queryType: 'rangePreview',
|
766
|
+
contentionFactor: 0,
|
767
|
+
rangeOptions: {
|
768
|
+
min: new BSON.Int32(0),
|
769
|
+
max: new BSON.Int32(10),
|
770
|
+
sparsity: new BSON.Long(1)
|
771
|
+
},
|
772
|
+
keyId: dataKey
|
773
|
+
};
|
774
|
+
});
|
775
|
+
|
776
|
+
afterEach(() => teardown());
|
777
|
+
|
778
|
+
it('throws if rangeOptions is not provided', async function () {
|
779
|
+
expect(delete completeOptions.rangeOptions).to.be.true;
|
780
|
+
const errorOrResult = await clientEncryption
|
781
|
+
.encryptExpression(expression, completeOptions)
|
782
|
+
.catch(e => e);
|
783
|
+
|
784
|
+
expect(errorOrResult).to.be.instanceof(TypeError);
|
785
|
+
});
|
786
|
+
|
787
|
+
it('throws if algorithm is not provided', async function () {
|
788
|
+
expect(delete completeOptions.algorithm).to.be.true;
|
789
|
+
const errorOrResult = await clientEncryption
|
790
|
+
.encryptExpression(expression, completeOptions)
|
791
|
+
.catch(e => e);
|
792
|
+
|
793
|
+
expect(errorOrResult).to.be.instanceof(TypeError);
|
794
|
+
});
|
795
|
+
|
796
|
+
it(`throws if algorithm does not equal 'rangePreview'`, async function () {
|
797
|
+
completeOptions['algorithm'] = 'equality';
|
798
|
+
const errorOrResult = await clientEncryption
|
799
|
+
.encryptExpression(expression, completeOptions)
|
800
|
+
.catch(e => e);
|
801
|
+
|
802
|
+
expect(errorOrResult).to.be.instanceof(TypeError);
|
803
|
+
});
|
804
|
+
|
805
|
+
it(`does not throw if algorithm has different casing than 'rangePreview'`, async function () {
|
806
|
+
completeOptions['algorithm'] = 'rAnGePrEvIeW';
|
807
|
+
const errorOrResult = await clientEncryption
|
808
|
+
.encryptExpression(expression, completeOptions)
|
809
|
+
.catch(e => e);
|
810
|
+
|
811
|
+
expect(errorOrResult).not.to.be.instanceof(Error);
|
812
|
+
});
|
813
|
+
|
814
|
+
context('when expressionMode is incorrectly provided as an argument', function () {
|
815
|
+
it('overrides the provided option with the correct value for expression mode', async function () {
|
816
|
+
const optionsWithExpressionMode = { ...completeOptions, expressionMode: false };
|
817
|
+
const result = await clientEncryption.encryptExpression(
|
818
|
+
expression,
|
819
|
+
optionsWithExpressionMode
|
820
|
+
);
|
821
|
+
|
822
|
+
expect(result).not.to.be.instanceof(Binary);
|
823
|
+
});
|
824
|
+
});
|
825
|
+
});
|
826
|
+
|
698
827
|
it('should provide the libmongocrypt version', function () {
|
699
828
|
expect(ClientEncryption.libmongocryptVersion).to.be.a('string');
|
700
829
|
});
|
830
|
+
|
831
|
+
describe('createEncryptedCollection()', () => {
|
832
|
+
/** @type {InstanceType<ClientEncryption>} */
|
833
|
+
let clientEncryption;
|
834
|
+
const client = new MockClient();
|
835
|
+
let db;
|
836
|
+
const collectionName = 'secure';
|
837
|
+
|
838
|
+
beforeEach(async function () {
|
839
|
+
clientEncryption = new ClientEncryption(client, {
|
840
|
+
keyVaultNamespace: 'client.encryption',
|
841
|
+
kmsProviders: { local: { key: Buffer.alloc(96, 0) } }
|
842
|
+
});
|
843
|
+
|
844
|
+
db = client.db('createEncryptedCollectionDb');
|
845
|
+
});
|
846
|
+
|
847
|
+
afterEach(async () => {
|
848
|
+
sinon.restore();
|
849
|
+
});
|
850
|
+
|
851
|
+
context('validates input', () => {
|
852
|
+
it('throws TypeError if options are omitted', async () => {
|
853
|
+
const error = await clientEncryption
|
854
|
+
.createEncryptedCollection(db, collectionName)
|
855
|
+
.catch(error => error);
|
856
|
+
expect(error).to.be.instanceOf(TypeError, /provider/);
|
857
|
+
});
|
858
|
+
|
859
|
+
it('throws TypeError if options.createCollectionOptions are omitted', async () => {
|
860
|
+
const error = await clientEncryption
|
861
|
+
.createEncryptedCollection(db, collectionName, {})
|
862
|
+
.catch(error => error);
|
863
|
+
expect(error).to.be.instanceOf(TypeError, /encryptedFields/);
|
864
|
+
});
|
865
|
+
|
866
|
+
it('throws TypeError if options.createCollectionOptions.encryptedFields are omitted', async () => {
|
867
|
+
const error = await clientEncryption
|
868
|
+
.createEncryptedCollection(db, collectionName, { createCollectionOptions: {} })
|
869
|
+
.catch(error => error);
|
870
|
+
expect(error).to.be.instanceOf(TypeError, /Cannot read properties/);
|
871
|
+
});
|
872
|
+
});
|
873
|
+
|
874
|
+
context('when options.encryptedFields.fields is not an array', () => {
|
875
|
+
it('does not generate any encryption keys', async () => {
|
876
|
+
const createCollectionSpy = sinon.spy(db, 'createCollection');
|
877
|
+
const createDataKeySpy = sinon.spy(clientEncryption, 'createDataKey');
|
878
|
+
await clientEncryption.createEncryptedCollection(db, collectionName, {
|
879
|
+
createCollectionOptions: { encryptedFields: { fields: 'not an array' } }
|
880
|
+
});
|
881
|
+
|
882
|
+
expect(createDataKeySpy.callCount).to.equal(0);
|
883
|
+
const options = createCollectionSpy.getCall(0).args[1];
|
884
|
+
expect(options).to.deep.equal({ encryptedFields: { fields: 'not an array' } });
|
885
|
+
});
|
886
|
+
});
|
887
|
+
|
888
|
+
context('when options.encryptedFields.fields elements are not objects', () => {
|
889
|
+
it('they are passed along to createCollection', async () => {
|
890
|
+
const createCollectionSpy = sinon.spy(db, 'createCollection');
|
891
|
+
const keyId = new Binary(Buffer.alloc(16, 0));
|
892
|
+
const createDataKeyStub = sinon.stub(clientEncryption, 'createDataKey').resolves(keyId);
|
893
|
+
await clientEncryption.createEncryptedCollection(db, collectionName, {
|
894
|
+
createCollectionOptions: {
|
895
|
+
encryptedFields: { fields: ['not an array', { keyId: null }, { keyId: {} }] }
|
896
|
+
}
|
897
|
+
});
|
898
|
+
|
899
|
+
expect(createDataKeyStub.callCount).to.equal(1);
|
900
|
+
const options = createCollectionSpy.getCall(0).args[1];
|
901
|
+
expect(options).to.deep.equal({
|
902
|
+
encryptedFields: { fields: ['not an array', { keyId: keyId }, { keyId: {} }] }
|
903
|
+
});
|
904
|
+
});
|
905
|
+
});
|
906
|
+
|
907
|
+
it('only passes options.masterKey to createDataKey', async () => {
|
908
|
+
const masterKey = Symbol('key');
|
909
|
+
const createDataKey = sinon
|
910
|
+
.stub(clientEncryption, 'createDataKey')
|
911
|
+
.resolves(new Binary(Buffer.alloc(16, 0)));
|
912
|
+
const result = await clientEncryption.createEncryptedCollection(db, collectionName, {
|
913
|
+
provider: 'aws',
|
914
|
+
createCollectionOptions: { encryptedFields: { fields: [{}] } },
|
915
|
+
masterKey
|
916
|
+
});
|
917
|
+
expect(result).to.have.property('collection');
|
918
|
+
expect(createDataKey).to.have.been.calledOnceWithExactly('aws', { masterKey });
|
919
|
+
});
|
920
|
+
|
921
|
+
context('when createDataKey rejects', () => {
|
922
|
+
const customErrorEvil = new Error('evil!');
|
923
|
+
const customErrorGood = new Error('good!');
|
924
|
+
const keyId = new Binary(Buffer.alloc(16, 0), 4);
|
925
|
+
const createCollectionOptions = {
|
926
|
+
encryptedFields: { fields: [{}, {}, { keyId: 'cool id!' }, {}] }
|
927
|
+
};
|
928
|
+
const createDataKeyRejection = async () => {
|
929
|
+
const stub = sinon.stub(clientEncryption, 'createDataKey');
|
930
|
+
stub.onCall(0).resolves(keyId);
|
931
|
+
stub.onCall(1).rejects(customErrorEvil);
|
932
|
+
stub.onCall(2).rejects(customErrorGood);
|
933
|
+
stub.onCall(4).resolves(keyId);
|
934
|
+
|
935
|
+
const error = await clientEncryption
|
936
|
+
.createEncryptedCollection(db, collectionName, {
|
937
|
+
provider: 'local',
|
938
|
+
createCollectionOptions
|
939
|
+
})
|
940
|
+
.catch(error => error);
|
941
|
+
|
942
|
+
// At least make sure the function did not succeed
|
943
|
+
expect(error).to.be.instanceOf(Error);
|
944
|
+
|
945
|
+
return error;
|
946
|
+
};
|
947
|
+
|
948
|
+
it('throws MongoCryptCreateDataKeyError', async () => {
|
949
|
+
const error = await createDataKeyRejection();
|
950
|
+
expect(error).to.be.instanceOf(MongoCryptCreateDataKeyError);
|
951
|
+
});
|
952
|
+
|
953
|
+
it('thrown error has a cause set to the first error that was thrown from createDataKey', async () => {
|
954
|
+
const error = await createDataKeyRejection();
|
955
|
+
expect(error.cause).to.equal(customErrorEvil);
|
956
|
+
expect(error.message).to.include(customErrorEvil.message);
|
957
|
+
});
|
958
|
+
|
959
|
+
it('thrown error contains partially filled encryptedFields.fields', async () => {
|
960
|
+
const error = await createDataKeyRejection();
|
961
|
+
expect(error.encryptedFields).property('fields').that.is.an('array');
|
962
|
+
expect(error.encryptedFields.fields).to.have.lengthOf(
|
963
|
+
createCollectionOptions.encryptedFields.fields.length
|
964
|
+
);
|
965
|
+
expect(error.encryptedFields.fields).to.have.nested.property('[0].keyId', keyId);
|
966
|
+
expect(error.encryptedFields.fields).to.not.have.nested.property('[1].keyId');
|
967
|
+
expect(error.encryptedFields.fields).to.have.nested.property('[2].keyId', 'cool id!');
|
968
|
+
});
|
969
|
+
});
|
970
|
+
|
971
|
+
context('when createCollection rejects', () => {
|
972
|
+
const customError = new Error('evil!');
|
973
|
+
const keyId = new Binary(Buffer.alloc(16, 0), 4);
|
974
|
+
const createCollectionRejection = async () => {
|
975
|
+
const stubCreateDataKey = sinon.stub(clientEncryption, 'createDataKey');
|
976
|
+
stubCreateDataKey.onCall(0).resolves(keyId);
|
977
|
+
stubCreateDataKey.onCall(1).resolves(keyId);
|
978
|
+
stubCreateDataKey.onCall(2).resolves(keyId);
|
979
|
+
|
980
|
+
sinon.stub(db, 'createCollection').rejects(customError);
|
981
|
+
|
982
|
+
const createCollectionOptions = {
|
983
|
+
encryptedFields: { fields: [{}, {}, { keyId: 'cool id!' }] }
|
984
|
+
};
|
985
|
+
const error = await clientEncryption
|
986
|
+
.createEncryptedCollection(db, collectionName, {
|
987
|
+
provider: 'local',
|
988
|
+
createCollectionOptions
|
989
|
+
})
|
990
|
+
.catch(error => error);
|
991
|
+
|
992
|
+
// At least make sure the function did not succeed
|
993
|
+
expect(error).to.be.instanceOf(Error);
|
994
|
+
|
995
|
+
return error;
|
996
|
+
};
|
997
|
+
|
998
|
+
it('throws MongoCryptCreateEncryptedCollectionError', async () => {
|
999
|
+
const error = await createCollectionRejection();
|
1000
|
+
expect(error).to.be.instanceOf(MongoCryptCreateEncryptedCollectionError);
|
1001
|
+
});
|
1002
|
+
|
1003
|
+
it('thrown error has a cause set to the error that was thrown from createCollection', async () => {
|
1004
|
+
const error = await createCollectionRejection();
|
1005
|
+
expect(error.cause).to.equal(customError);
|
1006
|
+
expect(error.message).to.include(customError.message);
|
1007
|
+
});
|
1008
|
+
|
1009
|
+
it('thrown error contains filled encryptedFields.fields', async () => {
|
1010
|
+
const error = await createCollectionRejection();
|
1011
|
+
expect(error.encryptedFields).property('fields').that.is.an('array');
|
1012
|
+
expect(error.encryptedFields.fields).to.have.nested.property('[0].keyId', keyId);
|
1013
|
+
expect(error.encryptedFields.fields).to.have.nested.property('[1].keyId', keyId);
|
1014
|
+
expect(error.encryptedFields.fields).to.have.nested.property('[2].keyId', 'cool id!');
|
1015
|
+
});
|
1016
|
+
});
|
1017
|
+
|
1018
|
+
context('when there are nullish keyIds in the encryptedFields.fields array', function () {
|
1019
|
+
it('does not mutate the input fields array when generating data keys', async () => {
|
1020
|
+
const encryptedFields = Object.freeze({
|
1021
|
+
escCollection: 'esc',
|
1022
|
+
eccCollection: 'ecc',
|
1023
|
+
ecocCollection: 'ecoc',
|
1024
|
+
fields: Object.freeze([
|
1025
|
+
Object.freeze({ keyId: false }),
|
1026
|
+
Object.freeze({
|
1027
|
+
keyId: null,
|
1028
|
+
path: 'name',
|
1029
|
+
bsonType: 'int',
|
1030
|
+
queries: Object.freeze({ contentionFactor: 0 })
|
1031
|
+
}),
|
1032
|
+
null
|
1033
|
+
])
|
1034
|
+
});
|
1035
|
+
|
1036
|
+
const keyId = new Binary(Buffer.alloc(16, 0), 4);
|
1037
|
+
sinon.stub(clientEncryption, 'createDataKey').resolves(keyId);
|
1038
|
+
|
1039
|
+
const { collection, encryptedFields: resultEncryptedFields } =
|
1040
|
+
await clientEncryption.createEncryptedCollection(db, collectionName, {
|
1041
|
+
provider: 'local',
|
1042
|
+
createCollectionOptions: {
|
1043
|
+
encryptedFields
|
1044
|
+
}
|
1045
|
+
});
|
1046
|
+
|
1047
|
+
expect(collection).to.have.property('namespace', 'createEncryptedCollectionDb.secure');
|
1048
|
+
expect(encryptedFields, 'original encryptedFields should be unmodified').nested.property(
|
1049
|
+
'fields[0].keyId',
|
1050
|
+
false
|
1051
|
+
);
|
1052
|
+
expect(
|
1053
|
+
resultEncryptedFields,
|
1054
|
+
'encryptedFields created by helper should have replaced nullish keyId'
|
1055
|
+
).nested.property('fields[1].keyId', keyId);
|
1056
|
+
expect(encryptedFields, 'original encryptedFields should be unmodified').nested.property(
|
1057
|
+
'fields[2]',
|
1058
|
+
null
|
1059
|
+
);
|
1060
|
+
});
|
1061
|
+
|
1062
|
+
it('generates dataKeys for all null keyIds in the fields array', async () => {
|
1063
|
+
const encryptedFields = Object.freeze({
|
1064
|
+
escCollection: 'esc',
|
1065
|
+
eccCollection: 'ecc',
|
1066
|
+
ecocCollection: 'ecoc',
|
1067
|
+
fields: Object.freeze([
|
1068
|
+
Object.freeze({ keyId: null }),
|
1069
|
+
Object.freeze({ keyId: null }),
|
1070
|
+
Object.freeze({ keyId: null })
|
1071
|
+
])
|
1072
|
+
});
|
1073
|
+
|
1074
|
+
const keyId = new Binary(Buffer.alloc(16, 0), 4);
|
1075
|
+
sinon.stub(clientEncryption, 'createDataKey').resolves(keyId);
|
1076
|
+
|
1077
|
+
const { collection, encryptedFields: resultEncryptedFields } =
|
1078
|
+
await clientEncryption.createEncryptedCollection(db, collectionName, {
|
1079
|
+
provider: 'local',
|
1080
|
+
createCollectionOptions: {
|
1081
|
+
encryptedFields
|
1082
|
+
}
|
1083
|
+
});
|
1084
|
+
|
1085
|
+
expect(collection).to.have.property('namespace', 'createEncryptedCollectionDb.secure');
|
1086
|
+
expect(resultEncryptedFields.fields).to.have.lengthOf(3);
|
1087
|
+
expect(resultEncryptedFields.fields.filter(({ keyId }) => keyId === null)).to.have.lengthOf(
|
1088
|
+
0
|
1089
|
+
);
|
1090
|
+
});
|
1091
|
+
});
|
1092
|
+
});
|
701
1093
|
});
|
@@ -0,0 +1,94 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const { expect } = require('chai');
|
4
|
+
const maybeCallback = require('../lib/common').maybeCallback;
|
5
|
+
|
6
|
+
describe('maybeCallback()', () => {
|
7
|
+
it('should accept two arguments', () => {
|
8
|
+
expect(maybeCallback).to.have.lengthOf(2);
|
9
|
+
});
|
10
|
+
|
11
|
+
describe('when handling an error case', () => {
|
12
|
+
it('should pass the error to the callback provided', done => {
|
13
|
+
const superPromiseRejection = Promise.reject(new Error('fail'));
|
14
|
+
const result = maybeCallback(
|
15
|
+
() => superPromiseRejection,
|
16
|
+
(error, result) => {
|
17
|
+
try {
|
18
|
+
expect(result).to.not.exist;
|
19
|
+
expect(error).to.be.instanceOf(Error);
|
20
|
+
return done();
|
21
|
+
} catch (assertionError) {
|
22
|
+
return done(assertionError);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
);
|
26
|
+
expect(result).to.be.undefined;
|
27
|
+
});
|
28
|
+
|
29
|
+
it('should return the rejected promise to the caller when no callback is provided', async () => {
|
30
|
+
const superPromiseRejection = Promise.reject(new Error('fail'));
|
31
|
+
const returnedPromise = maybeCallback(() => superPromiseRejection, undefined);
|
32
|
+
expect(returnedPromise).to.equal(superPromiseRejection);
|
33
|
+
// @ts-expect-error: There is no overload to change the return type not be nullish,
|
34
|
+
// and we do not want to add one in fear of making it too easy to neglect adding the callback argument
|
35
|
+
const thrownError = await returnedPromise.catch(error => error);
|
36
|
+
expect(thrownError).to.be.instanceOf(Error);
|
37
|
+
});
|
38
|
+
|
39
|
+
it('should not modify a rejection error promise', async () => {
|
40
|
+
class MyError extends Error {}
|
41
|
+
const driverError = Object.freeze(new MyError());
|
42
|
+
const rejection = Promise.reject(driverError);
|
43
|
+
// @ts-expect-error: There is no overload to change the return type not be nullish,
|
44
|
+
// and we do not want to add one in fear of making it too easy to neglect adding the callback argument
|
45
|
+
const thrownError = await maybeCallback(() => rejection, undefined).catch(error => error);
|
46
|
+
expect(thrownError).to.be.equal(driverError);
|
47
|
+
});
|
48
|
+
|
49
|
+
it('should not modify a rejection error when passed to callback', done => {
|
50
|
+
class MyError extends Error {}
|
51
|
+
const driverError = Object.freeze(new MyError());
|
52
|
+
const rejection = Promise.reject(driverError);
|
53
|
+
maybeCallback(
|
54
|
+
() => rejection,
|
55
|
+
error => {
|
56
|
+
try {
|
57
|
+
expect(error).to.exist;
|
58
|
+
expect(error).to.equal(driverError);
|
59
|
+
done();
|
60
|
+
} catch (assertionError) {
|
61
|
+
done(assertionError);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
);
|
65
|
+
});
|
66
|
+
});
|
67
|
+
|
68
|
+
describe('when handling a success case', () => {
|
69
|
+
it('should pass the result and undefined error to the callback provided', done => {
|
70
|
+
const superPromiseSuccess = Promise.resolve(2);
|
71
|
+
|
72
|
+
const result = maybeCallback(
|
73
|
+
() => superPromiseSuccess,
|
74
|
+
(error, result) => {
|
75
|
+
try {
|
76
|
+
expect(error).to.be.undefined;
|
77
|
+
expect(result).to.equal(2);
|
78
|
+
done();
|
79
|
+
} catch (assertionError) {
|
80
|
+
done(assertionError);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
);
|
84
|
+
expect(result).to.be.undefined;
|
85
|
+
});
|
86
|
+
|
87
|
+
it('should return the resolved promise to the caller when no callback is provided', async () => {
|
88
|
+
const superPromiseSuccess = Promise.resolve(2);
|
89
|
+
const result = maybeCallback(() => superPromiseSuccess);
|
90
|
+
expect(result).to.equal(superPromiseSuccess);
|
91
|
+
expect(await result).to.equal(2);
|
92
|
+
});
|
93
|
+
});
|
94
|
+
});
|