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

Commit 9827bb8

Browse files
author
Derik Evangelista
authored
v2/v3(binding): use binding name on audit logs (cloudfoundry#1915)
[#162082232](https://www.pivotaltracker.com/story/show/162082232)
1 parent ab01bc9 commit 9827bb8

3 files changed

Lines changed: 45 additions & 6 deletions

File tree

app/repositories/service_binding_event_repository.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def record_event(type:, service_binding:, user_audit_info:, metadata: {})
7373
actor_username: user_audit_info.user_name,
7474
actee: service_binding.guid,
7575
actee_type: 'service_binding',
76-
actee_name: '',
76+
actee_name: service_binding.name || '',
7777
space_guid: service_binding.space.guid,
7878
organization_guid: service_binding.space.organization.guid,
7979
timestamp: Sequel::CURRENT_TIMESTAMP,

spec/request/service_credential_bindings_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,7 @@ def check_filtered_bindings(*bindings)
970970
expect(last_response).to have_status_code(201)
971971
expect(parsed_response).to have_key('guid')
972972
@binding_guid = parsed_response['guid']
973+
@binding_name = parsed_response['name']
973974
end
974975

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

10211023
it 'sets the right details' do
@@ -1216,6 +1218,7 @@ def check_filtered_bindings(*bindings)
12161218
event = VCAP::CloudController::Event.find(type: 'audit.service_binding.create')
12171219
expect(event).to be
12181220
expect(event.actee).to eq(binding.guid)
1221+
expect(event.actee_name).to eq(binding.name)
12191222
expect(event.data).to include({
12201223
'request' => create_body.with_indifferent_access
12211224
})

spec/unit/repositories/service_binding_event_repository_spec.rb

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Repositories
88
let(:user_email) { 'some-email' }
99
let(:user_name) { 'some-username' }
1010
let(:user_audit_info) { UserAuditInfo.new(user_guid: user_guid, user_name: user_name, user_email: user_email) }
11-
let(:service_binding) { ServiceBinding.make }
11+
let(:service_binding) { ServiceBinding.make(name: 'some-binding-name') }
1212

1313
describe '.record_start_create' do
1414
it 'creates an audit.service_binding.start_create event' do
@@ -22,7 +22,7 @@ module Repositories
2222
expect(event.actor_username).to eq(user_name)
2323
expect(event.actee).to eq(service_binding.guid)
2424
expect(event.actee_type).to eq('service_binding')
25-
expect(event.actee_name).to eq('')
25+
expect(event.actee_name).to eq('some-binding-name')
2626
expect(event.space_guid).to eq(service_binding.space.guid)
2727
expect(event.organization_guid).to eq(service_binding.space.organization.guid)
2828
expect(event.metadata[:request]).to eq(
@@ -53,6 +53,15 @@ module Repositories
5353
expect(event.metadata[:manifest_triggered]).to eq(true)
5454
end
5555
end
56+
57+
context 'when binding name is not set' do
58+
let(:service_binding) { ServiceBinding.make(name: nil) }
59+
60+
it 'records actee_name as empty' do
61+
event = ServiceBindingEventRepository.record_start_create(service_binding, user_audit_info, {})
62+
expect(event.actee_name).to eq('')
63+
end
64+
end
5665
end
5766

5867
describe '.record_create' do
@@ -67,7 +76,7 @@ module Repositories
6776
expect(event.actor_username).to eq(user_name)
6877
expect(event.actee).to eq(service_binding.guid)
6978
expect(event.actee_type).to eq('service_binding')
70-
expect(event.actee_name).to eq('')
79+
expect(event.actee_name).to eq('some-binding-name')
7180
expect(event.space_guid).to eq(service_binding.space.guid)
7281
expect(event.organization_guid).to eq(service_binding.space.organization.guid)
7382
expect(event.metadata[:request]).to eq(
@@ -98,6 +107,15 @@ module Repositories
98107
expect(event.metadata[:manifest_triggered]).to eq(true)
99108
end
100109
end
110+
111+
context 'when binding name is not set' do
112+
let(:service_binding) { ServiceBinding.make(name: nil) }
113+
114+
it 'records actee_name as empty' do
115+
event = ServiceBindingEventRepository.record_create(service_binding, user_audit_info, {})
116+
expect(event.actee_name).to eq('')
117+
end
118+
end
101119
end
102120

103121
describe '.record_start_delete' do
@@ -111,7 +129,7 @@ module Repositories
111129
expect(event.actor_username).to eq(user_name)
112130
expect(event.actee).to eq(service_binding.guid)
113131
expect(event.actee_type).to eq('service_binding')
114-
expect(event.actee_name).to eq('')
132+
expect(event.actee_name).to eq('some-binding-name')
115133
expect(event.space_guid).to eq(service_binding.space.guid)
116134
expect(event.organization_guid).to eq(service_binding.space.organization.guid)
117135
expect(event.metadata).to eq(
@@ -121,6 +139,15 @@ module Repositories
121139
},
122140
)
123141
end
142+
143+
context 'when binding name is not set' do
144+
let(:service_binding) { ServiceBinding.make(name: nil) }
145+
146+
it 'records actee_name as empty' do
147+
event = ServiceBindingEventRepository.record_start_delete(service_binding, user_audit_info)
148+
expect(event.actee_name).to eq('')
149+
end
150+
end
124151
end
125152

126153
describe '.record_delete' do
@@ -134,7 +161,7 @@ module Repositories
134161
expect(event.actor_username).to eq(user_name)
135162
expect(event.actee).to eq(service_binding.guid)
136163
expect(event.actee_type).to eq('service_binding')
137-
expect(event.actee_name).to eq('')
164+
expect(event.actee_name).to eq('some-binding-name')
138165
expect(event.space_guid).to eq(service_binding.space.guid)
139166
expect(event.organization_guid).to eq(service_binding.space.organization.guid)
140167
expect(event.metadata).to eq(
@@ -144,6 +171,15 @@ module Repositories
144171
},
145172
)
146173
end
174+
175+
context 'when binding name is not set' do
176+
let(:service_binding) { ServiceBinding.make(name: nil) }
177+
178+
it 'records actee_name as empty' do
179+
event = ServiceBindingEventRepository.record_delete(service_binding, user_audit_info)
180+
expect(event.actee_name).to eq('')
181+
end
182+
end
147183
end
148184
end
149185
end

0 commit comments

Comments
 (0)