1414 space . add_developer ( user )
1515 headers_for ( user )
1616 end
17+ let ( :parameters_mixed_data_types_as_json_string ) do
18+ '{"boolean":true,"string":"a string","int":123,"float":3.14159,"optional":null,"object":{"a":"b"},"array":["c","d"]}'
19+ end
20+ let ( :parameters_mixed_data_types_as_hash ) do
21+ {
22+ boolean : true ,
23+ string : 'a string' ,
24+ int : 123 ,
25+ float : 3.14159 ,
26+ optional : nil ,
27+ object : { a : 'b' } ,
28+ array : %w[ c d ]
29+ }
30+ end
1731
1832 describe 'GET /v3/service_credential_bindings' do
1933 it_behaves_like 'list query endpoint' do
@@ -1072,11 +1086,7 @@ def check_filtered_bindings(*bindings)
10721086 end
10731087 end
10741088
1075- context 'when the broker will returns params' do
1076- before do
1077- stub_param_broker_request_for_binding ( binding , binding_params )
1078- end
1079-
1089+ context 'when the broker returns params' do
10801090 it 'sends a request to the broker including the identity header' do
10811091 api_call . call ( headers_for ( user , scopes : %w[ cloud_controller.admin ] ) )
10821092
@@ -1096,6 +1106,24 @@ def check_filtered_bindings(*bindings)
10961106 expect ( last_response ) . to have_status_code ( 200 )
10971107 expect ( parsed_response ) . to eq ( binding_params )
10981108 end
1109+
1110+ context 'when the broker returns params with mixed data types' do
1111+ before do
1112+ stub_param_broker_request_for_binding_with_json_string ( binding , parameters_mixed_data_types_as_json_string )
1113+ end
1114+
1115+ it 'correctly parses all data types and returns the desired JSON string' do
1116+ allow_any_instance_of ( VCAP ::CloudController ::ServiceBindingRead ) . to receive ( :fetch_parameters ) . and_wrap_original do |m , instance |
1117+ result = m . call ( instance )
1118+ expect ( result ) . to eq ( parameters_mixed_data_types_as_hash ) # correct internal representation
1119+ result
1120+ end
1121+
1122+ api_call . call ( admin_headers )
1123+ expect ( last_response ) . to have_status_code ( 200 )
1124+ expect ( last_response ) . to match ( /#{ Regexp . escape ( parameters_mixed_data_types_as_json_string ) } / )
1125+ end
1126+ end
10991127 end
11001128 end
11011129 end
@@ -1134,11 +1162,31 @@ def check_filtered_bindings(*bindings)
11341162 ) . to have_been_made . once
11351163 end
11361164
1137- it 'returns the params in the response body' do
1138- api_call . call ( admin_headers )
1165+ context 'when the broker returns params' do
1166+ it 'returns the params in the response body' do
1167+ api_call . call ( admin_headers )
11391168
1140- expect ( last_response ) . to have_status_code ( 200 )
1141- expect ( parsed_response ) . to eq ( binding_params )
1169+ expect ( last_response ) . to have_status_code ( 200 )
1170+ expect ( parsed_response ) . to eq ( binding_params )
1171+ end
1172+
1173+ context 'when the broker returns params with mixed data types' do
1174+ before do
1175+ stub_param_broker_request_for_binding_with_json_string ( binding , parameters_mixed_data_types_as_json_string )
1176+ end
1177+
1178+ it 'correctly parses all data types and returns the desired JSON string' do
1179+ allow_any_instance_of ( VCAP ::CloudController ::ServiceBindingRead ) . to receive ( :fetch_parameters ) . and_wrap_original do |m , instance |
1180+ result = m . call ( instance )
1181+ expect ( result ) . to eq ( parameters_mixed_data_types_as_hash ) # correct internal representation
1182+ result
1183+ end
1184+
1185+ api_call . call ( admin_headers )
1186+ expect ( last_response ) . to have_status_code ( 200 )
1187+ expect ( last_response ) . to match ( /#{ Regexp . escape ( parameters_mixed_data_types_as_json_string ) } / )
1188+ end
1189+ end
11421190 end
11431191
11441192 context "last service key operation is in 'create succeeded' state" do
@@ -1643,6 +1691,28 @@ def check_filtered_bindings(*bindings)
16431691 expect ( service_instance . service_bindings . count ) . to eq ( 0 )
16441692 end
16451693 end
1694+
1695+ context 'when providing parameters with mixed data types' do
1696+ let ( :request_body ) do
1697+ "{\" type\" :\" app\" ,\" name\" :\" #{ binding_name } \" ," \
1698+ "\" relationships\" :{\" service_instance\" :{\" data\" :{\" guid\" :\" #{ service_instance_guid } \" }},\" app\" :{\" data\" :{\" guid\" :\" #{ app_guid } \" }}}," \
1699+ "\" parameters\" :#{ parameters_mixed_data_types_as_json_string } }"
1700+ end
1701+
1702+ it 'correctly parses all data types and sends the desired JSON string to the service broker' do
1703+ post '/v3/service_credential_bindings' , request_body , admin_headers
1704+
1705+ expect_any_instance_of ( VCAP ::Services ::ServiceBrokers ::V2 ::Client ) . to receive ( :bind ) .
1706+ with ( binding , hash_including ( arbitrary_parameters : parameters_mixed_data_types_as_hash ) ) . # correct internal representation
1707+ and_call_original
1708+
1709+ stub_request ( :put , "#{ service_instance . service_broker . broker_url } /v2/service_instances/#{ service_instance_guid } /service_bindings/#{ binding . guid } " ) .
1710+ with ( query : { accepts_incomplete : true } , body : /"parameters":#{ Regexp . escape ( parameters_mixed_data_types_as_json_string ) } / ) .
1711+ to_return ( status : 201 , body : '{}' )
1712+
1713+ execute_all_jobs ( expected_successes : 1 , expected_failures : 0 )
1714+ end
1715+ end
16461716 end
16471717 end
16481718
@@ -1877,6 +1947,29 @@ def check_filtered_bindings(*bindings)
18771947 expect ( service_instance . service_keys . count ) . to eq ( 0 )
18781948 end
18791949 end
1950+
1951+ context 'when providing parameters with mixed data types' do
1952+ let ( :key ) { VCAP ::CloudController ::ServiceKey . last }
1953+ let ( :request_body ) do
1954+ "{\" type\" :\" key\" ,\" name\" :\" #{ binding_name } \" ," \
1955+ "\" relationships\" :{\" service_instance\" :{\" data\" :{\" guid\" :\" #{ service_instance_guid } \" }}}," \
1956+ "\" parameters\" :#{ parameters_mixed_data_types_as_json_string } }"
1957+ end
1958+
1959+ it 'correctly parses all data types and sends the desired JSON string to the service broker' do
1960+ post '/v3/service_credential_bindings' , request_body , admin_headers
1961+
1962+ expect_any_instance_of ( VCAP ::Services ::ServiceBrokers ::V2 ::Client ) . to receive ( :bind ) .
1963+ with ( key , hash_including ( arbitrary_parameters : parameters_mixed_data_types_as_hash ) ) . # correct internal representation
1964+ and_call_original
1965+
1966+ stub_request ( :put , "#{ service_instance . service_broker . broker_url } /v2/service_instances/#{ service_instance_guid } /service_bindings/#{ key . guid } " ) .
1967+ with ( query : { accepts_incomplete : true } , body : /"parameters":#{ Regexp . escape ( parameters_mixed_data_types_as_json_string ) } / ) .
1968+ to_return ( status : 201 , body : '{}' )
1969+
1970+ execute_all_jobs ( expected_successes : 1 , expected_failures : 0 )
1971+ end
1972+ end
18801973 end
18811974 end
18821975
@@ -2585,11 +2678,15 @@ def operate_on(binding)
25852678 end
25862679
25872680 def stub_param_broker_request_for_binding ( binding , binding_params , status : 200 )
2681+ stub_param_broker_request_for_binding_with_json_string ( binding , binding_params . to_json , status :)
2682+ end
2683+
2684+ def stub_param_broker_request_for_binding_with_json_string ( binding , binding_params_as_json_string , status : 200 )
25882685 instance = binding . service_instance
25892686 broker_url = instance . service_broker . broker_url
25902687 broker_binding_url = "#{ broker_url } /v2/service_instances/#{ instance . guid } /service_bindings/#{ binding . guid } "
25912688
25922689 stub_request ( :get , /#{ broker_binding_url } / ) .
2593- to_return ( status : status , body : { parameters : binding_params } . to_json )
2690+ to_return ( status : status , body : "{ \" parameters\" : #{ binding_params_as_json_string } }" )
25942691 end
25952692end
0 commit comments