Commit 79d3bd34 authored by James Fargher's avatar James Fargher

Merge branch '213929-move-package-apis-to-core' into 'master'

Move package APIS to core [RUN AS-IF-FOSS]

Closes #213929

See merge request gitlab-org/gitlab!35919
parents 1047ae11 62cf1104
......@@ -790,8 +790,8 @@ Style/RedundantSelf:
# Cop supports --auto-correct.
Style/RedundantSort:
Exclude:
- 'ee/app/presenters/packages/nuget/search_results_presenter.rb'
- 'ee/spec/presenters/packages/nuget/search_results_presenter_spec.rb'
- 'app/presenters/packages/nuget/search_results_presenter.rb'
- 'spec/presenters/packages/nuget/search_results_presenter_spec.rb'
# Offense count: 120
# Cop supports --auto-correct.
......@@ -976,21 +976,17 @@ Rails/SaveBang:
- 'ee/spec/policies/vulnerabilities/feedback_policy_spec.rb'
- 'ee/spec/presenters/audit_event_presenter_spec.rb'
- 'ee/spec/presenters/epic_presenter_spec.rb'
- 'ee/spec/presenters/packages/conan/package_presenter_spec.rb'
- 'ee/spec/requests/api/boards_spec.rb'
- 'ee/spec/requests/api/conan_packages_spec.rb'
- 'ee/spec/requests/api/epic_issues_spec.rb'
- 'ee/spec/requests/api/epic_links_spec.rb'
- 'ee/spec/requests/api/epics_spec.rb'
- 'ee/spec/requests/api/geo_nodes_spec.rb'
- 'ee/spec/requests/api/geo_spec.rb'
- 'ee/spec/requests/api/go_proxy_spec.rb'
- 'ee/spec/requests/api/graphql/group/epics_spec.rb'
- 'ee/spec/requests/api/graphql/mutations/epic_tree/reorder_spec.rb'
- 'ee/spec/requests/api/groups_spec.rb'
- 'ee/spec/requests/api/issues_spec.rb'
- 'ee/spec/requests/api/ldap_group_links_spec.rb'
- 'ee/spec/requests/api/maven_packages_spec.rb'
- 'ee/spec/requests/api/merge_request_approval_rules_spec.rb'
- 'ee/spec/requests/api/merge_request_approvals_spec.rb'
- 'ee/spec/requests/api/merge_requests_spec.rb'
......@@ -1059,9 +1055,7 @@ Rails/SaveBang:
- 'ee/spec/support/shared_examples/models/mentionable_shared_examples.rb'
- 'ee/spec/support/shared_examples/policies/protected_environments_shared_examples.rb'
- 'ee/spec/support/shared_examples/requests/api/graphql/geo/registries_shared_examples.rb'
- 'ee/spec/support/shared_examples/requests/api/nuget_packages_shared_examples.rb'
- 'ee/spec/support/shared_examples/requests/api/project_approval_rules_api_shared_examples.rb'
- 'ee/spec/support/shared_examples/requests/api/pypi_packages_shared_examples.rb'
- 'ee/spec/support/shared_examples/services/build_execute_shared_examples.rb'
- 'ee/spec/support/shared_examples/services/issue_epic_shared_examples.rb'
- 'ee/spec/views/layouts/nav/sidebar/_project.html.haml_spec.rb'
......@@ -1434,13 +1428,16 @@ Rails/SaveBang:
- 'spec/policies/project_policy_spec.rb'
- 'spec/presenters/ci/build_runner_presenter_spec.rb'
- 'spec/presenters/ci/trigger_presenter_spec.rb'
- 'spec/presenters/packages/conan/package_presenter_spec.rb'
- 'spec/requests/api/access_requests_spec.rb'
- 'spec/requests/api/boards_spec.rb'
- 'spec/requests/api/branches_spec.rb'
- 'spec/requests/api/ci/runner_spec.rb'
- 'spec/requests/api/commit_statuses_spec.rb'
- 'spec/requests/api/conan_packages_spec.rb'
- 'spec/requests/api/deployments_spec.rb'
- 'spec/requests/api/environments_spec.rb'
- 'spec/requests/api/go_proxy_spec.rb'
- 'spec/requests/api/graphql/mutations/merge_requests/set_labels_spec.rb'
- 'spec/requests/api/graphql/user_query_spec.rb'
- 'spec/requests/api/graphql_spec.rb'
......@@ -1451,6 +1448,7 @@ Rails/SaveBang:
- 'spec/requests/api/issues/post_projects_issues_spec.rb'
- 'spec/requests/api/jobs_spec.rb'
- 'spec/requests/api/labels_spec.rb'
- 'spec/requests/api/maven_packages_spec.rb'
- 'spec/requests/api/members_spec.rb'
- 'spec/requests/api/merge_request_diffs_spec.rb'
- 'spec/requests/api/merge_requests_spec.rb'
......@@ -1573,6 +1571,8 @@ Rails/SaveBang:
- 'spec/support/shared_examples/requests/api/award_emoji_todo_shared_examples.rb'
- 'spec/support/shared_examples/requests/api/boards_shared_examples.rb'
- 'spec/support/shared_examples/requests/api/custom_attributes_shared_examples.rb'
- 'spec/support/shared_examples/requests/api/nuget_packages_shared_examples.rb'
- 'spec/support/shared_examples/requests/api/pypi_packages_shared_examples.rb'
- 'spec/support/shared_examples/serializers/note_entity_shared_examples.rb'
- 'spec/support/shared_examples/services/common_system_notes_shared_examples.rb'
- 'spec/support/shared_examples/services/issuable_shared_examples.rb'
......
......@@ -5,15 +5,15 @@ module Resolvers
type Types::PackageType, null: true
def resolve(**args)
return unless packages_available?(object, current_user)
return unless packages_available?
::Packages::PackagesFinder.new(object).execute
end
private
def packages_available?(object, user)
::Gitlab.config.packages.enabled && object.feature_available?(:packages)
def packages_available?
::Gitlab.config.packages.enabled
end
end
end
......@@ -169,6 +169,10 @@ module Types
description: 'A single issue of the project',
resolver: Resolvers::IssuesResolver.single
field :packages, Types::PackageType.connection_type, null: true,
description: 'Packages of the project',
resolver: Resolvers::PackagesResolver
field :pipelines,
Types::Ci::PipelineType.connection_type,
null: true,
......
......@@ -45,7 +45,7 @@ class Packages::PackageFile < ApplicationRecord
end
def download_path
Gitlab::Routing.url_helpers.download_project_package_file_path(project, self)
Gitlab::Routing.url_helpers.download_project_package_file_path(project, self) if ::Gitlab.ee?
end
def local?
......
This diff is collapsed.
---
title: Package APIs moved to core
merge_request: 35919
author:
type: changed
......@@ -48,10 +48,6 @@ module EE
Hash.new(0).merge(project.requirements.counts_by_state)
end
field :packages, ::Types::PackageType.connection_type, null: true,
description: 'Packages of the project',
resolver: ::Resolvers::PackagesResolver
field :compliance_frameworks, ::Types::ComplianceManagement::ComplianceFrameworkType.connection_type,
description: 'Compliance frameworks associated with the project',
resolver: ::Resolvers::ComplianceFrameworksResolver,
......
This diff is collapsed.
......@@ -32,18 +32,8 @@ module EE
mount ::API::License
mount ::API::ProjectMirror
mount ::API::ProjectPushRule
mount ::API::NugetPackages
mount ::API::PypiPackages
mount ::API::ComposerPackages
mount ::API::ConanPackages
mount ::API::MavenPackages
mount ::API::NpmPackages
mount ::API::GoProxy
mount ::API::MergeTrains
mount ::API::ProjectPackages
mount ::API::GroupPackages
mount ::API::GroupHooks
mount ::API::PackageFiles
mount ::API::Scim
mount ::API::ManagedLicenses
mount ::API::ProjectApprovals
......
# frozen_string_literal: true
module EE
module API
module Entities
class GoModuleVersion < Grape::Entity
expose :name, as: 'Version'
expose :time, as: 'Time'
end
end
end
end
......@@ -37,9 +37,5 @@ module EE
def stub_elasticsearch_setting(messages)
allow(::Gitlab.config.elasticsearch).to receive_messages(to_settings(messages))
end
def stub_packages_setting(messages)
allow(::Gitlab.config.packages).to receive_messages(to_settings(messages))
end
end
end
......@@ -182,6 +182,16 @@ module API
mount ::API::ResourceMilestoneEvents
mount ::API::ResourceStateEvents
mount ::API::NotificationSettings
mount ::API::ProjectPackages
mount ::API::GroupPackages
mount ::API::PackageFiles
mount ::API::NugetPackages
mount ::API::PypiPackages
mount ::API::ComposerPackages
mount ::API::ConanPackages
mount ::API::MavenPackages
mount ::API::NpmPackages
mount ::API::GoProxy
mount ::API::Pages
mount ::API::PagesDomains
mount ::API::ProjectClusters
......
......@@ -54,7 +54,7 @@ module API
resource :group, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
before do
authorize_packages_feature!(user_group)
user_group
end
desc 'Composer packages endpoint at group level'
......@@ -98,7 +98,7 @@ module API
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
before do
authorize_packages_feature!(unauthorized_user_project!)
unauthorized_user_project!
end
desc 'Composer packages endpoint for registering packages'
......
# frozen_string_literal: true
module API
module Entities
class GoModuleVersion < Grape::Entity
expose :name, as: 'Version'
expose :time, as: 'Time'
end
end
end
......@@ -13,7 +13,9 @@ module API
expose :_links do
expose :web_path do |package|
::Gitlab::Routing.url_helpers.project_package_path(package.project, package)
if ::Gitlab.ee?
::Gitlab::Routing.url_helpers.project_package_path(package.project, package)
end
end
expose :delete_api_path, if: can_destroy(:package, &:project) do |package|
......
......@@ -74,7 +74,6 @@ module API
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
before do
authorize_read_package!
authorize_packages_feature!
end
namespace ':id/packages/go/*module_name/@v' do
......@@ -90,7 +89,7 @@ module API
desc 'Get information about the given module version' do
detail 'See `go help goproxy`, GET $GOPROXY/<module>/@v/<version>.info. This feature was introduced in GitLab 13.1.'
success EE::API::Entities::GoModuleVersion
success ::API::Entities::GoModuleVersion
end
params do
requires :module_version, type: String, desc: 'Module version'
......@@ -98,7 +97,7 @@ module API
get ':module_version.info', requirements: MODULE_VERSION_REQUIREMENTS do
ver = find_version
present ::Packages::Go::ModuleVersionPresenter.new(ver), with: EE::API::Entities::GoModuleVersion
present ::Packages::Go::ModuleVersionPresenter.new(ver), with: ::API::Entities::GoModuleVersion
end
desc 'Get the module file of the given module version' do
......
......@@ -125,7 +125,7 @@ module API
end
def track_push_package_event
if params[:file_name] == ::Packages::Conan::FileMetadatum::PACKAGE_BINARY && params['file.size'].positive?
if params[:file_name] == ::Packages::Conan::FileMetadatum::PACKAGE_BINARY && params['file.size'] > 0
track_event('push_package')
end
end
......
......@@ -13,10 +13,6 @@ module API
not_found! unless ::Gitlab.config.dependency_proxy.enabled
end
def authorize_packages_feature!(subject = user_project)
forbidden! unless subject.feature_available?(:packages)
end
def authorize_read_package!(subject = user_project)
authorize!(:read_package, subject)
end
......@@ -31,7 +27,6 @@ module API
def authorize_packages_access!(subject = user_project)
require_packages_enabled!
authorize_packages_feature!(subject)
authorize_read_package!(subject)
end
......
......@@ -98,8 +98,6 @@ module API
package = ::Packages::Maven::PackageFinder
.new(params[:path], current_user, project: project).execute!
authorize_packages_feature!(package.project)
package_file = ::Packages::PackageFileFinder
.new(package, file_name).execute!
......@@ -136,7 +134,6 @@ module API
package = ::Packages::Maven::PackageFinder
.new(params[:path], current_user, group: group).execute!
authorize_packages_feature!(package.project)
authorize_read_package!(package.project)
package_file = ::Packages::PackageFileFinder
......@@ -159,10 +156,6 @@ module API
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
before do
authorize_packages_feature!(user_project)
end
desc 'Download the maven package file' do
detail 'This feature was introduced in GitLab 11.3'
end
......
......@@ -38,7 +38,6 @@ module API
bad_request!('Package Name') if package_name.blank?
authorize_read_package!(project_by_package_name)
authorize_packages_feature!(project_by_package_name)
packages = ::Packages::Npm::PackageFinder.new(project_by_package_name, package_name)
.execute
......@@ -112,7 +111,6 @@ module API
redirect_registry_request(project_by_package_name.blank?, :npm, package_name: package_name) do
authorize_read_package!(project_by_package_name)
authorize_packages_feature!(project_by_package_name)
packages = ::Packages::Npm::PackageFinder
.new(project_by_package_name, package_name).execute
......@@ -126,10 +124,6 @@ module API
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
before do
authorize_packages_feature!(user_project)
end
desc 'Download the NPM tarball' do
detail 'This feature was introduced in GitLab 11.8'
end
......
......@@ -57,7 +57,7 @@ module API
route_setting :authentication, deploy_token_allowed: true
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
before do
authorize_packages_feature!(authorized_user_project)
authorized_user_project
end
namespace ':id/packages/nuget' do
......
......@@ -55,7 +55,7 @@ module API
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
before do
authorize_packages_feature!(unauthorized_user_project!)
unauthorized_user_project!
end
namespace ':id/packages/pypi' do
......
......@@ -12,34 +12,6 @@ RSpec.describe Resolvers::PackagesResolver do
describe '#resolve' do
subject(:packages) { resolve(described_class, ctx: { current_user: user }, obj: project) }
context 'when the package feature is enabled' do
before do
stub_licensed_features(packages: true)
end
context 'when the project has the package feature enabled' do
before do
allow(project).to receive(:feature_available?).with(:packages).and_return(true)
end
it { is_expected.to contain_exactly(package) }
end
context 'when the project has the package feature disabled' do
before do
allow(project).to receive(:feature_available?).with(:packages).and_return(false)
end
it { is_expected.to be_nil }
end
end
context 'when the package feature is not enabled' do
before do
stub_licensed_features(packages: false)
end
it { is_expected.to be_nil }
end
it { is_expected.to contain_exactly(package) }
end
end
......@@ -11,41 +11,12 @@ RSpec.describe API::Helpers::PackagesHelpers do
it 'authorizes packages access' do
expect(helper).to receive(:require_packages_enabled!)
expect(helper).to receive(:authorize_packages_feature!).with(project)
expect(helper).to receive(:authorize_read_package!).with(project)
expect(subject).to eq nil
end
end
describe 'authorize_packages_feature!' do
let(:feature_enabled) { true }
subject { helper.authorize_packages_feature!(project) }
before do
allow(project).to receive(:feature_available?).with(:packages).and_return(feature_enabled)
end
context 'with feature enabled' do
it "doesn't call forbidden!" do
expect(helper).to receive(:forbidden!).never
expect(subject).to eq nil
end
end
context 'with feature disabled' do
let(:feature_enabled) { false }
it 'calls forbidden!' do
expect(helper).to receive(:forbidden!).once
subject
end
end
end
%i[read_package create_package destroy_package].each do |action|
describe "authorize_#{action}!" do
subject { helper.send("authorize_#{action}!", project) }
......
......@@ -16,11 +16,7 @@ RSpec.describe API::ComposerPackages do
subject { get api(url), headers: headers }
context 'with packages features enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'with valid project' do
let!(:package) { create(:composer_package, :with_metadatum, project: project) }
......@@ -56,8 +52,6 @@ RSpec.describe API::ComposerPackages do
it_behaves_like 'rejects Composer access with unknown group id'
end
it_behaves_like 'rejects Composer packages access with packages features disabled'
end
describe 'GET /api/v4/group/:id/-/packages/composer/p/:sha.json' do
......@@ -67,11 +61,7 @@ RSpec.describe API::ComposerPackages do
subject { get api(url), headers: headers }
context 'with packages features enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'with valid project' do
using RSpec::Parameterized::TableSyntax
......@@ -105,8 +95,6 @@ RSpec.describe API::ComposerPackages do
it_behaves_like 'rejects Composer access with unknown group id'
end
it_behaves_like 'rejects Composer packages access with packages features disabled'
end
describe 'GET /api/v4/group/:id/-/packages/composer/*package_name.json' do
......@@ -115,18 +103,14 @@ RSpec.describe API::ComposerPackages do
subject { get api(url), headers: headers }
context 'with packages features enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'with no packages' do
include_context 'Composer user type', :developer, true do
it_behaves_like 'returning response status', :not_found
end
end
context 'with valid project and packages' do
context 'with valid project' do
using RSpec::Parameterized::TableSyntax
let!(:package) { create(:composer_package, :with_metadatum, name: package_name, project: project) }
......@@ -161,8 +145,6 @@ RSpec.describe API::ComposerPackages do
it_behaves_like 'rejects Composer access with unknown group id'
end
it_behaves_like 'rejects Composer packages access with packages features disabled'
end
describe 'POST /api/v4/projects/:id/packages/composer' do
......@@ -176,11 +158,7 @@ RSpec.describe API::ComposerPackages do
subject { post api(url), headers: headers, params: params }
shared_examples 'composer package publish' do
context 'with packages features enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'with valid project' do
using RSpec::Parameterized::TableSyntax
......@@ -216,15 +194,9 @@ RSpec.describe API::ComposerPackages do
end
end
it_behaves_like 'rejects Composer packages access with packages features disabled'
context 'with no tag or branch params' do
let(:headers) { build_basic_auth_header(user.username, personal_access_token.token) }
before do
stub_licensed_features(packages: true)
end
it_behaves_like 'process Composer api request', :developer, :bad_request
end
......@@ -239,10 +211,6 @@ RSpec.describe API::ComposerPackages do
let(:params) { { tag: 'non-existing-tag' } }
let(:headers) { build_basic_auth_header(user.username, personal_access_token.token) }
before do
stub_licensed_features(packages: true)
end
it_behaves_like 'process Composer api request', :developer, :not_found
end
end
......@@ -258,10 +226,6 @@ RSpec.describe API::ComposerPackages do
let(:params) { { branch: 'non-existing-branch' } }
let(:headers) { build_basic_auth_header(user.username, personal_access_token.token) }
before do
stub_licensed_features(packages: true)
end
it_behaves_like 'process Composer api request', :developer, :not_found
end
end
......@@ -274,11 +238,7 @@ RSpec.describe API::ComposerPackages do
subject { get api(url), headers: headers, params: params }
context 'with packages features enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'with valid project' do
let!(:package) { create(:composer_package, :with_metadatum, name: package_name, project: project) }
......@@ -338,7 +298,5 @@ RSpec.describe API::ComposerPackages do
it_behaves_like 'rejects Composer access with unknown project id'
end
it_behaves_like 'rejects Composer packages access with packages features disabled'
end
end
......@@ -31,7 +31,6 @@ RSpec.describe API::ConanPackages do
before do
project.add_developer(user)
stub_licensed_features(packages: true)
allow(Settings).to receive(:attr_encrypted_db_key_base).and_return(base_secret)
end
......
......@@ -30,7 +30,6 @@ RSpec.describe API::GoProxy do
before do
project.add_developer(user)
stub_licensed_features(packages: true)
stub_feature_flags(go_proxy_disable_gomod_validation: false)
modules
......
......@@ -28,11 +28,7 @@ RSpec.describe 'getting a package list for a project' do
)
end
context 'when package feature is available' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'when user has access to the project' do
before do
project.add_reporter(current_user)
......@@ -70,18 +66,4 @@ RSpec.describe 'getting a package list for a project' do
end
end
end
context 'when package feature is not available' do
before do
stub_licensed_features(packages: false)
project.add_reporter(current_user)
post_graphql(query, current_user: current_user)
end
it_behaves_like 'a working graphql query'
it 'returns nil' do
expect(graphql_data['project']['packages']).to be_nil
end
end
end
......@@ -13,11 +13,7 @@ RSpec.describe API::GroupPackages do
let(:url) { "/groups/#{group.id}/packages" }
let(:package_schema) { 'public_api/v4/packages/group_packages' }
context 'with packages feature enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'with sorting' do
let_it_be(:package1) { create(:npm_package, project: project, version: '3.1.0', name: "@#{project.root_namespace.path}/foo1") }
let_it_be(:package2) { create(:nuget_package, project: project, version: '2.0.4') }
......@@ -147,13 +143,5 @@ RSpec.describe API::GroupPackages do
it_behaves_like 'returning response status', :bad_request
end
end
context 'with packages feature disabled' do
before do
stub_licensed_features(packages: false)
end
it_behaves_like 'rejects packages access', :group, :no_type, :forbidden
end
end
end
......@@ -30,7 +30,6 @@ RSpec.describe API::MavenPackages do
before do
project.add_developer(user)
stub_licensed_features(packages: true)
end
shared_examples 'tracking the file download event' do
......@@ -196,14 +195,6 @@ RSpec.describe API::MavenPackages do
it_behaves_like 'downloads with a deploy token'
end
it 'rejects request if feature is not in the license' do
stub_licensed_features(packages: false)
download_file(package_file.file_name)
expect(response).to have_gitlab_http_status(:forbidden)
end
context 'project name is different from a package name' do
before do
maven_metadatum.update!(path: "wrong_name/#{package.version}")
......@@ -321,14 +312,6 @@ RSpec.describe API::MavenPackages do
it_behaves_like 'downloads with a deploy token'
end
it 'rejects request if feature is not in the license' do
stub_licensed_features(packages: false)
download_file(package_file.file_name)
expect(response).to have_gitlab_http_status(:forbidden)
end
def download_file(file_name, params = {}, request_headers = headers)
get api("/groups/#{group.id}/-/packages/maven/#{maven_metadatum.path}/#{file_name}"), params: params, headers: request_headers
end
......@@ -401,14 +384,6 @@ RSpec.describe API::MavenPackages do
it_behaves_like 'downloads with a deploy token'
end
it 'rejects request if feature is not in the license' do
stub_licensed_features(packages: false)
download_file(package_file.file_name)
expect(response).to have_gitlab_http_status(:forbidden)
end
def download_file(file_name, params = {}, request_headers = headers)
get api("/projects/#{project.id}/packages/maven/" \
"#{maven_metadatum.path}/#{file_name}"), params: params, headers: request_headers
......@@ -508,14 +483,6 @@ RSpec.describe API::MavenPackages do
expect(response).to have_gitlab_http_status(:unauthorized)
end
it 'rejects request if feature is not in the license' do
stub_licensed_features(packages: false)
upload_file_with_token
expect(response).to have_gitlab_http_status(:forbidden)
end
context 'without workhorse rewritten field' do
let(:send_rewritten_field) { false }
......
......@@ -17,7 +17,6 @@ RSpec.describe API::NpmPackages do
before do
project.add_developer(user)
stub_licensed_features(packages: true)
end
shared_examples 'a package that requires auth' do
......@@ -134,14 +133,6 @@ RSpec.describe API::NpmPackages do
end
end
it 'rejects request if feature is not in the license' do
stub_licensed_features(packages: false)
get_package(package)
expect(response).to have_gitlab_http_status(:forbidden)
end
def get_package(package, params = {}, headers = {})
get api("/packages/npm/#{package.name}"), params: params, headers: headers
end
......@@ -221,14 +212,6 @@ RSpec.describe API::NpmPackages do
it_behaves_like 'a package file that requires auth'
end
it 'rejects request if feature is not in the license' do
stub_licensed_features(packages: false)
get_file(package_file)
expect(response).to have_gitlab_http_status(:forbidden)
end
def get_file(package_file, params = {})
get api("/projects/#{project.id}/packages/npm/" \
"#{package_file.package.name}/-/#{package_file.file_name}"), params: params
......@@ -424,11 +407,7 @@ RSpec.describe API::NpmPackages do
subject { get api(url) }
context 'with packages feature enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'with public project' do
context 'with authenticated user' do
subject { get api(url, personal_access_token: personal_access_token) }
......@@ -463,14 +442,6 @@ RSpec.describe API::NpmPackages do
end
end
end
context 'with packages feature disabled' do
before do
stub_licensed_features(packages: false)
end
it_behaves_like 'rejects package tags access', :no_type, :forbidden
end
end
describe 'PUT /api/v4/packages/npm/-/package/*package_name/dist-tags/:tag' do
......@@ -482,11 +453,7 @@ RSpec.describe API::NpmPackages do
subject { put api(url), env: { 'api.request.body': version } }
context 'with packages feature enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'with public project' do
context 'with authenticated user' do
subject { put api(url, personal_access_token: personal_access_token), env: { 'api.request.body': version } }
......@@ -521,14 +488,6 @@ RSpec.describe API::NpmPackages do
end
end
end
context 'with packages feature disabled' do
before do
stub_licensed_features(packages: false)
end
it_behaves_like 'rejects package tags access', :no_type, :unauthorized
end
end
describe 'DELETE /api/v4/packages/npm/-/package/*package_name/dist-tags/:tag' do
......@@ -540,11 +499,7 @@ RSpec.describe API::NpmPackages do
subject { delete api(url) }
context 'with packages feature enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'with public project' do
context 'with authenticated user' do
subject { delete api(url, personal_access_token: personal_access_token) }
......@@ -579,14 +534,6 @@ RSpec.describe API::NpmPackages do
end
end
end
context 'with packages feature disabled' do
before do
stub_licensed_features(packages: false)
end
it_behaves_like 'rejects package tags access', :no_type, :unauthorized
end
end
def expect_a_valid_package_response
......
......@@ -16,11 +16,7 @@ RSpec.describe API::NugetPackages do
subject { get api(url) }
context 'with packages features enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'with valid project' do
using RSpec::Parameterized::TableSyntax
......@@ -65,8 +61,6 @@ RSpec.describe API::NugetPackages do
it_behaves_like 'rejects nuget access with invalid project id'
end
it_behaves_like 'rejects nuget packages access with packages features disabled'
end
describe 'PUT /api/v4/projects/:id/packages/nuget/authorize' do
......@@ -77,11 +71,7 @@ RSpec.describe API::NugetPackages do
subject { put api(url), headers: headers }
context 'with packages features enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'with valid project' do
using RSpec::Parameterized::TableSyntax
......@@ -125,8 +115,6 @@ RSpec.describe API::NugetPackages do
it_behaves_like 'rejects nuget access with invalid project id'
end
it_behaves_like 'rejects nuget packages access with packages features disabled'
end
describe 'PUT /api/v4/projects/:id/packages/nuget' do
......@@ -150,11 +138,7 @@ RSpec.describe API::NugetPackages do
)
end
context 'with packages features enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'with valid project' do
using RSpec::Parameterized::TableSyntax
......@@ -198,8 +182,6 @@ RSpec.describe API::NugetPackages do
it_behaves_like 'rejects nuget access with invalid project id'
end
it_behaves_like 'rejects nuget packages access with packages features disabled'
end
describe 'GET /api/v4/projects/:id/packages/nuget/metadata/*package_name/index' do
......@@ -216,11 +198,7 @@ RSpec.describe API::NugetPackages do
packages.each { |pkg| create_dependencies_for(pkg) }
end
context 'with packages features enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for license' do
context 'with valid project' do
using RSpec::Parameterized::TableSyntax
......@@ -265,8 +243,6 @@ RSpec.describe API::NugetPackages do
it_behaves_like 'rejects nuget access with invalid project id'
end
end
it_behaves_like 'rejects nuget packages access with packages features disabled'
end
describe 'GET /api/v4/projects/:id/packages/nuget/metadata/*package_name/*package_version' do
......@@ -283,11 +259,7 @@ RSpec.describe API::NugetPackages do
create_dependencies_for(package)
end
context 'with packages features enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'with valid project' do
using RSpec::Parameterized::TableSyntax
......@@ -334,8 +306,6 @@ RSpec.describe API::NugetPackages do
it_behaves_like 'rejects nuget packages access', :developer, :not_found
end
end
it_behaves_like 'rejects nuget packages access with packages features disabled'
end
describe 'GET /api/v4/projects/:id/packages/nuget/download/*package_name/index' do
......@@ -345,11 +315,7 @@ RSpec.describe API::NugetPackages do
subject { get api(url) }
context 'with packages features enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'with valid project' do
using RSpec::Parameterized::TableSyntax
......@@ -394,8 +360,6 @@ RSpec.describe API::NugetPackages do
it_behaves_like 'rejects nuget access with invalid project id'
end
it_behaves_like 'rejects nuget packages access with packages features disabled'
end
describe 'GET /api/v4/projects/:id/packages/nuget/download/*package_name/*package_version/*package_filename' do
......@@ -406,11 +370,7 @@ RSpec.describe API::NugetPackages do
subject { get api(url) }
context 'with packages features enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'with valid project' do
using RSpec::Parameterized::TableSyntax
......@@ -455,8 +415,6 @@ RSpec.describe API::NugetPackages do
it_behaves_like 'rejects nuget access with invalid project id'
end
it_behaves_like 'rejects nuget packages access with packages features disabled'
end
describe 'GET /api/v4/projects/:id/packages/nuget/query' do
......@@ -475,11 +433,7 @@ RSpec.describe API::NugetPackages do
subject { get api(url) }
context 'with packages features enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'with valid project' do
using RSpec::Parameterized::TableSyntax
......@@ -524,7 +478,5 @@ RSpec.describe API::NugetPackages do
it_behaves_like 'rejects nuget access with invalid project id'
end
it_behaves_like 'rejects nuget packages access with packages features disabled'
end
end
......@@ -14,11 +14,7 @@ RSpec.describe API::PackageFiles do
describe 'GET /projects/:id/packages/:package_id/package_files' do
let(:url) { "/projects/#{project.id}/packages/#{package.id}/package_files" }
context 'packages feature enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'project is public' do
it 'returns 200' do
get api(url)
......@@ -64,10 +60,6 @@ RSpec.describe API::PackageFiles do
let!(:package_file_2) { package.package_files[1] }
let!(:package_file_3) { package.package_files[2] }
before do
stub_licensed_features(packages: true)
end
context 'when viewing the first page' do
it 'returns first 2 packages' do
get api(url, user), params: { page: 1, per_page: per_page }
......@@ -85,17 +77,5 @@ RSpec.describe API::PackageFiles do
end
end
end
context 'packages feature disabled' do
before do
stub_licensed_features(packages: false)
end
it 'returns 403' do
get api(url, user)
expect(response).to have_gitlab_http_status(:forbidden)
end
end
end
end
......@@ -18,11 +18,7 @@ RSpec.describe API::ProjectPackages do
subject { get api(url) }
context 'packages feature enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'project is public' do
it_behaves_like 'returns packages', :project, :no_type
end
......@@ -109,18 +105,6 @@ RSpec.describe API::ProjectPackages do
end
end
end
context 'packages feature disabled' do
before do
stub_licensed_features(packages: false)
end
it 'returns 403' do
get api(url, user)
expect(response).to have_gitlab_http_status(:forbidden)
end
end
end
describe 'GET /projects/:id/packages/:package_id' do
......@@ -142,11 +126,7 @@ RSpec.describe API::ProjectPackages do
end
end
context 'packages feature enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'project is public' do
it 'returns 200 and the package information' do
subject
......@@ -222,26 +202,10 @@ RSpec.describe API::ProjectPackages do
end
end
end
context 'packages feature disabled' do
before do
stub_licensed_features(packages: false)
end
it 'returns 403' do
subject
expect(response).to have_gitlab_http_status(:forbidden)
end
end
end
describe 'DELETE /projects/:id/packages/:package_id' do
context 'packages feature enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'project is public' do
it 'returns 403 for non authenticated user' do
delete api(package_url)
......@@ -304,17 +268,5 @@ RSpec.describe API::ProjectPackages do
end
end
end
context 'packages feature disabled' do
before do
stub_licensed_features(packages: false)
end
it 'returns 403' do
delete api(package_url, user)
expect(response).to have_gitlab_http_status(:forbidden)
end
end
end
end
......@@ -17,11 +17,7 @@ RSpec.describe API::PypiPackages do
subject { get api(url) }
context 'with packages features enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'with valid project' do
using RSpec::Parameterized::TableSyntax
......@@ -64,8 +60,6 @@ RSpec.describe API::PypiPackages do
it_behaves_like 'rejects PyPI access with unknown project id'
end
it_behaves_like 'rejects PyPI packages access with packages features disabled'
end
describe 'POST /api/v4/projects/:id/packages/pypi/authorize' do
......@@ -76,11 +70,7 @@ RSpec.describe API::PypiPackages do
subject { post api(url), headers: headers }
context 'with packages features enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'with valid project' do
using RSpec::Parameterized::TableSyntax
......@@ -122,8 +112,6 @@ RSpec.describe API::PypiPackages do
it_behaves_like 'rejects PyPI access with unknown project id'
end
it_behaves_like 'rejects PyPI packages access with packages features disabled'
end
describe 'POST /api/v4/projects/:id/packages/pypi' do
......@@ -147,11 +135,7 @@ RSpec.describe API::PypiPackages do
)
end
context 'with packages features enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'with valid project' do
using RSpec::Parameterized::TableSyntax
......@@ -206,8 +190,6 @@ RSpec.describe API::PypiPackages do
it_behaves_like 'rejects PyPI access with unknown project id'
end
it_behaves_like 'rejects PyPI packages access with packages features disabled'
end
describe 'GET /api/v4/projects/:id/packages/pypi/files/:sha256/*file_identifier' do
......@@ -218,11 +200,7 @@ RSpec.describe API::PypiPackages do
subject { get api(url) }
context 'with packages features enabled' do
before do
stub_licensed_features(packages: true)
end
context 'without the need for a license' do
context 'with valid project' do
using RSpec::Parameterized::TableSyntax
......@@ -277,7 +255,5 @@ RSpec.describe API::PypiPackages do
it_behaves_like 'rejects PyPI access with unknown project id'
end
it_behaves_like 'rejects PyPI packages access with packages features disabled'
end
end
......@@ -117,6 +117,10 @@ module StubConfiguration
allow(::Gitlab.config.service_desk_email).to receive_messages(to_settings(messages))
end
def stub_packages_setting(messages)
allow(::Gitlab.config.packages).to receive_messages(to_settings(messages))
end
private
# Modifies stubbed messages to also stub possible predicate versions
......
......@@ -121,16 +121,6 @@ RSpec.shared_examples 'rejects Composer access with unknown group id' do
end
end
RSpec.shared_examples 'rejects Composer packages access with packages features disabled' do
context 'with packages features disabled' do
before do
stub_licensed_features(packages: false)
end
it_behaves_like 'process Composer api request', :anonymous, :forbidden
end
end
RSpec.shared_examples 'rejects Composer access with unknown project id' do
context 'with an unknown project' do
let(:project) { double(id: non_existing_record_id) }
......
......@@ -18,16 +18,6 @@ RSpec.shared_examples 'rejects nuget packages access' do |user_type, status, add
end
end
RSpec.shared_examples 'rejects nuget packages access with packages features disabled' do
context 'with packages features disabled' do
before do
stub_licensed_features(packages: false)
end
it_behaves_like 'rejects nuget packages access', :anonymous, :forbidden
end
end
RSpec.shared_examples 'process nuget service index request' do |user_type, status, add_member = true|
context "for user type #{user_type}" do
before do
......
......@@ -150,13 +150,3 @@ RSpec.shared_examples 'rejects PyPI access with unknown project id' do
end
end
end
RSpec.shared_examples 'rejects PyPI packages access with packages features disabled' do
context 'with packages features disabled' do
before do
stub_licensed_features(packages: false)
end
it_behaves_like 'process PyPi api request', :anonymous, :forbidden
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment