debian-mirror-gitlab/spec/lib/gitlab/robots_txt/parser_spec.rb

85 lines
2.1 KiB
Ruby
Raw Normal View History

2020-11-24 15:15:51 +05:30
# frozen_string_literal: true
require 'fast_spec_helper'
require 'rspec-parameterized'
RSpec.describe Gitlab::RobotsTxt::Parser do
describe '#disallowed?' do
subject { described_class.new(content).disallowed?(path) }
context 'a simple robots.txt file' do
using RSpec::Parameterized::TableSyntax
let(:content) do
<<~TXT
User-Agent: *
Disallow: /autocomplete/users
2021-01-29 00:20:46 +05:30
disallow: /search
2020-11-24 15:15:51 +05:30
Disallow: /api
2021-01-29 00:20:46 +05:30
Allow: /users
Disallow: /help
allow: /help
Disallow: /test$
Disallow: /ex$mple$
2020-11-24 15:15:51 +05:30
TXT
end
where(:path, :result) do
'/autocomplete/users' | true
'/autocomplete/users/a.html' | true
'/search' | true
'/search.html' | true
'/api' | true
'/api/grapql' | true
'/api/index.html' | true
'/projects' | false
2021-01-29 00:20:46 +05:30
'/users' | false
'/help' | false
'/test' | true
'/testfoo' | false
'/ex$mple' | true
'/ex$mplefoo' | false
2020-11-24 15:15:51 +05:30
end
with_them do
it { is_expected.to eq(result), "#{path} expected to be #{result}" }
end
end
context 'robots.txt file with wildcard' do
using RSpec::Parameterized::TableSyntax
let(:content) do
<<~TXT
User-Agent: *
Disallow: /search
User-Agent: *
Disallow: /*/*.git
Disallow: /*/archive/
Disallow: /*/repository/archive*
2021-01-29 00:20:46 +05:30
Allow: /*/repository/archive/foo
2020-11-24 15:15:51 +05:30
TXT
end
where(:path, :result) do
'/search' | true
'/namespace/project.git' | true
'/project/archive/' | true
'/project/archive/file.gz' | true
'/project/repository/archive' | true
'/project/repository/archive.gz' | true
'/project/repository/archive/file.gz' | true
'/projects' | false
'/git' | false
'/projects/git' | false
2021-01-29 00:20:46 +05:30
'/project/repository/archive/foo' | false
2020-11-24 15:15:51 +05:30
end
with_them do
it { is_expected.to eq(result), "#{path} expected to be #{result}" }
end
end
end
end