summaryrefslogtreecommitdiff
path: root/spec/ruby/core/marshal
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/marshal')
-rw-r--r--spec/ruby/core/marshal/dump_spec.rb36
-rw-r--r--spec/ruby/core/marshal/shared/load.rb136
2 files changed, 88 insertions, 84 deletions
diff --git a/spec/ruby/core/marshal/dump_spec.rb b/spec/ruby/core/marshal/dump_spec.rb
index 700f090a2f..3a7a083dd8 100644
--- a/spec/ruby/core/marshal/dump_spec.rb
+++ b/spec/ruby/core/marshal/dump_spec.rb
@@ -581,27 +581,29 @@ describe "Marshal.dump" do
-> { Marshal.dump(m) }.should raise_error(TypeError)
end
- it "returns an untainted string if object is untainted" do
- Marshal.dump(Object.new).tainted?.should be_false
- end
+ ruby_version_is ''...'2.7' do
+ it "returns an untainted string if object is untainted" do
+ Marshal.dump(Object.new).tainted?.should be_false
+ end
- it "returns a tainted string if object is tainted" do
- Marshal.dump(Object.new.taint).tainted?.should be_true
- end
+ it "returns a tainted string if object is tainted" do
+ Marshal.dump(Object.new.taint).tainted?.should be_true
+ end
- it "returns a tainted string if nested object is tainted" do
- Marshal.dump([[Object.new.taint]]).tainted?.should be_true
- end
+ it "returns a tainted string if nested object is tainted" do
+ Marshal.dump([[Object.new.taint]]).tainted?.should be_true
+ end
- it "returns a trusted string if object is trusted" do
- Marshal.dump(Object.new).untrusted?.should be_false
- end
+ it "returns a trusted string if object is trusted" do
+ Marshal.dump(Object.new).untrusted?.should be_false
+ end
- it "returns an untrusted string if object is untrusted" do
- Marshal.dump(Object.new.untrust).untrusted?.should be_true
- end
+ it "returns an untrusted string if object is untrusted" do
+ Marshal.dump(Object.new.untrust).untrusted?.should be_true
+ end
- it "returns an untrusted string if nested object is untrusted" do
- Marshal.dump([[Object.new.untrust]]).untrusted?.should be_true
+ it "returns an untrusted string if nested object is untrusted" do
+ Marshal.dump([[Object.new.untrust]]).untrusted?.should be_true
+ end
end
end
diff --git a/spec/ruby/core/marshal/shared/load.rb b/spec/ruby/core/marshal/shared/load.rb
index f92d49c68c..b90a6a99ce 100644
--- a/spec/ruby/core/marshal/shared/load.rb
+++ b/spec/ruby/core/marshal/shared/load.rb
@@ -182,85 +182,87 @@ describe :marshal_load, shared: true do
end
end
- it "returns an untainted object if source is untainted" do
- x = Object.new
- y = Marshal.send(@method, Marshal.dump(x))
- y.tainted?.should be_false
- end
-
- describe "when source is tainted" do
- it "returns a tainted object" do
+ ruby_version_is ''...'2.7' do
+ it "returns an untainted object if source is untainted" do
x = Object.new
- x.taint
- s = Marshal.dump(x)
- y = Marshal.send(@method, s)
- y.tainted?.should be_true
+ y = Marshal.send(@method, Marshal.dump(x))
+ y.tainted?.should be_false
+ end
+
+ describe "when source is tainted" do
+ it "returns a tainted object" do
+ x = Object.new
+ x.taint
+ s = Marshal.dump(x)
+ y = Marshal.send(@method, s)
+ y.tainted?.should be_true
+
+ # note that round-trip via Marshal does not preserve
+ # the taintedness at each level of the nested structure
+ y = Marshal.send(@method, Marshal.dump([[x]]))
+ y.tainted?.should be_true
+ y.first.tainted?.should be_true
+ y.first.first.tainted?.should be_true
+ end
- # note that round-trip via Marshal does not preserve
- # the taintedness at each level of the nested structure
- y = Marshal.send(@method, Marshal.dump([[x]]))
- y.tainted?.should be_true
- y.first.tainted?.should be_true
- y.first.first.tainted?.should be_true
- end
+ it "does not taint Symbols" do
+ x = [:x]
+ y = Marshal.send(@method, Marshal.dump(x).taint)
+ y.tainted?.should be_true
+ y.first.tainted?.should be_false
+ end
- it "does not taint Symbols" do
- x = [:x]
- y = Marshal.send(@method, Marshal.dump(x).taint)
- y.tainted?.should be_true
- y.first.tainted?.should be_false
- end
+ it "does not taint Fixnums" do
+ x = [1]
+ y = Marshal.send(@method, Marshal.dump(x).taint)
+ y.tainted?.should be_true
+ y.first.tainted?.should be_false
+ end
- it "does not taint Fixnums" do
- x = [1]
- y = Marshal.send(@method, Marshal.dump(x).taint)
- y.tainted?.should be_true
- y.first.tainted?.should be_false
- end
+ it "does not taint Bignums" do
+ x = [bignum_value]
+ y = Marshal.send(@method, Marshal.dump(x).taint)
+ y.tainted?.should be_true
+ y.first.tainted?.should be_false
+ end
- it "does not taint Bignums" do
- x = [bignum_value]
- y = Marshal.send(@method, Marshal.dump(x).taint)
- y.tainted?.should be_true
- y.first.tainted?.should be_false
+ it "does not taint Floats" do
+ x = [1.2]
+ y = Marshal.send(@method, Marshal.dump(x).taint)
+ y.tainted?.should be_true
+ y.first.tainted?.should be_false
+ end
end
- it "does not taint Floats" do
- x = [1.2]
- y = Marshal.send(@method, Marshal.dump(x).taint)
+ it "preserves taintedness of nested structure" do
+ x = Object.new
+ a = [[x]]
+ x.taint
+ y = Marshal.send(@method, Marshal.dump(a))
y.tainted?.should be_true
- y.first.tainted?.should be_false
+ y.first.tainted?.should be_true
+ y.first.first.tainted?.should be_true
end
- end
- it "preserves taintedness of nested structure" do
- x = Object.new
- a = [[x]]
- x.taint
- y = Marshal.send(@method, Marshal.dump(a))
- y.tainted?.should be_true
- y.first.tainted?.should be_true
- y.first.first.tainted?.should be_true
- end
-
- it "returns a trusted object if source is trusted" do
- x = Object.new
- y = Marshal.send(@method, Marshal.dump(x))
- y.untrusted?.should be_false
- end
+ it "returns a trusted object if source is trusted" do
+ x = Object.new
+ y = Marshal.send(@method, Marshal.dump(x))
+ y.untrusted?.should be_false
+ end
- it "returns an untrusted object if source is untrusted" do
- x = Object.new
- x.untrust
- y = Marshal.send(@method, Marshal.dump(x))
- y.untrusted?.should be_true
+ it "returns an untrusted object if source is untrusted" do
+ x = Object.new
+ x.untrust
+ y = Marshal.send(@method, Marshal.dump(x))
+ y.untrusted?.should be_true
- # note that round-trip via Marshal does not preserve
- # the untrustedness at each level of the nested structure
- y = Marshal.send(@method, Marshal.dump([[x]]))
- y.untrusted?.should be_true
- y.first.untrusted?.should be_true
- y.first.first.untrusted?.should be_true
+ # note that round-trip via Marshal does not preserve
+ # the untrustedness at each level of the nested structure
+ y = Marshal.send(@method, Marshal.dump([[x]]))
+ y.untrusted?.should be_true
+ y.first.untrusted?.should be_true
+ y.first.first.untrusted?.should be_true
+ end
end
# Note: Ruby 1.9 should be compatible with older marshal format