Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
81eaa356
Commit
81eaa356
authored
Jul 12, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
f31dbe5b
53c9885d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
5 deletions
+38
-5
app/services/audit_event_service.rb
app/services/audit_event_service.rb
+5
-1
changelogs/unreleased/sh-audit-event-json-log-format-from-and-to.yml
...unreleased/sh-audit-event-json-log-format-from-and-to.yml
+5
-0
spec/services/audit_event_service_spec.rb
spec/services/audit_event_service_spec.rb
+28
-4
No files found.
app/services/audit_event_service.rb
View file @
81eaa356
...
...
@@ -35,8 +35,12 @@ class AuditEventService
@file_logger
||=
Gitlab
::
AuditJsonLogger
.
build
end
def
formatted_details
@details
.
merge
(
@details
.
slice
(
:from
,
:to
).
transform_values
(
&
:to_s
))
end
def
log_security_event_to_file
file_logger
.
info
(
base_payload
.
merge
(
@
details
))
file_logger
.
info
(
base_payload
.
merge
(
formatted_
details
))
end
def
log_security_event_to_database
...
...
changelogs/unreleased/sh-audit-event-json-log-format-from-and-to.yml
0 → 100644
View file @
81eaa356
---
title
:
Format `from` and `to` fields in JSON audit log
merge_request
:
30333
author
:
type
:
changed
spec/services/audit_event_service_spec.rb
View file @
81eaa356
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment