Skip to content

Commit b07b708

Browse files
johnnyshieldscomandeo-mongo
authored andcommitted
Use ::Utils.load_spec_yaml_file to fix unified spec test loading
Cherry-picked from 62e9725: RUBY-2859 Add GH Actions setup for ruby 3.1 (#2398) Co-authored-by: shields <[email protected]> Co-authored-by: Dmitry Rybakov <[email protected]>
1 parent 6281bea commit b07b708

File tree

14 files changed

+44
-15
lines changed

14 files changed

+44
-15
lines changed

spec/runners/auth.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Spec
4848
attr_reader :tests
4949

5050
def initialize(test_path)
51-
@spec = YAML.load(File.read(test_path))
51+
@spec = ::Utils.load_spec_yaml_file(test_path)
5252
@description = File.basename(test_path)
5353
end
5454

spec/runners/change_streams/spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Spec
3232
#
3333
# @since 2.6.0
3434
def initialize(test_path)
35-
@spec = YAML.load(File.read(test_path))
35+
@spec = ::Utils.load_spec_yaml_file(test_path)
3636
@description = File.basename(test_path)
3737
@spec_tests = @spec['tests']
3838
@collection_name = @spec['collection_name']

spec/runners/cmap.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Spec
4040
#
4141
# @param [ String ] test_path The path to the file.
4242
def initialize(test_path)
43-
@test = YAML.load(File.read(test_path))
43+
@test = ::Utils.load_spec_yaml_file(test_path)
4444

4545
@description = @test['description']
4646
@pool_options = ::Utils.snakeize_hash(process_options(@test['poolOptions']))

spec/runners/command_monitoring.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class Spec
204204
#
205205
# @since 2.1.0
206206
def initialize(test_path)
207-
@spec = YAML.load(File.read(test_path))
207+
@spec = ::Utils.load_spec_yaml_file(test_path)
208208
@data = @spec['data']
209209
@tests = @spec['tests']
210210
end

spec/runners/connection_string.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class Spec
100100
#
101101
# @since 2.0.0
102102
def initialize(test_path)
103-
@spec = YAML.load(File.read(test_path))
103+
@spec = ::Utils.load_spec_yaml_file(test_path)
104104
@description = File.basename(test_path)
105105
end
106106

spec/runners/crud/spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ class Spec
1212
#
1313
# @since 2.0.0
1414
def initialize(test_path)
15-
contents = File.read(test_path)
16-
17-
@spec = YAML.load(contents)
15+
@spec = ::Utils.load_spec_yaml_file(test_path)
1816
@description = File.basename(test_path)
1917
@data = BSON::ExtJSON.parse_obj(@spec['data'])
2018
@tests = @spec['tests']

spec/runners/gridfs.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class Spec
100100
#
101101
# @since 2.1.0
102102
def initialize(test_path)
103-
@spec = YAML.load(File.read(test_path))
103+
@spec = ::Utils.load_spec_yaml_file(test_path)
104104
@description = File.basename(test_path)
105105
@data = @spec['data']
106106
end

spec/runners/read_write_concern_document.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Spec
1313
#
1414
# @since 2.0.0
1515
def initialize(test_path)
16-
@spec = YAML.load(File.read(test_path))
16+
@spec = ::Utils.load_spec_yaml_file(test_path)
1717
@description = File.basename(test_path)
1818
end
1919

spec/runners/sdam.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Spec
7777
#
7878
# @since 2.0.0
7979
def initialize(test_path)
80-
@test = YAML.load(File.read(test_path))
80+
@test = ::Utils.load_spec_yaml_file(test_path)
8181
@description = @test['description']
8282
@uri_string = @test['uri']
8383
@uri = URI.new(uri_string)

spec/runners/server_selection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Spec
6464
#
6565
# @since 2.0.0
6666
def initialize(test_path)
67-
@test = YAML.load(File.read(test_path))
67+
@test = ::Utils.load_spec_yaml_file(test_path)
6868
@description = "#{@test['topology_description']['type']}: #{File.basename(test_path)}"
6969
@heartbeat_frequency = @test['heartbeatFrequencyMS'] / 1000 if @test['heartbeatFrequencyMS']
7070
@read_preference = @test['read_preference']

spec/runners/server_selection_rtt.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Spec
2828
#
2929
# @since 2.0.0
3030
def initialize(test_path)
31-
@test = YAML.load(File.read(test_path))
31+
@test = ::Utils.load_spec_yaml_file(test_path)
3232
@description = "#{File.basename(test_path)}: avg_rtt_ms: #{@test['avg_rtt_ms']}, new_rtt_ms: #{@test['new_rtt_ms']}," +
3333
" new_avg_rtt: #{@test['new_avg_rtt']}"
3434
@average_rtt = @test['avg_rtt_ms'] == 'NULL' ? nil : @test['avg_rtt_ms'].to_f / 1000

spec/runners/unified/test_group.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Unified
66
class TestGroup
77
def initialize(path, **opts)
88
if String === path
9-
data = YAML.load(File.read(path))
9+
data = ::Utils.load_spec_yaml_file(path)
1010
else
1111
data = path
1212
end

spec/spec_tests/seed_list_discovery_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
SEED_LIST_DISCOVERY_TESTS.each do |test_path|
1717

18-
spec = YAML.load(File.read(test_path))
18+
spec = ::Utils.load_spec_yaml_file(test_path)
1919

2020
test = Mongo::ConnectionString::Test.new(spec)
2121

spec/support/utils.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,4 +595,35 @@ def match_with_type?(expected, actual)
595595
end
596596
end
597597
end
598+
599+
module_function def load_spec_yaml_file(path)
600+
permitted_classes = [
601+
BigDecimal,
602+
Date,
603+
Time,
604+
Range,
605+
Regexp,
606+
Symbol,
607+
BSON::Binary,
608+
BSON::Code,
609+
BSON::CodeWithScope,
610+
BSON::DbPointer,
611+
BSON::Decimal128,
612+
BSON::Int32,
613+
BSON::Int64,
614+
BSON::MaxKey,
615+
BSON::MinKey,
616+
BSON::ObjectId,
617+
BSON::Regexp::Raw,
618+
BSON::Symbol::Raw,
619+
BSON::Timestamp,
620+
BSON::Undefined,
621+
]
622+
if RUBY_VERSION.start_with?("2.5")
623+
YAML.safe_load(File.read(path), permitted_classes, [], true)
624+
else
625+
# Here we have Ruby 2.6+ that supports the new syntax of `safe_load``.
626+
YAML.safe_load(File.read(path), permitted_classes: permitted_classes, aliases: true)
627+
end
628+
end
598629
end

0 commit comments

Comments
 (0)