Skip to content

Commit

Permalink
Don't show service route binding parameters not in state create succe…
Browse files Browse the repository at this point in the history
…eded (cloudfoundry#3443)

* Throw error for GET /v3/service_route_bindings/:guid/parameters with state create initial or create failed

For GET /v3/service_route_bindings/:guid/parameters, if the state is create initial or create failed, it should not return parameters.
It should raise an error when GET /v3/service_route_bindings/:guid/parameters, is called instead of showing empty data.
Co-authored-by: Josh Russett <[email protected]>
  • Loading branch information
kathap authored and jrussett committed Oct 19, 2023
1 parent f86be66 commit 38e7fdd
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 5 deletions.
8 changes: 8 additions & 0 deletions app/controllers/v3/service_route_bindings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ def destroy

def parameters
route_binding_not_found! unless @route_binding && can_read_from_space?(@route_binding.route.space)
not_found_with_message!(@route_binding) unless @route_binding.create_succeeded?

unauthorized! unless can_write_to_active_space?(@route_binding.route.space)
suspended! unless is_space_active?(@route_binding.route.space)

Expand Down Expand Up @@ -244,6 +246,12 @@ def route_binding_not_found!
resource_not_found!(:service_route_binding)
end

def not_found_with_message!(service_route_binding)
operation = service_route_binding.last_operation.type == 'create' ? 'Creation' : 'Deletion'
state = service_route_binding.last_operation.state
resource_not_found_with_message!("#{operation} of route binding #{state}")
end

def service_instance_not_found!(guid)
unprocessable!("The service instance could not be found: #{guid}")
end
Expand Down
84 changes: 79 additions & 5 deletions spec/request/service_route_bindings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1628,7 +1628,24 @@
end
end

context 'when there is an operation in progress' do
context "when last binding operation is in 'create succeeded' state" do
before do
binding.save_with_new_operation({}, {
type: 'create',
state: 'succeeded'
})
end

it 'returns the parameters' do
api_call.call(admin_headers)
expect(last_response).to have_status_code(200)
expect(parsed_response).to include(
{ 'abra' => 'kadabra', 'kadabra' => 'alakazan' }
)
end
end

context "when last binding operation is in 'create in progress' state" do
before do
binding.save_with_new_operation({}, {
type: 'create',
Expand All @@ -1638,16 +1655,73 @@

it 'returns the appropriate error' do
api_call.call(admin_headers)
expect(last_response).to have_status_code(422)
expect(last_response).to have_status_code(404)
expect(parsed_response['errors']).to include(
include({
'detail' => 'There is an operation in progress for the service route binding.',
'title' => 'CF-UnprocessableEntity',
'code' => 10_008
'detail' => 'Creation of route binding in progress',
'title' => 'CF-ResourceNotFound',
'code' => 10_010
})
)
end
end

context "when last binding operation is in 'create failed' state" do
before do
binding.save_with_new_operation({}, {
type: 'create',
state: 'failed'
})
end

it 'returns an error' do
api_call.call(admin_headers)
expect(last_response).to have_status_code(404)
expect(parsed_response['errors']).to include(include({
'detail' => 'Creation of route binding failed',
'title' => 'CF-ResourceNotFound',
'code' => 10_010
}))
end
end

context "when last binding operation is in 'delete failed' state" do
before do
binding.save_with_new_operation({}, {
type: 'delete',
state: 'failed'
})
end

it 'returns an error' do
api_call.call(admin_headers)
expect(last_response).to have_status_code(404)
expect(parsed_response['errors']).to include(include({
'detail' => 'Deletion of route binding failed',
'title' => 'CF-ResourceNotFound',
'code' => 10_010
}))
end
end

context "when last binding operation is in 'delete in progress' state" do
before do
binding.save_with_new_operation({}, {
type: 'delete',
state: 'in progress'
})
end

it 'returns an error' do
api_call.call(admin_headers)
expect(last_response).to have_status_code(404)
expect(parsed_response['errors']).to include(include({
'detail' => 'Deletion of route binding in progress',
'title' => 'CF-ResourceNotFound',
'code' => 10_010
}))
end
end
end

context 'user provided service instances' do
Expand Down

0 comments on commit 38e7fdd

Please sign in to comment.