Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/repositories/service_binding_event_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def record_event(type:, service_binding:, user_audit_info:, metadata: {})
actor_username: user_audit_info.user_name,
actee: service_binding.guid,
actee_type: 'service_binding',
actee_name: '',
actee_name: service_binding.name || '',
space_guid: service_binding.space.guid,
organization_guid: service_binding.space.organization.guid,
timestamp: Sequel::CURRENT_TIMESTAMP,
Expand Down
3 changes: 3 additions & 0 deletions spec/request/service_credential_bindings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,7 @@ def check_filtered_bindings(*bindings)
expect(last_response).to have_status_code(201)
expect(parsed_response).to have_key('guid')
@binding_guid = parsed_response['guid']
@binding_name = parsed_response['name']
end

it 'creates a new service credential binding' do
Expand Down Expand Up @@ -1016,6 +1017,7 @@ def check_filtered_bindings(*bindings)
event = VCAP::CloudController::Event.find(type: 'audit.service_binding.create')
expect(event).to be
expect(event.actee).to eq(@binding_guid)
expect(event.actee_name).to eq(@binding_name)
end

it 'sets the right details' do
Expand Down Expand Up @@ -1216,6 +1218,7 @@ def check_filtered_bindings(*bindings)
event = VCAP::CloudController::Event.find(type: 'audit.service_binding.create')
expect(event).to be
expect(event.actee).to eq(binding.guid)
expect(event.actee_name).to eq(binding.name)
expect(event.data).to include({
'request' => create_body.with_indifferent_access
})
Expand Down
46 changes: 41 additions & 5 deletions spec/unit/repositories/service_binding_event_repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Repositories
let(:user_email) { 'some-email' }
let(:user_name) { 'some-username' }
let(:user_audit_info) { UserAuditInfo.new(user_guid: user_guid, user_name: user_name, user_email: user_email) }
let(:service_binding) { ServiceBinding.make }
let(:service_binding) { ServiceBinding.make(name: 'some-binding-name') }

describe '.record_start_create' do
it 'creates an audit.service_binding.start_create event' do
Expand All @@ -22,7 +22,7 @@ module Repositories
expect(event.actor_username).to eq(user_name)
expect(event.actee).to eq(service_binding.guid)
expect(event.actee_type).to eq('service_binding')
expect(event.actee_name).to eq('')
expect(event.actee_name).to eq('some-binding-name')
expect(event.space_guid).to eq(service_binding.space.guid)
expect(event.organization_guid).to eq(service_binding.space.organization.guid)
expect(event.metadata[:request]).to eq(
Expand Down Expand Up @@ -53,6 +53,15 @@ module Repositories
expect(event.metadata[:manifest_triggered]).to eq(true)
end
end

context 'when binding name is not set' do
let(:service_binding) { ServiceBinding.make(name: nil) }

it 'records actee_name as empty' do
event = ServiceBindingEventRepository.record_start_create(service_binding, user_audit_info, {})
expect(event.actee_name).to eq('')
end
end
end

describe '.record_create' do
Expand All @@ -67,7 +76,7 @@ module Repositories
expect(event.actor_username).to eq(user_name)
expect(event.actee).to eq(service_binding.guid)
expect(event.actee_type).to eq('service_binding')
expect(event.actee_name).to eq('')
expect(event.actee_name).to eq('some-binding-name')
expect(event.space_guid).to eq(service_binding.space.guid)
expect(event.organization_guid).to eq(service_binding.space.organization.guid)
expect(event.metadata[:request]).to eq(
Expand Down Expand Up @@ -98,6 +107,15 @@ module Repositories
expect(event.metadata[:manifest_triggered]).to eq(true)
end
end

context 'when binding name is not set' do
let(:service_binding) { ServiceBinding.make(name: nil) }

it 'records actee_name as empty' do
event = ServiceBindingEventRepository.record_create(service_binding, user_audit_info, {})
expect(event.actee_name).to eq('')
end
end
end

describe '.record_start_delete' do
Expand All @@ -111,7 +129,7 @@ module Repositories
expect(event.actor_username).to eq(user_name)
expect(event.actee).to eq(service_binding.guid)
expect(event.actee_type).to eq('service_binding')
expect(event.actee_name).to eq('')
expect(event.actee_name).to eq('some-binding-name')
expect(event.space_guid).to eq(service_binding.space.guid)
expect(event.organization_guid).to eq(service_binding.space.organization.guid)
expect(event.metadata).to eq(
Expand All @@ -121,6 +139,15 @@ module Repositories
},
)
end

context 'when binding name is not set' do
let(:service_binding) { ServiceBinding.make(name: nil) }

it 'records actee_name as empty' do
event = ServiceBindingEventRepository.record_start_delete(service_binding, user_audit_info)
expect(event.actee_name).to eq('')
end
end
end

describe '.record_delete' do
Expand All @@ -134,7 +161,7 @@ module Repositories
expect(event.actor_username).to eq(user_name)
expect(event.actee).to eq(service_binding.guid)
expect(event.actee_type).to eq('service_binding')
expect(event.actee_name).to eq('')
expect(event.actee_name).to eq('some-binding-name')
expect(event.space_guid).to eq(service_binding.space.guid)
expect(event.organization_guid).to eq(service_binding.space.organization.guid)
expect(event.metadata).to eq(
Expand All @@ -144,6 +171,15 @@ module Repositories
},
)
end

context 'when binding name is not set' do
let(:service_binding) { ServiceBinding.make(name: nil) }

it 'records actee_name as empty' do
event = ServiceBindingEventRepository.record_delete(service_binding, user_audit_info)
expect(event.actee_name).to eq('')
end
end
end
end
end
Expand Down