diff options
author | Stan Hu <stanhu@gmail.com> | 2019-07-04 01:58:05 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-07-11 23:46:51 +0300 |
commit | e19499caf53c7da022333b1f354be058955991e8 (patch) | |
tree | 9c39d30f9e357c40d2afad0b38c0c17bdd8b8365 /spec/services/audit_event_service_spec.rb | |
parent | d50125a03fffe64cd8976f1c8b2e5b66e5fc5b2d (diff) |
Format `from` and `to` fields in JSON audit log
To make it possible to index the `from` and `to` fields with
Elasticsearch and other tools, we need the types to be the same.
Currently they are a mix of boolean and string values.
Part of https://gitlab.com/gitlab-org/gitlab-ee/issues/12599
Diffstat (limited to 'spec/services/audit_event_service_spec.rb')
-rw-r--r-- | spec/services/audit_event_service_spec.rb | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/spec/services/audit_event_service_spec.rb b/spec/services/audit_event_service_spec.rb index 32fd98e6ef9..e42bff607b2 100644 --- a/spec/services/audit_event_service_spec.rb +++ b/spec/services/audit_event_service_spec.rb @@ -10,11 +10,8 @@ describe AuditEventService do let(:logger) { instance_double(Gitlab::AuditJsonLogger) } describe '#security_event' do - before do - expect(service).to receive(:file_logger).and_return(logger) - end - it 'creates an event and logs to a file' do + expect(service).to receive(:file_logger).and_return(logger) expect(logger).to receive(:info).with(author_id: user.id, entity_id: project.id, entity_type: "Project", @@ -22,5 +19,32 @@ describe AuditEventService do expect { service.security_event }.to change(SecurityEvent, :count).by(1) end + + it 'formats from and to fields' do + service = described_class.new( + user, project, + { + from: true, + to: false, + action: :create, + target_id: 1 + }) + expect(service).to receive(:file_logger).and_return(logger) + expect(logger).to receive(:info).with(author_id: user.id, + entity_type: 'Project', + entity_id: project.id, + from: 'true', + to: 'false', + action: :create, + target_id: 1) + + expect { service.security_event }.to change(SecurityEvent, :count).by(1) + + details = SecurityEvent.last.details + expect(details[:from]).to be true + expect(details[:to]).to be false + expect(details[:action]).to eq(:create) + expect(details[:target_id]).to eq(1) + end end end |