File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed
Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ def read_body
1515 if directory?
1616 yield dir_body
1717 else
18- open @file_path , 'rb' do |io |
18+ :: File . open ( @file_path , 'rb' ) do |io |
1919 yield io . read
2020 end
2121 end
Original file line number Diff line number Diff line change 11require 'mechanize/test_case'
22
33class TestMechanizeFileResponse < Mechanize ::TestCase
4-
54 def test_content_type
65 Tempfile . open %w[ pi .nothtml ] do |tempfile |
76 res = Mechanize ::FileResponse . new tempfile . path
@@ -19,5 +18,24 @@ def test_content_type
1918 end
2019 end
2120
22- end
21+ def test_read_body
22+ Tempfile . open %w[ pi .html ] do |tempfile |
23+ tempfile . write ( "asdfasdfasdf" )
24+ tempfile . close
2325
26+ res = Mechanize ::FileResponse . new ( tempfile . path )
27+ res . read_body do |input |
28+ assert_equal ( "asdfasdfasdf" , input )
29+ end
30+ end
31+ end
32+
33+ def test_read_body_does_not_allow_command_injection
34+ in_tmpdir do
35+ FileUtils . touch ( '| ruby -rfileutils -e \'FileUtils.touch("vul.txt")\'' )
36+ res = Mechanize ::FileResponse . new ( '| ruby -rfileutils -e \'FileUtils.touch("vul.txt")\'' )
37+ res . read_body { |_ | }
38+ refute_operator ( File , :exist? , "vul.txt" )
39+ end
40+ end
41+ end
You can’t perform that action at this time.
0 commit comments