github_webhook 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +10 -8
- data/README.md +1 -1
- data/github_webhook.gemspec +1 -0
- data/lib/github_webhook/processor.rb +15 -1
- data/lib/github_webhook/version.rb +1 -1
- data/spec/github_webhook/processor_spec.rb +24 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e1aafa2b371f63f8ff7276d892c0279845d4a84
|
4
|
+
data.tar.gz: 203d5fca9f09fd28ac501eabf2ae1f656b4358be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe0d6e2cc1f78f99cf0ec4b9825ee086332058c764ec117c1011007f81e458d13e2aa9352fa31c9e30ae30a067a1945fc63aed24dbd02eebca3678e5f4ed35f7
|
7
|
+
data.tar.gz: b2de02e5b6cc046efa2fc07bbe74057eed8571592f1f7260d3831b4f5788cba3392f466c43f1ee31816f8094b86a1b4628741663f068d59eeea25e4508f788c1
|
data/Gemfile.lock
CHANGED
@@ -1,25 +1,27 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
github_webhook (0.
|
4
|
+
github_webhook (0.4.0)
|
5
5
|
activesupport (~> 4)
|
6
|
+
rack (~> 1.3)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
|
-
activesupport (4.
|
11
|
-
i18n (~> 0.
|
11
|
+
activesupport (4.2.5.1)
|
12
|
+
i18n (~> 0.7)
|
12
13
|
json (~> 1.7, >= 1.7.7)
|
13
14
|
minitest (~> 5.1)
|
14
|
-
thread_safe (~> 0.
|
15
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
15
16
|
tzinfo (~> 1.1)
|
16
17
|
codeclimate-test-reporter (0.4.8)
|
17
18
|
simplecov (>= 0.7.1, < 1.0.0)
|
18
19
|
diff-lcs (1.2.5)
|
19
20
|
docile (1.1.5)
|
20
|
-
i18n (0.
|
21
|
+
i18n (0.7.0)
|
21
22
|
json (1.8.3)
|
22
|
-
minitest (5.
|
23
|
+
minitest (5.8.4)
|
24
|
+
rack (1.6.4)
|
23
25
|
rake (10.3.1)
|
24
26
|
rspec (2.14.1)
|
25
27
|
rspec-core (~> 2.14.0)
|
@@ -34,8 +36,8 @@ GEM
|
|
34
36
|
json (~> 1.8)
|
35
37
|
simplecov-html (~> 0.10.0)
|
36
38
|
simplecov-html (0.10.0)
|
37
|
-
thread_safe (0.3.
|
38
|
-
tzinfo (1.2.
|
39
|
+
thread_safe (0.3.5)
|
40
|
+
tzinfo (1.2.2)
|
39
41
|
thread_safe (~> 0.1)
|
40
42
|
|
41
43
|
PLATFORMS
|
data/README.md
CHANGED
data/github_webhook.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_dependency "rack", "~> 1.3"
|
21
22
|
spec.add_dependency "activesupport", "~> 4"
|
22
23
|
|
23
24
|
spec.add_development_dependency "bundler", "~> 1.5"
|
@@ -9,6 +9,7 @@ module GithubWebhook::Processor
|
|
9
9
|
class SignatureError < StandardError; end
|
10
10
|
class UnspecifiedWebhookSecretError < StandardError; end
|
11
11
|
class UnsupportedGithubEventError < StandardError; end
|
12
|
+
class UnsupportedContentTypeError < StandardError; end
|
12
13
|
|
13
14
|
GITHUB_EVENTS_WHITELIST = %w(ping commit_comment create delete deployment deployment_status download follow fork fork_apply gist gollum issue_comment issues member membership page_build public pull_request pull_request_review_comment push release repository status team_add watch)
|
14
15
|
|
@@ -53,7 +54,20 @@ module GithubWebhook::Processor
|
|
53
54
|
end
|
54
55
|
|
55
56
|
def json_body
|
56
|
-
@json_body ||=
|
57
|
+
@json_body ||= (
|
58
|
+
content_type = request.headers['Content-Type']
|
59
|
+
case content_type
|
60
|
+
when 'application/x-www-form-urlencoded'
|
61
|
+
require 'rack'
|
62
|
+
payload = Rack::Utils.parse_query(request_body)['payload']
|
63
|
+
when 'application/json'
|
64
|
+
payload = request_body
|
65
|
+
else
|
66
|
+
raise UnsupportedContentTypeError.new(
|
67
|
+
"Content-Type #{content_type} is not supported. Use 'application/x-www-form-urlencoded' or 'application.json")
|
68
|
+
end
|
69
|
+
ActiveSupport::HashWithIndifferentAccess.new(JSON.load(payload))
|
70
|
+
)
|
57
71
|
end
|
58
72
|
|
59
73
|
def signature_header
|
@@ -49,10 +49,22 @@ module GithubWebhook
|
|
49
49
|
expect { controller_without_secret.send :authenticate_github_request! }.to raise_error(Processor::UnspecifiedWebhookSecretError)
|
50
50
|
end
|
51
51
|
|
52
|
-
it "calls the #push method in controller" do
|
52
|
+
it "calls the #push method in controller (json)" do
|
53
53
|
controller.request.body = StringIO.new({ :foo => "bar" }.to_json.to_s)
|
54
54
|
controller.request.headers['X-Hub-Signature'] = "sha1=52b582138706ac0c597c315cfc1a1bf177408a4d"
|
55
55
|
controller.request.headers['X-GitHub-Event'] = 'push'
|
56
|
+
controller.request.headers['Content-Type'] = 'application/json'
|
57
|
+
controller.send :authenticate_github_request! # Manually as we don't have the before_filter logic in our Mock object
|
58
|
+
controller.create
|
59
|
+
expect(controller.pushed).to eq "bar"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "calls the #push method (x-www-form-urlencoded encoded)" do
|
63
|
+
body = "payload=" + CGI::escape({ :foo => "bar" }.to_json.to_s)
|
64
|
+
controller.request.body = StringIO.new(body)
|
65
|
+
controller.request.headers['X-Hub-Signature'] = "sha1=6986874ecdf710b04de7ef5a040161d41687407a"
|
66
|
+
controller.request.headers['X-GitHub-Event'] = 'push'
|
67
|
+
controller.request.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
56
68
|
controller.send :authenticate_github_request! # Manually as we don't have the before_filter logic in our Mock object
|
57
69
|
controller.create
|
58
70
|
expect(controller.pushed).to eq "bar"
|
@@ -62,18 +74,29 @@ module GithubWebhook
|
|
62
74
|
controller.request.body = StringIO.new({ :foo => "bar" }.to_json.to_s)
|
63
75
|
controller.request.headers['X-Hub-Signature'] = "sha1=FOOBAR"
|
64
76
|
controller.request.headers['X-GitHub-Event'] = 'push'
|
77
|
+
controller.request.headers['Content-Type'] = 'application/json'
|
65
78
|
expect { controller.send :authenticate_github_request! }.to raise_error(Processor::SignatureError)
|
66
79
|
end
|
67
80
|
|
68
81
|
it "raises an error when the github event method is not implemented" do
|
69
82
|
controller.request.headers['X-GitHub-Event'] = 'deployment'
|
83
|
+
controller.request.headers['Content-Type'] = 'application/json'
|
70
84
|
expect { controller.create }.to raise_error(NoMethodError)
|
71
85
|
end
|
72
86
|
|
73
87
|
it "raises an error when the github event is not in the whitelist" do
|
74
88
|
controller.request.headers['X-GitHub-Event'] = 'fake_event'
|
89
|
+
controller.request.headers['Content-Type'] = 'application/json'
|
75
90
|
expect { controller.send :check_github_event! }.to raise_error(Processor::UnsupportedGithubEventError)
|
76
91
|
end
|
92
|
+
|
93
|
+
it "raises an error when the content type is not correct" do
|
94
|
+
controller.request.body = StringIO.new({ :foo => "bar" }.to_json.to_s)
|
95
|
+
controller.request.headers['X-Hub-Signature'] = "sha1=52b582138706ac0c597c315cfc1a1bf177408a4d"
|
96
|
+
controller.request.headers['X-GitHub-Event'] = 'ping'
|
97
|
+
controller.request.headers['Content-Type'] = 'application/xml'
|
98
|
+
expect { controller.send :authenticate_github_request! }.to raise_error(Processor::UnsupportedContentTypeError)
|
99
|
+
end
|
77
100
|
end
|
78
101
|
end
|
79
102
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github_webhook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastien Saunier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02
|
11
|
+
date: 2016-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: activesupport
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|