Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't allow selecting resources from another region when creating a catalog item #14468

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/models/miq_provision_virt_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def allowed_templates(options = {})
end

rails_logger('allowed_templates', 0)
vms = VmOrTemplate.all
vms = VmOrTemplate.in_my_region.all
condition = allowed_template_condition

unless options[:tag_filters].blank?
Expand All @@ -309,7 +309,7 @@ def allowed_templates(options = {})

unless tag_conditions.blank?
_log.info "Filtering VM templates with the following tag_filters: <#{tag_conditions.inspect}>"
vms = MiqTemplate.where(condition).find_tags_by_grouping(tag_conditions, :ns => "/managed")
vms = MiqTemplate.in_my_region.where(condition).find_tags_by_grouping(tag_conditions, :ns => "/managed")
end
end

Expand Down
19 changes: 19 additions & 0 deletions spec/models/miq_provision_virt_workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,23 @@
expect(request.source_id).to eq(template.id)
end
end

context "#allowed_templates" do
let(:external_region_id) do
remote_region_number = ApplicationRecord.my_region_number + 1
ApplicationRecord.region_to_range(remote_region_number).first
end

let(:remote_vmware) { FactoryGirl.create(:ems_vmware_with_authentication, :id => external_region_id) }
let(:local_vmware) { FactoryGirl.create(:ems_vmware_with_authentication) }

it "only returns records from its region" do
EvmSpecHelper.local_guid_miq_server_zone # Because there is no default timezone in settings
FactoryGirl.create(:template_vmware, :ext_management_system => remote_vmware, :id => external_region_id)
FactoryGirl.create(:template_vmware, :ext_management_system => local_vmware)

expect(MiqTemplate.count).to eq(2)
expect(workflow.allowed_templates.count).to eq(1)
end
end
end