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
9e201575
Commit
9e201575
authored
Sep 07, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix a wrong `X-Gitlab-Event` header when testing webhooks
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
d2cafa89
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
34 additions
and
18 deletions
+34
-18
app/services/test_hooks/base_service.rb
app/services/test_hooks/base_service.rb
+3
-4
app/services/web_hook_service.rb
app/services/web_hook_service.rb
+1
-1
changelogs/unreleased/37288-fix-wrong-header-when-testing-webhook.yml
...nreleased/37288-fix-wrong-header-when-testing-webhook.yml
+5
-0
spec/services/test_hooks/project_service_spec.rb
spec/services/test_hooks/project_service_spec.rb
+18
-9
spec/services/test_hooks/system_service_spec.rb
spec/services/test_hooks/system_service_spec.rb
+6
-3
spec/services/web_hook_service_spec.rb
spec/services/web_hook_service_spec.rb
+1
-1
No files found.
app/services/test_hooks/base_service.rb
View file @
9e201575
...
...
@@ -9,18 +9,17 @@ module TestHooks
end
def
execute
trigger_key
=
hook
.
class
::
TRIGGERS
.
key
(
trigger
.
to_sym
)
trigger_data_method
=
"
#{
trigger
}
_data"
if
!
self
.
respond_to?
(
trigger_data_method
,
true
)
||
!
hook
.
class
::
TRIGGERS
.
value?
(
trigger
.
to_sym
)
if
trigger_key
.
nil?
||
!
self
.
respond_to?
(
trigger_data_method
,
true
)
return
error
(
'Testing not available for this hook'
)
end
error_message
=
catch
(
:validation_error
)
do
sample_data
=
self
.
__send__
(
trigger_data_method
)
# rubocop:disable GitlabSecurity/PublicSend
return
hook
.
execute
(
sample_data
,
trigger
)
return
hook
.
execute
(
sample_data
,
trigger
_key
)
end
error
(
error_message
)
...
...
app/services/web_hook_service.rb
View file @
9e201575
...
...
@@ -19,7 +19,7 @@ class WebHookService
def
initialize
(
hook
,
data
,
hook_name
)
@hook
=
hook
@data
=
data
@hook_name
=
hook_name
@hook_name
=
hook_name
.
to_s
end
def
execute
...
...
changelogs/unreleased/37288-fix-wrong-header-when-testing-webhook.yml
0 → 100644
View file @
9e201575
---
title
:
Fix a wrong `X-Gitlab-Event` header when testing webhooks
merge_request
:
14108
author
:
type
:
fixed
spec/services/test_hooks/project_service_spec.rb
View file @
9e201575
...
...
@@ -21,6 +21,7 @@ describe TestHooks::ProjectService do
context
'push_events'
do
let
(
:trigger
)
{
'push_events'
}
let
(
:trigger_key
)
{
:push_hooks
}
it
'returns error message if not enough data'
do
allow
(
project
).
to
receive
(
:empty_repo?
).
and_return
(
true
)
...
...
@@ -33,13 +34,14 @@ describe TestHooks::ProjectService do
allow
(
project
).
to
receive
(
:empty_repo?
).
and_return
(
false
)
allow
(
Gitlab
::
DataBuilder
::
Push
).
to
receive
(
:build_sample
).
and_return
(
sample_data
)
expect
(
hook
).
to
receive
(
:execute
).
with
(
sample_data
,
trigger
).
and_return
(
success_result
)
expect
(
hook
).
to
receive
(
:execute
).
with
(
sample_data
,
trigger
_key
).
and_return
(
success_result
)
expect
(
service
.
execute
).
to
include
(
success_result
)
end
end
context
'tag_push_events'
do
let
(
:trigger
)
{
'tag_push_events'
}
let
(
:trigger_key
)
{
:tag_push_hooks
}
it
'returns error message if not enough data'
do
allow
(
project
).
to
receive
(
:empty_repo?
).
and_return
(
true
)
...
...
@@ -52,13 +54,14 @@ describe TestHooks::ProjectService do
allow
(
project
).
to
receive
(
:empty_repo?
).
and_return
(
false
)
allow
(
Gitlab
::
DataBuilder
::
Push
).
to
receive
(
:build_sample
).
and_return
(
sample_data
)
expect
(
hook
).
to
receive
(
:execute
).
with
(
sample_data
,
trigger
).
and_return
(
success_result
)
expect
(
hook
).
to
receive
(
:execute
).
with
(
sample_data
,
trigger
_key
).
and_return
(
success_result
)
expect
(
service
.
execute
).
to
include
(
success_result
)
end
end
context
'note_events'
do
let
(
:trigger
)
{
'note_events'
}
let
(
:trigger_key
)
{
:note_hooks
}
it
'returns error message if not enough data'
do
expect
(
hook
).
not_to
receive
(
:execute
)
...
...
@@ -69,13 +72,14 @@ describe TestHooks::ProjectService do
allow
(
project
).
to
receive
(
:notes
).
and_return
([
Note
.
new
])
allow
(
Gitlab
::
DataBuilder
::
Note
).
to
receive
(
:build
).
and_return
(
sample_data
)
expect
(
hook
).
to
receive
(
:execute
).
with
(
sample_data
,
trigger
).
and_return
(
success_result
)
expect
(
hook
).
to
receive
(
:execute
).
with
(
sample_data
,
trigger
_key
).
and_return
(
success_result
)
expect
(
service
.
execute
).
to
include
(
success_result
)
end
end
context
'issues_events'
do
let
(
:trigger
)
{
'issues_events'
}
let
(
:trigger_key
)
{
:issue_hooks
}
let
(
:issue
)
{
build
(
:issue
)
}
it
'returns error message if not enough data'
do
...
...
@@ -87,13 +91,14 @@ describe TestHooks::ProjectService do
allow
(
project
).
to
receive
(
:issues
).
and_return
([
issue
])
allow
(
issue
).
to
receive
(
:to_hook_data
).
and_return
(
sample_data
)
expect
(
hook
).
to
receive
(
:execute
).
with
(
sample_data
,
trigger
).
and_return
(
success_result
)
expect
(
hook
).
to
receive
(
:execute
).
with
(
sample_data
,
trigger
_key
).
and_return
(
success_result
)
expect
(
service
.
execute
).
to
include
(
success_result
)
end
end
context
'confidential_issues_events'
do
let
(
:trigger
)
{
'confidential_issues_events'
}
let
(
:trigger_key
)
{
:confidential_issue_hooks
}
let
(
:issue
)
{
build
(
:issue
)
}
it
'returns error message if not enough data'
do
...
...
@@ -105,13 +110,14 @@ describe TestHooks::ProjectService do
allow
(
project
).
to
receive
(
:issues
).
and_return
([
issue
])
allow
(
issue
).
to
receive
(
:to_hook_data
).
and_return
(
sample_data
)
expect
(
hook
).
to
receive
(
:execute
).
with
(
sample_data
,
trigger
).
and_return
(
success_result
)
expect
(
hook
).
to
receive
(
:execute
).
with
(
sample_data
,
trigger
_key
).
and_return
(
success_result
)
expect
(
service
.
execute
).
to
include
(
success_result
)
end
end
context
'merge_requests_events'
do
let
(
:trigger
)
{
'merge_requests_events'
}
let
(
:trigger_key
)
{
:merge_request_hooks
}
it
'returns error message if not enough data'
do
expect
(
hook
).
not_to
receive
(
:execute
)
...
...
@@ -122,13 +128,14 @@ describe TestHooks::ProjectService do
create
(
:merge_request
,
source_project:
project
)
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:to_hook_data
).
and_return
(
sample_data
)
expect
(
hook
).
to
receive
(
:execute
).
with
(
sample_data
,
trigger
).
and_return
(
success_result
)
expect
(
hook
).
to
receive
(
:execute
).
with
(
sample_data
,
trigger
_key
).
and_return
(
success_result
)
expect
(
service
.
execute
).
to
include
(
success_result
)
end
end
context
'job_events'
do
let
(
:trigger
)
{
'job_events'
}
let
(
:trigger_key
)
{
:job_hooks
}
it
'returns error message if not enough data'
do
expect
(
hook
).
not_to
receive
(
:execute
)
...
...
@@ -139,13 +146,14 @@ describe TestHooks::ProjectService do
create
(
:ci_build
,
project:
project
)
allow
(
Gitlab
::
DataBuilder
::
Build
).
to
receive
(
:build
).
and_return
(
sample_data
)
expect
(
hook
).
to
receive
(
:execute
).
with
(
sample_data
,
trigger
).
and_return
(
success_result
)
expect
(
hook
).
to
receive
(
:execute
).
with
(
sample_data
,
trigger
_key
).
and_return
(
success_result
)
expect
(
service
.
execute
).
to
include
(
success_result
)
end
end
context
'pipeline_events'
do
let
(
:trigger
)
{
'pipeline_events'
}
let
(
:trigger_key
)
{
:pipeline_hooks
}
it
'returns error message if not enough data'
do
expect
(
hook
).
not_to
receive
(
:execute
)
...
...
@@ -156,13 +164,14 @@ describe TestHooks::ProjectService do
create
(
:ci_empty_pipeline
,
project:
project
)
allow
(
Gitlab
::
DataBuilder
::
Pipeline
).
to
receive
(
:build
).
and_return
(
sample_data
)
expect
(
hook
).
to
receive
(
:execute
).
with
(
sample_data
,
trigger
).
and_return
(
success_result
)
expect
(
hook
).
to
receive
(
:execute
).
with
(
sample_data
,
trigger
_key
).
and_return
(
success_result
)
expect
(
service
.
execute
).
to
include
(
success_result
)
end
end
context
'wiki_page_events'
do
let
(
:trigger
)
{
'wiki_page_events'
}
let
(
:trigger_key
)
{
:wiki_page_hooks
}
it
'returns error message if wiki disabled'
do
allow
(
project
).
to
receive
(
:wiki_enabled?
).
and_return
(
false
)
...
...
@@ -180,7 +189,7 @@ describe TestHooks::ProjectService do
create
(
:wiki_page
,
wiki:
project
.
wiki
)
allow
(
Gitlab
::
DataBuilder
::
WikiPage
).
to
receive
(
:build
).
and_return
(
sample_data
)
expect
(
hook
).
to
receive
(
:execute
).
with
(
sample_data
,
trigger
).
and_return
(
success_result
)
expect
(
hook
).
to
receive
(
:execute
).
with
(
sample_data
,
trigger
_key
).
and_return
(
success_result
)
expect
(
service
.
execute
).
to
include
(
success_result
)
end
end
...
...
spec/services/test_hooks/system_service_spec.rb
View file @
9e201575
...
...
@@ -24,36 +24,39 @@ describe TestHooks::SystemService do
context
'push_events'
do
let
(
:trigger
)
{
'push_events'
}
let
(
:trigger_key
)
{
:push_hooks
}
it
'executes hook'
do
allow
(
project
).
to
receive
(
:empty_repo?
).
and_return
(
false
)
expect
(
Gitlab
::
DataBuilder
::
Push
).
to
receive
(
:sample_data
).
and_call_original
expect
(
hook
).
to
receive
(
:execute
).
with
(
Gitlab
::
DataBuilder
::
Push
::
SAMPLE_DATA
,
trigger
).
and_return
(
success_result
)
expect
(
hook
).
to
receive
(
:execute
).
with
(
Gitlab
::
DataBuilder
::
Push
::
SAMPLE_DATA
,
trigger
_key
).
and_return
(
success_result
)
expect
(
service
.
execute
).
to
include
(
success_result
)
end
end
context
'tag_push_events'
do
let
(
:trigger
)
{
'tag_push_events'
}
let
(
:trigger_key
)
{
:tag_push_hooks
}
it
'executes hook'
do
allow
(
project
.
repository
).
to
receive
(
:tags
).
and_return
([
'tag'
])
expect
(
Gitlab
::
DataBuilder
::
Push
).
to
receive
(
:sample_data
).
and_call_original
expect
(
hook
).
to
receive
(
:execute
).
with
(
Gitlab
::
DataBuilder
::
Push
::
SAMPLE_DATA
,
trigger
).
and_return
(
success_result
)
expect
(
hook
).
to
receive
(
:execute
).
with
(
Gitlab
::
DataBuilder
::
Push
::
SAMPLE_DATA
,
trigger
_key
).
and_return
(
success_result
)
expect
(
service
.
execute
).
to
include
(
success_result
)
end
end
context
'repository_update_events'
do
let
(
:trigger
)
{
'repository_update_events'
}
let
(
:trigger_key
)
{
:repository_update_hooks
}
it
'executes hook'
do
allow
(
project
).
to
receive
(
:empty_repo?
).
and_return
(
false
)
expect
(
Gitlab
::
DataBuilder
::
Repository
).
to
receive
(
:sample_data
).
and_call_original
expect
(
hook
).
to
receive
(
:execute
).
with
(
Gitlab
::
DataBuilder
::
Repository
::
SAMPLE_DATA
,
trigger
).
and_return
(
success_result
)
expect
(
hook
).
to
receive
(
:execute
).
with
(
Gitlab
::
DataBuilder
::
Repository
::
SAMPLE_DATA
,
trigger
_key
).
and_return
(
success_result
)
expect
(
service
.
execute
).
to
include
(
success_result
)
end
end
...
...
spec/services/web_hook_service_spec.rb
View file @
9e201575
...
...
@@ -12,7 +12,7 @@ describe WebHookService do
let
(
:data
)
do
{
before:
'oldrev'
,
after:
'newrev'
,
ref:
'ref'
}
end
let
(
:service_instance
)
{
described_class
.
new
(
project_hook
,
data
,
'push_hooks'
)
}
let
(
:service_instance
)
{
described_class
.
new
(
project_hook
,
data
,
:push_hooks
)
}
describe
'#execute'
do
before
do
...
...
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