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

Commit 38a5419

Browse files
author
Derik Evangelista
authored
v3(bindings): can create bindings with params (cloudfoundry#1904)
[#175203762](https://www.pivotaltracker.com/story/show/175203762)
1 parent 4049f82 commit 38a5419

3 files changed

Lines changed: 53 additions & 10 deletions

File tree

app/models/services/service_binding.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def save_with_attributes_and_new_operation(attributes, operation)
152152
def save_with_new_operation(last_operation, attributes: {})
153153
ServiceBinding.db.transaction do
154154
self.lock!
155-
set(attributes)
155+
set(attributes.except(:parameters, :route_services_url, :endpoints))
156156
save_changes
157157

158158
if self.last_operation

spec/request/service_credential_bindings_spec.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,11 +1307,15 @@ def check_filtered_bindings(*bindings)
13071307
let(:state) { 'succeeded' }
13081308
let(:fetch_binding_status_code) { 200 }
13091309
let(:syslog_drain_url) { 'http://syslog.example.com/wow' }
1310+
let(:route_service_url) { 'http://route.example.com/wow' }
13101311
let(:credentials) { { password: 'foo' } }
1312+
let(:parameters) { { foo: 'bar', another_foo: 'another_bar' } }
1313+
13111314
let(:fetch_binding_body) do
13121315
{
13131316
syslog_drain_url: syslog_drain_url,
1314-
credentials: credentials
1317+
credentials: credentials,
1318+
parameters: parameters
13151319
}
13161320
end
13171321

@@ -1338,6 +1342,13 @@ def check_filtered_bindings(*bindings)
13381342
expect(job.state).to eq(VCAP::CloudController::PollableJobModel::COMPLETE_STATE)
13391343
end
13401344

1345+
it 'updates the binding details with the fetch binding response' do
1346+
execute_all_jobs(expected_successes: 1, expected_failures: 0)
1347+
1348+
expect(binding.reload.syslog_drain_url).to eq(syslog_drain_url)
1349+
expect(binding.credentials).to eq(credentials.with_indifferent_access)
1350+
end
1351+
13411352
context 'fetching binding fails ' do
13421353
let(:fetch_binding_status_code) { 404 }
13431354
let(:fetch_binding_body) {}

spec/unit/models/services/service_binding_spec.rb

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -498,22 +498,54 @@ def new_model
498498
end
499499

500500
context 'when attributes are passed in' do
501-
it 'updates the attributes' do
502-
last_operation = {
503-
state: 'in progress',
504-
type: 'create',
505-
description: '10%'
501+
let(:credentials) { { password: 'rice' } }
502+
let(:syslog_drain_url) { 'http://foo.example.com/bar' }
503+
let(:volume_mounts) { [{
504+
container_dir: '/var/vcap/data/153e3c4b-1151-4cf7-b311-948dd77fce64',
505+
device_type: 'shared',
506+
mode: 'rw'
507+
}.with_indifferent_access]
508+
}
509+
let(:attributes) {
510+
{
511+
name: 'gohan',
512+
credentials: credentials,
513+
syslog_drain_url: syslog_drain_url,
514+
volume_mounts: volume_mounts
506515
}
507-
attributes = { name: 'gohan', credentials: { password: 'rice' } }
508-
binding.save_with_new_operation(last_operation, attributes: attributes)
516+
}
517+
let(:last_operation) { {
518+
state: 'in progress',
519+
type: 'create',
520+
description: '10%'
521+
}
522+
}
509523

524+
it 'updates the attributes' do
525+
binding.save_with_new_operation(last_operation, attributes: attributes)
526+
binding.reload
510527
expect(binding.last_operation.state).to eq 'in progress'
511528
expect(binding.last_operation.description).to eq '10%'
512529
expect(binding.last_operation.type).to eq 'create'
513530
expect(binding.name).to eq 'gohan'
514-
expect(binding.credentials).to eq({ 'password' => 'rice' })
531+
expect(binding.credentials).to eq(credentials.with_indifferent_access)
532+
expect(binding.syslog_drain_url).to eq('http://foo.example.com/bar')
533+
expect(binding.volume_mounts).to eq(volume_mounts)
515534
expect(ServiceBinding.count).to eq(1)
516535
end
536+
537+
it 'only saves permitted attributes' do
538+
expect {
539+
binding.save_with_new_operation(last_operation, attributes: attributes.merge(
540+
parameters: {
541+
foo: 'bar',
542+
ding: 'dong'
543+
},
544+
endpoints: [{ host: 'mysqlhost', ports: ['3306'] }],
545+
route_services_url: 'http://route.example.com'
546+
))
547+
} .not_to raise_error
548+
end
517549
end
518550
end
519551

0 commit comments

Comments
 (0)