mongo 2.13.3 → 2.14.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/mongo/address/ipv4.rb +1 -1
  4. data/lib/mongo/address/ipv6.rb +1 -1
  5. data/lib/mongo/address.rb +1 -1
  6. data/lib/mongo/bulk_write.rb +17 -0
  7. data/lib/mongo/caching_cursor.rb +74 -0
  8. data/lib/mongo/client.rb +47 -8
  9. data/lib/mongo/cluster/topology/single.rb +1 -1
  10. data/lib/mongo/cluster.rb +3 -3
  11. data/lib/mongo/collection/view/aggregation.rb +25 -4
  12. data/lib/mongo/collection/view/builder/find_command.rb +38 -18
  13. data/lib/mongo/collection/view/explainable.rb +27 -8
  14. data/lib/mongo/collection/view/iterable.rb +72 -12
  15. data/lib/mongo/collection/view/readable.rb +12 -2
  16. data/lib/mongo/collection/view/writable.rb +15 -1
  17. data/lib/mongo/collection/view.rb +24 -20
  18. data/lib/mongo/collection.rb +26 -2
  19. data/lib/mongo/crypt/encryption_io.rb +6 -6
  20. data/lib/mongo/cursor.rb +1 -0
  21. data/lib/mongo/database/view.rb +1 -1
  22. data/lib/mongo/database.rb +8 -14
  23. data/lib/mongo/error/invalid_read_concern.rb +28 -0
  24. data/lib/mongo/error/server_certificate_revoked.rb +22 -0
  25. data/lib/mongo/error/unsupported_option.rb +14 -12
  26. data/lib/mongo/error.rb +2 -0
  27. data/lib/mongo/grid/fs_bucket.rb +37 -37
  28. data/lib/mongo/lint.rb +2 -1
  29. data/lib/mongo/logger.rb +3 -3
  30. data/lib/mongo/operation/aggregate/result.rb +9 -8
  31. data/lib/mongo/operation/collections_info/command.rb +0 -5
  32. data/lib/mongo/operation/collections_info/result.rb +3 -16
  33. data/lib/mongo/operation/delete/bulk_result.rb +2 -0
  34. data/lib/mongo/operation/delete/result.rb +3 -0
  35. data/lib/mongo/operation/explain/command.rb +4 -0
  36. data/lib/mongo/operation/explain/legacy.rb +4 -0
  37. data/lib/mongo/operation/explain/op_msg.rb +6 -0
  38. data/lib/mongo/operation/explain/result.rb +3 -0
  39. data/lib/mongo/operation/find/legacy/result.rb +2 -0
  40. data/lib/mongo/operation/find/result.rb +3 -0
  41. data/lib/mongo/operation/get_more/result.rb +3 -0
  42. data/lib/mongo/operation/indexes/result.rb +5 -0
  43. data/lib/mongo/operation/insert/bulk_result.rb +5 -0
  44. data/lib/mongo/operation/insert/result.rb +5 -0
  45. data/lib/mongo/operation/list_collections/result.rb +5 -0
  46. data/lib/mongo/operation/map_reduce/result.rb +10 -0
  47. data/lib/mongo/operation/parallel_scan/command.rb +2 -1
  48. data/lib/mongo/operation/parallel_scan/result.rb +4 -0
  49. data/lib/mongo/operation/result.rb +35 -6
  50. data/lib/mongo/operation/shared/bypass_document_validation.rb +1 -0
  51. data/lib/mongo/operation/shared/causal_consistency_supported.rb +1 -0
  52. data/lib/mongo/operation/shared/collections_info_or_list_collections.rb +2 -0
  53. data/lib/mongo/operation/shared/executable.rb +1 -0
  54. data/lib/mongo/operation/shared/idable.rb +2 -1
  55. data/lib/mongo/operation/shared/limited.rb +1 -0
  56. data/lib/mongo/operation/shared/object_id_generator.rb +1 -0
  57. data/lib/mongo/operation/shared/read_preference_supported.rb +36 -38
  58. data/lib/mongo/operation/shared/result/aggregatable.rb +1 -0
  59. data/lib/mongo/operation/shared/sessions_supported.rb +3 -3
  60. data/lib/mongo/operation/shared/specifiable.rb +1 -0
  61. data/lib/mongo/operation/shared/write.rb +1 -0
  62. data/lib/mongo/operation/shared/write_concern_supported.rb +1 -0
  63. data/lib/mongo/operation/update/legacy/result.rb +7 -0
  64. data/lib/mongo/operation/update/result.rb +8 -0
  65. data/lib/mongo/operation/users_info/result.rb +3 -0
  66. data/lib/mongo/operation.rb +2 -0
  67. data/lib/mongo/protocol/msg.rb +2 -2
  68. data/lib/mongo/protocol/query.rb +11 -11
  69. data/lib/mongo/query_cache.rb +242 -0
  70. data/lib/mongo/retryable.rb +8 -1
  71. data/lib/mongo/server/connection_common.rb +2 -2
  72. data/lib/mongo/server/connection_pool.rb +3 -0
  73. data/lib/mongo/server/monitor/connection.rb +3 -3
  74. data/lib/mongo/server/monitor.rb +1 -1
  75. data/lib/mongo/server/pending_connection.rb +2 -2
  76. data/lib/mongo/server/push_monitor.rb +1 -1
  77. data/lib/mongo/server.rb +5 -1
  78. data/lib/mongo/server_selector/base.rb +5 -1
  79. data/lib/mongo/server_selector/secondary_preferred.rb +7 -2
  80. data/lib/mongo/session.rb +3 -0
  81. data/lib/mongo/socket/ocsp_cache.rb +97 -0
  82. data/lib/mongo/socket/ocsp_verifier.rb +368 -0
  83. data/lib/mongo/socket/ssl.rb +45 -24
  84. data/lib/mongo/socket.rb +6 -4
  85. data/lib/mongo/srv/monitor.rb +7 -13
  86. data/lib/mongo/srv/resolver.rb +14 -10
  87. data/lib/mongo/timeout.rb +2 -0
  88. data/lib/mongo/uri/options_mapper.rb +582 -0
  89. data/lib/mongo/uri/srv_protocol.rb +3 -2
  90. data/lib/mongo/uri.rb +21 -390
  91. data/lib/mongo/utils.rb +12 -1
  92. data/lib/mongo/version.rb +1 -1
  93. data/lib/mongo.rb +9 -0
  94. data/spec/NOTES.aws-auth.md +12 -7
  95. data/spec/README.md +56 -1
  96. data/spec/integration/bson_symbol_spec.rb +2 -4
  97. data/spec/integration/bulk_write_spec.rb +48 -0
  98. data/spec/integration/client_authentication_options_spec.rb +55 -28
  99. data/spec/integration/connection_pool_populator_spec.rb +3 -1
  100. data/spec/integration/cursor_reaping_spec.rb +53 -17
  101. data/spec/integration/ocsp_connectivity_spec.rb +26 -0
  102. data/spec/integration/ocsp_verifier_cache_spec.rb +188 -0
  103. data/spec/integration/ocsp_verifier_spec.rb +334 -0
  104. data/spec/integration/query_cache_spec.rb +1045 -0
  105. data/spec/integration/query_cache_transactions_spec.rb +179 -0
  106. data/spec/integration/retryable_writes/retryable_writes_40_and_newer_spec.rb +1 -0
  107. data/spec/integration/retryable_writes/shared/performs_legacy_retries.rb +2 -0
  108. data/spec/integration/sdam_error_handling_spec.rb +69 -18
  109. data/spec/integration/sdam_events_spec.rb +7 -8
  110. data/spec/integration/server_selection_spec.rb +36 -0
  111. data/spec/integration/srv_monitoring_spec.rb +38 -3
  112. data/spec/integration/srv_spec.rb +56 -0
  113. data/spec/lite_spec_helper.rb +4 -2
  114. data/spec/mongo/address_spec.rb +1 -1
  115. data/spec/mongo/caching_cursor_spec.rb +70 -0
  116. data/spec/mongo/client_construction_spec.rb +54 -1
  117. data/spec/mongo/client_encryption_spec.rb +10 -16
  118. data/spec/mongo/client_spec.rb +40 -0
  119. data/spec/mongo/cluster/topology/single_spec.rb +14 -5
  120. data/spec/mongo/cluster_spec.rb +3 -0
  121. data/spec/mongo/collection/view/explainable_spec.rb +87 -4
  122. data/spec/mongo/collection/view/map_reduce_spec.rb +2 -0
  123. data/spec/mongo/collection_spec.rb +60 -0
  124. data/spec/mongo/crypt/auto_decryption_context_spec.rb +1 -1
  125. data/spec/mongo/crypt/auto_encryption_context_spec.rb +1 -1
  126. data/spec/mongo/crypt/data_key_context_spec.rb +1 -1
  127. data/spec/mongo/crypt/explicit_decryption_context_spec.rb +1 -1
  128. data/spec/mongo/crypt/explicit_encryption_context_spec.rb +1 -1
  129. data/spec/mongo/database_spec.rb +44 -64
  130. data/spec/mongo/error/no_server_available_spec.rb +1 -1
  131. data/spec/mongo/index/view_spec.rb +2 -4
  132. data/spec/mongo/logger_spec.rb +13 -11
  133. data/spec/mongo/operation/read_preference_legacy_spec.rb +19 -9
  134. data/spec/mongo/operation/read_preference_op_msg_spec.rb +3 -3
  135. data/spec/mongo/query_cache_spec.rb +279 -0
  136. data/spec/mongo/server/app_metadata_shared.rb +7 -33
  137. data/spec/mongo/server/connection_pool_spec.rb +7 -3
  138. data/spec/mongo/server/connection_spec.rb +14 -7
  139. data/spec/mongo/server_selector/secondary_preferred_spec.rb +6 -6
  140. data/spec/mongo/socket/ssl_spec.rb +1 -1
  141. data/spec/mongo/socket_spec.rb +1 -1
  142. data/spec/mongo/uri/srv_protocol_spec.rb +64 -33
  143. data/spec/mongo/uri_option_parsing_spec.rb +11 -11
  144. data/spec/mongo/uri_spec.rb +68 -41
  145. data/spec/mongo/utils_spec.rb +39 -0
  146. data/spec/runners/auth.rb +3 -0
  147. data/spec/runners/connection_string.rb +35 -124
  148. data/spec/runners/transactions/operation.rb +2 -13
  149. data/spec/spec_tests/cmap_spec.rb +7 -3
  150. data/spec/spec_tests/data/change_streams/change-streams-errors.yml +0 -1
  151. data/spec/spec_tests/data/change_streams/change-streams.yml +0 -1
  152. data/spec/spec_tests/data/cmap/pool-checkout-connection.yml +6 -2
  153. data/spec/spec_tests/data/cmap/pool-create-min-size.yml +3 -0
  154. data/spec/spec_tests/data/connection_string/valid-warnings.yml +24 -0
  155. data/spec/spec_tests/data/sdam_monitoring/discovered_standalone.yml +1 -3
  156. data/spec/spec_tests/data/sdam_monitoring/standalone.yml +2 -2
  157. data/spec/spec_tests/data/sdam_monitoring/standalone_repeated.yml +2 -2
  158. data/spec/spec_tests/data/sdam_monitoring/standalone_suppress_equal_description_changes.yml +2 -2
  159. data/spec/spec_tests/data/sdam_monitoring/standalone_to_rs_with_me_mismatch.yml +2 -2
  160. data/spec/spec_tests/data/uri_options/auth-options.yml +25 -0
  161. data/spec/spec_tests/data/uri_options/compression-options.yml +6 -3
  162. data/spec/spec_tests/data/uri_options/read-preference-options.yml +24 -0
  163. data/spec/spec_tests/data/uri_options/ruby-connection-options.yml +1 -0
  164. data/spec/spec_tests/data/uri_options/tls-options.yml +160 -4
  165. data/spec/spec_tests/dns_seedlist_discovery_spec.rb +9 -1
  166. data/spec/spec_tests/uri_options_spec.rb +31 -33
  167. data/spec/support/certificates/atlas-ocsp-ca.crt +28 -0
  168. data/spec/support/certificates/atlas-ocsp.crt +41 -0
  169. data/spec/support/client_registry.rb +4 -8
  170. data/spec/support/client_registry_macros.rb +4 -4
  171. data/spec/support/common_shortcuts.rb +45 -0
  172. data/spec/support/constraints.rb +23 -0
  173. data/spec/support/lite_constraints.rb +24 -0
  174. data/spec/support/matchers.rb +16 -0
  175. data/spec/support/ocsp +1 -0
  176. data/spec/support/session_registry.rb +52 -0
  177. data/spec/support/spec_config.rb +22 -12
  178. data/spec/support/spec_setup.rb +38 -48
  179. data/spec/support/utils.rb +19 -1
  180. data.tar.gz.sig +1 -3
  181. metadata +938 -933
  182. metadata.gz.sig +0 -0
  183. data/spec/integration/secondary_reads_spec.rb +0 -102
  184. data/spec/shared/LICENSE +0 -20
  185. data/spec/shared/bin/get-mongodb-download-url +0 -17
  186. data/spec/shared/lib/mrss/child_process_helper.rb +0 -80
  187. data/spec/shared/lib/mrss/cluster_config.rb +0 -221
  188. data/spec/shared/lib/mrss/constraints.rb +0 -346
  189. data/spec/shared/lib/mrss/docker_runner.rb +0 -265
  190. data/spec/shared/lib/mrss/lite_constraints.rb +0 -191
  191. data/spec/shared/lib/mrss/server_version_registry.rb +0 -115
  192. data/spec/shared/lib/mrss/spec_organizer.rb +0 -152
  193. data/spec/shared/lib/mrss/utils.rb +0 -15
  194. data/spec/shared/share/Dockerfile.erb +0 -231
  195. data/spec/shared/shlib/distro.sh +0 -73
  196. data/spec/shared/shlib/server.sh +0 -290
  197. data/spec/shared/shlib/set_env.sh +0 -128
@@ -0,0 +1,52 @@
1
+ require 'singleton'
2
+
3
+ module Mongo
4
+ class Client
5
+ alias :get_session_without_tracking :get_session
6
+
7
+ def get_session(options = {})
8
+ get_session_without_tracking(options).tap do |session|
9
+ SessionRegistry.instance.register(session)
10
+ end
11
+ end
12
+ end
13
+
14
+ class Session
15
+ alias :end_session_without_tracking :end_session
16
+
17
+ def end_session
18
+ SessionRegistry.instance.unregister(self)
19
+ end_session_without_tracking
20
+ end
21
+ end
22
+ end
23
+
24
+
25
+ class SessionRegistry
26
+ include Singleton
27
+
28
+ def initialize
29
+ @registry = {}
30
+ end
31
+
32
+ def register(session)
33
+ @registry[session.session_id] = session if session
34
+ end
35
+
36
+ def unregister(session)
37
+ @registry.delete(session.session_id) unless session.ended?
38
+ end
39
+
40
+ def verify_sessions_ended!
41
+ @registry.delete_if { |_, session| session.ended? }
42
+
43
+ unless @registry.empty?
44
+ sessions = @registry.map { |_, session| session }
45
+ raise "Session registry contains live sessions: #{sessions.join(', ')}"
46
+ end
47
+ end
48
+
49
+ def clear_registry
50
+ @registry = {}
51
+ end
52
+ end
@@ -110,14 +110,6 @@ class SpecConfig
110
110
  !!(RUBY_PLATFORM =~ /\bjava\b/)
111
111
  end
112
112
 
113
- def linux?
114
- !!(RbConfig::CONFIG['host_os'].downcase =~ /\blinux/)
115
- end
116
-
117
- def macos?
118
- !!(RbConfig::CONFIG['host_os'].downcase =~ /\bdarwin/)
119
- end
120
-
121
113
  def platform
122
114
  RUBY_PLATFORM
123
115
  end
@@ -130,6 +122,24 @@ class SpecConfig
130
122
  %w(1 true yes).include?(ENV['FORK']&.downcase)
131
123
  end
132
124
 
125
+ # OCSP tests require python and various dependencies.
126
+ # Assumes an OCSP responder is running on port 8100 (configured externally
127
+ # to the test suite).
128
+ def ocsp?
129
+ %w(1 true yes).include?(ENV['OCSP']&.downcase)
130
+ end
131
+
132
+ # OCSP tests require python and various dependencies.
133
+ # When testing OCSP verifier, there cannot be a responder running on
134
+ # port 8100 or the tests will fail.
135
+ def ocsp_verifier?
136
+ %w(1 true yes).include?(ENV['OCSP_VERIFIER']&.downcase)
137
+ end
138
+
139
+ def ocsp_connectivity?
140
+ ENV.key?('OCSP_CONNECTIVITY') && ENV['OCSP_CONNECTIVITY'] != ''
141
+ end
142
+
133
143
  # Test suite configuration
134
144
 
135
145
  def client_debug?
@@ -229,6 +239,10 @@ EOT
229
239
  Pathname.new("#{spec_root}/support/certificates")
230
240
  end
231
241
 
242
+ def ocsp_files_dir
243
+ Pathname.new("#{spec_root}/../.mod/drivers-evergreen-tools/.evergreen/ocsp")
244
+ end
245
+
232
246
  # TLS certificates & keys
233
247
 
234
248
  def local_client_key_path
@@ -350,10 +364,6 @@ EOT
350
364
  end
351
365
  end
352
366
 
353
- def auth?
354
- x509_auth? || user
355
- end
356
-
357
367
  # Option hashes
358
368
 
359
369
  def auth_options
@@ -8,50 +8,38 @@ class SpecSetup
8
8
  return
9
9
  end
10
10
 
11
- with_client do |client|
12
- # For historical reasons, the test suite always uses
13
- # password-authenticated users, even when authentication is not
14
- # requested in the configuration. When authentication is requested
15
- # and password authentication is used (i.e., not x509 and not kerberos),
16
- # a suitable user already exists (it's the one specified in the URI)
17
- # and no additional users are needed. In other cases, including x509
18
- # auth and kerberos, create the "root user".
19
- # TODO redo the test suite so that this password-authenticated root user
20
- # is not required and the test suite uses whichever user is specified
21
- # in the URI, which could be none.
22
- if !SpecConfig.instance.auth? || SpecConfig.instance.x509_auth?
23
- # Create the root user administrator as the first user to be added to the
24
- # database. This user will need to be authenticated in order to add any
25
- # more users to any other databases.
26
- begin
27
- create_user(client, SpecConfig.instance.root_user)
28
- rescue Mongo::Error::OperationFailure => e
29
- # When testing a cluster that requires auth, root user is already set up
30
- # and it is not creatable without auth.
31
- # Seems like every mongodb version has its own error message
32
- # for trying to make a user when not authenticated,
33
- # and prior to 4.0 or so the codes are supposedly not reliable either.
34
- # In order: 4.0, 3.6, 3.4 through 2.6
35
- if e.message =~ /command createUser requires authentication|there are no users authenticated|not authorized on admin to execute command.*createUser/
36
- # However, if the cluster is configured to require auth but
37
- # test suite has wrong credentials, then admin_authorized_test_client
38
- # won't be authenticated and the following line will raise an
39
- # exception
40
- if client.use('admin').database.users.info(SpecConfig.instance.root_user.name).any?
41
- warn "Skipping root user creation, likely auth is enabled on cluster"
42
- else
43
- raise
44
- end
45
- else
46
- raise
47
- end
11
+ # Create the root user administrator as the first user to be added to the
12
+ # database. This user will need to be authenticated in order to add any
13
+ # more users to any other databases.
14
+ begin
15
+ create_user(admin_unauthorized_client, SpecConfig.instance.root_user)
16
+ rescue Mongo::Error::OperationFailure => e
17
+ # When testing a cluster that requires auth, root user is already set up
18
+ # and it is not creatable without auth.
19
+ # Seems like every mongodb version has its own error message
20
+ # for trying to make a user when not authenticated,
21
+ # and prior to 4.0 or so the codes are supposedly not reliable either.
22
+ # In order: 4.0, 3.6, 3.4 through 2.6
23
+ if e.message =~ /command createUser requires authentication|there are no users authenticated|not authorized on admin to execute command.*createUser/
24
+ # However, if the cluster is configured to require auth but
25
+ # test suite has wrong credentials, then admin_authorized_test_client
26
+ # won't be authenticated and the following line will raise an
27
+ # exception
28
+ if admin_authorized_test_client.with(database: 'admin').database.users.info(SpecConfig.instance.root_user.name).any?
29
+ warn "Skipping root user creation, likely auth is enabled on cluster"
30
+ else
31
+ raise
48
32
  end
33
+ else
34
+ raise
49
35
  end
50
-
51
- # Adds the test user to the test database with permissions on all
52
- # databases that will be used in the test suite.
53
- create_user(client, SpecConfig.instance.test_user)
54
36
  end
37
+ admin_unauthorized_client.close
38
+
39
+ # Adds the test user to the test database with permissions on all
40
+ # databases that will be used in the test suite.
41
+ create_user(admin_authorized_test_client, SpecConfig.instance.test_user)
42
+ admin_authorized_test_client.close
55
43
  end
56
44
 
57
45
  def create_user(client, user)
@@ -68,13 +56,15 @@ class SpecSetup
68
56
  end
69
57
  end
70
58
 
71
- def with_client(&block)
72
- Mongo::Client.new(
73
- SpecConfig.instance.addresses,
74
- SpecConfig.instance.all_test_options.merge(
75
- socket_timeout: 5, connect_timeout: 5,
76
- ),
77
- &block
59
+ def admin_unauthorized_client
60
+ ClientRegistry.instance.global_client('admin_unauthorized').with(
61
+ socket_timeout: 5, connect_timeout: 5,
62
+ )
63
+ end
64
+
65
+ def admin_authorized_test_client
66
+ ClientRegistry.instance.global_client('root_authorized').with(
67
+ socket_timeout: 5, connect_timeout: 5,
78
68
  )
79
69
  end
80
70
  end
@@ -85,6 +85,13 @@ module Utils
85
85
  end
86
86
  module_function :camelize
87
87
 
88
+ module_function def downcase_keys(hash)
89
+ # TODO replace with Hash#transform_keys when we require Ruby 2.5+
90
+ Hash[hash.map do |k, v|
91
+ [k.downcase, v]
92
+ end]
93
+ end
94
+
88
95
  module_function def disable_retries_client_options
89
96
  {
90
97
  retry_reads: false,
@@ -98,6 +105,7 @@ module Utils
98
105
  # to Ruby driver underscore options.
99
106
  def convert_client_options(spec_test_options)
100
107
  uri = Mongo::URI.new('mongodb://localhost')
108
+ mapper = Mongo::URI::OptionsMapper.new
101
109
  spec_test_options.reduce({}) do |opts, (name, value)|
102
110
  if name == 'autoEncryptOpts'
103
111
  opts.merge!(
@@ -111,7 +119,7 @@ module Utils
111
119
  )
112
120
  )
113
121
  else
114
- uri.send(:add_uri_option, name, value.to_s, opts)
122
+ mapper.add_uri_option(name, value.to_s, opts)
115
123
  end
116
124
 
117
125
  opts
@@ -494,4 +502,14 @@ module Utils
494
502
 
495
503
  subscriber.single_command_started_event(command_name, include_auth: include_auth)
496
504
  end
505
+
506
+ # Drops and creates a collection for the purpose of starting the test from
507
+ # a clean slate.
508
+ #
509
+ # @param [ Mongo::Client ] client
510
+ # @param [ String ] collection_name
511
+ module_function def create_collection(client, collection_name)
512
+ client[collection_name].drop
513
+ client[collection_name].create
514
+ end
497
515
  end
data.tar.gz.sig CHANGED
@@ -1,3 +1 @@
1
- ����3aG��0��"�#8��^�o3V�hi[�~���K>%�~���1�0�yLv{�m�L׸"��E� �(�Bg�T�!��1沏&��[�t�ɚXT1�G��'�'���}�� ֛��
2
- w����q�E}��)܄~Q�XA�jIC;8eA5>�*��܎�R���
3
- ��9���|���x�5�m� �2u��pM|M�l<�EQS�;d�������-��҆ͥ�ӆ�r3�������3$�1�v��Gp{�]��
1
+ lb~�{������zx�%����~��n��3G���k�j*R)ڗ0