github_webhook 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 884527952c3de87ab10113b15faa48a4a3943557
4
- data.tar.gz: e9d7222f4ea4724f6426ccf6643f5270063502c9
3
+ metadata.gz: 482d71a9312b1b80aeee8af5c230e80ca9b5cd15
4
+ data.tar.gz: 8e788b3145ab2874ff71f5a4fda3c2a8f89557a3
5
5
  SHA512:
6
- metadata.gz: 55a2b86574e657e4c2d50149d0c2fbf928a7ba7acbfd0f89032615142c4f03541728a0aee4c666ed5c33ec748d3963ebc4911877be33b0cfcc5ee9a724cd710b
7
- data.tar.gz: 507a45eb2713452ad0513e4bf6396a50aae2e639fde460b91a43b03358753faef905102cb1ec2b7db837c584a115f5c881e8da60cecdbf422406ff4c49379e5c
6
+ metadata.gz: cbe5e47e926c147748387234219b18a2b330b526f2f7804a5e8bb9d1fbe4ef16c978a72437525bdbfbdcd95f2f62901d5b7f26a4eb637721d734ac87c0a0b354
7
+ data.tar.gz: 8eda80c2a630d17eed37e66b8c15c30ae4eadf57d71430ba1ea1e3665d68c9514d39b8c75bcd1f4d8f8d86c0e550a53dd5bd1203f60438cd5759fffd2171e479
@@ -0,0 +1 @@
1
+ 2.4.2
@@ -1,8 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.4.1
4
- - 2.3.4
5
- - 2.2.5
3
+ - 2.4.2
4
+ - 2.3.5
6
5
  addons:
7
6
  code_climate:
8
7
  repo_token: 50425d682162d68af0b65bd9e5160da8337d2159fc3ebc00d2a5b14386548ac5
@@ -1,27 +1,64 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- github_webhook (1.0.5)
4
+ github_webhook (1.1.0)
5
5
  activesupport (>= 4)
6
6
  rack (>= 1.3)
7
+ railties (>= 4)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
11
- activesupport (5.1.2)
12
+ actionpack (5.1.4)
13
+ actionview (= 5.1.4)
14
+ activesupport (= 5.1.4)
15
+ rack (~> 2.0)
16
+ rack-test (>= 0.6.3)
17
+ rails-dom-testing (~> 2.0)
18
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
19
+ actionview (5.1.4)
20
+ activesupport (= 5.1.4)
21
+ builder (~> 3.1)
22
+ erubi (~> 1.4)
23
+ rails-dom-testing (~> 2.0)
24
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
25
+ activesupport (5.1.4)
12
26
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
27
  i18n (~> 0.7)
14
28
  minitest (~> 5.1)
15
29
  tzinfo (~> 1.1)
30
+ builder (3.2.3)
16
31
  codeclimate-test-reporter (0.4.8)
17
32
  simplecov (>= 0.7.1, < 1.0.0)
18
33
  concurrent-ruby (1.0.5)
34
+ crass (1.0.2)
19
35
  diff-lcs (1.2.5)
20
36
  docile (1.1.5)
37
+ erubi (1.6.1)
21
38
  i18n (0.8.6)
22
39
  json (1.8.6)
40
+ loofah (2.1.1)
41
+ crass (~> 1.0.2)
42
+ nokogiri (>= 1.5.9)
43
+ method_source (0.9.0)
44
+ mini_portile2 (2.3.0)
23
45
  minitest (5.10.3)
46
+ nokogiri (1.8.1)
47
+ mini_portile2 (~> 2.3.0)
24
48
  rack (2.0.3)
49
+ rack-test (0.7.0)
50
+ rack (>= 1.0, < 3)
51
+ rails-dom-testing (2.0.3)
52
+ activesupport (>= 4.2.0)
53
+ nokogiri (>= 1.6)
54
+ rails-html-sanitizer (1.0.3)
55
+ loofah (~> 2.0)
56
+ railties (5.1.4)
57
+ actionpack (= 5.1.4)
58
+ activesupport (= 5.1.4)
59
+ method_source
60
+ rake (>= 0.8.7)
61
+ thor (>= 0.18.1, < 2.0)
25
62
  rake (10.3.1)
26
63
  rspec (2.14.1)
27
64
  rspec-core (~> 2.14.0)
@@ -36,6 +73,7 @@ GEM
36
73
  json (~> 1.8)
37
74
  simplecov-html (~> 0.10.0)
38
75
  simplecov-html (0.10.0)
76
+ thor (0.20.0)
39
77
  thread_safe (0.3.6)
40
78
  tzinfo (1.2.3)
41
79
  thread_safe (~> 0.1)
@@ -51,4 +89,4 @@ DEPENDENCIES
51
89
  rspec (~> 2.14)
52
90
 
53
91
  BUNDLED WITH
54
- 1.15.3
92
+ 1.16.0.pre.2
data/README.md CHANGED
@@ -13,7 +13,7 @@ to a [GitHub webhook](https://developer.github.com/webhooks/)
13
13
  Add this line to your application's Gemfile:
14
14
 
15
15
  ```ruby
16
- gem 'github_webhook', '~> 1.0.5'
16
+ gem 'github_webhook', '~> 1.1'
17
17
  ```
18
18
 
19
19
  And then execute:
@@ -46,6 +46,8 @@ class GithubWebhooksController < ActionController::Base
46
46
  # TODO: handle create webhook
47
47
  end
48
48
 
49
+ private
50
+
49
51
  def webhook_secret(payload)
50
52
  ENV['GITHUB_WEBHOOK_SECRET']
51
53
  end
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "rack", ">= 1.3"
22
22
  spec.add_dependency "activesupport", ">= 4"
23
+ spec.add_dependency "railties", ">= 4"
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.5"
25
26
  spec.add_development_dependency "rake", "~> 10.1"
@@ -4,4 +4,11 @@ require 'active_support/concern'
4
4
  require 'active_support/core_ext/hash/indifferent_access'
5
5
 
6
6
  require 'github_webhook/version'
7
- require 'github_webhook/processor'
7
+ require 'github_webhook/processor'
8
+ require 'github_webhook/railtie'
9
+
10
+ module GithubWebhook
11
+ class <<self
12
+ attr_accessor :logger
13
+ end
14
+ end
@@ -64,7 +64,7 @@ module GithubWebhook::Processor
64
64
  )
65
65
 
66
66
  def create
67
- if self.respond_to? event_method
67
+ if self.respond_to?(event_method, true)
68
68
  self.send event_method, json_body
69
69
  head(:ok)
70
70
  else
@@ -73,7 +73,8 @@ module GithubWebhook::Processor
73
73
  end
74
74
 
75
75
  def github_ping(payload)
76
- puts "[GithubWebhook::Processor] Hook ping received, hook_id: #{payload[:hook_id]}, #{payload[:zen]}"
76
+ GithubWebhook.logger && GithubWebhook.logger.info("[GithubWebhook::Processor] Hook ping "\
77
+ "received, hook_id: #{payload[:hook_id]}, #{payload[:zen]}")
77
78
  end
78
79
 
79
80
  private
@@ -81,12 +82,14 @@ module GithubWebhook::Processor
81
82
  HMAC_DIGEST = OpenSSL::Digest.new('sha1')
82
83
 
83
84
  def authenticate_github_request!
84
- raise UnspecifiedWebhookSecretError.new unless respond_to?(:webhook_secret)
85
+ raise UnspecifiedWebhookSecretError.new unless respond_to?(:webhook_secret, true)
85
86
  secret = webhook_secret(json_body)
86
87
 
87
88
  expected_signature = "sha1=#{OpenSSL::HMAC.hexdigest(HMAC_DIGEST, secret, request_body)}"
88
89
  if signature_header != expected_signature
89
- raise SignatureError.new "Actual: #{signature_header}, Expected: #{expected_signature}"
90
+ GithubWebhook.logger && GithubWebhook.logger.warn("[GithubWebhook::Processor] signature "\
91
+ "invalid, actual: #{signature_header}, expected: #{expected_signature}")
92
+ raise SignatureError
90
93
  end
91
94
  end
92
95
 
@@ -0,0 +1,9 @@
1
+ require 'rails'
2
+
3
+ module GithubWebhook
4
+ class Railties < ::Rails::Railtie
5
+ initializer 'Rails logger' do
6
+ GithubWebhook.logger = Rails.logger
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module GithubWebhook
2
- VERSION = "1.0.5"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -28,25 +28,49 @@ module GithubWebhook
28
28
  end
29
29
  end
30
30
 
31
+ class ControllerWithPrivateSecret < ControllerWithoutSecret
32
+ private
33
+ def webhook_secret(payload)
34
+ "secret"
35
+ end
36
+ end
37
+
31
38
  class Controller < ControllerWithoutSecret
32
39
  def webhook_secret(payload)
33
40
  "secret"
34
41
  end
35
42
  end
36
43
 
44
+ let(:controller_class) { Controller }
45
+
37
46
  let(:controller) do
38
- controller = Controller.new
47
+ controller = controller_class.new
39
48
  controller.request = Request.new
40
49
  controller
41
50
  end
42
51
 
43
- let(:controller_without_secret) do
44
- ControllerWithoutSecret.new
45
- end
46
-
47
52
  describe "#create" do
48
- it "raises an error when secret is not defined" do
49
- expect { controller_without_secret.send :authenticate_github_request! }.to raise_error(Processor::UnspecifiedWebhookSecretError)
53
+ context 'when #webhook_secret is not defined' do
54
+ let(:controller_class) { ControllerWithoutSecret }
55
+
56
+ it "raises a Processor::UnspecifiedWebhookSecretError" do
57
+ expect { controller.send :authenticate_github_request! }
58
+ .to raise_error(Processor::UnspecifiedWebhookSecretError)
59
+ end
60
+ end
61
+
62
+ context 'when #webhook_secret is private' do
63
+ let(:controller_class) { ControllerWithPrivateSecret }
64
+
65
+ it "calls the #push method in controller" do
66
+ expect(controller).to receive(:github_push)
67
+ controller.request.body = StringIO.new({ :foo => "bar" }.to_json.to_s)
68
+ controller.request.headers['X-Hub-Signature'] = "sha1=52b582138706ac0c597c315cfc1a1bf177408a4d"
69
+ controller.request.headers['X-GitHub-Event'] = 'push'
70
+ controller.request.headers['Content-Type'] = 'application/json'
71
+ controller.send :authenticate_github_request! # Manually as we don't have the before_filter logic in our Mock object
72
+ controller.create
73
+ end
50
74
  end
51
75
 
52
76
  it "calls the #push method in controller (json)" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github_webhook
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.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: 2017-07-24 00:00:00.000000000 Z
11
+ date: 2017-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: railties
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '4'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -102,6 +116,7 @@ extensions: []
102
116
  extra_rdoc_files: []
103
117
  files:
104
118
  - ".gitignore"
119
+ - ".ruby-version"
105
120
  - ".travis.yml"
106
121
  - Gemfile
107
122
  - Gemfile.lock
@@ -111,6 +126,7 @@ files:
111
126
  - github_webhook.gemspec
112
127
  - lib/github_webhook.rb
113
128
  - lib/github_webhook/processor.rb
129
+ - lib/github_webhook/railtie.rb
114
130
  - lib/github_webhook/version.rb
115
131
  - spec/github_webhook/processor_spec.rb
116
132
  - spec/spec_helper.rb
@@ -134,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
150
  version: '0'
135
151
  requirements: []
136
152
  rubyforge_project:
137
- rubygems_version: 2.6.12
153
+ rubygems_version: 2.6.13
138
154
  signing_key:
139
155
  specification_version: 4
140
156
  summary: Process GitHub Webhooks in your Rails app (Controller mixin)