diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_struct.rb | 14 | ||||
-rw-r--r-- | test/ruby/test_time.rb | 17 |
2 files changed, 30 insertions, 1 deletions
diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb index 49dcdb45b2..d769e47dc5 100644 --- a/test/ruby/test_struct.rb +++ b/test/ruby/test_struct.rb @@ -1,5 +1,6 @@ require 'test/unit' require 'timeout' +require_relative 'envutil' class TestStruct < Test::Unit::TestCase def test_struct @@ -249,4 +250,17 @@ class TestStruct < Test::Unit::TestCase assert !x.eql?(z) } end + + def test_struct_subclass + bug5036 = '[ruby-dev:44122]' + st = Class.new(Struct) + s = st.new("S", :m).new + error = assert_raise(SecurityError) do + proc do + $SAFE = 4 + s.m = 1 + end.call + end + assert_equal("Insecure: can't modify #{st}::S", error.message, bug5036) + end end diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index aea4c2edc0..38e567a703 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -3,6 +3,7 @@ require 'rational' require 'delegate' require 'timeout' require 'delegate' +require_relative 'envutil' class TestTime < Test::Unit::TestCase def setup @@ -702,7 +703,7 @@ class TestTime < Test::Unit::TestCase bug5012 = "[ruby-dev:44071]" t0 = Time.now - class <<t0; end + class << t0; end t1 = t0.getlocal def t0.m @@ -711,4 +712,18 @@ class TestTime < Test::Unit::TestCase assert_raise(NoMethodError, bug5012) { t1.m } end + + def test_time_subclass + bug5036 = '[ruby-dev:44122]' + tc = Class.new(Time) + tc.inspect + t = tc.now + error = assert_raise(SecurityError) do + proc do + $SAFE = 4 + t.gmtime + end.call + end + assert_equal("Insecure: can't modify #{tc}", error.message, bug5036) + end end |