libmongocrypt-helper 1.8.0.0.1001 → 1.11.0.0.1001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (385) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +33 -0
  3. data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +12 -1
  4. data/ext/libmongocrypt/libmongocrypt/CODEOWNERS +1 -4
  5. data/ext/libmongocrypt/libmongocrypt/Earthfile +151 -3
  6. data/ext/libmongocrypt/libmongocrypt/README.md +36 -40
  7. data/ext/libmongocrypt/libmongocrypt/bindings/cs/CMakeLists.txt +1 -0
  8. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Driver.snk +0 -0
  9. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/AssemblyInfo.cs +2 -2
  10. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Binary.cs +16 -2
  11. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClientFactory.cs +8 -4
  12. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Library.cs +10 -0
  13. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/LibraryLoader.cs +81 -44
  14. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/MongoDB.Libmongocrypt.csproj +2 -1
  15. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/MongoDB.Libmongocrypt.Test.csproj +2 -0
  16. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test32/MongoDB.Libmongocrypt.Test32.csproj +2 -0
  17. data/ext/libmongocrypt/libmongocrypt/bindings/cs/README.md +3 -0
  18. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.cake +21 -26
  19. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.config +3 -0
  20. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.sh +0 -0
  21. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/build.gradle.kts +28 -0
  22. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/src/main/java/com/mongodb/crypt/benchmark/BenchmarkRunner.java +217 -0
  23. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/src/main/resources/keyDocument.json +24 -0
  24. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/build.gradle.kts +21 -6
  25. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradle/wrapper/gradle-wrapper.jar +0 -0
  26. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradle/wrapper/gradle-wrapper.properties +1 -1
  27. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradlew +154 -108
  28. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradlew.bat +7 -18
  29. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/settings.gradle.kts +1 -0
  30. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CAPI.java +41 -6
  31. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CAPIHelper.java +5 -5
  32. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CipherCallback.java +27 -1
  33. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/MongoCryptImpl.java +34 -19
  34. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/MongoExplicitEncryptOptions.java +6 -4
  35. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/resources/META-INF/native-image/jni-config.json +180 -0
  36. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/resources/META-INF/native-image/reflect-config.json +134 -0
  37. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/java/com/mongodb/crypt/capi/MongoCryptTest.java +44 -2
  38. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/encrypted-payload.json +1 -1
  39. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/rangeopts.json +3 -0
  40. data/ext/libmongocrypt/libmongocrypt/bindings/node/README.md +4 -900
  41. data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +60 -0
  42. data/ext/libmongocrypt/libmongocrypt/bindings/python/README.rst +41 -20
  43. data/ext/libmongocrypt/libmongocrypt/bindings/python/RELEASE.rst +6 -24
  44. data/ext/libmongocrypt/libmongocrypt/bindings/python/build-manylinux-wheel.sh +4 -13
  45. data/ext/libmongocrypt/libmongocrypt/bindings/python/hatch_build.py +36 -0
  46. data/ext/libmongocrypt/libmongocrypt/bindings/python/libmongocrypt-version.txt +1 -0
  47. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/__init__.py +2 -2
  48. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/auto_encrypter.py +61 -0
  49. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/credentials.py +156 -0
  50. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/explicit_encrypter.py +156 -0
  51. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/state_machine.py +149 -0
  52. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/auto_encrypter.py +2 -46
  53. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binary.py +14 -17
  54. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +107 -61
  55. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/compat.py +6 -4
  56. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/credentials.py +2 -121
  57. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/crypto.py +31 -20
  58. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/errors.py +2 -2
  59. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/explicit_encrypter.py +2 -233
  60. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +168 -238
  61. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/options.py +265 -0
  62. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/state_machine.py +2 -141
  63. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/auto_encrypter.py +61 -0
  64. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/credentials.py +156 -0
  65. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/explicit_encrypter.py +156 -0
  66. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/state_machine.py +149 -0
  67. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +2 -2
  68. data/ext/libmongocrypt/libmongocrypt/bindings/python/pyproject.toml +118 -0
  69. data/ext/libmongocrypt/libmongocrypt/bindings/python/release.sh +97 -61
  70. data/ext/libmongocrypt/libmongocrypt/bindings/python/{test-requirements.txt → requirements-test.txt} +4 -1
  71. data/ext/libmongocrypt/libmongocrypt/bindings/python/requirements.txt +4 -0
  72. data/ext/libmongocrypt/libmongocrypt/bindings/python/sbom.json +76 -0
  73. data/ext/libmongocrypt/libmongocrypt/bindings/python/strip_header.py +6 -7
  74. data/ext/libmongocrypt/libmongocrypt/bindings/python/synchro.py +64 -0
  75. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/__init__.py +1 -0
  76. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/collection-info.json +1 -1
  77. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/command.json +1 -1
  78. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/compact/success/encrypted-payload.json +21 -21
  79. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/encrypted-command-reply.json +1 -1
  80. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/encrypted-field-config-map.json +1 -1
  81. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/encrypted-payload.json +1 -1
  82. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/rangeopts.json +3 -0
  83. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-rangePreview-explicit/int32/rangeopts.json +11 -0
  84. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-rangePreview-explicit/int32/value-to-encrypt.json +20 -0
  85. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document-azure.json +1 -1
  86. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document-gcp.json +1 -1
  87. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document.json +1 -1
  88. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-filter.json +1 -1
  89. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/list-collections-filter.json +1 -1
  90. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/mongocryptd-command.json +1 -1
  91. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/mongocryptd-reply.json +1 -1
  92. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/schema-map.json +1 -1
  93. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/performance/keyDocument.json +24 -0
  94. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/performance/perf_test.py +165 -0
  95. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_binding.py +8 -12
  96. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_crypto.py +9 -11
  97. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_mongocrypt.py +988 -340
  98. data/ext/libmongocrypt/libmongocrypt/bindings/python/update-sbom.sh +14 -0
  99. data/ext/libmongocrypt/libmongocrypt/cmake/FetchMongoC.cmake +19 -1
  100. data/ext/libmongocrypt/libmongocrypt/cmake/ImportBSON.cmake +23 -0
  101. data/ext/libmongocrypt/libmongocrypt/cmake/IntelDFP.cmake +19 -227
  102. data/ext/libmongocrypt/libmongocrypt/cmake/Patch.cmake +54 -0
  103. data/ext/libmongocrypt/libmongocrypt/doc/img/cli-icon.png +0 -0
  104. data/ext/libmongocrypt/libmongocrypt/doc/img/reference-targets.png +0 -0
  105. data/ext/libmongocrypt/libmongocrypt/doc/releasing.md +153 -0
  106. data/ext/libmongocrypt/libmongocrypt/etc/calc_release_version.py +61 -28
  107. data/ext/libmongocrypt/libmongocrypt/etc/calc_release_version_selftest.sh +73 -0
  108. data/ext/libmongocrypt/libmongocrypt/etc/cyclonedx.sbom.json +108 -0
  109. data/ext/libmongocrypt/libmongocrypt/etc/format.sh +1 -1
  110. data/ext/libmongocrypt/libmongocrypt/etc/libbson-remove-GCC-diagnostic-pragma.patch +27 -0
  111. data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-alpine-arm-fix.patch +17 -0
  112. data/ext/libmongocrypt/libmongocrypt/etc/packager.py +120 -91
  113. data/ext/libmongocrypt/libmongocrypt/etc/purls.txt +14 -0
  114. data/ext/libmongocrypt/libmongocrypt/etc/repo_config.yaml +56 -0
  115. data/ext/libmongocrypt/libmongocrypt/etc/silk-create-asset-group.sh +70 -0
  116. data/ext/libmongocrypt/libmongocrypt/etc/ssdlc_compliance_report.md +37 -0
  117. data/ext/libmongocrypt/libmongocrypt/etc/third_party_vulnerabilities.md +42 -0
  118. data/ext/libmongocrypt/libmongocrypt/integrating.md +18 -1
  119. data/ext/libmongocrypt/libmongocrypt/kms-message/CMakeLists.txt +11 -3
  120. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_gcp_request.c +1 -1
  121. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_reader_writer.c +17 -0
  122. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_reader_writer_private.h +6 -0
  123. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_request.c +211 -1
  124. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_response.c +163 -0
  125. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_tag_type_private.h +2 -1
  126. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_message/kms_kmip_request.h +17 -0
  127. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_message/kms_kmip_response.h +6 -0
  128. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_port.c +3 -2
  129. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_request.c +4 -2
  130. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_request_str.c +2 -2
  131. data/ext/libmongocrypt/libmongocrypt/kms-message/test/test_kmip_reader_writer.c +23 -2
  132. data/ext/libmongocrypt/libmongocrypt/src/crypto/libcrypto.c +13 -10
  133. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.h +1 -1
  134. data/ext/libmongocrypt/libmongocrypt/src/mc-efc-private.h +16 -2
  135. data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +94 -6
  136. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +15 -5
  137. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +114 -53
  138. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private-v2.h +1 -1
  139. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private.h +1 -1
  140. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-v2.c +2 -2
  141. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload.c +2 -2
  142. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private-v2.h +21 -6
  143. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private.h +5 -5
  144. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +38 -2
  145. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload.c +1 -1
  146. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private-v2.h +20 -7
  147. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private.h +8 -8
  148. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +89 -1
  149. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-v2.c +3 -3
  150. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev.c +1 -23
  151. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds-private.h +4 -3
  152. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +15 -12
  153. data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +11 -0
  154. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +16 -6
  155. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +64 -22
  156. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +23 -4
  157. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +359 -65
  158. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +26 -14
  159. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +17 -6
  160. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +31 -13
  161. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +16 -3
  162. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +259 -63
  163. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens-private.h +40 -24
  164. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +57 -13
  165. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.h +17 -0
  166. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +5 -0
  167. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary-private.h +0 -5
  168. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer.c +5 -7
  169. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key.c +1 -0
  170. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth-private.h +16 -18
  171. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth.c +105 -76
  172. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto.c +9 -3
  173. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +170 -89
  174. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +5 -5
  175. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +505 -124
  176. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-private.h +31 -6
  177. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +81 -13
  178. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +7 -0
  179. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek-private.h +5 -1
  180. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek.c +161 -103
  181. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker-private.h +2 -7
  182. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +191 -69
  183. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key.c +1 -1
  184. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx-private.h +50 -15
  185. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx.c +365 -69
  186. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking-private.h +2 -1
  187. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +200 -107
  188. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +50 -5
  189. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +591 -15
  190. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +6 -13
  191. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util.c +3 -2
  192. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +47 -234
  193. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.h +75 -24
  194. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +18 -2
  195. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +4 -0
  196. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/bypassQueryAnalysis/payload.json +53 -0
  197. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/jsonSchema/cmd-to-mongocryptd.json +23 -0
  198. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/jsonSchema/cmd.json +20 -0
  199. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/cmd-to-mongocryptd.json +50 -0
  200. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/cmd.json +20 -0
  201. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/collinfo.json +44 -0
  202. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/encrypted-field-map.json +24 -0
  203. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/encrypted-payload-pattern.json +53 -0
  204. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/mongocryptd-reply.json +62 -0
  205. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/cmd-to-mongocryptd.json +30 -0
  206. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/cmd.json +17 -0
  207. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/mongocryptd-reply.json +39 -0
  208. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/payload.json +21 -0
  209. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/missing-key-id/collinfo.json +20 -0
  210. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/no-fields/collinfo.json +9 -0
  211. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/no-fields/encrypted-payload.json +4 -0
  212. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/cmd.json +1 -0
  213. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/collinfo.json +63 -0
  214. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-field-config-map.json +61 -0
  215. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-payload-range-v2.json +37 -0
  216. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-payload.json +29 -0
  217. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/cmd.json +1 -0
  218. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/collinfo.json +64 -0
  219. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/encrypted-payload-range-v2.json +105 -0
  220. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/encrypted-payload.json +30 -0
  221. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/cmd.json +1 -0
  222. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/collinfo.json +49 -0
  223. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/encrypted-field-config-map.json +47 -0
  224. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/encrypted-payload.json +23 -0
  225. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/collinfo.json +15 -0
  226. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-field-config-map.json +10 -0
  227. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-payload-range-v2.json +104 -0
  228. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-payload.json +6 -0
  229. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/collinfo.json +4 -4
  230. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/encrypted-payload.json +3 -3
  231. data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/decrypt-response.txt +16 -0
  232. data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/encrypt-response.txt +16 -0
  233. data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/oauth-response.txt +19 -0
  234. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/cmd.json +9 -0
  235. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/encrypted-field-map.json +19 -0
  236. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/encrypted-payload.json +62 -0
  237. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/mongocryptd-reply.json +69 -0
  238. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/cmd.json +11 -0
  239. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/encrypted-field-map.json +19 -0
  240. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/encrypted-payload.json +40 -0
  241. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/mongocryptd-reply.json +47 -0
  242. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_decimal128.cstruct +1 -1
  243. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_double.cstruct +8637 -7958
  244. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_int32.cstruct +5522 -1382
  245. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_int64.cstruct +5042 -1262
  246. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_decimal128.cstruct +1 -1
  247. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_decimal128_precision.cstruct +1 -1
  248. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_double.cstruct +1 -1
  249. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_double_precision.cstruct +2 -2
  250. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_int32.cstruct +1 -1
  251. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_int64.cstruct +1 -1
  252. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/cmd.json +8 -0
  253. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/encrypted-field-map.json +19 -0
  254. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/encrypted-payload.json +53 -0
  255. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/mongocryptd-reply.json +58 -0
  256. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/cmd.json +11 -0
  257. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/encrypted-field-map.json +19 -0
  258. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/encrypted-payload.json +40 -0
  259. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/mongocryptd-reply.json +45 -0
  260. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32/expected.json +26 -0
  261. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32/to-encrypt.json +20 -0
  262. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32-defaults/expected.json +26 -0
  263. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32-defaults/to-encrypt.json +20 -0
  264. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-double/expected.json +8 -0
  265. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-int32/expected.json +8 -0
  266. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-int32-defaults/expected.json +8 -0
  267. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/README.md +7 -4
  268. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +9 -5
  269. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +9 -5
  270. data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +1 -0
  271. data/ext/libmongocrypt/libmongocrypt/test/test-gcp-auth.c +8 -8
  272. data/ext/libmongocrypt/libmongocrypt/test/test-mc-efc.c +6 -4
  273. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-range-payload-v2.c +43 -3
  274. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup-v2.c +76 -0
  275. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-rfds.c +5 -5
  276. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-edge-generation.c +89 -14
  277. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +342 -76
  278. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +94 -12
  279. data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +205 -7
  280. data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +49 -23
  281. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +16 -19
  282. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.h +22 -1
  283. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache-oauth.c +94 -11
  284. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cleanup.c +374 -0
  285. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-compact.c +121 -42
  286. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +134 -4
  287. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +40 -0
  288. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.h +16 -0
  289. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-csfle-lib.c +11 -11
  290. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-decrypt.c +8 -5
  291. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +922 -92
  292. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +2 -2
  293. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +114 -12
  294. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +14 -9
  295. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-ctx.c +424 -3
  296. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-log.c +1 -1
  297. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-marking.c +447 -28
  298. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-opts.c +42 -0
  299. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-traverse-util.c +30 -26
  300. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.c +7 -0
  301. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.h +3 -0
  302. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +66 -14
  303. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +11 -0
  304. data/ext/libmongocrypt/libmongocrypt/test/test-named-kms-providers.c +2381 -0
  305. data/ext/libmongocrypt/libmongocrypt/test/util/HELP.autogen +3 -1
  306. data/ext/libmongocrypt/libmongocrypt/test/util/README.md +1 -0
  307. data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +4 -0
  308. data/ext/libmongocrypt/libmongocrypt/test/util/make_includes.py +1 -1
  309. data/ext/libmongocrypt/libmongocrypt/test/util/util.c +38 -3
  310. data/lib/libmongocrypt_helper/version.rb +2 -2
  311. metadata +112 -106
  312. checksums.yaml.gz.sig +0 -0
  313. data/ext/libmongocrypt/libmongocrypt/VERSION_CURRENT +0 -1
  314. data/ext/libmongocrypt/libmongocrypt/bindings/cs/cs.sln +0 -79
  315. data/ext/libmongocrypt/libmongocrypt/bindings/node/CHANGELOG.md +0 -105
  316. data/ext/libmongocrypt/libmongocrypt/bindings/node/LICENSE +0 -201
  317. data/ext/libmongocrypt/libmongocrypt/bindings/node/binding.gyp +0 -79
  318. data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/README.hbs +0 -44
  319. data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/build-static.sh +0 -36
  320. data/ext/libmongocrypt/libmongocrypt/bindings/node/index.d.ts +0 -641
  321. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/autoEncrypter.js +0 -420
  322. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/buffer_pool.js +0 -123
  323. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/clientEncryption.js +0 -821
  324. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/common.js +0 -98
  325. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/cryptoCallbacks.js +0 -87
  326. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/errors.js +0 -75
  327. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/index.js +0 -73
  328. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/mongocryptdManager.js +0 -66
  329. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/aws.js +0 -26
  330. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/azure.js +0 -178
  331. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/gcp.js +0 -24
  332. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/index.js +0 -54
  333. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/utils.js +0 -39
  334. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/stateMachine.js +0 -492
  335. data/ext/libmongocrypt/libmongocrypt/bindings/node/package-lock.json +0 -15302
  336. data/ext/libmongocrypt/libmongocrypt/bindings/node/package.json +0 -100
  337. data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.cc +0 -956
  338. data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.h +0 -114
  339. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/autoEncrypter.test.js +0 -950
  340. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/buffer_pool.test.js +0 -91
  341. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/clientEncryption.test.js +0 -1093
  342. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/common.test.js +0 -94
  343. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/cryptoCallbacks.test.js +0 -240
  344. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/README.md +0 -5
  345. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/cmd.json +0 -6
  346. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/collection-info.json +0 -37
  347. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encrypted-document-nested.json +0 -8
  348. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encrypted-document.json +0 -11
  349. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encryptedFields.json +0 -30
  350. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/key-document.json +0 -32
  351. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/key1-document.json +0 -30
  352. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/mongocryptd-reply.json +0 -18
  353. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/index.test.js +0 -45
  354. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/mongocryptdManager.test.js +0 -48
  355. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/providers/credentialsProvider.test.js +0 -551
  356. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/release.test.js +0 -66
  357. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/requirements.helper.js +0 -51
  358. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/stateMachine.test.js +0 -331
  359. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/chai-addons.js +0 -8
  360. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/mongodb_reporter.js +0 -325
  361. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/types/index.test-d.ts +0 -63
  362. data/ext/libmongocrypt/libmongocrypt/bindings/python/setup.py +0 -89
  363. data/ext/libmongocrypt/libmongocrypt/debian/build_snapshot.sh +0 -79
  364. data/ext/libmongocrypt/libmongocrypt/debian/changelog +0 -105
  365. data/ext/libmongocrypt/libmongocrypt/debian/compat +0 -1
  366. data/ext/libmongocrypt/libmongocrypt/debian/control +0 -41
  367. data/ext/libmongocrypt/libmongocrypt/debian/copyright +0 -129
  368. data/ext/libmongocrypt/libmongocrypt/debian/gbp.conf +0 -23
  369. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt-dev.dirs +0 -2
  370. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt-dev.install +0 -5
  371. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt0.dirs +0 -1
  372. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt0.install +0 -1
  373. data/ext/libmongocrypt/libmongocrypt/debian/rules +0 -46
  374. data/ext/libmongocrypt/libmongocrypt/debian/source/format +0 -1
  375. data/ext/libmongocrypt/libmongocrypt/debian/source/lintian-overrides +0 -3
  376. data/ext/libmongocrypt/libmongocrypt/debian/source/options +0 -1
  377. data/ext/libmongocrypt/libmongocrypt/debian/watch +0 -3
  378. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/mongocryptd-reply.json +0 -72
  379. data.tar.gz.sig +0 -1
  380. metadata.gz.sig +0 -0
  381. /data/ext/libmongocrypt/libmongocrypt/{bindings/node/test/data/kms-decrypt-reply.txt → test/data/kms-aws/decrypt-response.txt} +0 -0
  382. /data/ext/libmongocrypt/libmongocrypt/{bindings/node/test/data/kms-encrypt-reply.txt → test/data/kms-aws/encrypt-response.txt} +0 -0
  383. /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/decrypt-response.txt +0 -0
  384. /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/encrypt-response.txt +0 -0
  385. /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/oauth-response.txt +0 -0
@@ -1,950 +0,0 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const sinon = require('sinon');
6
- const mongodb = require('mongodb');
7
- const BSON = mongodb.BSON;
8
- const EJSON = BSON.EJSON;
9
- const requirements = require('./requirements.helper');
10
- const MongoNetworkTimeoutError = mongodb.MongoNetworkTimeoutError || mongodb.MongoTimeoutError;
11
- const MongoError = mongodb.MongoError;
12
- const stateMachine = require('../lib/stateMachine')({ mongodb });
13
- const StateMachine = stateMachine.StateMachine;
14
- const MongocryptdManager = require('../lib/mongocryptdManager').MongocryptdManager;
15
-
16
- const { expect } = require('chai');
17
-
18
- const sharedLibrarySuffix =
19
- process.platform === 'win32' ? 'dll' : process.platform === 'darwin' ? 'dylib' : 'so';
20
- let sharedLibraryStub = path.resolve(
21
- __dirname,
22
- '..',
23
- '..',
24
- '..',
25
- `mongo_crypt_v1.${sharedLibrarySuffix}`
26
- );
27
- if (!fs.existsSync(sharedLibraryStub)) {
28
- sharedLibraryStub = path.resolve(
29
- __dirname,
30
- '..',
31
- 'deps',
32
- 'tmp',
33
- 'libmongocrypt-build',
34
- ...(process.platform === 'win32' ? ['RelWithDebInfo'] : []),
35
- `mongo_crypt_v1.${sharedLibrarySuffix}`
36
- );
37
- }
38
-
39
- function readExtendedJsonToBuffer(path) {
40
- const ejson = EJSON.parse(fs.readFileSync(path, 'utf8'));
41
- return BSON.serialize(ejson);
42
- }
43
-
44
- function readHttpResponse(path) {
45
- let data = fs.readFileSync(path, 'utf8');
46
- data = data.split('\n').join('\r\n');
47
- return Buffer.from(data, 'utf8');
48
- }
49
-
50
- const TEST_COMMAND = JSON.parse(fs.readFileSync(`${__dirname}/data/cmd.json`));
51
- const MOCK_COLLINFO_RESPONSE = readExtendedJsonToBuffer(`${__dirname}/data/collection-info.json`);
52
- const MOCK_MONGOCRYPTD_RESPONSE = readExtendedJsonToBuffer(
53
- `${__dirname}/data/mongocryptd-reply.json`
54
- );
55
- const MOCK_KEYDOCUMENT_RESPONSE = readExtendedJsonToBuffer(`${__dirname}/data/key-document.json`);
56
- const MOCK_KMS_DECRYPT_REPLY = readHttpResponse(`${__dirname}/data/kms-decrypt-reply.txt`);
57
-
58
- class MockClient {
59
- constructor() {
60
- this.topology = {
61
- bson: BSON
62
- };
63
- }
64
- }
65
-
66
- const originalAccessKeyId = process.env.AWS_ACCESS_KEY_ID;
67
- const originalSecretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
68
-
69
- const AutoEncrypter = require('../lib/autoEncrypter')({ mongodb, stateMachine }).AutoEncrypter;
70
- describe('AutoEncrypter', function () {
71
- this.timeout(12000);
72
- let ENABLE_LOG_TEST = false;
73
- let sandbox = sinon.createSandbox();
74
- beforeEach(() => {
75
- sandbox.restore();
76
- sandbox.stub(StateMachine.prototype, 'kmsRequest').callsFake(request => {
77
- request.addResponse(MOCK_KMS_DECRYPT_REPLY);
78
- return Promise.resolve();
79
- });
80
-
81
- sandbox
82
- .stub(StateMachine.prototype, 'fetchCollectionInfo')
83
- .callsFake((client, ns, filter, callback) => {
84
- callback(null, MOCK_COLLINFO_RESPONSE);
85
- });
86
-
87
- sandbox
88
- .stub(StateMachine.prototype, 'markCommand')
89
- .callsFake((client, ns, command, callback) => {
90
- if (ENABLE_LOG_TEST) {
91
- const response = BSON.deserialize(MOCK_MONGOCRYPTD_RESPONSE);
92
- response.schemaRequiresEncryption = false;
93
-
94
- ENABLE_LOG_TEST = false; // disable test after run
95
- callback(null, BSON.serialize(response));
96
- return;
97
- }
98
-
99
- callback(null, MOCK_MONGOCRYPTD_RESPONSE);
100
- });
101
-
102
- sandbox.stub(StateMachine.prototype, 'fetchKeys').callsFake((client, ns, filter, callback) => {
103
- // mock data is already serialized, our action deals with the result of a cursor
104
- const deserializedKey = BSON.deserialize(MOCK_KEYDOCUMENT_RESPONSE);
105
- callback(null, [deserializedKey]);
106
- });
107
- });
108
-
109
- afterEach(() => {
110
- sandbox.restore();
111
- });
112
-
113
- describe('#constructor', function () {
114
- context('when mongodb exports BSON (driver >= 4.9.0)', function () {
115
- context('when a bson option is provided', function () {
116
- const bson = Object.assign({}, BSON);
117
- const encrypter = new AutoEncrypter(
118
- {},
119
- {
120
- bson: bson,
121
- kmsProviders: {
122
- local: { key: Buffer.alloc(96) }
123
- }
124
- }
125
- );
126
-
127
- it('uses the bson option', function () {
128
- expect(encrypter._bson).to.equal(bson);
129
- });
130
- });
131
-
132
- context('when a bson option is not provided', function () {
133
- const encrypter = new AutoEncrypter(
134
- {},
135
- {
136
- kmsProviders: {
137
- local: { key: Buffer.alloc(96) }
138
- }
139
- }
140
- );
141
-
142
- it('uses the mongodb exported BSON', function () {
143
- expect(encrypter._bson).to.equal(BSON);
144
- });
145
- });
146
-
147
- it('never uses bson from the topology', function () {
148
- expect(() => {
149
- new AutoEncrypter(
150
- {},
151
- {
152
- kmsProviders: {
153
- local: { key: Buffer.alloc(96) }
154
- }
155
- }
156
- );
157
- }).not.to.throw();
158
- });
159
- });
160
-
161
- context('when mongodb does not export BSON (driver < 4.9.0)', function () {
162
- context('when a bson option is provided', function () {
163
- const bson = Object.assign({}, BSON);
164
- const encrypter = new AutoEncrypter(
165
- {},
166
- {
167
- bson: bson,
168
- kmsProviders: {
169
- local: { key: Buffer.alloc(96) }
170
- }
171
- }
172
- );
173
-
174
- it('uses the bson option', function () {
175
- expect(encrypter._bson).to.equal(bson);
176
- });
177
- });
178
-
179
- context('when a bson option is not provided', function () {
180
- const mongoNoBson = { ...mongodb, BSON: undefined };
181
- const AutoEncrypterNoBson = require('../lib/autoEncrypter')({
182
- mongodb: mongoNoBson,
183
- stateMachine
184
- }).AutoEncrypter;
185
-
186
- context('when the client has a topology', function () {
187
- const client = new MockClient();
188
- const encrypter = new AutoEncrypterNoBson(client, {
189
- kmsProviders: {
190
- local: { key: Buffer.alloc(96) }
191
- }
192
- });
193
-
194
- it('uses the bson on the topology', function () {
195
- expect(encrypter._bson).to.equal(client.topology.bson);
196
- });
197
- });
198
-
199
- context('when the client does not have a topology', function () {
200
- it('raises an error', function () {
201
- expect(() => {
202
- new AutoEncrypterNoBson({}, {});
203
- }).to.throw(/bson/);
204
- });
205
- });
206
- });
207
- });
208
-
209
- context('when using mongocryptd', function () {
210
- const client = new MockClient();
211
- const autoEncrypterOptions = {
212
- mongocryptdBypassSpawn: true,
213
- keyVaultNamespace: 'admin.datakeys',
214
- logger: () => {},
215
- kmsProviders: {
216
- aws: { accessKeyId: 'example', secretAccessKey: 'example' },
217
- local: { key: Buffer.alloc(96) }
218
- }
219
- };
220
- const autoEncrypter = new AutoEncrypter(client, autoEncrypterOptions);
221
-
222
- it('instantiates a mongo client on the auto encrypter', function () {
223
- expect(autoEncrypter)
224
- .to.have.property('_mongocryptdClient')
225
- .to.be.instanceOf(mongodb.MongoClient);
226
- });
227
-
228
- it('sets the 3x legacy client options on the mongo client', function () {
229
- expect(autoEncrypter).to.have.nested.property('_mongocryptdClient.s.options');
230
- const options = autoEncrypter._mongocryptdClient.s.options;
231
- expect(options).to.have.property('useUnifiedTopology', true);
232
- expect(options).to.have.property('useNewUrlParser', true);
233
- });
234
-
235
- it('sets serverSelectionTimeoutMS to 10000ms', function () {
236
- expect(autoEncrypter).to.have.nested.property('_mongocryptdClient.s.options');
237
- const options = autoEncrypter._mongocryptdClient.s.options;
238
- expect(options).to.have.property('serverSelectionTimeoutMS', 10000);
239
- });
240
-
241
- context('when mongocryptdURI is not specified', () => {
242
- it('sets the ip address family to ipv4', function () {
243
- expect(autoEncrypter).to.have.nested.property('_mongocryptdClient.s.options');
244
- const options = autoEncrypter._mongocryptdClient.s.options;
245
- expect(options).to.have.property('family', 4);
246
- });
247
- });
248
-
249
- context('when mongocryptdURI is specified', () => {
250
- it('does not set the ip address family to ipv4', function () {
251
- const autoEncrypter = new AutoEncrypter(client, {
252
- ...autoEncrypterOptions,
253
- extraOptions: { mongocryptdURI: MongocryptdManager.DEFAULT_MONGOCRYPTD_URI }
254
- });
255
-
256
- expect(autoEncrypter).to.have.nested.property('_mongocryptdClient.s.options');
257
- const options = autoEncrypter._mongocryptdClient.s.options;
258
- expect(options).not.to.have.property('family', 4);
259
- });
260
- });
261
- });
262
- });
263
-
264
- it('should support `bypassAutoEncryption`', function (done) {
265
- const client = new MockClient();
266
- const autoEncrypter = new AutoEncrypter(client, {
267
- bypassAutoEncryption: true,
268
- mongocryptdBypassSpawn: true,
269
- keyVaultNamespace: 'admin.datakeys',
270
- logger: () => {},
271
- kmsProviders: {
272
- aws: { accessKeyId: 'example', secretAccessKey: 'example' },
273
- local: { key: Buffer.alloc(96) }
274
- }
275
- });
276
-
277
- autoEncrypter.encrypt('test.test', { test: 'command' }, (err, encrypted) => {
278
- expect(err).to.not.exist;
279
- expect(encrypted).to.eql({ test: 'command' });
280
- done();
281
- });
282
- });
283
-
284
- describe('state machine', function () {
285
- it('should decrypt mock data', function (done) {
286
- const input = readExtendedJsonToBuffer(`${__dirname}/data/encrypted-document.json`);
287
- const client = new MockClient();
288
- const mc = new AutoEncrypter(client, {
289
- keyVaultNamespace: 'admin.datakeys',
290
- logger: () => {},
291
- kmsProviders: {
292
- aws: { accessKeyId: 'example', secretAccessKey: 'example' },
293
- local: { key: Buffer.alloc(96) }
294
- }
295
- });
296
- mc.decrypt(input, (err, decrypted) => {
297
- if (err) return done(err);
298
- expect(decrypted).to.eql({ filter: { find: 'test', ssn: '457-55-5462' } });
299
- expect(decrypted).to.not.have.property(Symbol.for('@@mdb.decryptedKeys'));
300
- expect(decrypted.filter).to.not.have.property(Symbol.for('@@mdb.decryptedKeys'));
301
- done();
302
- });
303
- });
304
-
305
- it('should decrypt mock data and mark decrypted items if enabled for testing', function (done) {
306
- const input = readExtendedJsonToBuffer(`${__dirname}/data/encrypted-document.json`);
307
- const nestedInput = readExtendedJsonToBuffer(
308
- `${__dirname}/data/encrypted-document-nested.json`
309
- );
310
- const client = new MockClient();
311
- const mc = new AutoEncrypter(client, {
312
- keyVaultNamespace: 'admin.datakeys',
313
- logger: () => {},
314
- kmsProviders: {
315
- aws: { accessKeyId: 'example', secretAccessKey: 'example' },
316
- local: { key: Buffer.alloc(96) }
317
- }
318
- });
319
- mc[Symbol.for('@@mdb.decorateDecryptionResult')] = true;
320
- mc.decrypt(input, (err, decrypted) => {
321
- if (err) return done(err);
322
- expect(decrypted).to.eql({ filter: { find: 'test', ssn: '457-55-5462' } });
323
- expect(decrypted).to.not.have.property(Symbol.for('@@mdb.decryptedKeys'));
324
- expect(decrypted.filter[Symbol.for('@@mdb.decryptedKeys')]).to.eql(['ssn']);
325
-
326
- // The same, but with an object containing different data types as the input
327
- mc.decrypt({ a: [null, 1, { c: new BSON.Binary('foo', 1) }] }, (err, decrypted) => {
328
- if (err) return done(err);
329
- expect(decrypted).to.eql({ a: [null, 1, { c: new BSON.Binary('foo', 1) }] });
330
- expect(decrypted).to.not.have.property(Symbol.for('@@mdb.decryptedKeys'));
331
-
332
- // The same, but with nested data inside the decrypted input
333
- mc.decrypt(nestedInput, (err, decrypted) => {
334
- if (err) return done(err);
335
- expect(decrypted).to.eql({ nested: { x: { y: 1234 } } });
336
- expect(decrypted[Symbol.for('@@mdb.decryptedKeys')]).to.eql(['nested']);
337
- expect(decrypted.nested).to.not.have.property(Symbol.for('@@mdb.decryptedKeys'));
338
- expect(decrypted.nested.x).to.not.have.property(Symbol.for('@@mdb.decryptedKeys'));
339
- expect(decrypted.nested.x.y).to.not.have.property(Symbol.for('@@mdb.decryptedKeys'));
340
- done();
341
- });
342
- });
343
- });
344
- });
345
-
346
- it('should decrypt mock data with per-context KMS credentials', function (done) {
347
- const input = readExtendedJsonToBuffer(`${__dirname}/data/encrypted-document.json`);
348
- const client = new MockClient();
349
- const mc = new AutoEncrypter(client, {
350
- keyVaultNamespace: 'admin.datakeys',
351
- logger: () => {},
352
- kmsProviders: {
353
- aws: {}
354
- },
355
- async onKmsProviderRefresh() {
356
- return { aws: { accessKeyId: 'example', secretAccessKey: 'example' } };
357
- }
358
- });
359
- mc.decrypt(input, (err, decrypted) => {
360
- if (err) return done(err);
361
- expect(decrypted).to.eql({ filter: { find: 'test', ssn: '457-55-5462' } });
362
- done();
363
- });
364
- });
365
-
366
- context('when no refresh function is provided', function () {
367
- const accessKey = 'example';
368
- const secretKey = 'example';
369
-
370
- before(function () {
371
- if (!requirements.credentialProvidersInstalled.aws) {
372
- this.currentTest.skipReason = 'Cannot refresh credentials without sdk provider';
373
- this.currentTest.skip();
374
- return;
375
- }
376
- // After the entire suite runs, set the env back for the rest of the test run.
377
- process.env.AWS_ACCESS_KEY_ID = accessKey;
378
- process.env.AWS_SECRET_ACCESS_KEY = secretKey;
379
- });
380
-
381
- after(function () {
382
- // After the entire suite runs, set the env back for the rest of the test run.
383
- process.env.AWS_ACCESS_KEY_ID = originalAccessKeyId;
384
- process.env.AWS_SECRET_ACCESS_KEY = originalSecretAccessKey;
385
- });
386
-
387
- it('should decrypt mock data with KMS credentials from the environment', function (done) {
388
- const input = readExtendedJsonToBuffer(`${__dirname}/data/encrypted-document.json`);
389
- const client = new MockClient();
390
- const mc = new AutoEncrypter(client, {
391
- keyVaultNamespace: 'admin.datakeys',
392
- logger: () => {},
393
- kmsProviders: {
394
- aws: {}
395
- }
396
- });
397
- mc.decrypt(input, (err, decrypted) => {
398
- if (err) return done(err);
399
- expect(decrypted).to.eql({ filter: { find: 'test', ssn: '457-55-5462' } });
400
- done();
401
- });
402
- });
403
- });
404
-
405
- context('when no refresh function is provided and no optional sdk', function () {
406
- const accessKey = 'example';
407
- const secretKey = 'example';
408
-
409
- before(function () {
410
- if (requirements.credentialProvidersInstalled.aws) {
411
- this.currentTest.skipReason = 'With optional sdk installed credentials would be loaded.';
412
- this.currentTest.skip();
413
- return;
414
- }
415
- // After the entire suite runs, set the env back for the rest of the test run.
416
- process.env.AWS_ACCESS_KEY_ID = accessKey;
417
- process.env.AWS_SECRET_ACCESS_KEY = secretKey;
418
- });
419
-
420
- after(function () {
421
- // After the entire suite runs, set the env back for the rest of the test run.
422
- process.env.AWS_ACCESS_KEY_ID = originalAccessKeyId;
423
- process.env.AWS_SECRET_ACCESS_KEY = originalSecretAccessKey;
424
- });
425
-
426
- it('errors without the optional sdk credential provider', function (done) {
427
- const input = readExtendedJsonToBuffer(`${__dirname}/data/encrypted-document.json`);
428
- const client = new MockClient();
429
- const mc = new AutoEncrypter(client, {
430
- keyVaultNamespace: 'admin.datakeys',
431
- logger: () => {},
432
- kmsProviders: {
433
- aws: {}
434
- }
435
- });
436
- mc.decrypt(input, err => {
437
- expect(err.message).to.equal(
438
- 'client not configured with KMS provider necessary to decrypt'
439
- );
440
- done();
441
- });
442
- });
443
- });
444
-
445
- it('should encrypt mock data', function (done) {
446
- const client = new MockClient();
447
- const mc = new AutoEncrypter(client, {
448
- keyVaultNamespace: 'admin.datakeys',
449
- logger: () => {},
450
- kmsProviders: {
451
- aws: { accessKeyId: 'example', secretAccessKey: 'example' },
452
- local: { key: Buffer.alloc(96) }
453
- }
454
- });
455
-
456
- mc.encrypt('test.test', TEST_COMMAND, (err, encrypted) => {
457
- if (err) return done(err);
458
- const expected = EJSON.parse(
459
- JSON.stringify({
460
- find: 'test',
461
- filter: {
462
- ssn: {
463
- $binary: {
464
- base64:
465
- 'AWFhYWFhYWFhYWFhYWFhYWECRTOW9yZzNDn5dGwuqsrJQNLtgMEKaujhs9aRWRp+7Yo3JK8N8jC8P0Xjll6C1CwLsE/iP5wjOMhVv1KMMyOCSCrHorXRsb2IKPtzl2lKTqQ=',
466
- subType: '6'
467
- }
468
- }
469
- }
470
- })
471
- );
472
-
473
- expect(encrypted).to.containSubset(expected);
474
- done();
475
- });
476
- });
477
-
478
- it('should encrypt mock data with per-context KMS credentials', function (done) {
479
- const client = new MockClient();
480
- const mc = new AutoEncrypter(client, {
481
- keyVaultNamespace: 'admin.datakeys',
482
- logger: () => {},
483
- kmsProviders: {
484
- aws: {}
485
- },
486
- async onKmsProviderRefresh() {
487
- return { aws: { accessKeyId: 'example', secretAccessKey: 'example' } };
488
- }
489
- });
490
-
491
- mc.encrypt('test.test', TEST_COMMAND, (err, encrypted) => {
492
- if (err) return done(err);
493
- const expected = EJSON.parse(
494
- JSON.stringify({
495
- find: 'test',
496
- filter: {
497
- ssn: {
498
- $binary: {
499
- base64:
500
- 'AWFhYWFhYWFhYWFhYWFhYWECRTOW9yZzNDn5dGwuqsrJQNLtgMEKaujhs9aRWRp+7Yo3JK8N8jC8P0Xjll6C1CwLsE/iP5wjOMhVv1KMMyOCSCrHorXRsb2IKPtzl2lKTqQ=',
501
- subType: '6'
502
- }
503
- }
504
- }
505
- })
506
- );
507
-
508
- expect(encrypted).to.containSubset(expected);
509
- done();
510
- });
511
- });
512
-
513
- // TODO(NODE-4089): Enable test once https://github.com/mongodb/libmongocrypt/pull/263 is done
514
- it.skip('should encrypt mock data when using the crypt_shared library', function (done) {
515
- const client = new MockClient();
516
- const mc = new AutoEncrypter(client, {
517
- keyVaultNamespace: 'admin.datakeys',
518
- logger: () => {},
519
- kmsProviders: {
520
- aws: {}
521
- },
522
- async onKmsProviderRefresh() {
523
- return { aws: { accessKeyId: 'example', secretAccessKey: 'example' } };
524
- },
525
- extraOptions: {
526
- cryptSharedLibPath: sharedLibraryStub
527
- }
528
- });
529
-
530
- expect(mc).to.not.have.property('_mongocryptdManager');
531
- expect(mc).to.not.have.property('_mongocryptdClient');
532
-
533
- mc.encrypt('test.test', TEST_COMMAND, (err, encrypted) => {
534
- if (err) return done(err);
535
- const expected = EJSON.parse(
536
- JSON.stringify({
537
- find: 'test',
538
- filter: {
539
- ssn: {
540
- $binary: {
541
- base64:
542
- 'AWFhYWFhYWFhYWFhYWFhYWECRTOW9yZzNDn5dGwuqsrJQNLtgMEKaujhs9aRWRp+7Yo3JK8N8jC8P0Xjll6C1CwLsE/iP5wjOMhVv1KMMyOCSCrHorXRsb2IKPtzl2lKTqQ=',
543
- subType: '6'
544
- }
545
- }
546
- }
547
- })
548
- );
549
-
550
- expect(encrypted).to.containSubset(expected);
551
- done();
552
- });
553
- });
554
- });
555
-
556
- describe('logging', function () {
557
- it('should allow registration of a log handler', function (done) {
558
- ENABLE_LOG_TEST = true;
559
-
560
- let loggerCalled = false;
561
- const logger = (level, message) => {
562
- if (loggerCalled) return;
563
-
564
- loggerCalled = true;
565
- expect(level).to.be.oneOf([2, 3]);
566
- expect(message).to.not.be.empty;
567
- };
568
-
569
- const client = new MockClient();
570
- const mc = new AutoEncrypter(client, {
571
- logger,
572
- kmsProviders: {
573
- aws: { accessKeyId: 'example', secretAccessKey: 'example' },
574
- local: { key: Buffer.alloc(96) }
575
- }
576
- });
577
-
578
- mc.encrypt('test.test', TEST_COMMAND, (err, encrypted) => {
579
- if (err) return done(err);
580
- const expected = EJSON.parse(
581
- JSON.stringify({
582
- find: 'test',
583
- filter: {
584
- ssn: '457-55-5462'
585
- }
586
- })
587
- );
588
-
589
- expect(encrypted).to.containSubset(expected);
590
- done();
591
- });
592
- });
593
- });
594
-
595
- describe('autoSpawn', function () {
596
- beforeEach(function () {
597
- if (requirements.SKIP_LIVE_TESTS) {
598
- this.currentTest.skipReason = `requirements.SKIP_LIVE_TESTS=${requirements.SKIP_LIVE_TESTS}`;
599
- this.currentTest.skip();
600
- return;
601
- }
602
- });
603
- afterEach(function (done) {
604
- if (this.mc) {
605
- this.mc.teardown(false, err => {
606
- this.mc = undefined;
607
- done(err);
608
- });
609
- } else {
610
- done();
611
- }
612
- });
613
-
614
- it('should autoSpawn a mongocryptd on init by default', function (done) {
615
- const client = new MockClient();
616
- this.mc = new AutoEncrypter(client, {
617
- keyVaultNamespace: 'admin.datakeys',
618
- logger: () => {},
619
- kmsProviders: {
620
- aws: { accessKeyId: 'example', secretAccessKey: 'example' },
621
- local: { key: Buffer.alloc(96) }
622
- }
623
- });
624
-
625
- expect(this.mc).to.have.property('cryptSharedLibVersionInfo', null);
626
-
627
- const localMcdm = this.mc._mongocryptdManager;
628
- sandbox.spy(localMcdm, 'spawn');
629
-
630
- this.mc.init(err => {
631
- if (err) return done(err);
632
- expect(localMcdm.spawn).to.have.been.calledOnce;
633
- done();
634
- });
635
- });
636
-
637
- it('should not attempt to kick off mongocryptd on a normal error', function (done) {
638
- let called = false;
639
- StateMachine.prototype.markCommand.callsFake((client, ns, filter, callback) => {
640
- if (!called) {
641
- called = true;
642
- callback(new Error('msg'));
643
- return;
644
- }
645
-
646
- callback(null, MOCK_MONGOCRYPTD_RESPONSE);
647
- });
648
-
649
- const client = new MockClient();
650
- this.mc = new AutoEncrypter(client, {
651
- keyVaultNamespace: 'admin.datakeys',
652
- logger: () => {},
653
- kmsProviders: {
654
- aws: { accessKeyId: 'example', secretAccessKey: 'example' },
655
- local: { key: Buffer.alloc(96) }
656
- }
657
- });
658
- expect(this.mc).to.have.property('cryptSharedLibVersionInfo', null);
659
-
660
- const localMcdm = this.mc._mongocryptdManager;
661
- this.mc.init(err => {
662
- if (err) return done(err);
663
-
664
- sandbox.spy(localMcdm, 'spawn');
665
-
666
- this.mc.encrypt('test.test', TEST_COMMAND, err => {
667
- expect(localMcdm.spawn).to.not.have.been.called;
668
- expect(err).to.be.an.instanceOf(Error);
669
- done();
670
- });
671
- });
672
- });
673
-
674
- it('should restore the mongocryptd and retry once if a MongoNetworkTimeoutError is experienced', function (done) {
675
- let called = false;
676
- StateMachine.prototype.markCommand.callsFake((client, ns, filter, callback) => {
677
- if (!called) {
678
- called = true;
679
- callback(new MongoNetworkTimeoutError('msg'));
680
- return;
681
- }
682
-
683
- callback(null, MOCK_MONGOCRYPTD_RESPONSE);
684
- });
685
-
686
- const client = new MockClient();
687
- this.mc = new AutoEncrypter(client, {
688
- keyVaultNamespace: 'admin.datakeys',
689
- logger: () => {},
690
- kmsProviders: {
691
- aws: { accessKeyId: 'example', secretAccessKey: 'example' },
692
- local: { key: Buffer.alloc(96) }
693
- }
694
- });
695
- expect(this.mc).to.have.property('cryptSharedLibVersionInfo', null);
696
-
697
- const localMcdm = this.mc._mongocryptdManager;
698
- this.mc.init(err => {
699
- if (err) return done(err);
700
-
701
- sandbox.spy(localMcdm, 'spawn');
702
-
703
- this.mc.encrypt('test.test', TEST_COMMAND, err => {
704
- expect(localMcdm.spawn).to.have.been.calledOnce;
705
- expect(err).to.not.exist;
706
- done();
707
- });
708
- });
709
- });
710
-
711
- it('should propagate error if MongoNetworkTimeoutError is experienced twice in a row', function (done) {
712
- let counter = 2;
713
- StateMachine.prototype.markCommand.callsFake((client, ns, filter, callback) => {
714
- if (counter) {
715
- counter -= 1;
716
- callback(new MongoNetworkTimeoutError('msg'));
717
- return;
718
- }
719
-
720
- callback(null, MOCK_MONGOCRYPTD_RESPONSE);
721
- });
722
-
723
- const client = new MockClient();
724
- this.mc = new AutoEncrypter(client, {
725
- keyVaultNamespace: 'admin.datakeys',
726
- logger: () => {},
727
- kmsProviders: {
728
- aws: { accessKeyId: 'example', secretAccessKey: 'example' },
729
- local: { key: Buffer.alloc(96) }
730
- }
731
- });
732
- expect(this.mc).to.have.property('cryptSharedLibVersionInfo', null);
733
-
734
- const localMcdm = this.mc._mongocryptdManager;
735
- this.mc.init(err => {
736
- if (err) return done(err);
737
-
738
- sandbox.spy(localMcdm, 'spawn');
739
-
740
- this.mc.encrypt('test.test', TEST_COMMAND, err => {
741
- expect(localMcdm.spawn).to.have.been.calledOnce;
742
- expect(err).to.be.an.instanceof(MongoNetworkTimeoutError);
743
- done();
744
- });
745
- });
746
- });
747
-
748
- it('should return a useful message if mongocryptd fails to autospawn', function (done) {
749
- const client = new MockClient();
750
- this.mc = new AutoEncrypter(client, {
751
- keyVaultNamespace: 'admin.datakeys',
752
- logger: () => {},
753
- kmsProviders: {
754
- aws: { accessKeyId: 'example', secretAccessKey: 'example' },
755
- local: { key: Buffer.alloc(96) }
756
- },
757
- extraOptions: {
758
- mongocryptdURI: 'mongodb://something.invalid:27020/'
759
- }
760
- });
761
- expect(this.mc).to.have.property('cryptSharedLibVersionInfo', null);
762
-
763
- sandbox.stub(MongocryptdManager.prototype, 'spawn').callsFake(callback => {
764
- callback();
765
- });
766
-
767
- this.mc.init(err => {
768
- expect(err).to.exist;
769
- expect(err).to.be.instanceOf(MongoError);
770
- done();
771
- });
772
- });
773
- });
774
-
775
- describe('noAutoSpawn', function () {
776
- beforeEach('start MongocryptdManager', function (done) {
777
- if (requirements.SKIP_LIVE_TESTS) {
778
- this.currentTest.skipReason = `requirements.SKIP_LIVE_TESTS=${requirements.SKIP_LIVE_TESTS}`;
779
- this.skip();
780
- }
781
-
782
- this.mcdm = new MongocryptdManager({});
783
- this.mcdm.spawn(done);
784
- });
785
-
786
- afterEach(function (done) {
787
- if (this.mc) {
788
- this.mc.teardown(false, err => {
789
- this.mc = undefined;
790
- done(err);
791
- });
792
- } else {
793
- done();
794
- }
795
- });
796
-
797
- ['mongocryptdBypassSpawn', 'bypassAutoEncryption', 'bypassQueryAnalysis'].forEach(opt => {
798
- const encryptionOptions = {
799
- keyVaultNamespace: 'admin.datakeys',
800
- logger: () => {},
801
- kmsProviders: {
802
- aws: { accessKeyId: 'example', secretAccessKey: 'example' },
803
- local: { key: Buffer.alloc(96) }
804
- },
805
- extraOptions: {
806
- mongocryptdBypassSpawn: opt === 'mongocryptdBypassSpawn'
807
- },
808
- bypassAutoEncryption: opt === 'bypassAutoEncryption',
809
- bypassQueryAnalysis: opt === 'bypassQueryAnalysis'
810
- };
811
-
812
- it(`should not spawn mongocryptd on startup if ${opt} is true`, function (done) {
813
- const client = new MockClient();
814
- this.mc = new AutoEncrypter(client, encryptionOptions);
815
-
816
- const localMcdm = this.mc._mongocryptdManager || { spawn: () => {} };
817
- sandbox.spy(localMcdm, 'spawn');
818
-
819
- this.mc.init(err => {
820
- expect(err).to.not.exist;
821
- expect(localMcdm.spawn).to.have.a.callCount(0);
822
- done();
823
- });
824
- });
825
- });
826
-
827
- it('should not spawn a mongocryptd or retry on a server selection error if mongocryptdBypassSpawn: true', function (done) {
828
- let called = false;
829
- const timeoutError = new MongoNetworkTimeoutError('msg');
830
- StateMachine.prototype.markCommand.callsFake((client, ns, filter, callback) => {
831
- if (!called) {
832
- called = true;
833
- callback(timeoutError);
834
- return;
835
- }
836
-
837
- callback(null, MOCK_MONGOCRYPTD_RESPONSE);
838
- });
839
-
840
- const client = new MockClient();
841
- this.mc = new AutoEncrypter(client, {
842
- keyVaultNamespace: 'admin.datakeys',
843
- logger: () => {},
844
- kmsProviders: {
845
- aws: { accessKeyId: 'example', secretAccessKey: 'example' },
846
- local: { key: Buffer.alloc(96) }
847
- },
848
- extraOptions: {
849
- mongocryptdBypassSpawn: true
850
- }
851
- });
852
-
853
- const localMcdm = this.mc._mongocryptdManager;
854
- sandbox.spy(localMcdm, 'spawn');
855
-
856
- this.mc.init(err => {
857
- expect(err).to.not.exist;
858
- expect(localMcdm.spawn).to.not.have.been.called;
859
-
860
- this.mc.encrypt('test.test', TEST_COMMAND, (err, response) => {
861
- expect(localMcdm.spawn).to.not.have.been.called;
862
- expect(response).to.not.exist;
863
- expect(err).to.equal(timeoutError);
864
- done();
865
- });
866
- });
867
- });
868
- });
869
-
870
- describe('crypt_shared library', function () {
871
- it('should fail if no library can be found in the search path and cryptSharedLibRequired is set', function () {
872
- // NB: This test has to be run before the tests/without having previously
873
- // loaded a CSFLE shared library below to get the right error path.
874
- const client = new MockClient();
875
- try {
876
- new AutoEncrypter(client, {
877
- keyVaultNamespace: 'admin.datakeys',
878
- logger: () => {},
879
- kmsProviders: {
880
- aws: { accessKeyId: 'example', secretAccessKey: 'example' },
881
- local: { key: Buffer.alloc(96) }
882
- },
883
- extraOptions: {
884
- cryptSharedLibSearchPaths: ['/nonexistent'],
885
- cryptSharedLibRequired: true
886
- }
887
- });
888
- expect.fail('missed exception');
889
- } catch (err) {
890
- expect(err.message).to.include(
891
- '`cryptSharedLibRequired` set but no crypt_shared library loaded'
892
- );
893
- }
894
- });
895
-
896
- it('should load a shared library by specifying its path', function (done) {
897
- const client = new MockClient();
898
- this.mc = new AutoEncrypter(client, {
899
- keyVaultNamespace: 'admin.datakeys',
900
- logger: () => {},
901
- kmsProviders: {
902
- aws: { accessKeyId: 'example', secretAccessKey: 'example' },
903
- local: { key: Buffer.alloc(96) }
904
- },
905
- extraOptions: {
906
- cryptSharedLibPath: sharedLibraryStub
907
- }
908
- });
909
-
910
- expect(this.mc).to.not.have.property('_mongocryptdManager');
911
- expect(this.mc).to.not.have.property('_mongocryptdClient');
912
- expect(this.mc).to.have.deep.property('cryptSharedLibVersionInfo', {
913
- // eslint-disable-next-line no-undef
914
- version: BigInt(0x000600020001000),
915
- versionStr: 'stubbed-crypt_shared'
916
- });
917
-
918
- this.mc.teardown(true, done);
919
- });
920
-
921
- it('should load a shared library by specifying a search path', function (done) {
922
- const client = new MockClient();
923
- this.mc = new AutoEncrypter(client, {
924
- keyVaultNamespace: 'admin.datakeys',
925
- logger: () => {},
926
- kmsProviders: {
927
- aws: { accessKeyId: 'example', secretAccessKey: 'example' },
928
- local: { key: Buffer.alloc(96) }
929
- },
930
- extraOptions: {
931
- cryptSharedLibSearchPaths: [path.dirname(sharedLibraryStub)]
932
- }
933
- });
934
-
935
- expect(this.mc).to.not.have.property('_mongocryptdManager');
936
- expect(this.mc).to.not.have.property('_mongocryptdClient');
937
- expect(this.mc).to.have.deep.property('cryptSharedLibVersionInfo', {
938
- // eslint-disable-next-line no-undef
939
- version: BigInt(0x000600020001000),
940
- versionStr: 'stubbed-crypt_shared'
941
- });
942
-
943
- this.mc.teardown(true, done);
944
- });
945
- });
946
-
947
- it('should provide the libmongocrypt version', function () {
948
- expect(AutoEncrypter.libmongocryptVersion).to.be.a('string');
949
- });
950
- });