Commit 935b0bc3 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'refactor-composer-license-specs' into 'master'

Refactor composer license specs

See merge request gitlab-org/gitlab!38461
parents c7945a65 ad7f54d1
......@@ -16,42 +16,40 @@ RSpec.describe API::ComposerPackages do
subject { get api(url), headers: headers }
context 'without the need for a license' do
context 'with valid project' do
let!(:package) { create(:composer_package, :with_metadatum, project: project) }
using RSpec::Parameterized::TableSyntax
context 'with valid project' do
let!(:package) { create(:composer_package, :with_metadatum, project: project) }
using RSpec::Parameterized::TableSyntax
where(:project_visibility_level, :user_role, :member, :user_token, :shared_examples_name, :expected_status) do
'PUBLIC' | :developer | true | true | 'Composer package index' | :success
'PUBLIC' | :guest | true | true | 'Composer package index' | :success
'PUBLIC' | :developer | true | false | 'Composer package index' | :success
'PUBLIC' | :guest | true | false | 'Composer package index' | :success
'PUBLIC' | :developer | false | true | 'Composer package index' | :success
'PUBLIC' | :guest | false | true | 'Composer package index' | :success
'PUBLIC' | :developer | false | false | 'Composer package index' | :success
'PUBLIC' | :guest | false | false | 'Composer package index' | :success
'PUBLIC' | :anonymous | false | true | 'Composer package index' | :success
'PRIVATE' | :developer | true | true | 'Composer package index' | :success
'PRIVATE' | :guest | true | true | 'Composer package index' | :success
'PRIVATE' | :developer | true | false | 'process Composer api request' | :not_found
'PRIVATE' | :guest | true | false | 'process Composer api request' | :not_found
'PRIVATE' | :developer | false | true | 'process Composer api request' | :not_found
'PRIVATE' | :guest | false | true | 'process Composer api request' | :not_found
'PRIVATE' | :developer | false | false | 'process Composer api request' | :not_found
'PRIVATE' | :guest | false | false | 'process Composer api request' | :not_found
'PRIVATE' | :anonymous | false | true | 'process Composer api request' | :not_found
end
where(:project_visibility_level, :user_role, :member, :user_token, :shared_examples_name, :expected_status) do
'PUBLIC' | :developer | true | true | 'Composer package index' | :success
'PUBLIC' | :guest | true | true | 'Composer package index' | :success
'PUBLIC' | :developer | true | false | 'Composer package index' | :success
'PUBLIC' | :guest | true | false | 'Composer package index' | :success
'PUBLIC' | :developer | false | true | 'Composer package index' | :success
'PUBLIC' | :guest | false | true | 'Composer package index' | :success
'PUBLIC' | :developer | false | false | 'Composer package index' | :success
'PUBLIC' | :guest | false | false | 'Composer package index' | :success
'PUBLIC' | :anonymous | false | true | 'Composer package index' | :success
'PRIVATE' | :developer | true | true | 'Composer package index' | :success
'PRIVATE' | :guest | true | true | 'Composer package index' | :success
'PRIVATE' | :developer | true | false | 'process Composer api request' | :not_found
'PRIVATE' | :guest | true | false | 'process Composer api request' | :not_found
'PRIVATE' | :developer | false | true | 'process Composer api request' | :not_found
'PRIVATE' | :guest | false | true | 'process Composer api request' | :not_found
'PRIVATE' | :developer | false | false | 'process Composer api request' | :not_found
'PRIVATE' | :guest | false | false | 'process Composer api request' | :not_found
'PRIVATE' | :anonymous | false | true | 'process Composer api request' | :not_found
end
with_them do
include_context 'Composer api group access', params[:project_visibility_level], params[:user_role], params[:user_token] do
it_behaves_like params[:shared_examples_name], params[:user_role], params[:expected_status], params[:member]
end
with_them do
include_context 'Composer api group access', params[:project_visibility_level], params[:user_role], params[:user_token] do
it_behaves_like params[:shared_examples_name], params[:user_role], params[:expected_status], params[:member]
end
end
it_behaves_like 'rejects Composer access with unknown group id'
end
it_behaves_like 'rejects Composer access with unknown group id'
end
describe 'GET /api/v4/group/:id/-/packages/composer/p/:sha.json' do
......@@ -61,40 +59,38 @@ RSpec.describe API::ComposerPackages do
subject { get api(url), headers: headers }
context 'without the need for a license' do
context 'with valid project' do
using RSpec::Parameterized::TableSyntax
where(:project_visibility_level, :user_role, :member, :user_token, :shared_examples_name, :expected_status) do
'PUBLIC' | :developer | true | true | 'Composer provider index' | :success
'PUBLIC' | :guest | true | true | 'Composer provider index' | :success
'PUBLIC' | :developer | true | false | 'Composer provider index' | :success
'PUBLIC' | :guest | true | false | 'Composer provider index' | :success
'PUBLIC' | :developer | false | true | 'Composer provider index' | :success
'PUBLIC' | :guest | false | true | 'Composer provider index' | :success
'PUBLIC' | :developer | false | false | 'Composer provider index' | :success
'PUBLIC' | :guest | false | false | 'Composer provider index' | :success
'PUBLIC' | :anonymous | false | true | 'Composer provider index' | :success
'PRIVATE' | :developer | true | true | 'Composer provider index' | :success
'PRIVATE' | :guest | true | true | 'Composer empty provider index' | :success
'PRIVATE' | :developer | true | false | 'process Composer api request' | :not_found
'PRIVATE' | :guest | true | false | 'process Composer api request' | :not_found
'PRIVATE' | :developer | false | true | 'process Composer api request' | :not_found
'PRIVATE' | :guest | false | true | 'process Composer api request' | :not_found
'PRIVATE' | :developer | false | false | 'process Composer api request' | :not_found
'PRIVATE' | :guest | false | false | 'process Composer api request' | :not_found
'PRIVATE' | :anonymous | false | true | 'process Composer api request' | :not_found
end
context 'with valid project' do
using RSpec::Parameterized::TableSyntax
where(:project_visibility_level, :user_role, :member, :user_token, :shared_examples_name, :expected_status) do
'PUBLIC' | :developer | true | true | 'Composer provider index' | :success
'PUBLIC' | :guest | true | true | 'Composer provider index' | :success
'PUBLIC' | :developer | true | false | 'Composer provider index' | :success
'PUBLIC' | :guest | true | false | 'Composer provider index' | :success
'PUBLIC' | :developer | false | true | 'Composer provider index' | :success
'PUBLIC' | :guest | false | true | 'Composer provider index' | :success
'PUBLIC' | :developer | false | false | 'Composer provider index' | :success
'PUBLIC' | :guest | false | false | 'Composer provider index' | :success
'PUBLIC' | :anonymous | false | true | 'Composer provider index' | :success
'PRIVATE' | :developer | true | true | 'Composer provider index' | :success
'PRIVATE' | :guest | true | true | 'Composer empty provider index' | :success
'PRIVATE' | :developer | true | false | 'process Composer api request' | :not_found
'PRIVATE' | :guest | true | false | 'process Composer api request' | :not_found
'PRIVATE' | :developer | false | true | 'process Composer api request' | :not_found
'PRIVATE' | :guest | false | true | 'process Composer api request' | :not_found
'PRIVATE' | :developer | false | false | 'process Composer api request' | :not_found
'PRIVATE' | :guest | false | false | 'process Composer api request' | :not_found
'PRIVATE' | :anonymous | false | true | 'process Composer api request' | :not_found
end
with_them do
include_context 'Composer api group access', params[:project_visibility_level], params[:user_role], params[:user_token] do
it_behaves_like params[:shared_examples_name], params[:user_role], params[:expected_status], params[:member]
end
with_them do
include_context 'Composer api group access', params[:project_visibility_level], params[:user_role], params[:user_token] do
it_behaves_like params[:shared_examples_name], params[:user_role], params[:expected_status], params[:member]
end
end
it_behaves_like 'rejects Composer access with unknown group id'
end
it_behaves_like 'rejects Composer access with unknown group id'
end
describe 'GET /api/v4/group/:id/-/packages/composer/*package_name.json' do
......@@ -103,48 +99,46 @@ RSpec.describe API::ComposerPackages do
subject { get api(url), headers: headers }
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
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' do
using RSpec::Parameterized::TableSyntax
let!(:package) { create(:composer_package, :with_metadatum, name: package_name, project: project) }
where(:project_visibility_level, :user_role, :member, :user_token, :shared_examples_name, :expected_status) do
'PUBLIC' | :developer | true | true | 'Composer package api request' | :success
'PUBLIC' | :guest | true | true | 'Composer package api request' | :success
'PUBLIC' | :developer | true | false | 'Composer package api request' | :success
'PUBLIC' | :guest | true | false | 'Composer package api request' | :success
'PUBLIC' | :developer | false | true | 'Composer package api request' | :success
'PUBLIC' | :guest | false | true | 'Composer package api request' | :success
'PUBLIC' | :developer | false | false | 'Composer package api request' | :success
'PUBLIC' | :guest | false | false | 'Composer package api request' | :success
'PUBLIC' | :anonymous | false | true | 'Composer package api request' | :success
'PRIVATE' | :developer | true | true | 'Composer package api request' | :success
'PRIVATE' | :guest | true | true | 'process Composer api request' | :not_found
'PRIVATE' | :developer | true | false | 'process Composer api request' | :not_found
'PRIVATE' | :guest | true | false | 'process Composer api request' | :not_found
'PRIVATE' | :developer | false | true | 'process Composer api request' | :not_found
'PRIVATE' | :guest | false | true | 'process Composer api request' | :not_found
'PRIVATE' | :developer | false | false | 'process Composer api request' | :not_found
'PRIVATE' | :guest | false | false | 'process Composer api request' | :not_found
'PRIVATE' | :anonymous | false | true | 'process Composer api request' | :not_found
end
context 'with valid project' do
using RSpec::Parameterized::TableSyntax
let!(:package) { create(:composer_package, :with_metadatum, name: package_name, project: project) }
where(:project_visibility_level, :user_role, :member, :user_token, :shared_examples_name, :expected_status) do
'PUBLIC' | :developer | true | true | 'Composer package api request' | :success
'PUBLIC' | :guest | true | true | 'Composer package api request' | :success
'PUBLIC' | :developer | true | false | 'Composer package api request' | :success
'PUBLIC' | :guest | true | false | 'Composer package api request' | :success
'PUBLIC' | :developer | false | true | 'Composer package api request' | :success
'PUBLIC' | :guest | false | true | 'Composer package api request' | :success
'PUBLIC' | :developer | false | false | 'Composer package api request' | :success
'PUBLIC' | :guest | false | false | 'Composer package api request' | :success
'PUBLIC' | :anonymous | false | true | 'Composer package api request' | :success
'PRIVATE' | :developer | true | true | 'Composer package api request' | :success
'PRIVATE' | :guest | true | true | 'process Composer api request' | :not_found
'PRIVATE' | :developer | true | false | 'process Composer api request' | :not_found
'PRIVATE' | :guest | true | false | 'process Composer api request' | :not_found
'PRIVATE' | :developer | false | true | 'process Composer api request' | :not_found
'PRIVATE' | :guest | false | true | 'process Composer api request' | :not_found
'PRIVATE' | :developer | false | false | 'process Composer api request' | :not_found
'PRIVATE' | :guest | false | false | 'process Composer api request' | :not_found
'PRIVATE' | :anonymous | false | true | 'process Composer api request' | :not_found
end
with_them do
include_context 'Composer api group access', params[:project_visibility_level], params[:user_role], params[:user_token] do
it_behaves_like params[:shared_examples_name], params[:user_role], params[:expected_status], params[:member]
end
with_them do
include_context 'Composer api group access', params[:project_visibility_level], params[:user_role], params[:user_token] do
it_behaves_like params[:shared_examples_name], params[:user_role], params[:expected_status], params[:member]
end
end
it_behaves_like 'rejects Composer access with unknown group id'
end
it_behaves_like 'rejects Composer access with unknown group id'
end
describe 'POST /api/v4/projects/:id/packages/composer' do
......@@ -158,40 +152,38 @@ RSpec.describe API::ComposerPackages do
subject { post api(url), headers: headers, params: params }
shared_examples 'composer package publish' do
context 'without the need for a license' do
context 'with valid project' do
using RSpec::Parameterized::TableSyntax
where(:project_visibility_level, :user_role, :member, :user_token, :shared_examples_name, :expected_status) do
'PUBLIC' | :developer | true | true | 'Composer package creation' | :created
'PUBLIC' | :guest | true | true | 'process Composer api request' | :forbidden
'PUBLIC' | :developer | true | false | 'process Composer api request' | :unauthorized
'PUBLIC' | :guest | true | false | 'process Composer api request' | :unauthorized
'PUBLIC' | :developer | false | true | 'process Composer api request' | :forbidden
'PUBLIC' | :guest | false | true | 'process Composer api request' | :forbidden
'PUBLIC' | :developer | false | false | 'process Composer api request' | :unauthorized
'PUBLIC' | :guest | false | false | 'process Composer api request' | :unauthorized
'PUBLIC' | :anonymous | false | true | 'process Composer api request' | :unauthorized
'PRIVATE' | :developer | true | true | 'Composer package creation' | :created
'PRIVATE' | :guest | true | true | 'process Composer api request' | :forbidden
'PRIVATE' | :developer | true | false | 'process Composer api request' | :unauthorized
'PRIVATE' | :guest | true | false | 'process Composer api request' | :unauthorized
'PRIVATE' | :developer | false | true | 'process Composer api request' | :not_found
'PRIVATE' | :guest | false | true | 'process Composer api request' | :not_found
'PRIVATE' | :developer | false | false | 'process Composer api request' | :unauthorized
'PRIVATE' | :guest | false | false | 'process Composer api request' | :unauthorized
'PRIVATE' | :anonymous | false | true | 'process Composer api request' | :unauthorized
end
context 'with valid project' do
using RSpec::Parameterized::TableSyntax
with_them do
include_context 'Composer api project access', params[:project_visibility_level], params[:user_role], params[:user_token] do
it_behaves_like params[:shared_examples_name], params[:user_role], params[:expected_status], params[:member]
end
end
where(:project_visibility_level, :user_role, :member, :user_token, :shared_examples_name, :expected_status) do
'PUBLIC' | :developer | true | true | 'Composer package creation' | :created
'PUBLIC' | :guest | true | true | 'process Composer api request' | :forbidden
'PUBLIC' | :developer | true | false | 'process Composer api request' | :unauthorized
'PUBLIC' | :guest | true | false | 'process Composer api request' | :unauthorized
'PUBLIC' | :developer | false | true | 'process Composer api request' | :forbidden
'PUBLIC' | :guest | false | true | 'process Composer api request' | :forbidden
'PUBLIC' | :developer | false | false | 'process Composer api request' | :unauthorized
'PUBLIC' | :guest | false | false | 'process Composer api request' | :unauthorized
'PUBLIC' | :anonymous | false | true | 'process Composer api request' | :unauthorized
'PRIVATE' | :developer | true | true | 'Composer package creation' | :created
'PRIVATE' | :guest | true | true | 'process Composer api request' | :forbidden
'PRIVATE' | :developer | true | false | 'process Composer api request' | :unauthorized
'PRIVATE' | :guest | true | false | 'process Composer api request' | :unauthorized
'PRIVATE' | :developer | false | true | 'process Composer api request' | :not_found
'PRIVATE' | :guest | false | true | 'process Composer api request' | :not_found
'PRIVATE' | :developer | false | false | 'process Composer api request' | :unauthorized
'PRIVATE' | :guest | false | false | 'process Composer api request' | :unauthorized
'PRIVATE' | :anonymous | false | true | 'process Composer api request' | :unauthorized
end
it_behaves_like 'rejects Composer access with unknown project id'
with_them do
include_context 'Composer api project access', params[:project_visibility_level], params[:user_role], params[:user_token] do
it_behaves_like params[:shared_examples_name], params[:user_role], params[:expected_status], params[:member]
end
end
end
it_behaves_like 'rejects Composer access with unknown project id'
end
context 'with no tag or branch params' do
......@@ -238,65 +230,63 @@ RSpec.describe API::ComposerPackages do
subject { get api(url), headers: headers, params: params }
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) }
context 'with valid project' do
let!(:package) { create(:composer_package, :with_metadatum, name: package_name, project: project) }
context 'when the sha does not match the package name' do
let(:sha) { '123' }
context 'when the sha does not match the package name' do
let(:sha) { '123' }
it_behaves_like 'process Composer api request', :anonymous, :not_found
end
it_behaves_like 'process Composer api request', :anonymous, :not_found
end
context 'when the package name does not match the sha' do
let(:branch) { project.repository.find_branch('master') }
let(:sha) { branch.target }
let(:url) { "/projects/#{project.id}/packages/composer/archives/unexisting-package-name.zip" }
context 'when the package name does not match the sha' do
let(:branch) { project.repository.find_branch('master') }
let(:sha) { branch.target }
let(:url) { "/projects/#{project.id}/packages/composer/archives/unexisting-package-name.zip" }
it_behaves_like 'process Composer api request', :anonymous, :not_found
end
it_behaves_like 'process Composer api request', :anonymous, :not_found
end
context 'with a match package name and sha' do
let(:branch) { project.repository.find_branch('master') }
let(:sha) { branch.target }
using RSpec::Parameterized::TableSyntax
where(:project_visibility_level, :user_role, :member, :user_token, :expected_status) do
'PUBLIC' | :developer | true | true | :success
'PUBLIC' | :guest | true | true | :success
'PUBLIC' | :developer | true | false | :success
'PUBLIC' | :guest | true | false | :success
'PUBLIC' | :developer | false | true | :success
'PUBLIC' | :guest | false | true | :success
'PUBLIC' | :developer | false | false | :success
'PUBLIC' | :guest | false | false | :success
'PUBLIC' | :anonymous | false | true | :success
'PRIVATE' | :developer | true | true | :success
'PRIVATE' | :guest | true | true | :success
'PRIVATE' | :developer | true | false | :success
'PRIVATE' | :guest | true | false | :success
'PRIVATE' | :developer | false | true | :success
'PRIVATE' | :guest | false | true | :success
'PRIVATE' | :developer | false | false | :success
'PRIVATE' | :guest | false | false | :success
'PRIVATE' | :anonymous | false | true | :success
end
context 'with a match package name and sha' do
let(:branch) { project.repository.find_branch('master') }
let(:sha) { branch.target }
with_them do
let(:token) { user_token ? personal_access_token.token : 'wrong' }
let(:headers) { user_role == :anonymous ? {} : build_basic_auth_header(user.username, token) }
using RSpec::Parameterized::TableSyntax
where(:project_visibility_level, :user_role, :member, :user_token, :expected_status) do
'PUBLIC' | :developer | true | true | :success
'PUBLIC' | :guest | true | true | :success
'PUBLIC' | :developer | true | false | :success
'PUBLIC' | :guest | true | false | :success
'PUBLIC' | :developer | false | true | :success
'PUBLIC' | :guest | false | true | :success
'PUBLIC' | :developer | false | false | :success
'PUBLIC' | :guest | false | false | :success
'PUBLIC' | :anonymous | false | true | :success
'PRIVATE' | :developer | true | true | :success
'PRIVATE' | :guest | true | true | :success
'PRIVATE' | :developer | true | false | :success
'PRIVATE' | :guest | true | false | :success
'PRIVATE' | :developer | false | true | :success
'PRIVATE' | :guest | false | true | :success
'PRIVATE' | :developer | false | false | :success
'PRIVATE' | :guest | false | false | :success
'PRIVATE' | :anonymous | false | true | :success
end
before do
project.update!(visibility_level: Gitlab::VisibilityLevel.const_get(project_visibility_level, false))
end
with_them do
let(:token) { user_token ? personal_access_token.token : 'wrong' }
let(:headers) { user_role == :anonymous ? {} : build_basic_auth_header(user.username, token) }
it_behaves_like 'process Composer api request', params[:user_role], params[:expected_status], params[:member]
before do
project.update!(visibility_level: Gitlab::VisibilityLevel.const_get(project_visibility_level, false))
end
it_behaves_like 'process Composer api request', params[:user_role], params[:expected_status], params[:member]
end
end
it_behaves_like 'rejects Composer access with unknown project id'
end
it_behaves_like 'rejects Composer access with unknown project id'
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