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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
0135d57b
Commit
0135d57b
authored
Aug 01, 2017
by
Alexander Randa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix encoding error for WebHook logging
parent
1ec24154
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
1 deletion
+28
-1
app/services/web_hook_service.rb
app/services/web_hook_service.rb
+7
-1
changelogs/unreleased/35815-webhook-log-encoding-error.yml
changelogs/unreleased/35815-webhook-log-encoding-error.yml
+4
-0
spec/services/web_hook_service_spec.rb
spec/services/web_hook_service_spec.rb
+17
-0
No files found.
app/services/web_hook_service.rb
View file @
0135d57b
...
@@ -101,7 +101,7 @@ class WebHookService
...
@@ -101,7 +101,7 @@ class WebHookService
request_headers:
build_headers
(
hook_name
),
request_headers:
build_headers
(
hook_name
),
request_data:
request_data
,
request_data:
request_data
,
response_headers:
format_response_headers
(
response
),
response_headers:
format_response_headers
(
response
),
response_body:
response
.
body
,
response_body:
safe_response_body
(
response
)
,
response_status:
response
.
code
,
response_status:
response
.
code
,
internal_error_message:
error_message
internal_error_message:
error_message
)
)
...
@@ -124,4 +124,10 @@ class WebHookService
...
@@ -124,4 +124,10 @@ class WebHookService
def
format_response_headers
(
response
)
def
format_response_headers
(
response
)
response
.
headers
.
each_capitalized
.
to_h
response
.
headers
.
each_capitalized
.
to_h
end
end
def
safe_response_body
(
response
)
return
''
unless
response
.
body
response
.
body
.
encode
(
'UTF-8'
,
invalid: :replace
,
undef: :replace
,
replace:
''
)
end
end
end
changelogs/unreleased/35815-webhook-log-encoding-error.yml
0 → 100644
View file @
0135d57b
---
title
:
Fix encoding error for WebHook logging
merge_request
:
13230
author
:
Alexander Randa (@randaalex)
spec/services/web_hook_service_spec.rb
View file @
0135d57b
...
@@ -112,6 +112,23 @@ describe WebHookService do
...
@@ -112,6 +112,23 @@ describe WebHookService do
end
end
end
end
context
'with unsafe response body'
do
before
do
WebMock
.
stub_request
(
:post
,
project_hook
.
url
).
to_return
(
status:
200
,
body:
"
\xBB
"
)
service_instance
.
execute
end
it
'log successful execution'
do
expect
(
hook_log
.
trigger
).
to
eq
(
'push_hooks'
)
expect
(
hook_log
.
url
).
to
eq
(
project_hook
.
url
)
expect
(
hook_log
.
request_headers
).
to
eq
(
headers
)
expect
(
hook_log
.
response_body
).
to
eq
(
''
)
expect
(
hook_log
.
response_status
).
to
eq
(
'200'
)
expect
(
hook_log
.
execution_duration
).
to
be
>
0
expect
(
hook_log
.
internal_error_message
).
to
be_nil
end
end
context
'should not log ServiceHooks'
do
context
'should not log ServiceHooks'
do
let
(
:service_hook
)
{
create
(
:service_hook
)
}
let
(
:service_hook
)
{
create
(
:service_hook
)
}
let
(
:service_instance
)
{
described_class
.
new
(
service_hook
,
data
,
'service_hook'
)
}
let
(
:service_instance
)
{
described_class
.
new
(
service_hook
,
data
,
'service_hook'
)
}
...
...
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