Commit 1b410f85 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch '10io-cleanup-maven-api-specs' into 'master'

Clean up the maven API specs code

See merge request gitlab-org/gitlab!28350
parents f731ade4 adc07290
......@@ -2,18 +2,19 @@
require 'spec_helper'
describe API::MavenPackages do
let(:group) { create(:group) }
let(:user) { create(:user) }
let(:project) { create(:project, :public, namespace: group) }
let(:package) { create(:maven_package, project: project) }
let(:maven_metadatum) { package.maven_metadatum }
let(:package_file) { package.package_files.find_by('file_name like ?', '%.xml') }
let(:jar_file) { package.package_files.find_by('file_name like ?', '%.jar') }
let(:personal_access_token) { create(:personal_access_token, user: user) }
let_it_be(:group) { create(:group) }
let_it_be(:user) { create(:user) }
let_it_be(:project, reload: true) { create(:project, :public, namespace: group) }
let_it_be(:package, reload: true) { create(:maven_package, project: project, name: project.full_path) }
let_it_be(:maven_metadatum, reload: true) { package.maven_metadatum }
let_it_be(:package_file) { package.package_files.with_file_name_like('%.xml').first }
let_it_be(:jar_file) { package.package_files.with_file_name_like('%.jar').first }
let_it_be(:personal_access_token) { create(:personal_access_token, user: user) }
let_it_be(:job) { create(:ci_build, user: user) }
let(:workhorse_token) { JWT.encode({ 'iss' => 'gitlab-workhorse' }, Gitlab::Workhorse.secret, 'HS256') }
let(:headers) { { 'GitLab-Workhorse' => '1.0', Gitlab::Workhorse::INTERNAL_API_REQUEST_HEADER => workhorse_token } }
let(:headers_with_token) { headers.merge('Private-Token' => personal_access_token.token) }
let(:job) { create(:ci_build, user: user) }
let(:version) { '1.0-SNAPSHOT' }
before do
......@@ -23,7 +24,7 @@ describe API::MavenPackages do
shared_examples 'tracking the file download event' do
context 'with jar file' do
let(:package_file) { jar_file }
let_it_be(:package_file) { jar_file }
it_behaves_like 'a gitlab tracking event', described_class.name, 'pull_package'
end
......@@ -78,8 +79,6 @@ describe API::MavenPackages do
end
describe 'GET /api/v4/packages/maven/*path/:file_name' do
let(:package) { create(:maven_package, project: project, name: project.full_path) }
context 'a public project' do
subject { download_file(package_file.file_name) }
......@@ -179,7 +178,9 @@ describe API::MavenPackages do
end
context 'project name is different from a package name' do
let(:package) { create(:maven_package, project: project) }
before do
maven_metadatum.update!(path: "wrong_name/#{package.version}")
end
it 'rejects request' do
download_file(package_file.file_name)
......@@ -198,9 +199,6 @@ describe API::MavenPackages do
end
describe 'HEAD /api/v4/packages/maven/*path/:file_name' do
let_it_be(:project) { create(:project, :public) }
let_it_be(:package) { create(:maven_package, project: project, name: project.full_path) }
let_it_be(:package_file) { package.package_files.where('file_name like ?', '%.xml').first }
let(:url) { "/packages/maven/#{package.maven_metadatum.path}/#{package_file.file_name}" }
it_behaves_like 'processing HEAD requests'
......@@ -320,10 +318,6 @@ describe API::MavenPackages do
end
describe 'HEAD /api/v4/groups/:id/-/packages/maven/*path/:file_name' do
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :public, namespace: group) }
let_it_be(:package) { create(:maven_package, project: project, name: project.full_path) }
let_it_be(:package_file) { package.package_files.where('file_name like ?', '%.xml').first }
let(:url) { "/groups/#{group.id}/-/packages/maven/#{package.maven_metadatum.path}/#{package_file.file_name}" }
it_behaves_like 'processing HEAD requests'
......@@ -408,9 +402,6 @@ describe API::MavenPackages do
end
describe 'HEAD /api/v4/projects/:id/packages/maven/*path/:file_name' do
let_it_be(:project) { create(:project, :public) }
let_it_be(:package) { create(:maven_package, project: project, name: project.full_path) }
let_it_be(:package_file) { package.package_files.where('file_name like ?', '%.xml').first }
let(:url) { "/projects/#{project.id}/packages/maven/#{package.maven_metadatum.path}/#{package_file.file_name}" }
it_behaves_like 'processing HEAD requests'
......@@ -499,8 +490,6 @@ describe API::MavenPackages do
end
context 'when params from workhorse are correct' do
let(:package) { project.packages.reload.last }
let(:package_file) { package.package_files.reload.last }
let(:params) do
{
'file.path' => file_upload.path,
......@@ -521,8 +510,6 @@ describe API::MavenPackages do
end
context 'event tracking' do
let(:package_file) { jar_file }
subject { upload_file_with_token(params) }
it_behaves_like 'a gitlab tracking event', described_class.name, 'push_package'
......@@ -534,14 +521,14 @@ describe API::MavenPackages do
.and change { Packages::PackageFile.count }.by(1)
expect(response).to have_gitlab_http_status(:ok)
expect(package_file.file_name).to eq(file_upload.original_filename)
expect(jar_file.file_name).to eq(file_upload.original_filename)
end
it 'allows upload with job token' do
upload_file(params.merge(job_token: job.token))
expect(response).to have_gitlab_http_status(:ok)
expect(package.build_info.pipeline).to eq job.pipeline
expect(project.reload.packages.last.build_info.pipeline).to eq job.pipeline
end
context 'version is not correct' do
......
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