47 lines
1.6 KiB
Ruby
47 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
RSpec.describe Gitlab::RackAttack::Request do
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
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
|
|
|
|
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
|
|
end
|