diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-02 11:33:08 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-02 11:33:08 +0000 |
commit | ae15c7b16ee7731c4785052c47937b024befac1b (patch) | |
tree | 7901f0f78d8da03c0b845eb893f67b6efab6fc12 /test | |
parent | 3bda4df9add877fd3b46f1a9b06bd58431874963 (diff) | |
download | ruby-ae15c7b16ee7731c4785052c47937b024befac1b.tar.gz ruby-ae15c7b16ee7731c4785052c47937b024befac1b.tar.xz ruby-ae15c7b16ee7731c4785052c47937b024befac1b.zip |
adds a test case for r21955 and r21917.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@21974 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_require.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb index 4048ba038..4bc44eff0 100644 --- a/test/ruby/test_require.rb +++ b/test/ruby/test_require.rb @@ -195,4 +195,50 @@ class TestRequire < Test::Unit::TestCase assert_raise(ArgumentError) { at_exit } end + + def test_tainted_loadpath + t = Tempfile.new(["test_ruby_test_require", ".rb"]) + abs_dir, file = File.dirname(t.path), File.basename(t.path) + abs_dir = File.expand_path(abs_dir).untaint + + assert_in_out_err([], <<-INPUT, %w(:ok), []) + abs_dir = "#{ abs_dir }" + $: << abs_dir + require "#{ file }" + p :ok + INPUT + + assert_in_out_err([], <<-INPUT, %w(:ok), []) + abs_dir = "#{ abs_dir }" + $: << abs_dir.taint + require "#{ file }" + p :ok + INPUT + + assert_in_out_err([], <<-INPUT, %w(:ok), []) + abs_dir = "#{ abs_dir }" + $: << abs_dir.taint + $SAFE = 1 + begin + require "#{ file }" + rescue SecurityError + p :ok + end + INPUT + + assert_in_out_err([], <<-INPUT, %w(:ok), []) + abs_dir = "#{ abs_dir }" + $: << abs_dir.taint + $SAFE = 1 + require "#{ t.path }" + p :ok + INPUT + + assert_in_out_err([], <<-INPUT, %w(:ok), []) + abs_dir = "#{ abs_dir }" + $: << abs_dir << 'elsewhere'.taint + require "#{ file }" + p :ok + INPUT + end end |