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

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

65 lines
1.7 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::DependencyProxy, api: true, feature_category: :dependency_proxy do
2021-01-29 00:20:46 +05:30
let_it_be(:user) { create(:user) }
2023-01-13 00:05:48 +05:30
let_it_be(:blob) { create(:dependency_proxy_blob) }
2021-01-29 00:20:46 +05:30
let_it_be(:group, reload: true) { blob.group }
before do
group.add_owner(user)
stub_config(dependency_proxy: { enabled: true })
stub_last_activity_update
end
describe 'DELETE /groups/:id/dependency_proxy/cache' do
2021-11-11 11:23:49 +05:30
subject { delete api("/groups/#{group_id}/dependency_proxy/cache", user) }
2021-01-29 00:20:46 +05:30
2021-11-11 11:23:49 +05:30
shared_examples 'responding to purge requests' do
context 'with feature available and enabled' do
context 'an admin user' do
it 'deletes the blobs and returns no content' do
expect(PurgeDependencyProxyCacheWorker).to receive(:perform_async)
2021-01-29 00:20:46 +05:30
2021-11-11 11:23:49 +05:30
subject
2021-01-29 00:20:46 +05:30
2021-11-11 11:23:49 +05:30
expect(response).to have_gitlab_http_status(:accepted)
expect(response.body).to eq('202')
end
end
2021-01-29 00:20:46 +05:30
2021-11-11 11:23:49 +05:30
context 'a non-admin' do
let(:user) { create(:user) }
2021-01-29 00:20:46 +05:30
2021-11-11 11:23:49 +05:30
before do
group.add_maintainer(user)
2021-01-29 00:20:46 +05:30
end
2021-11-11 11:23:49 +05:30
it_behaves_like 'returning response status', :forbidden
2021-01-29 00:20:46 +05:30
end
end
2021-11-11 11:23:49 +05:30
context 'depencency proxy is not enabled in the config' do
2021-01-29 00:20:46 +05:30
before do
2021-11-11 11:23:49 +05:30
stub_config(dependency_proxy: { enabled: false })
2021-01-29 00:20:46 +05:30
end
2021-11-11 11:23:49 +05:30
it_behaves_like 'returning response status', :not_found
2021-01-29 00:20:46 +05:30
end
end
2021-11-11 11:23:49 +05:30
context 'with a group id' do
let(:group_id) { group.id }
it_behaves_like 'responding to purge requests'
end
context 'with an url encoded group id' do
let(:group_id) { ERB::Util.url_encode(group.full_path) }
2021-01-29 00:20:46 +05:30
2021-11-11 11:23:49 +05:30
it_behaves_like 'responding to purge requests'
2021-01-29 00:20:46 +05:30
end
end
end