2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../../spec_helper'
|
|
|
|
require_relative 'fixtures/classes'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
describe "Kernel#taint" do
|
2019-09-24 23:59:12 -04:00
|
|
|
ruby_version_is ''...'2.7' do
|
|
|
|
it "returns self" do
|
|
|
|
o = Object.new
|
|
|
|
o.taint.should equal(o)
|
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2019-09-24 23:59:12 -04:00
|
|
|
it "sets the tainted bit" do
|
|
|
|
o = Object.new
|
|
|
|
o.taint
|
|
|
|
o.tainted?.should == true
|
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2019-09-24 23:59:12 -04:00
|
|
|
it "raises #{frozen_error_class} on an untainted, frozen object" do
|
|
|
|
o = Object.new.freeze
|
|
|
|
-> { o.taint }.should raise_error(frozen_error_class)
|
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2019-09-24 23:59:12 -04:00
|
|
|
it "does not raise an error on a tainted, frozen object" do
|
|
|
|
o = Object.new.taint.freeze
|
|
|
|
o.taint.should equal(o)
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
2019-09-24 23:59:12 -04:00
|
|
|
it "has no effect on immediate values" do
|
|
|
|
[nil, true, false].each do |v|
|
|
|
|
v.taint
|
|
|
|
v.tainted?.should == false
|
|
|
|
end
|
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2019-09-24 23:59:12 -04:00
|
|
|
it "no raises a RuntimeError on symbols" do
|
|
|
|
v = :sym
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { v.taint }.should_not raise_error(RuntimeError)
|
2017-05-07 08:04:49 -04:00
|
|
|
v.tainted?.should == false
|
|
|
|
end
|
2019-09-24 23:59:12 -04:00
|
|
|
|
|
|
|
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
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
end
|