From 93f99db3725c702ab34d2db3211c46fa49823b7c Mon Sep 17 00:00:00 2001 From: Gilles Dubreuil Date: Fri, 7 Jul 2017 13:27:07 +1000 Subject: [PATCH 1/2] Floating IPs: initial API Initial API service definition for FloatingIP with show list --- .../api/floating_ips_controller.rb | 4 ++ config/api.yml | 27 ++++++++++ spec/requests/api/floating_ips_spec.rb | 49 +++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 app/controllers/api/floating_ips_controller.rb create mode 100644 spec/requests/api/floating_ips_spec.rb diff --git a/app/controllers/api/floating_ips_controller.rb b/app/controllers/api/floating_ips_controller.rb new file mode 100644 index 00000000000..53713f24f04 --- /dev/null +++ b/app/controllers/api/floating_ips_controller.rb @@ -0,0 +1,4 @@ +module Api + class FloatingIpsController < BaseController + end +end diff --git a/config/api.yml b/config/api.yml index 39bd7b2d237..e0332c1a5a4 100644 --- a/config/api.yml +++ b/config/api.yml @@ -807,6 +807,33 @@ :get: - :name: read :identifier: flavor_show + :floating_ips: + :description: Floating IPs + :identifier: floating_ip + :options: + - :collection + - :subcollection + :verbs: *gp + :klass: FloatingIp + :collection_actions: + :get: + - :name: read + :identifier: floating_ip_show_list + :post: + - :name: query + :identifier: floating_ip_show_list + :resource_actions: + :get: + - :name: read + :identifier: floating_ip_show + :subcollection_actions: + :get: + - :name: read + :identifier: cloud_tenant_show_list + :subresource_actions: + :get: + - :name: read + :identifier: cloud_tenant_show :groups: :description: Groups :identifier: rbac_group diff --git a/spec/requests/api/floating_ips_spec.rb b/spec/requests/api/floating_ips_spec.rb new file mode 100644 index 00000000000..46f558c0b29 --- /dev/null +++ b/spec/requests/api/floating_ips_spec.rb @@ -0,0 +1,49 @@ +RSpec.describe 'FloatingIp API' do + describe 'GET /api/floating_ips' do + it 'lists all cloud subnets with an appropriate role' do + floating_ip = FactoryGirl.create(:floating_ip) + api_basic_authorize collection_action_identifier(:floating_ips, :read, :get) + run_get(floating_ips_url) + + expected = { + 'count' => 1, + 'subcount' => 1, + 'name' => 'floating_ips', + 'resources' => [ + hash_including('href' => a_string_matching(floating_ips_url(floating_ip.id))) + ] + } + expect(response).to have_http_status(:ok) + expect(response.parsed_body).to include(expected) + end + + it 'forbids access to cloud subnets without an appropriate role' do + api_basic_authorize + + run_get(floating_ips_url) + + expect(response).to have_http_status(:forbidden) + end + end + + describe 'GET /api/floating_ips/:id' do + it 'will show a cloud subnet with an appropriate role' do + floating_ip = FactoryGirl.create(:floating_ip) + api_basic_authorize action_identifier(:floating_ips, :read, :resource_actions, :get) + + run_get(floating_ips_url(floating_ip.id)) + + expect(response.parsed_body).to include('href' => a_string_matching(floating_ips_url(floating_ip.id))) + expect(response).to have_http_status(:ok) + end + + it 'forbids access to a cloud tenant without an appropriate role' do + floating_ip = FactoryGirl.create(:floating_ip) + api_basic_authorize + + run_get(floating_ips_url(floating_ip.id)) + + expect(response).to have_http_status(:forbidden) + end + end +end From 9aa40772a22df014bebe3a1c7bbf4376d475b8b3 Mon Sep 17 00:00:00 2001 From: Gilles Dubreuil Date: Fri, 14 Jul 2017 12:11:37 +1000 Subject: [PATCH 2/2] No subcollection; Adds tests query and bulk query --- config/api.yml | 9 --------- spec/requests/api/collections_spec.rb | 5 +++++ spec/requests/api/floating_ips_spec.rb | 8 ++++++++ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/config/api.yml b/config/api.yml index e0332c1a5a4..76e0acfe081 100644 --- a/config/api.yml +++ b/config/api.yml @@ -812,7 +812,6 @@ :identifier: floating_ip :options: - :collection - - :subcollection :verbs: *gp :klass: FloatingIp :collection_actions: @@ -826,14 +825,6 @@ :get: - :name: read :identifier: floating_ip_show - :subcollection_actions: - :get: - - :name: read - :identifier: cloud_tenant_show_list - :subresource_actions: - :get: - - :name: read - :identifier: cloud_tenant_show :groups: :description: Groups :identifier: rbac_group diff --git a/spec/requests/api/collections_spec.rb b/spec/requests/api/collections_spec.rb index 81c19aeccee..3a9a86f5618 100644 --- a/spec/requests/api/collections_spec.rb +++ b/spec/requests/api/collections_spec.rb @@ -387,6 +387,11 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil) test_collection_bulk_query(:flavors, flavors_url, Flavor) end + it "bulk query FloatingIps" do + FactoryGirl.create(:floating_ip) + test_collection_bulk_query(:floating_ips, floating_ips_url, FloatingIp) + end + it "bulk query Groups" do group = FactoryGirl.create(:miq_group) test_collection_bulk_query(:groups, groups_url, MiqGroup, group.id) diff --git a/spec/requests/api/floating_ips_spec.rb b/spec/requests/api/floating_ips_spec.rb index 46f558c0b29..fe87b77fcca 100644 --- a/spec/requests/api/floating_ips_spec.rb +++ b/spec/requests/api/floating_ips_spec.rb @@ -46,4 +46,12 @@ expect(response).to have_http_status(:forbidden) end end + + describe 'POST /api/floating_ips' do + it 'forbids access to floating ips without an appropriate role' do + api_basic_authorize + run_post(floating_ips_url, gen_request(:query, "")) + expect(response).to have_http_status(:forbidden) + end + end end