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

Fix cloud networks access in API #13865

Merged
merged 4 commits into from
Feb 13, 2017
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
12 changes: 8 additions & 4 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,14 @@
:post:
- :name: query
:identifier: miq_cloud_networks_view
:subcollection_actions:
:get:
- :name: read
:identifier: miq_cloud_networks_view
:subresource_actions:
:get:
- :name: read
:identifier: miq_cloud_networks_view
:clusters:
:description: Clusters
:identifier: ems_cluster
Expand Down Expand Up @@ -1124,10 +1132,6 @@
:identifier: ems_infra_protect
- :name: unassign
:identifier: ems_infra_protect
:cloud_networks_subcollection_actions:
:get:
- :name: show
- :identifier: miq_cloud_networks_view
:provision_dialogs:
:description: Provisioning Dialogs
:identifier: miq_ae_customization_explorer
Expand Down
24 changes: 21 additions & 3 deletions spec/requests/api/cloud_networks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,24 @@

it 'queries Providers cloud_networks' do
cloud_network_ids = provider.cloud_networks.pluck(:id)
api_basic_authorize collection_action_identifier(:providers, :read, :get)
api_basic_authorize subcollection_action_identifier(:providers, :cloud_networks, :read, :get)

run_get providers_cloud_networks_url, :expand => 'resources'

expect_query_result(:cloud_networks, 2)
expect_result_resources_to_include_data('resources', 'id' => cloud_network_ids)
end

it "will not list cloud networks of a provider without the appropriate role" do
api_basic_authorize

run_get providers_cloud_networks_url

expect(response).to have_http_status(:forbidden)
end

it 'queries individual provider cloud_network' do
api_basic_authorize collection_action_identifier(:providers, :read, :get)
api_basic_authorize(action_identifier(:cloud_networks, :read, :subresource_actions, :get))
network = provider.cloud_networks.first
cloud_network_url = "#{providers_cloud_networks_url}/#{network.id}"

Expand All @@ -44,6 +52,16 @@
expect_single_resource_query('name' => network.name, 'id' => network.id, 'ems_ref' => network.ems_ref)
end

it "will not show the cloud network of a provider without the appropriate role" do
api_basic_authorize
network = provider.cloud_networks.first
cloud_network_url = "#{providers_cloud_networks_url}/#{network.id}"

run_get cloud_network_url

expect(response).to have_http_status(:forbidden)
end

it 'successfully returns providers on query when providers do not have cloud_networks attribute' do
FactoryGirl.create(:ems_openshift) # Openshift does not respond to #cloud_networks
FactoryGirl.create(:ems_amazon_with_cloud_networks) # Provider with cloud networks
Expand All @@ -70,7 +88,7 @@
openshift = FactoryGirl.create(:ems_openshift)
openshift_cloud_networks_url = "#{providers_url(openshift.id)}/cloud_networks"

api_basic_authorize collection_action_identifier(:providers, :read, :get)
api_basic_authorize subcollection_action_identifier(:providers, :cloud_networks, :read, :get)

run_get openshift_cloud_networks_url, :expand => 'resources'

Expand Down