1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* object.c (rb_obj_untrusted): new method Object#untrusted?.

(rb_obj_untrust): new method Object#untrust.
  (rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
  string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
  ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
  test/ruby/test_object.rb, test/ruby/test_string.rb,
  test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
  Object#untrusted?.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shugo 2008-08-13 07:25:05 +00:00
parent 55c141c624
commit f433d710d0
23 changed files with 364 additions and 88 deletions

View file

@ -320,4 +320,82 @@ class TestObject < Test::Unit::TestCase
1.extend
end
end
def test_untrusted
obj = lambda {
$SAFE = 4
x = Object.new
x.instance_eval { @foo = 1 }
x
}.call
assert_equal(true, obj.untrusted?)
assert_equal(true, obj.tainted?)
x = Object.new
assert_equal(false, x.untrusted?)
assert_raise(SecurityError) do
lambda {
$SAFE = 4
x.instance_eval { @foo = 1 }
}.call
end
x = Object.new
x.taint
assert_raise(SecurityError) do
lambda {
$SAFE = 4
x.instance_eval { @foo = 1 }
}.call
end
x.untrust
assert_equal(true, x.untrusted?)
assert_nothing_raised do
lambda {
$SAFE = 4
x.instance_eval { @foo = 1 }
}.call
end
x.trust
assert_equal(false, x.untrusted?)
assert_raise(SecurityError) do
lambda {
$SAFE = 4
x.instance_eval { @foo = 1 }
}.call
end
a = Object.new
a.untrust
assert_equal(true, a.untrusted?)
b = a.dup
assert_equal(true, b.untrusted?)
c = a.clone
assert_equal(true, c.untrusted?)
a = Object.new
b = lambda {
$SAFE = 4
a.dup
}.call
assert_equal(true, b.untrusted?)
a = Object.new
b = lambda {
$SAFE = 4
a.clone
}.call
assert_equal(true, b.untrusted?)
end
def test_to_s
x = Object.new
x.taint
x.untrust
s = x.to_s
assert_equal(true, s.untrusted?)
assert_equal(true, s.tainted?)
end
end