Permalink
Browse files

Make <<< files read-only

  • Loading branch information...
1 parent bc53cac commit 766223b7a17937d91263980baefc559d171ef873 @gdb committed Oct 13, 2013
Showing with 23 additions and 3 deletions.
  1. +6 −3 lib/rubysh/triple_less_than.rb
  2. +17 −0 test/functional/lib/triple_less_than.rb
@@ -32,16 +32,19 @@ def initialize(fd, literal)
def prepare!(runner)
tempfile = Tempfile.new('buffer')
+ tempfile_read_only = File.open(tempfile.path, 'r')
+
tempfile.delete
tempfile.write(@literal)
tempfile.flush
tempfile.rewind
+ tempfile.close
- Util.set_cloexec(tempfile)
+ Util.set_cloexec(tempfile_read_only)
state = state(runner)
- state[:tempfile] = tempfile
- state[:redirect] = Redirect.new(@fd, '<', tempfile)
+ state[:tempfile] = tempfile_read_only
+ state[:redirect] = Redirect.new(@fd, '<', tempfile_read_only)
end
def stringify
@@ -11,6 +11,23 @@ class TripleLessThanTest < FunctionalTest
output = result.read(:stdout)
assert_equal('test', output)
end
+
+ it 'stdin is read-only' do
+ cmd = Rubysh(
+ 'ruby', '-e', '
+i = IO.new(0)
+begin
+ i.write("hi")
+rescue IOError => e
+ raise "Bad error: #{e}" unless e.message == "not opened for writing"
+else
+ raise "Perfectly writable FD 0"
+end
+', Rubysh.<<< 'test')
+ result = cmd.run
+
+ assert_equal(0, result.exitstatus)
+ end
end
end
end

0 comments on commit 766223b

Please sign in to comment.