summaryrefslogtreecommitdiff
path: root/spec/ruby/security/cve_2018_6914_spec.rb
blob: a40225799dba4d6e743ebf45c81d76ecd05cca83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require_relative '../spec_helper'

require 'tempfile'

describe "CVE-2018-6914 is resisted by" do
  before :all do
    @traversal_path = Array.new(Dir.pwd.split('/').count, '..').join('/') + Dir.pwd + '/'
    @traversal_path.delete!(':') if /mswin|mingw/ =~ RUBY_PLATFORM
  end

  it "Tempfile.open by deleting separators" do
    begin
      expect = Dir.glob(@traversal_path + '*').count
      t = Tempfile.open([@traversal_path, 'foo'])
      actual = Dir.glob(@traversal_path + '*').count
      actual.should == expect
    ensure
      t.close!
    end
  end

  it "Tempfile.new by deleting separators" do
    begin
      expect = Dir.glob(@traversal_path + '*').count
      t = Tempfile.new(@traversal_path + 'foo')
      actual = Dir.glob(@traversal_path + '*').count
      actual.should == expect
    ensure
      t.close!
    end
  end

  it "Tempfile.create by deleting separators" do
    expect = Dir.glob(@traversal_path + '*').count
    Tempfile.create(@traversal_path + 'foo') do
      actual = Dir.glob(@traversal_path + '*').count
      actual.should == expect
    end
  end

  it "Dir.mktmpdir by deleting separators" do
    expect = Dir.glob(@traversal_path + '*').count
    Dir.mktmpdir(@traversal_path + 'foo') do
      actual = Dir.glob(@traversal_path + '*').count
      actual.should == expect
    end
  end

  it "Dir.mktmpdir with an array by deleting separators" do
    expect = Dir.glob(@traversal_path + '*').count
    Dir.mktmpdir([@traversal_path, 'foo']) do
      actual = Dir.glob(@traversal_path + '*').count
      actual.should == expect
    end
  end
end