mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	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.
This commit is contained in:
		
							parent
							
								
									c5c05460ac
								
							
						
					
					
						commit
						ffd0820ab3
					
				
				
				Notes:
				
					git
				
				2019-11-18 08:01:15 +09:00 
				
			
			
			
		
		
					 201 changed files with 2292 additions and 2874 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
 | 
			
		||||
      # 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]]))
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
      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 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 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 "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 "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
 | 
			
		||||
    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 "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
 | 
			
		||||
    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
 | 
			
		||||
    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 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 "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 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
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # Note: Ruby 1.9 should be compatible with older marshal format
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue