debian-mirror-gitlab/spec/services/packages/conan/search_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

100 lines
2.8 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-03-17 16:20:25 +05:30
RSpec.describe Packages::Conan::SearchService, feature_category: :package_registry do
2020-07-28 23:09:34 +05:30
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :public) }
2021-09-30 23:02:18 +05:30
2020-07-28 23:09:34 +05:30
let!(:conan_package) { create(:conan_package, project: project) }
let!(:conan_package2) { create(:conan_package, project: project) }
2023-07-09 08:55:56 +05:30
subject { described_class.new(project, user, query: query) }
2020-07-28 23:09:34 +05:30
before do
project.add_developer(user)
end
describe '#execute' do
context 'with wildcard' do
let(:partial_name) { conan_package.name.first[0, 3] }
let(:query) { "#{partial_name}*" }
it 'makes a wildcard query' do
result = subject.execute
expect(result.status).to eq :success
2023-07-09 08:55:56 +05:30
expect(result.payload).to eq(results: [conan_package2.conan_recipe, conan_package.conan_recipe])
2020-07-28 23:09:34 +05:30
end
end
context 'with only wildcard' do
let(:query) { '*' }
it 'returns empty' do
result = subject.execute
expect(result.status).to eq :success
expect(result.payload).to eq(results: [])
end
end
context 'with no wildcard' do
let(:query) { conan_package.name }
it 'makes a search using the beginning of the recipe' do
result = subject.execute
expect(result.status).to eq :success
expect(result.payload).to eq(results: [conan_package.conan_recipe])
end
end
context 'with full recipe match' do
let(:query) { conan_package.conan_recipe }
it 'makes an exact search' do
result = subject.execute
expect(result.status).to eq :success
expect(result.payload).to eq(results: [conan_package.conan_recipe])
end
end
context 'with malicious query' do
let(:query) { 'DROP TABLE foo;' }
it 'returns empty' do
result = subject.execute
expect(result.status).to eq :success
expect(result.payload).to eq(results: [])
end
end
2023-07-09 08:55:56 +05:30
context 'for project' do
let_it_be(:project2) { create(:project, :public) }
let(:query) { conan_package.name }
let!(:conan_package3) { create(:conan_package, name: conan_package.name, project: project2) }
context 'when passing a project' do
it 'returns only packages of the given project' do
result = subject.execute
expect(result.status).to eq :success
expect(result[:results]).to match_array([conan_package.conan_recipe])
end
end
context 'when passing a project with nil' do
it 'returns all packages' do
result = described_class.new(nil, user, query: query).execute
expect(result.status).to eq :success
expect(result[:results]).to eq([conan_package3.conan_recipe, conan_package.conan_recipe])
end
end
end
2020-07-28 23:09:34 +05:30
end
end