Skip to content

Commit

Permalink
Merge pull request #15524 from gildub/floating_IPs_API-initial
Browse files Browse the repository at this point in the history
Floating IPs: Initial API
  • Loading branch information
abellotti authored Jul 24, 2017
2 parents 3eeabd5 + 9aa4077 commit f3bf8c7
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/controllers/api/floating_ips_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Api
class FloatingIpsController < BaseController
end
end
18 changes: 18 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,24 @@
:get:
- :name: read
:identifier: flavor_show
:floating_ips:
:description: Floating IPs
:identifier: floating_ip
:options:
- :collection
: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
:groups:
:description: Groups
:identifier: rbac_group
Expand Down
5 changes: 5 additions & 0 deletions spec/requests/api/collections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
57 changes: 57 additions & 0 deletions spec/requests/api/floating_ips_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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

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

0 comments on commit f3bf8c7

Please sign in to comment.