Skip to content

Commit

Permalink
Refactor symlink attack specs
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez committed Oct 8, 2021
1 parent 02e3cf4 commit 9180b39
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions test/rubygems/test_gem_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -574,18 +574,16 @@ def test_extract_symlink_parent
destination_subdir = File.join @destination, 'subdir'
FileUtils.mkdir_p destination_subdir

e = assert_raise(Gem::Package::PathError, Errno::EACCES) do
expected_exceptions = win_platform? ? [Gem::Package::PathError, Errno::EACCES] : [Gem::Package::PathError]

e = assert_raise(*expected_exceptions) do
package.extract_tar_gz tgz_io, destination_subdir
end

if Gem::Package::PathError === e
assert_equal("installing into parent path lib/link/outside.txt of " +
"#{destination_subdir} is not allowed", e.message)
elsif win_platform?
pend "symlink - must be admin with no UAC on Windows"
else
raise e
end
pend "symlink - must be admin with no UAC on Windows" if Errno::EACCES === e

assert_equal("installing into parent path lib/link/outside.txt of " +
"#{destination_subdir} is not allowed", e.message)
end

def test_extract_symlink_parent_doesnt_delete_user_dir
Expand All @@ -608,20 +606,18 @@ def test_extract_symlink_parent_doesnt_delete_user_dir
tar.add_symlink 'link/dir', '.', 16877
end

e = assert_raise(Gem::Package::PathError, Errno::EACCES) do
expected_exceptions = win_platform? ? [Gem::Package::PathError, Errno::EACCES] : [Gem::Package::PathError]

e = assert_raise(*expected_exceptions) do
package.extract_tar_gz tgz_io, destination_subdir
end

assert_path_exist destination_user_subdir
pend "symlink - must be admin with no UAC on Windows" if Errno::EACCES === e

if Gem::Package::PathError === e
assert_equal("installing into parent path #{destination_user_subdir} of " +
"#{destination_subdir} is not allowed", e.message)
elsif win_platform?
pend "symlink - must be admin with no UAC on Windows"
else
raise e
end
assert_equal("installing into parent path #{destination_user_subdir} of " +
"#{destination_subdir} is not allowed", e.message)

assert_path_exist destination_user_subdir
end

def test_extract_tar_gz_directory
Expand Down

0 comments on commit 9180b39

Please sign in to comment.