summaryrefslogtreecommitdiff
path: root/test/ruby/test_marshal.rb
diff options
context:
space:
mode:
authornahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-12-28 13:01:28 +0000
committernahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-12-28 13:01:28 +0000
commit26269cbd5d7827ecfba3df54e167a11076d6c59f (patch)
treeea10b91e7360f5bcbf86651dd4cfc0ba12e8b5e5 /test/ruby/test_marshal.rb
parent7844ea1c64a008983f03d76d96ea6c061cbf7cb6 (diff)
* test/ruby/test_marshal.rb: added tests for taintness/untrustness
propagation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_marshal.rb')
-rw-r--r--test/ruby/test_marshal.rb64
1 files changed, 64 insertions, 0 deletions
diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb
index 12d1bff30c..704385897c 100644
--- a/test/ruby/test_marshal.rb
+++ b/test/ruby/test_marshal.rb
@@ -193,6 +193,70 @@ class TestMarshal < Test::Unit::TestCase
assert_equal(true, y.untrusted?)
end
+ def test_taint_and_untrust_each_object
+ x = Object.new
+ obj = [[x]]
+
+ # clean object causes crean stream
+ assert_equal(false, obj.tainted?)
+ assert_equal(false, obj.untrusted?)
+ assert_equal(false, obj.first.tainted?)
+ assert_equal(false, obj.first.untrusted?)
+ assert_equal(false, obj.first.first.tainted?)
+ assert_equal(false, obj.first.first.untrusted?)
+ s = Marshal.dump(obj)
+ assert_equal(false, s.tainted?)
+ assert_equal(false, s.untrusted?)
+
+ # tainted/untrusted object causes tainted/untrusted stream
+ x.taint
+ x.untrust
+ assert_equal(false, obj.tainted?)
+ assert_equal(false, obj.untrusted?)
+ assert_equal(false, obj.first.tainted?)
+ assert_equal(false, obj.first.untrusted?)
+ assert_equal(true, obj.first.first.tainted?)
+ assert_equal(true, obj.first.first.untrusted?)
+ t = Marshal.dump(obj)
+ assert_equal(true, t.tainted?)
+ assert_equal(true, t.untrusted?)
+
+ # clean stream causes clean objects
+ assert_equal(false, s.tainted?)
+ assert_equal(false, s.untrusted?)
+ y = Marshal.load(s)
+ assert_equal(false, y.tainted?)
+ assert_equal(false, y.untrusted?)
+ assert_equal(false, y.first.tainted?)
+ assert_equal(false, y.first.untrusted?)
+ assert_equal(false, y.first.first.tainted?)
+ assert_equal(false, y.first.first.untrusted?)
+
+ # tainted/untrusted stream causes tainted/untrusted objects
+ assert_equal(true, t.tainted?)
+ assert_equal(true, t.untrusted?)
+ y = Marshal.load(t)
+ assert_equal(true, y.tainted?)
+ assert_equal(true, y.untrusted?)
+ assert_equal(true, y.first.tainted?)
+ assert_equal(true, y.first.untrusted?)
+ assert_equal(true, y.first.first.tainted?)
+ assert_equal(true, y.first.first.untrusted?)
+
+ # same tests by different senario
+ s.taint
+ s.untrust
+ assert_equal(true, s.tainted?)
+ assert_equal(true, s.untrusted?)
+ y = Marshal.load(s)
+ assert_equal(true, y.tainted?)
+ assert_equal(true, y.untrusted?)
+ assert_equal(true, y.first.tainted?)
+ assert_equal(true, y.first.untrusted?)
+ assert_equal(true, y.first.first.tainted?)
+ assert_equal(true, y.first.first.untrusted?)
+ end
+
def test_symbol
[:ruby, :"\u{7d05}\u{7389}"].each do |sym|
assert_equal(sym, Marshal.load(Marshal.dump(sym)), '[ruby-core:24788]')