2021-11-11 11:23:49 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Gitlab::RackAttack::Request do
|
2021-11-18 22:05:49 +05:30
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
describe 'FILES_PATH_REGEX' do
|
|
|
|
subject { described_class::FILES_PATH_REGEX }
|
|
|
|
|
|
|
|
it { is_expected.to match('/api/v4/projects/1/repository/files/README') }
|
|
|
|
it { is_expected.to match('/api/v4/projects/1/repository/files/README?ref=master') }
|
|
|
|
it { is_expected.to match('/api/v4/projects/1/repository/files/README/blame') }
|
|
|
|
it { is_expected.to match('/api/v4/projects/1/repository/files/README/raw') }
|
|
|
|
it { is_expected.to match('/api/v4/projects/some%2Fnested%2Frepo/repository/files/README') }
|
|
|
|
it { is_expected.not_to match('/api/v4/projects/some/nested/repo/repository/files/README') }
|
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
describe '#deprecated_api_request?' do
|
|
|
|
let(:env) { { 'REQUEST_METHOD' => 'GET', 'rack.input' => StringIO.new, 'PATH_INFO' => path, 'QUERY_STRING' => query } }
|
|
|
|
let(:request) { ::Rack::Attack::Request.new(env) }
|
|
|
|
|
|
|
|
subject { !!request.__send__(:deprecated_api_request?) }
|
|
|
|
|
|
|
|
where(:path, :query, :expected) do
|
|
|
|
'/' | '' | false
|
|
|
|
|
|
|
|
'/api/v4/groups/1/' | '' | true
|
|
|
|
'/api/v4/groups/1' | '' | true
|
|
|
|
'/api/v4/groups/foo/' | '' | true
|
|
|
|
'/api/v4/groups/foo' | '' | true
|
|
|
|
|
|
|
|
'/api/v4/groups/1' | 'with_projects=' | true
|
|
|
|
'/api/v4/groups/1' | 'with_projects=1' | true
|
|
|
|
'/api/v4/groups/1' | 'with_projects=0' | false
|
|
|
|
|
|
|
|
'/foo/api/v4/groups/1' | '' | false
|
|
|
|
'/api/v4/groups/1/foo' | '' | false
|
|
|
|
|
|
|
|
'/api/v4/groups/nested%2Fgroup' | '' | true
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it { is_expected.to eq(expected) }
|
|
|
|
end
|
|
|
|
end
|
2021-11-11 11:23:49 +05:30
|
|
|
end
|