Skip to content

Commit

Permalink
Do not allow a linktobranch for metapackages like _pattern
Browse files Browse the repository at this point in the history
Fixes #17305
  • Loading branch information
danidoni committed Jan 29, 2025
1 parent 29e0459 commit 07a74a8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/api/app/controllers/source_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,10 @@ def package_command_deleteuploadrev

# POST /source/<project>/<package>?cmd=linktobranch
def package_command_linktobranch
if @package.nil?
render_error status: 404
return
end
pkg_rev = params[:rev]
pkg_linkrev = params[:linkrev]

Expand Down
30 changes: 30 additions & 0 deletions src/api/spec/controllers/source_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,34 @@
it { expect(response).to have_http_status(:ok) }
end
end

describe 'POST #linktobranch', vcr: false do
context 'when accessing a regular package' do
let(:package) { create(:package, name: 'some_package', project: project) }

before do
login user

post :package_command, params: {
cmd: 'linktobranch', project: package.project, package: package
}
end

it { expect(response).to have_http_status(:found) }
end

context 'when accessing a _patterns package' do
let(:package) { create(:package, name: 'some_package', project: project) }

before do
login user

post :package_command, params: {
cmd: 'linktobranch', project: package.project, package: '_pattern'
}
end

it { expect(response).to have_http_status(:not_found) }
end
end
end

0 comments on commit 07a74a8

Please sign in to comment.