Skip to content

Commit 9573e73

Browse files
committed
Remove more 2.5 guards with remove_old_guards.rb 2.5.[1-9]
1 parent 571bbfa commit 9573e73

File tree

6 files changed

+103
-132
lines changed

6 files changed

+103
-132
lines changed

core/exception/full_message_spec.rb

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,42 @@
1212
full_message.should include "b.rb:2"
1313
end
1414

15-
ruby_version_is "2.5.1" do
16-
it "supports :highlight option and adds escape sequences to highlight some strings" do
17-
e = RuntimeError.new("Some runtime error")
15+
it "supports :highlight option and adds escape sequences to highlight some strings" do
16+
e = RuntimeError.new("Some runtime error")
1817

19-
full_message = e.full_message(highlight: true, order: :bottom)
20-
full_message.should include "\e[1mTraceback\e[m (most recent call last)"
21-
full_message.should include "\e[1mSome runtime error (\e[1;4mRuntimeError\e[m\e[1m)"
18+
full_message = e.full_message(highlight: true, order: :bottom)
19+
full_message.should include "\e[1mTraceback\e[m (most recent call last)"
20+
full_message.should include "\e[1mSome runtime error (\e[1;4mRuntimeError\e[m\e[1m)"
2221

23-
full_message = e.full_message(highlight: false, order: :bottom)
24-
full_message.should include "Traceback (most recent call last)"
25-
full_message.should include "Some runtime error (RuntimeError)"
26-
end
22+
full_message = e.full_message(highlight: false, order: :bottom)
23+
full_message.should include "Traceback (most recent call last)"
24+
full_message.should include "Some runtime error (RuntimeError)"
25+
end
2726

28-
it "supports :order option and places the error message and the backtrace at the top or the bottom" do
29-
e = RuntimeError.new("Some runtime error")
30-
e.set_backtrace(["a.rb:1", "b.rb:2"])
27+
it "supports :order option and places the error message and the backtrace at the top or the bottom" do
28+
e = RuntimeError.new("Some runtime error")
29+
e.set_backtrace(["a.rb:1", "b.rb:2"])
3130

32-
e.full_message(order: :top, highlight: false).should =~ /a.rb:1.*b.rb:2/m
33-
e.full_message(order: :bottom, highlight: false).should =~ /b.rb:2.*a.rb:1/m
34-
end
31+
e.full_message(order: :top, highlight: false).should =~ /a.rb:1.*b.rb:2/m
32+
e.full_message(order: :bottom, highlight: false).should =~ /b.rb:2.*a.rb:1/m
33+
end
3534

36-
it "shows the caller if the exception has no backtrace" do
37-
e = RuntimeError.new("Some runtime error")
38-
e.backtrace.should == nil
39-
full_message = e.full_message(highlight: false, order: :top)
40-
full_message.should include("#{__FILE__}:#{__LINE__-1}:in `")
41-
full_message.should include("': Some runtime error (RuntimeError)\n")
42-
end
35+
it "shows the caller if the exception has no backtrace" do
36+
e = RuntimeError.new("Some runtime error")
37+
e.backtrace.should == nil
38+
full_message = e.full_message(highlight: false, order: :top)
39+
full_message.should include("#{__FILE__}:#{__LINE__-1}:in `")
40+
full_message.should include("': Some runtime error (RuntimeError)\n")
41+
end
4342

44-
it "shows the exception class at the end of the first line of the message when the message contains multiple lines" do
45-
begin
46-
line = __LINE__; raise "first line\nsecond line"
47-
rescue => e
48-
full_message = e.full_message(highlight: false, order: :top).lines
49-
full_message[0].should include("#{__FILE__}:#{line}:in `")
50-
full_message[0].should include(": first line (RuntimeError)\n")
51-
full_message[1].should == "second line\n"
52-
end
43+
it "shows the exception class at the end of the first line of the message when the message contains multiple lines" do
44+
begin
45+
line = __LINE__; raise "first line\nsecond line"
46+
rescue => e
47+
full_message = e.full_message(highlight: false, order: :top).lines
48+
full_message[0].should include("#{__FILE__}:#{line}:in `")
49+
full_message[0].should include(": first line (RuntimeError)\n")
50+
full_message[1].should == "second line\n"
5351
end
5452
end
5553

core/hash/transform_keys_spec.rb

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,9 @@
6060
end
6161

6262
# https://bugs.ruby-lang.org/issues/14380
63-
ruby_version_is ""..."2.5.1" do
64-
it "does not prevent conflicts between new keys and old ones" do
65-
@hash.transform_keys!(&:succ)
66-
@hash.should == { e: 1 }
67-
end
68-
end
69-
70-
ruby_version_is "2.5.1" do
71-
it "prevents conflicts between new keys and old ones" do
72-
@hash.transform_keys!(&:succ)
73-
@hash.should == { b: 1, c: 2, d: 3, e: 4 }
74-
end
75-
end
76-
77-
ruby_version_is ""..."2.5.1" do
78-
it "partially modifies the contents if we broke from the block" do
79-
@hash.transform_keys! do |v|
80-
break if v == :c
81-
v.succ
82-
end
83-
@hash.should == { c: 1, d: 4 }
84-
end
63+
it "prevents conflicts between new keys and old ones" do
64+
@hash.transform_keys!(&:succ)
65+
@hash.should == { b: 1, c: 2, d: 3, e: 4 }
8566
end
8667

8768
ruby_version_is "2.5.1"..."3.0.2" do # https://bugs.ruby-lang.org/issues/17735

security/cve_2019_8321_spec.rb

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@
33
require 'rubygems'
44
require 'rubygems/user_interaction'
55

6-
ruby_version_is "2.5.5" do
7-
describe "CVE-2019-8321 is resisted by" do
8-
it "sanitising verbose messages" do
9-
ui = Class.new {
10-
include Gem::UserInteraction
11-
}.new
12-
ui.should_receive(:say).with(".]2;nyan.")
13-
verbose_before = Gem.configuration.verbose
14-
begin
15-
Gem.configuration.verbose = :really_verbose
16-
ui.verbose("\e]2;nyan\a")
17-
ensure
18-
Gem.configuration.verbose = verbose_before
19-
end
6+
describe "CVE-2019-8321 is resisted by" do
7+
it "sanitising verbose messages" do
8+
ui = Class.new {
9+
include Gem::UserInteraction
10+
}.new
11+
ui.should_receive(:say).with(".]2;nyan.")
12+
verbose_before = Gem.configuration.verbose
13+
begin
14+
Gem.configuration.verbose = :really_verbose
15+
ui.verbose("\e]2;nyan\a")
16+
ensure
17+
Gem.configuration.verbose = verbose_before
2018
end
2119
end
2220
end

security/cve_2019_8322_spec.rb

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@
55
require 'rubygems/safe_yaml'
66
require 'rubygems/commands/owner_command'
77

8-
ruby_version_is "2.5.5" do
9-
describe "CVE-2019-8322 is resisted by" do
10-
it "sanitising owner names" do
11-
command = Gem::Commands::OwnerCommand.new
12-
def command.rubygems_api_request(*args)
13-
Struct.new(:body).new("---\n- email: \"\e]2;nyan\a\"\n handle: handle\n id: id\n")
14-
end
15-
def command.with_response(response)
16-
yield response
17-
end
18-
command.should_receive(:say).with("Owners for gem: name")
19-
command.should_receive(:say).with("- .]2;nyan.")
20-
command.show_owners "name"
8+
describe "CVE-2019-8322 is resisted by" do
9+
it "sanitising owner names" do
10+
command = Gem::Commands::OwnerCommand.new
11+
def command.rubygems_api_request(*args)
12+
Struct.new(:body).new("---\n- email: \"\e]2;nyan\a\"\n handle: handle\n id: id\n")
2113
end
14+
def command.with_response(response)
15+
yield response
16+
end
17+
command.should_receive(:say).with("Owners for gem: name")
18+
command.should_receive(:say).with("- .]2;nyan.")
19+
command.show_owners "name"
2220
end
2321
end

security/cve_2019_8323_spec.rb

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,32 @@
55
require 'rubygems'
66
require 'rubygems/gemcutter_utilities'
77

8-
ruby_version_is "2.5.5" do
9-
describe "CVE-2019-8323 is resisted by" do
10-
describe "sanitising the body" do
11-
it "for success codes" do
12-
cutter = Class.new {
13-
include Gem::GemcutterUtilities
14-
}.new
15-
response = Net::HTTPSuccess.new(nil, nil, nil)
16-
def response.body
17-
"\e]2;nyan\a"
18-
end
19-
cutter.should_receive(:say).with(".]2;nyan.")
20-
cutter.with_response response
8+
describe "CVE-2019-8323 is resisted by" do
9+
describe "sanitising the body" do
10+
it "for success codes" do
11+
cutter = Class.new {
12+
include Gem::GemcutterUtilities
13+
}.new
14+
response = Net::HTTPSuccess.new(nil, nil, nil)
15+
def response.body
16+
"\e]2;nyan\a"
2117
end
18+
cutter.should_receive(:say).with(".]2;nyan.")
19+
cutter.with_response response
20+
end
2221

23-
it "for error codes" do
24-
cutter = Class.new {
25-
include Gem::GemcutterUtilities
26-
}.new
27-
def cutter.terminate_interaction(n)
28-
end
29-
response = Net::HTTPNotFound.new(nil, nil, nil)
30-
def response.body
31-
"\e]2;nyan\a"
32-
end
33-
cutter.should_receive(:say).with(".]2;nyan.")
34-
cutter.with_response response
22+
it "for error codes" do
23+
cutter = Class.new {
24+
include Gem::GemcutterUtilities
25+
}.new
26+
def cutter.terminate_interaction(n)
27+
end
28+
response = Net::HTTPNotFound.new(nil, nil, nil)
29+
def response.body
30+
"\e]2;nyan\a"
3531
end
32+
cutter.should_receive(:say).with(".]2;nyan.")
33+
cutter.with_response response
3634
end
3735
end
3836
end

security/cve_2019_8325_spec.rb

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,35 @@
33
require 'rubygems'
44
require 'rubygems/command_manager'
55

6-
ruby_version_is "2.5.5" do
7-
platform_is_not :darwin do # frequent timeout/hang on macOS
8-
describe "CVE-2019-8325 is resisted by" do
9-
describe "sanitising error message components" do
10-
it "for the 'while executing' message" do
11-
manager = Gem::CommandManager.new
12-
def manager.process_args(args, build_args)
13-
raise StandardError, "\e]2;nyan\a"
14-
end
15-
def manager.terminate_interaction(n)
16-
end
17-
manager.should_receive(:alert_error).with("While executing gem ... (StandardError)\n .]2;nyan.")
18-
manager.run nil, nil
6+
platform_is_not :darwin do # frequent timeout/hang on macOS
7+
describe "CVE-2019-8325 is resisted by" do
8+
describe "sanitising error message components" do
9+
it "for the 'while executing' message" do
10+
manager = Gem::CommandManager.new
11+
def manager.process_args(args, build_args)
12+
raise StandardError, "\e]2;nyan\a"
1913
end
14+
def manager.terminate_interaction(n)
15+
end
16+
manager.should_receive(:alert_error).with("While executing gem ... (StandardError)\n .]2;nyan.")
17+
manager.run nil, nil
18+
end
2019

21-
it "for the 'invalid option' message" do
22-
manager = Gem::CommandManager.new
23-
def manager.terminate_interaction(n)
24-
end
25-
manager.should_receive(:alert_error).with("Invalid option: --.]2;nyan.. See 'gem --help'.")
26-
manager.process_args ["--\e]2;nyan\a"], nil
20+
it "for the 'invalid option' message" do
21+
manager = Gem::CommandManager.new
22+
def manager.terminate_interaction(n)
2723
end
24+
manager.should_receive(:alert_error).with("Invalid option: --.]2;nyan.. See 'gem --help'.")
25+
manager.process_args ["--\e]2;nyan\a"], nil
26+
end
2827

29-
it "for the 'loading command' message" do
30-
manager = Gem::CommandManager.new
31-
def manager.require(x)
32-
raise 'foo'
33-
end
34-
manager.should_receive(:alert_error).with("Loading command: .]2;nyan. (RuntimeError)\n\tfoo")
35-
manager.send :load_and_instantiate, "\e]2;nyan\a"
28+
it "for the 'loading command' message" do
29+
manager = Gem::CommandManager.new
30+
def manager.require(x)
31+
raise 'foo'
3632
end
33+
manager.should_receive(:alert_error).with("Loading command: .]2;nyan. (RuntimeError)\n\tfoo")
34+
manager.send :load_and_instantiate, "\e]2;nyan\a"
3735
end
3836
end
3937
end

0 commit comments

Comments
 (0)