debian-mirror-gitlab/spec/features/file_uploads/maven_package_spec.rb

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

63 lines
2.3 KiB
Ruby
Raw Normal View History

2020-11-24 15:15:51 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Upload a maven package', :api, :js do
include_context 'file upload requests helpers'
let_it_be(:project) { create(:project) }
2022-04-04 11:22:00 +05:30
let_it_be(:user) { project.first_owner }
2020-11-24 15:15:51 +05:30
let_it_be(:personal_access_token) { create(:personal_access_token, user: user) }
2021-04-29 21:17:54 +05:30
let(:project_id) { project.id }
let(:api_path) { "/projects/#{project_id}/packages/maven/com/example/my-app/1.0/my-app-1.0-20180724.124855-1.jar" }
2020-11-24 15:15:51 +05:30
let(:url) { capybara_url(api(api_path, personal_access_token: personal_access_token)) }
let(:file) { fixture_file_upload('spec/fixtures/dk.png') }
subject { HTTParty.put(url, body: file.read) }
2021-04-29 21:17:54 +05:30
shared_examples 'for a maven package' do
2020-11-24 15:15:51 +05:30
it 'creates package files' do
expect { subject }
.to change { Packages::Package.maven.count }.by(1)
.and change { Packages::PackageFile.count }.by(1)
end
it { expect(subject.code).to eq(200) }
end
2021-04-29 21:17:54 +05:30
shared_examples 'for a maven sha1' do
2021-01-03 14:25:43 +05:30
let(:dummy_package) { double(Packages::Package) }
2021-04-29 21:17:54 +05:30
let(:api_path) { "/projects/#{project_id}/packages/maven/com/example/my-app/1.0/my-app-1.0-20180724.124855-1.jar.sha1" }
2021-01-03 14:25:43 +05:30
before do
# The sha verification done by the maven api is between:
# - the sha256 set by workhorse
# - the sha256 of the sha1 of the uploaded package file
# We're going to send `file` for the sha1 and stub the sha1 of the package file so that
# both sha256 being the same
expect(::Packages::PackageFileFinder).to receive(:new).and_return(double(execute!: dummy_package))
expect(dummy_package).to receive(:file_sha1).and_return(File.read(file.path))
end
it { expect(subject.code).to eq(204) }
end
2021-04-29 21:17:54 +05:30
shared_examples 'for a maven md5' do
let(:api_path) { "/projects/#{project_id}/packages/maven/com/example/my-app/1.0/my-app-1.0-20180724.124855-1.jar.md5" }
2021-01-03 14:25:43 +05:30
let(:file) { StringIO.new('dummy_package') }
it { expect(subject.code).to eq(200) }
end
2020-11-24 15:15:51 +05:30
it_behaves_like 'handling file uploads', 'for a maven package'
2021-01-03 14:25:43 +05:30
it_behaves_like 'handling file uploads', 'for a maven sha1'
it_behaves_like 'handling file uploads', 'for a maven md5'
2021-04-29 21:17:54 +05:30
context 'with an encoded project ID' do
let(:project_id) { "#{project.namespace.path}%2F#{project.path}" }
it_behaves_like 'handling file uploads', 'for a maven package'
end
2020-11-24 15:15:51 +05:30
end