summaryrefslogtreecommitdiff
path: root/spec/ruby/security/cve_2018_6914_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/security/cve_2018_6914_spec.rb')
-rw-r--r--spec/ruby/security/cve_2018_6914_spec.rb54
1 files changed, 29 insertions, 25 deletions
diff --git a/spec/ruby/security/cve_2018_6914_spec.rb b/spec/ruby/security/cve_2018_6914_spec.rb
index a40225799d..1eab3b84cc 100644
--- a/spec/ruby/security/cve_2018_6914_spec.rb
+++ b/spec/ruby/security/cve_2018_6914_spec.rb
@@ -1,55 +1,59 @@
require_relative '../spec_helper'
require 'tempfile'
+require 'tmpdir'
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
+ before :each do
+ @dir = tmp("CVE-2018-6914")
+ Dir.mkdir(@dir)
+ touch "#{@dir}/bar"
+
+ @traversal_path = Array.new(@dir.count('/'), '..').join('/') + @dir + '/'
+ @traversal_path.delete!(':') if platform_is(:windows)
+
+ @tempfile = nil
+ end
+
+ after :each do
+ @tempfile.close! if @tempfile
+ rm_r @dir
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
+ expect = Dir.glob(@traversal_path + '*').size
+ @tempfile = Tempfile.open([@traversal_path, 'foo'])
+ actual = Dir.glob(@traversal_path + '*').size
+ actual.should == expect
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
+ expect = Dir.glob(@traversal_path + '*').size
+ @tempfile = Tempfile.new(@traversal_path + 'foo')
+ actual = Dir.glob(@traversal_path + '*').size
+ actual.should == expect
end
it "Tempfile.create by deleting separators" do
- expect = Dir.glob(@traversal_path + '*').count
+ expect = Dir.glob(@traversal_path + '*').size
Tempfile.create(@traversal_path + 'foo') do
- actual = Dir.glob(@traversal_path + '*').count
+ actual = Dir.glob(@traversal_path + '*').size
actual.should == expect
end
end
it "Dir.mktmpdir by deleting separators" do
- expect = Dir.glob(@traversal_path + '*').count
+ expect = Dir.glob(@traversal_path + '*').size
Dir.mktmpdir(@traversal_path + 'foo') do
- actual = Dir.glob(@traversal_path + '*').count
+ actual = Dir.glob(@traversal_path + '*').size
actual.should == expect
end
end
it "Dir.mktmpdir with an array by deleting separators" do
- expect = Dir.glob(@traversal_path + '*').count
+ expect = Dir.glob(@traversal_path + '*').size
Dir.mktmpdir([@traversal_path, 'foo']) do
- actual = Dir.glob(@traversal_path + '*').count
+ actual = Dir.glob(@traversal_path + '*').size
actual.should == expect
end
end