summaryrefslogtreecommitdiff
path: root/spec/lib/api/validations/validators/file_path_spec.rb
blob: 2c79260b8d546ef27870a52d9a998e3dc1ba1c8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe API::Validations::Validators::FilePath do
  include ApiValidatorsHelpers

  subject do
    described_class.new(['test'], {}, false, scope.new)
  end

  context 'valid file path' do
    it 'does not raise a validation error' do
      expect_no_validation_error('test' => './foo')
      expect_no_validation_error('test' => './bar.rb')
      expect_no_validation_error('test' => 'foo%2Fbar%2Fnew%2Ffile.rb')
      expect_no_validation_error('test' => 'foo%2Fbar%2Fnew')
      expect_no_validation_error('test' => 'foo%252Fbar%252Fnew%252Ffile.rb')
    end
  end

  context 'invalid file path' do
    it 'raise a validation error' do
      expect_validation_error('test' => '../foo')
      expect_validation_error('test' => '../')
      expect_validation_error('test' => 'foo/../../bar')
      expect_validation_error('test' => 'foo/../')
      expect_validation_error('test' => 'foo/..')
      expect_validation_error('test' => '../')
      expect_validation_error('test' => '..\\')
      expect_validation_error('test' => '..\/')
      expect_validation_error('test' => '%2e%2e%2f')
      expect_validation_error('test' => '/etc/passwd')
    end
  end
end