Skip to content

Commit 63408d4

Browse files
authored
Adapt response handling for /v3/service_credential_bindings/:guid/parameters (#3465)
For GET /v3/service_credential_bindings/:guid/parameters, if the state is not create succeeded, it should not return parameters and it should raise an appropriate error.
1 parent ce3ee7b commit 63408d4

File tree

2 files changed

+143
-3
lines changed

2 files changed

+143
-3
lines changed

app/controllers/v3/service_credential_bindings_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def details
147147

148148
def parameters
149149
ensure_service_credential_binding_is_accessible!
150+
not_found_with_message!(service_credential_binding) unless service_credential_binding.create_succeeded?
150151

151152
fetcher = ServiceBindingRead.new
152153
parameters = fetcher.fetch_parameters(service_credential_binding)

spec/request/service_credential_bindings_spec.rb

Lines changed: 142 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -927,17 +927,81 @@ def check_filtered_bindings(*bindings)
927927
context 'when the service allows bindings to be fetched' do
928928
before do
929929
instance.service.update(bindings_retrievable: true)
930+
stub_param_broker_request_for_binding(binding, binding_params)
931+
end
932+
933+
context "last binding operation is in 'create succeeded' state" do
934+
before do
935+
binding.save_with_attributes_and_new_operation({}, { type: 'create', state: 'succeeded' })
936+
end
937+
938+
it 'returns parameters' do
939+
api_call.call(admin_headers)
940+
expect(last_response).to have_status_code(200)
941+
end
930942
end
931943

932-
context 'when an operation is still on going for the binding' do
944+
context "last binding operation is in 'create in progress' state" do
933945
before do
934946
binding.save_with_attributes_and_new_operation({}, { type: 'create', state: 'in progress' })
935947
end
936948

937-
it 'fails as not allowed' do
949+
it 'returns an error' do
938950
api_call.call(admin_headers)
951+
expect(last_response).to have_status_code(404)
952+
expect(parsed_response['errors']).to include(include({
953+
'detail' => 'Creation of service binding in progress',
954+
'title' => 'CF-ResourceNotFound',
955+
'code' => 10_010
956+
}))
957+
end
958+
end
939959

940-
expect(last_response).to have_status_code(409)
960+
context "last binding operation is in 'create failed' state" do
961+
before do
962+
binding.save_with_attributes_and_new_operation({}, { type: 'create', state: 'failed' })
963+
end
964+
965+
it 'returns an error' do
966+
api_call.call(admin_headers)
967+
expect(last_response).to have_status_code(404)
968+
expect(parsed_response['errors']).to include(include({
969+
'detail' => 'Creation of service binding failed',
970+
'title' => 'CF-ResourceNotFound',
971+
'code' => 10_010
972+
}))
973+
end
974+
end
975+
976+
context "last binding operation is in 'delete in progress' state" do
977+
before do
978+
binding.save_with_attributes_and_new_operation({}, { type: 'delete', state: 'in progress' })
979+
end
980+
981+
it 'returns an error' do
982+
api_call.call(admin_headers)
983+
expect(last_response).to have_status_code(404)
984+
expect(parsed_response['errors']).to include(include({
985+
'detail' => 'Deletion of service binding in progress',
986+
'title' => 'CF-ResourceNotFound',
987+
'code' => 10_010
988+
}))
989+
end
990+
end
991+
992+
context "last binding operation is in 'delete failed' state" do
993+
before do
994+
binding.save_with_attributes_and_new_operation({}, { type: 'delete', state: 'failed' })
995+
end
996+
997+
it 'returns an error' do
998+
api_call.call(admin_headers)
999+
expect(last_response).to have_status_code(404)
1000+
expect(parsed_response['errors']).to include(include({
1001+
'detail' => 'Deletion of service binding failed',
1002+
'title' => 'CF-ResourceNotFound',
1003+
'code' => 10_010
1004+
}))
9411005
end
9421006
end
9431007

@@ -1009,6 +1073,81 @@ def check_filtered_bindings(*bindings)
10091073
expect(last_response).to have_status_code(200)
10101074
expect(parsed_response).to eq(binding_params)
10111075
end
1076+
1077+
context "last service key operation is in 'create succeeded' state" do
1078+
before do
1079+
binding.save_with_attributes_and_new_operation({}, { type: 'create', state: 'succeeded' })
1080+
end
1081+
1082+
it 'returns parameters' do
1083+
api_call.call(admin_headers)
1084+
expect(last_response).to have_status_code(200)
1085+
end
1086+
end
1087+
1088+
context "last service key operation is in 'create in progress' state" do
1089+
before do
1090+
binding.save_with_attributes_and_new_operation({}, { type: 'create', state: 'in progress' })
1091+
end
1092+
1093+
it 'returns an error' do
1094+
api_call.call(admin_headers)
1095+
expect(last_response).to have_status_code(404)
1096+
expect(parsed_response['errors']).to include(include({
1097+
'detail' => 'Creation of service key in progress',
1098+
'title' => 'CF-ResourceNotFound',
1099+
'code' => 10_010
1100+
}))
1101+
end
1102+
end
1103+
1104+
context "last service key operation is in 'create failed' state" do
1105+
before do
1106+
binding.save_with_attributes_and_new_operation({}, { type: 'create', state: 'failed' })
1107+
end
1108+
1109+
it 'returns an error' do
1110+
api_call.call(admin_headers)
1111+
expect(last_response).to have_status_code(404)
1112+
expect(parsed_response['errors']).to include(include({
1113+
'detail' => 'Creation of service key failed',
1114+
'title' => 'CF-ResourceNotFound',
1115+
'code' => 10_010
1116+
}))
1117+
end
1118+
end
1119+
1120+
context "last service key operation is in 'delete in progress' state" do
1121+
before do
1122+
binding.save_with_attributes_and_new_operation({}, { type: 'delete', state: 'in progress' })
1123+
end
1124+
1125+
it 'returns an error' do
1126+
api_call.call(admin_headers)
1127+
expect(last_response).to have_status_code(404)
1128+
expect(parsed_response['errors']).to include(include({
1129+
'detail' => 'Deletion of service key in progress',
1130+
'title' => 'CF-ResourceNotFound',
1131+
'code' => 10_010
1132+
}))
1133+
end
1134+
end
1135+
1136+
context "last service key operation is in 'delete failed' state" do
1137+
before do
1138+
binding.save_with_attributes_and_new_operation({}, { type: 'delete', state: 'failed' })
1139+
end
1140+
1141+
it 'returns an error' do
1142+
api_call.call(admin_headers)
1143+
expect(last_response).to have_status_code(404)
1144+
expect(parsed_response['errors']).to include(include({
1145+
'detail' => 'Deletion of service key failed',
1146+
'title' => 'CF-ResourceNotFound',
1147+
'code' => 10_010
1148+
}))
1149+
end
1150+
end
10121151
end
10131152
end
10141153
end

0 commit comments

Comments
 (0)