Skip to content

Commit

Permalink
Fixes #35368 - Prevent multiple envs in host registration (Katello#10236
Browse files Browse the repository at this point in the history
)

(cherry picked from commit bb5d05d)
  • Loading branch information
chris1984 authored and sjha4 committed Aug 29, 2022
1 parent d2458d0 commit d43df9c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ def find_content_view_environment

if params.key?(:environment_id)
environment = get_content_view_environment("cp_id", params[:environment_id])
elsif params.key?(:environments)
fail HttpErrors::BadRequest, _('Multiple environments are not supported.') if params['environments'].length > 1
environment = get_content_view_environment("cp_id", params['environments'].first['id'])
elsif params.key?(:organization_id) && !params.key?(:environment_id)
organization = Organization.current
environment = organization.library.content_view_environment
Expand Down
21 changes: 21 additions & 0 deletions test/controllers/api/rhsm/candlepin_proxies_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,27 @@ module Katello
assert_response :success
end

it "should register with new environments param" do
Resources::Candlepin::Consumer.stubs(:get)

::Katello::RegistrationManager.expects(:process_registration).with({'facts' => @facts }, @content_view_environment).returns(@host)

post(:consumer_create, params: { :organization_id => @content_view_environment.content_view.organization.label, :environments => [{id: @content_view_environment.cp_id}], :facts => @facts })

assert_response :success
end

it "should not register with multiple envs" do
::Katello::RegistrationManager.expects(:process_registration).never

post(:consumer_create, params: { :organization_id => @content_view_environment.content_view.organization.label, :environments => [{id: @content_view_environment.cp_id}, {id: @content_view_environment.cp_id}], :facts => @facts })

body = JSON.parse(response.body)

assert_equal 'Multiple environments are not supported.', body['displayMessage']
assert_response 400
end

it "should not register" do
::Katello::RegistrationManager.expects(:check_registration_services).returns(false)
::Katello::RegistrationManager.expects(:process_registration).never
Expand Down

0 comments on commit d43df9c

Please sign in to comment.