diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-09-24 20:59:12 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2019-11-18 01:00:25 +0200 |
commit | ffd0820ab317542f8780aac475da590a4bdbc7a8 (patch) | |
tree | 6a5d774933c15fd2b9ea948bd3ae2fa587faaf82 /spec/ruby/core/kernel | |
parent | c5c05460ac20abcbc0ed686eb4acf06da7a39a79 (diff) | |
download | ruby-ffd0820ab317542f8780aac475da590a4bdbc7a8.tar.gz |
Deprecate taint/trust and related methods, and make the methods no-ops
This removes the related tests, and puts the related specs behind
version guards. This affects all code in lib, including some
libraries that may want to support older versions of Ruby.
Diffstat (limited to 'spec/ruby/core/kernel')
-rw-r--r-- | spec/ruby/core/kernel/clone_spec.rb | 12 | ||||
-rw-r--r-- | spec/ruby/core/kernel/inspect_spec.rb | 12 | ||||
-rw-r--r-- | spec/ruby/core/kernel/shared/dup_clone.rb | 34 | ||||
-rw-r--r-- | spec/ruby/core/kernel/taint_spec.rb | 62 | ||||
-rw-r--r-- | spec/ruby/core/kernel/tainted_spec.rb | 14 | ||||
-rw-r--r-- | spec/ruby/core/kernel/to_s_spec.rb | 12 | ||||
-rw-r--r-- | spec/ruby/core/kernel/trust_spec.rb | 34 | ||||
-rw-r--r-- | spec/ruby/core/kernel/untaint_spec.rb | 34 | ||||
-rw-r--r-- | spec/ruby/core/kernel/untrust_spec.rb | 34 | ||||
-rw-r--r-- | spec/ruby/core/kernel/untrusted_spec.rb | 42 |
10 files changed, 158 insertions, 132 deletions
diff --git a/spec/ruby/core/kernel/clone_spec.rb b/spec/ruby/core/kernel/clone_spec.rb index eb8739d571..f20ea618b5 100644 --- a/spec/ruby/core/kernel/clone_spec.rb +++ b/spec/ruby/core/kernel/clone_spec.rb @@ -108,9 +108,15 @@ describe "Kernel#clone" do cloned.bar.should == ['a'] end - it 'copies frozen? and tainted?' do - o = ''.taint.freeze.clone + it 'copies frozen?' do + o = ''.freeze.clone o.frozen?.should be_true - o.tainted?.should be_true + end + + ruby_version_is ''...'2.7' do + it 'copies tainted?' do + o = ''.taint.clone + o.tainted?.should be_true + end end end diff --git a/spec/ruby/core/kernel/inspect_spec.rb b/spec/ruby/core/kernel/inspect_spec.rb index b5ba1a3903..a946d032db 100644 --- a/spec/ruby/core/kernel/inspect_spec.rb +++ b/spec/ruby/core/kernel/inspect_spec.rb @@ -6,12 +6,14 @@ describe "Kernel#inspect" do Object.new.inspect.should be_an_instance_of(String) end - it "returns a tainted string if self is tainted" do - Object.new.taint.inspect.tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "returns a tainted string if self is tainted" do + Object.new.taint.inspect.tainted?.should be_true + end - it "returns an untrusted string if self is untrusted" do - Object.new.untrust.inspect.untrusted?.should be_true + it "returns an untrusted string if self is untrusted" do + Object.new.untrust.inspect.untrusted?.should be_true + end end it "does not call #to_s if it is defined" do diff --git a/spec/ruby/core/kernel/shared/dup_clone.rb b/spec/ruby/core/kernel/shared/dup_clone.rb index d1ee64bd09..a52ccab359 100644 --- a/spec/ruby/core/kernel/shared/dup_clone.rb +++ b/spec/ruby/core/kernel/shared/dup_clone.rb @@ -52,14 +52,16 @@ describe :kernel_dup_clone, shared: true do o2.original.should equal(o) end - it "preserves tainted state from the original" do - o = ObjectSpecDupInitCopy.new - o2 = o.send(@method) - o.taint - o3 = o.send(@method) - - o2.tainted?.should == false - o3.tainted?.should == true + ruby_version_is ''...'2.7' do + it "preserves tainted state from the original" do + o = ObjectSpecDupInitCopy.new + o2 = o.send(@method) + o.taint + o3 = o.send(@method) + + o2.tainted?.should == false + o3.tainted?.should == true + end end it "does not preserve the object_id" do @@ -69,14 +71,16 @@ describe :kernel_dup_clone, shared: true do o2.object_id.should_not == old_object_id end - it "preserves untrusted state from the original" do - o = ObjectSpecDupInitCopy.new - o2 = o.send(@method) - o.untrust - o3 = o.send(@method) + ruby_version_is ''...'2.7' do + it "preserves untrusted state from the original" do + o = ObjectSpecDupInitCopy.new + o2 = o.send(@method) + o.untrust + o3 = o.send(@method) - o2.untrusted?.should == false - o3.untrusted?.should == true + o2.untrusted?.should == false + o3.untrusted?.should == true + end end it "returns nil for NilClass" do diff --git a/spec/ruby/core/kernel/taint_spec.rb b/spec/ruby/core/kernel/taint_spec.rb index 000295f6d2..6de009a46c 100644 --- a/spec/ruby/core/kernel/taint_spec.rb +++ b/spec/ruby/core/kernel/taint_spec.rb @@ -2,44 +2,46 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' describe "Kernel#taint" do - it "returns self" do - o = Object.new - o.taint.should equal(o) - end - - it "sets the tainted bit" do - o = Object.new - o.taint - o.tainted?.should == true - end + ruby_version_is ''...'2.7' do + it "returns self" do + o = Object.new + o.taint.should equal(o) + end - it "raises #{frozen_error_class} on an untainted, frozen object" do - o = Object.new.freeze - -> { o.taint }.should raise_error(frozen_error_class) - end + it "sets the tainted bit" do + o = Object.new + o.taint + o.tainted?.should == true + end - it "does not raise an error on a tainted, frozen object" do - o = Object.new.taint.freeze - o.taint.should equal(o) - end + it "raises #{frozen_error_class} on an untainted, frozen object" do + o = Object.new.freeze + -> { o.taint }.should raise_error(frozen_error_class) + end - it "has no effect on immediate values" do - [nil, true, false].each do |v| - v.taint - v.tainted?.should == false + it "does not raise an error on a tainted, frozen object" do + o = Object.new.taint.freeze + o.taint.should equal(o) end - end - it "no raises a RuntimeError on symbols" do - v = :sym - -> { v.taint }.should_not raise_error(RuntimeError) - v.tainted?.should == false - end + it "has no effect on immediate values" do + [nil, true, false].each do |v| + v.taint + v.tainted?.should == false + end + end - it "no raises error on fixnum values" do - [1].each do |v| + it "no raises a RuntimeError on symbols" do + v = :sym -> { v.taint }.should_not raise_error(RuntimeError) v.tainted?.should == false end + + it "no raises error on fixnum values" do + [1].each do |v| + -> { v.taint }.should_not raise_error(RuntimeError) + v.tainted?.should == false + end + end end end diff --git a/spec/ruby/core/kernel/tainted_spec.rb b/spec/ruby/core/kernel/tainted_spec.rb index c024756110..72ce346dda 100644 --- a/spec/ruby/core/kernel/tainted_spec.rb +++ b/spec/ruby/core/kernel/tainted_spec.rb @@ -2,11 +2,13 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' describe "Kernel#tainted?" do - it "returns true if Object is tainted" do - o = mock('o') - p = mock('p') - p.taint - o.tainted?.should == false - p.tainted?.should == true + ruby_version_is ''...'2.7' do + it "returns true if Object is tainted" do + o = mock('o') + p = mock('p') + p.taint + o.tainted?.should == false + p.tainted?.should == true + end end end diff --git a/spec/ruby/core/kernel/to_s_spec.rb b/spec/ruby/core/kernel/to_s_spec.rb index 4b59520ce7..64b40f46e5 100644 --- a/spec/ruby/core/kernel/to_s_spec.rb +++ b/spec/ruby/core/kernel/to_s_spec.rb @@ -6,11 +6,13 @@ describe "Kernel#to_s" do Object.new.to_s.should =~ /Object/ end - it "returns a tainted result if self is tainted" do - Object.new.taint.to_s.tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "returns a tainted result if self is tainted" do + Object.new.taint.to_s.tainted?.should be_true + end - it "returns an untrusted result if self is untrusted" do - Object.new.untrust.to_s.untrusted?.should be_true + it "returns an untrusted result if self is untrusted" do + Object.new.untrust.to_s.untrusted?.should be_true + end end end diff --git a/spec/ruby/core/kernel/trust_spec.rb b/spec/ruby/core/kernel/trust_spec.rb index d34aa293ec..13f085f420 100644 --- a/spec/ruby/core/kernel/trust_spec.rb +++ b/spec/ruby/core/kernel/trust_spec.rb @@ -2,24 +2,26 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' describe "Kernel#trust" do - it "returns self" do - o = Object.new - o.trust.should equal(o) - end + ruby_version_is ''...'2.7' do + it "returns self" do + o = Object.new + o.trust.should equal(o) + end - it "clears the untrusted bit" do - o = Object.new.untrust - o.trust - o.untrusted?.should == false - end + it "clears the untrusted bit" do + o = Object.new.untrust + o.trust + o.untrusted?.should == false + end - it "raises #{frozen_error_class} on an untrusted, frozen object" do - o = Object.new.untrust.freeze - -> { o.trust }.should raise_error(frozen_error_class) - end + it "raises #{frozen_error_class} on an untrusted, frozen object" do + o = Object.new.untrust.freeze + -> { o.trust }.should raise_error(frozen_error_class) + end - it "does not raise an error on a trusted, frozen object" do - o = Object.new.freeze - o.trust.should equal(o) + it "does not raise an error on a trusted, frozen object" do + o = Object.new.freeze + o.trust.should equal(o) + end end end diff --git a/spec/ruby/core/kernel/untaint_spec.rb b/spec/ruby/core/kernel/untaint_spec.rb index 94e4a8fd44..58485fcc58 100644 --- a/spec/ruby/core/kernel/untaint_spec.rb +++ b/spec/ruby/core/kernel/untaint_spec.rb @@ -2,24 +2,26 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' describe "Kernel#untaint" do - it "returns self" do - o = Object.new - o.untaint.should equal(o) - end + ruby_version_is ''...'2.7' do + it "returns self" do + o = Object.new + o.untaint.should equal(o) + end - it "clears the tainted bit" do - o = Object.new.taint - o.untaint - o.tainted?.should == false - end + it "clears the tainted bit" do + o = Object.new.taint + o.untaint + o.tainted?.should == false + end - it "raises #{frozen_error_class} on a tainted, frozen object" do - o = Object.new.taint.freeze - -> { o.untaint }.should raise_error(frozen_error_class) - end + it "raises #{frozen_error_class} on a tainted, frozen object" do + o = Object.new.taint.freeze + -> { o.untaint }.should raise_error(frozen_error_class) + end - it "does not raise an error on an untainted, frozen object" do - o = Object.new.freeze - o.untaint.should equal(o) + it "does not raise an error on an untainted, frozen object" do + o = Object.new.freeze + o.untaint.should equal(o) + end end end diff --git a/spec/ruby/core/kernel/untrust_spec.rb b/spec/ruby/core/kernel/untrust_spec.rb index 2ee3dbb170..c6eb79af1c 100644 --- a/spec/ruby/core/kernel/untrust_spec.rb +++ b/spec/ruby/core/kernel/untrust_spec.rb @@ -2,24 +2,26 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' describe "Kernel#untrust" do - it "returns self" do - o = Object.new - o.untrust.should equal(o) - end + ruby_version_is ''...'2.7' do + it "returns self" do + o = Object.new + o.untrust.should equal(o) + end - it "sets the untrusted bit" do - o = Object.new - o.untrust - o.untrusted?.should == true - end + it "sets the untrusted bit" do + o = Object.new + o.untrust + o.untrusted?.should == true + end - it "raises #{frozen_error_class} on a trusted, frozen object" do - o = Object.new.freeze - -> { o.untrust }.should raise_error(frozen_error_class) - end + it "raises #{frozen_error_class} on a trusted, frozen object" do + o = Object.new.freeze + -> { o.untrust }.should raise_error(frozen_error_class) + end - it "does not raise an error on an untrusted, frozen object" do - o = Object.new.untrust.freeze - o.untrust.should equal(o) + it "does not raise an error on an untrusted, frozen object" do + o = Object.new.untrust.freeze + o.untrust.should equal(o) + end end end diff --git a/spec/ruby/core/kernel/untrusted_spec.rb b/spec/ruby/core/kernel/untrusted_spec.rb index 3f894b0bab..ccebfe38be 100644 --- a/spec/ruby/core/kernel/untrusted_spec.rb +++ b/spec/ruby/core/kernel/untrusted_spec.rb @@ -2,27 +2,29 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' describe "Kernel#untrusted?" do - it "returns the untrusted status of an object" do - o = mock('o') - o.untrusted?.should == false - o.untrust - o.untrusted?.should == true - end + ruby_version_is ''...'2.7' do + it "returns the untrusted status of an object" do + o = mock('o') + o.untrusted?.should == false + o.untrust + o.untrusted?.should == true + end - it "has no effect on immediate values" do - a = nil - b = true - c = false - a.untrust - b.untrust - c.untrust - a.untrusted?.should == false - b.untrusted?.should == false - c.untrusted?.should == false - end + it "has no effect on immediate values" do + a = nil + b = true + c = false + a.untrust + b.untrust + c.untrust + a.untrusted?.should == false + b.untrusted?.should == false + c.untrusted?.should == false + end - it "has effect on immediate values" do - d = 1 - -> { d.untrust }.should_not raise_error(RuntimeError) + it "has effect on immediate values" do + d = 1 + -> { d.untrust }.should_not raise_error(RuntimeError) + end end end |