Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 0 additions & 82 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,12 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 7
# This cop supports safe autocorrection (--autocorrect).
Layout/MultilineBlockLayout:
Exclude:
- 'lib/mongo/crypt/handle.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
Layout/RescueEnsureAlignment:
Exclude:
- 'spec/mongo/collection/view/change_stream_spec.rb'
- 'spec/mongo/collection/view/readable_spec.rb'

# Offense count: 8
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: RequireParenthesesForMethodChains.
Lint/AmbiguousRange:
Exclude:
- 'spec/integration/sdam_events_spec.rb'
- 'spec/mongo/server/description/features_spec.rb'
- 'spec/runners/unified.rb'

# Offense count: 190
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowSafeAssignment.
Lint/AssignmentInCondition:
Enabled: false

# Offense count: 10
# Configuration parameters: AllowedMethods.
# AllowedMethods: enums
Lint/ConstantDefinitionInBlock:
Exclude:
- 'spec/integration/heartbeat_events_spec.rb'
- 'spec/mongo/id_spec.rb'
- 'spec/mongo/operation/result_spec.rb'
- 'spec/mongo/server/connection_spec.rb'
- 'spec/spec_tests/sdam_spec.rb'

# Offense count: 16
# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches, IgnoreDuplicateElseBranch.
Lint/DuplicateBranch:
Expand All @@ -63,56 +30,13 @@ Lint/DuplicateBranch:
- 'spec/runners/sdam.rb'
- 'spec/support/client_registry.rb'

# Offense count: 3
Lint/DuplicateMethods:
Exclude:
- 'spec/runners/auth.rb'
- 'spec/runners/cmap.rb'
- 'spec/support/spec_config.rb'

# Offense count: 8
# Configuration parameters: AllowComments, AllowEmptyLambdas.
Lint/EmptyBlock:
Exclude:
- 'spec/integration/cursor_memory_leak_spec.rb'
- 'spec/mongo/auth/user_spec.rb'
- 'spec/mongo/cursor_spec.rb'
- 'spec/mongo/server/description_spec.rb'
- 'spec/mongo/server/round_trip_time_calculator_spec.rb'
- 'spec/mongo/uri/srv_protocol_spec.rb'

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowComments.
Lint/EmptyConditionalBody:
Exclude:
- 'spec/runners/transactions.rb'
- 'spec/spec_tests/uri_options_spec.rb'

# Offense count: 4
# This cop supports unsafe autocorrection (--autocorrect-all).
Lint/IncompatibleIoSelectWithFiberScheduler:
Exclude:
- 'lib/mongo/socket/ssl.rb'
- 'lib/mongo/socket/tcp.rb'

# Offense count: 7
Lint/IneffectiveAccessModifier:
Exclude:
- 'lib/mongo/operation/shared/polymorphic_result.rb'
- 'lib/mongo/protocol/message.rb'
- 'lib/mongo/uri/options_mapper.rb'

# Offense count: 4
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: standard_error, runtime_error
Lint/InheritException:
Exclude:
- 'lib/mongo/error/raise_original_error.rb'
- 'spec/mongo/server/connection_spec.rb'
- 'spec/mongo/socket_spec.rb'

# Offense count: 31
# Configuration parameters: AllowedParentClasses.
Lint/MissingSuper:
Expand All @@ -128,12 +52,6 @@ Lint/NextWithoutAccumulator:
Exclude:
- 'lib/mongo/operation/shared/result/aggregatable.rb'

# Offense count: 2
Lint/NoReturnInBeginEndBlocks:
Exclude:
- 'lib/mongo/socket/ocsp_verifier.rb'
- 'spec/runners/change_streams/test.rb'

# Offense count: 1
Lint/NonLocalExitFromIterator:
Exclude:
Expand Down
21 changes: 7 additions & 14 deletions lib/mongo/crypt/handle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,7 @@ def do_rsaes_pkcs_signature(key_binary_p, input_binary_p,
# Every crypto binding ignores its first argument, which is an option
# mongocrypt_ctx_t object and is not required to use crypto hooks.
def set_crypto_hooks
@aes_encrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p,
output_binary_p, response_length_p, status_p|
@aes_encrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p, output_binary_p, response_length_p, status_p|
do_aes(
key_binary_p,
iv_binary_p,
Expand All @@ -300,8 +299,7 @@ def set_crypto_hooks
)
end

@aes_decrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p,
output_binary_p, response_length_p, status_p|
@aes_decrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p, output_binary_p, response_length_p, status_p|
do_aes(
key_binary_p,
iv_binary_p,
Expand All @@ -319,13 +317,11 @@ def set_crypto_hooks
end
end

@hmac_sha_512 = proc do |_, key_binary_p, input_binary_p,
output_binary_p, status_p|
@hmac_sha_512 = proc do |_, key_binary_p, input_binary_p, output_binary_p, status_p|
do_hmac_sha('SHA512', key_binary_p, input_binary_p, output_binary_p, status_p)
end

@hmac_sha_256 = proc do |_, key_binary_p, input_binary_p,
output_binary_p, status_p|
@hmac_sha_256 = proc do |_, key_binary_p, input_binary_p, output_binary_p, status_p|
do_hmac_sha('SHA256', key_binary_p, input_binary_p, output_binary_p, status_p)
end

Expand All @@ -347,8 +343,7 @@ def set_crypto_hooks
@hmac_hash
)

@aes_ctr_encrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p,
output_binary_p, response_length_p, status_p|
@aes_ctr_encrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p, output_binary_p, response_length_p, status_p|
do_aes(
key_binary_p,
iv_binary_p,
Expand All @@ -360,8 +355,7 @@ def set_crypto_hooks
)
end

@aes_ctr_decrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p,
output_binary_p, response_length_p, status_p|
@aes_ctr_decrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p, output_binary_p, response_length_p, status_p|
do_aes(
key_binary_p,
iv_binary_p,
Expand All @@ -380,8 +374,7 @@ def set_crypto_hooks
@aes_ctr_decrypt
)

@rsaes_pkcs_signature_cb = proc do |_, key_binary_p, input_binary_p,
output_binary_p, status_p|
@rsaes_pkcs_signature_cb = proc do |_, key_binary_p, input_binary_p, output_binary_p, status_p|
do_rsaes_pkcs_signature(key_binary_p, input_binary_p, output_binary_p, status_p)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/mongo/error/raise_original_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Error
# @note This class must not derive from Error.
#
# @api private
class RaiseOriginalError < Exception
class RaiseOriginalError < Exception # rubocop:disable Lint/InheritException
end
end
end
4 changes: 2 additions & 2 deletions lib/mongo/operation/shared/polymorphic_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ module Operation
module PolymorphicResult
include PolymorphicLookup

private

def self.included(base)
base.extend ClassMethods
end

private

module ClassMethods
attr_accessor :result_class
end
Expand Down
99 changes: 52 additions & 47 deletions lib/mongo/protocol/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,64 +320,19 @@ def number_returned
0
end

private

# A method for getting the fields for a message class
#
# @return [Integer] the fields for the message class
def fields
self.class.fields
end

# A class method for getting the fields for a message class
#
# @return [Integer] the fields for the message class
# @api private
def self.fields
@fields ||= []
end

# Serializes message fields into a buffer
#
# @param buffer [String] buffer to receive the field
# @return [String] buffer with serialized field
def serialize_fields(buffer, max_bson_size = nil)
fields.each do |field|
value = instance_variable_get(field[:name])
if field[:multi]
value.each do |item|
if field[:type].respond_to?(:size_limited?)
field[:type].serialize(buffer, item, max_bson_size)
else
field[:type].serialize(buffer, item)
end
end
elsif field[:type].respond_to?(:size_limited?)
field[:type].serialize(buffer, value, max_bson_size)
else
field[:type].serialize(buffer, value)
end
end
end

# Serializes the header of the message consisting of 4 32bit integers
#
# The integers represent a message length placeholder (calculation of
# the actual length is deferred) the request id, the response to id,
# and the op code for the message
#
# Currently uses hardcoded 0 for request id and response to as their
# values are irrelevent to the server
#
# @param buffer [String] Buffer to receive the header
# @return [String] Serialized header
def serialize_header(buffer)
Header.serialize(buffer, [ 0, request_id, 0, op_code ])
end

# Deserializes the header of the message
#
# @param io [IO] Stream containing the header.
# @return [Array<Fixnum>] Deserialized header.
# @api private
def self.deserialize_header(io)
Header.deserialize(io)
end
Expand All @@ -397,6 +352,7 @@ def self.deserialize_header(io)
# fields that use the number.
#
# @return [NilClass]
# @api private
def self.field(name, type, multi = false)
fields << {
name: :"@#{name}",
Expand All @@ -422,6 +378,7 @@ def self.field(name, type, multi = false)
# each of the elements in this array using BSON types wherever possible.
#
# @return [Message] Message with deserialized array.
# @api private
def self.deserialize_array(message, io, field, options = {})
elements = []
count = message.instance_variable_get(field[:multi])
Expand All @@ -440,12 +397,60 @@ def self.deserialize_array(message, io, field, options = {})
# this field using BSON types wherever possible.
#
# @return [Message] Message with deserialized field.
# @api private
def self.deserialize_field(message, io, field, options = {})
message.instance_variable_set(
field[:name],
field[:type].deserialize(io, options)
)
end

private

# A method for getting the fields for a message class
#
# @return [Integer] the fields for the message class
def fields
self.class.fields
end

# Serializes message fields into a buffer
#
# @param buffer [String] buffer to receive the field
# @return [String] buffer with serialized field
def serialize_fields(buffer, max_bson_size = nil)
fields.each do |field|
value = instance_variable_get(field[:name])
if field[:multi]
value.each do |item|
if field[:type].respond_to?(:size_limited?)
field[:type].serialize(buffer, item, max_bson_size)
else
field[:type].serialize(buffer, item)
end
end
elsif field[:type].respond_to?(:size_limited?)
field[:type].serialize(buffer, value, max_bson_size)
else
field[:type].serialize(buffer, value)
end
end
end

# Serializes the header of the message consisting of 4 32bit integers
#
# The integers represent a message length placeholder (calculation of
# the actual length is deferred) the request id, the response to id,
# and the op code for the message
#
# Currently uses hardcoded 0 for request id and response to as their
# values are irrelevent to the server
#
# @param buffer [String] Buffer to receive the header
# @return [String] Serialized header
def serialize_header(buffer)
Header.serialize(buffer, [ 0, request_id, 0, op_code ])
end
end
end
end
4 changes: 2 additions & 2 deletions lib/mongo/socket/ocsp_verifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ def verify_one_responder(uri)
redirect_count = 0
http_response = nil
loop do
http_response = begin
begin
uri = URI(uri)
Net::HTTP.start(uri.hostname, uri.port) do |http|
http_response = Net::HTTP.start(uri.hostname, uri.port) do |http|
path = uri.path
path = '/' if path.empty?
http.post(path, @serialized_req,
Expand Down
Loading
Loading