Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 2dbf62c

Browse files
v3(services): Only update expected binding fields when creating a
binding OSBAPI spec outlines the broker expected response for a create binding and indicates that any other field return by brokers should be ignored. v2 has this behaviour but was missing in v3 and was causing failures when the broker response includes attributes that are not part of the CC DB. This is so we don't try to update any other fields. [#175662475](https://www.pivotaltracker.com/story/show/175662475)
1 parent ce3d1a0 commit 2dbf62c

3 files changed

Lines changed: 35 additions & 6 deletions

File tree

app/actions/service_credential_binding_app_create.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def initialize(user_audit_info, audit_hash)
1717
@audit_hash = audit_hash
1818
end
1919

20+
PERMITTED_BINDING_ATTRIBUTES = [:credentials, :syslog_drain_url, :volume_mounts].freeze
21+
2022
def precursor(service_instance, app: nil, name: nil, volume_mount_services_enabled: false)
2123
validate!(service_instance, app, volume_mount_services_enabled)
2224

@@ -45,7 +47,7 @@ def precursor(service_instance, app: nil, name: nil, volume_mount_services_enabl
4547

4648
def complete_binding_and_save(binding, binding_details, last_operation)
4749
binding.save_with_attributes_and_new_operation(
48-
binding_details,
50+
binding_details.symbolize_keys().slice(*PERMITTED_BINDING_ATTRIBUTES),
4951
{
5052
type: 'create',
5153
state: last_operation[:state],

spec/request/service_credential_bindings_spec.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,18 @@ def check_filtered_bindings(*bindings)
13821382
{
13831383
syslog_drain_url: syslog_drain_url,
13841384
credentials: credentials,
1385-
parameters: parameters
1385+
parameters: parameters,
1386+
service_id:'extra-field-service_id',
1387+
plan_id:'extra-field-plan_id',
1388+
name: 'extra-field-name',
1389+
bind_resource:{
1390+
app_guid:'extra-field',
1391+
space_guid:'extra-field'
1392+
},
1393+
context:
1394+
{
1395+
platform:'extra-field',
1396+
}
13861397
}
13871398
end
13881399

@@ -1409,11 +1420,12 @@ def check_filtered_bindings(*bindings)
14091420
expect(job.state).to eq(VCAP::CloudController::PollableJobModel::COMPLETE_STATE)
14101421
end
14111422

1412-
it 'updates the binding details with the fetch binding response' do
1423+
it 'updates the binding details with the fetch binding response ignoring extra fields' do
14131424
execute_all_jobs(expected_successes: 1, expected_failures: 0)
14141425

14151426
expect(binding.reload.syslog_drain_url).to eq(syslog_drain_url)
14161427
expect(binding.credentials).to eq(credentials.with_indifferent_access)
1428+
expect(binding.name).to eq('some-name')
14171429
end
14181430

14191431
context 'fetching binding fails ' do

spec/unit/actions/service_credential_binding_app_create_spec.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,23 @@ module V3
258258
end
259259

260260
describe '#poll' do
261-
let(:binding) { action.precursor(service_instance, app: app) }
261+
let(:binding) { action.precursor(service_instance, app: app, name: 'original-name') }
262262
let(:credentials) { { 'password' => 'rennt', 'username' => 'lola' } }
263+
let(:volume_mounts) { [{
264+
'driver' => 'cephdriver',
265+
'container_dir' => '/data/images',
266+
'mode' => 'r',
267+
'device_type' => 'shared',
268+
'device' => {
269+
'volume_id' => 'bc2c1eab-05b9-482d-b0cf-750ee07de311',
270+
'mount_config' => {
271+
'key' => 'value'
272+
}
273+
}
274+
}]
275+
}
263276
let(:syslog_drain_url) { 'https://drain.syslog.example.com/runlolarun' }
264-
let(:fetch_binding_response) { { credentials: credentials, syslog_drain_url: syslog_drain_url } }
277+
let(:fetch_binding_response) { { credentials: credentials, syslog_drain_url: syslog_drain_url, volume_mounts: volume_mounts, name: 'updated-name' } }
265278

266279
it_behaves_like 'polling service binding creation'
267280

@@ -302,14 +315,16 @@ module V3
302315
let(:description) { Sham.description }
303316
let(:state) { 'succeeded' }
304317

305-
it 'fetches the service binding and updates the route_services_url' do
318+
it 'fetches the service binding and updates only the credentials, volume_mounts and syslog_drain_url' do
306319
action.poll(binding)
307320

308321
expect(broker_client).to have_received(:fetch_service_binding).with(binding)
309322

310323
binding.reload
311324
expect(binding.credentials).to eq(credentials)
312325
expect(binding.syslog_drain_url).to eq(syslog_drain_url)
326+
expect(binding.volume_mounts).to eq(volume_mounts)
327+
expect(binding.name).to eq('original-name')
313328
end
314329

315330
it 'creates an audit event' do

0 commit comments

Comments
 (0)