debian-mirror-gitlab/spec/rubocop/cop/file_decompression_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.5 KiB
Ruby
Raw Normal View History

2022-04-04 11:22:00 +05:30
# frozen_string_literal: true
2022-10-11 01:57:18 +05:30
require 'rubocop_spec_helper'
2022-04-04 11:22:00 +05:30
require_relative '../../../rubocop/cop/file_decompression'
RSpec.describe RuboCop::Cop::FileDecompression do
it 'does not flag when using a system command not related to file decompression' do
expect_no_offenses('system("ls")')
end
described_class::FORBIDDEN_COMMANDS.map { [_1, '^' * _1.length] }.each do |cmd, len|
it "flags the when using '#{cmd}' system command" do
expect_offense(<<~SOURCE)
system('#{cmd}')
^^^^^^^^#{len}^^ While extracting files check for symlink to avoid arbitrary file reading[...]
SOURCE
expect_offense(<<~SOURCE)
exec('#{cmd}')
^^^^^^#{len}^^ While extracting files check for symlink to avoid arbitrary file reading[...]
SOURCE
expect_offense(<<~SOURCE)
Kernel.spawn('#{cmd}')
^^^^^^^^^^^^^^#{len}^^ While extracting files check for symlink to avoid arbitrary file reading[...]
SOURCE
expect_offense(<<~SOURCE)
IO.popen('#{cmd}')
^^^^^^^^^^#{len}^^ While extracting files check for symlink to avoid arbitrary file reading[...]
SOURCE
end
it "flags the when using '#{cmd}' subshell command" do
expect_offense(<<~SOURCE)
`#{cmd}`
^#{len}^ While extracting files check for symlink to avoid arbitrary file reading[...]
SOURCE
expect_offense(<<~SOURCE)
%x(#{cmd})
^^^#{len}^ While extracting files check for symlink to avoid arbitrary file reading[...]
SOURCE
end
end
end