debian-mirror-gitlab/spec/requests/api/npm_instance_packages_spec.rb

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

80 lines
2.9 KiB
Ruby
Raw Permalink Normal View History

2021-01-29 00:20:46 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe API::NpmInstancePackages, feature_category: :package_registry do
2021-04-17 20:07:23 +05:30
# We need to create a subgroup with the same name as the hosting group.
# It has to be created first to exhibit this bug: https://gitlab.com/gitlab-org/gitlab/-/issues/321958
let_it_be(:another_namespace) { create(:group, :public) }
let_it_be(:similarly_named_group) { create(:group, :public, parent: another_namespace, name: 'test-group') }
2021-01-29 00:20:46 +05:30
include_context 'npm api setup'
describe 'GET /api/v4/packages/npm/*package_name' do
2023-05-27 22:25:52 +05:30
let(:url) { api("/packages/npm/#{package_name}") }
2023-07-07 10:43:13 +05:30
subject { get(url) }
2023-05-27 22:25:52 +05:30
it_behaves_like 'handling get metadata requests', scope: :instance
2023-07-07 10:43:13 +05:30
it_behaves_like 'rejects invalid package names'
2023-05-27 22:25:52 +05:30
context 'with a duplicate package name in another project' do
let_it_be(:project2) { create(:project, :public, namespace: namespace) }
let_it_be(:package2) do
create(:npm_package,
project: project2,
name: "@#{group.path}/scoped_package",
version: '1.2.0')
end
it 'includes all matching package versions in the response' do
subject
expect(json_response['versions'].keys).to match_array([package.version, package2.version])
end
context 'with the feature flag disabled' do
before do
stub_feature_flags(npm_allow_packages_in_multiple_projects: false)
end
it 'returns matching package versions from only one project' do
subject
expect(json_response['versions'].keys).to match_array([package2.version])
end
end
2021-01-29 00:20:46 +05:30
end
end
describe 'GET /api/v4/packages/npm/-/package/*package_name/dist-tags' do
it_behaves_like 'handling get dist tags requests', scope: :instance do
let(:url) { api("/packages/npm/-/package/#{package_name}/dist-tags") }
end
end
describe 'PUT /api/v4/packages/npm/-/package/*package_name/dist-tags/:tag' do
it_behaves_like 'handling create dist tag requests', scope: :instance do
let(:url) { api("/packages/npm/-/package/#{package_name}/dist-tags/#{tag_name}") }
end
end
describe 'DELETE /api/v4/packages/npm/-/package/*package_name/dist-tags/:tag' do
it_behaves_like 'handling delete dist tag requests', scope: :instance do
let(:url) { api("/packages/npm/-/package/#{package_name}/dist-tags/#{tag_name}") }
end
end
2023-03-04 22:38:38 +05:30
describe 'POST /api/v4/packages/npm/-/npm/v1/security/advisories/bulk' do
it_behaves_like 'handling audit request', path: 'advisories/bulk', scope: :instance do
let(:url) { api('/packages/npm/-/npm/v1/security/advisories/bulk') }
end
end
describe 'POST /api/v4/packages/npm/-/npm/v1/security/audits/quick' do
it_behaves_like 'handling audit request', path: 'audits/quick', scope: :instance do
let(:url) { api('/packages/npm/-/npm/v1/security/audits/quick') }
end
end
2021-01-29 00:20:46 +05:30
end