Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/rubocop/cop/file_decompression_spec.rb')
-rw-r--r--spec/rubocop/cop/file_decompression_spec.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/rubocop/cop/file_decompression_spec.rb b/spec/rubocop/cop/file_decompression_spec.rb
new file mode 100644
index 00000000000..7be1a784001
--- /dev/null
+++ b/spec/rubocop/cop/file_decompression_spec.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+require_relative '../../../rubocop/cop/file_decompression'
+
+RSpec.describe RuboCop::Cop::FileDecompression do
+ subject(:cop) { described_class.new }
+
+ 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