Commit 7f5f452b authored by Fabio Pitino's avatar Fabio Pitino

Fix bug that unlocked artifacts for the wrong CI ref

When looking for a CI ref for a given ref_path we were not
scoping the search for a given project, causing refs from
other projects to have artifacts being unlocked.
parent 8e1c405d
......@@ -10,7 +10,7 @@ module Ci
def perform(project_id, user_id, ref_path)
::Project.find_by_id(project_id).try do |project|
::User.find_by_id(user_id).try do |user|
::Ci::Ref.find_by_ref_path(ref_path).try do |ci_ref|
project.ci_refs.find_by_ref_path(ref_path).try do |ci_ref|
::Ci::UnlockArtifactsService
.new(project, user)
.execute(ci_ref)
......
......@@ -29,10 +29,8 @@ RSpec.describe Ci::RefDeleteUnlockArtifactsWorker do
context 'when user exists' do
let(:user_id) { project.creator.id }
context 'when ci ref exists' do
before do
create(:ci_ref, ref_path: ref)
end
context 'when ci ref exists for project' do
let!(:ci_ref) { create(:ci_ref, ref_path: ref, project: project) }
it 'calls the service' do
service = spy(Ci::UnlockArtifactsService)
......@@ -40,17 +38,33 @@ RSpec.describe Ci::RefDeleteUnlockArtifactsWorker do
perform
expect(service).to have_received(:execute)
expect(service).to have_received(:execute).with(ci_ref)
end
end
context 'when ci ref does not exist' do
context 'when ci ref does not exist for the given project' do
let!(:another_ci_ref) { create(:ci_ref, ref_path: ref) }
it 'does not call the service' do
expect(Ci::UnlockArtifactsService).not_to receive(:new)
perform
end
end
context 'when same ref path exists for a different project' do
let!(:another_ci_ref) { create(:ci_ref, ref_path: ref) }
let!(:ci_ref) { create(:ci_ref, ref_path: ref, project: project) }
it 'calls the service with the correct ref_id' do
service = spy(Ci::UnlockArtifactsService)
expect(Ci::UnlockArtifactsService).to receive(:new).and_return(service)
perform
expect(service).to have_received(:execute).with(ci_ref)
end
end
end
context 'when user does not exist' 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