github_webhook 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68085b2caf36fbd2af5d858a0fd98ce539d0c98a0c23b45e399eca378f17175b
4
- data.tar.gz: 547ce4ef7686bb5a886a03e2f7c550a8602729608302aa1f9daeaacee9a26acd
3
+ metadata.gz: ec22b9a09fcb0d2833a46cffacf39ac9703b33fd0b909bfee2258f4191fdfc21
4
+ data.tar.gz: 0f0fc361b3f1ccccb93dc66baf1b75d3ebc1f34fa3ef6022a0598dd6abc20c1b
5
5
  SHA512:
6
- metadata.gz: e4cd1c3ff4f074510e1228e950b9d71d2e663869cb78e5f7f98cc0028d365ece7ddacd447c0bfd1525ed04739d3b156ffe1cc8f9fde12a865212ab379eed5252
7
- data.tar.gz: 549b72dcc5a79abddbd693c1771c96f51a35a58dd53012240bad08164f5217f71c399d71ca4c4d30aff3d8047775907bb1132515601c6d0f0eea37bce4bff519
6
+ metadata.gz: 4292322d0e533e85de5fdedf0c67efe57847114beda60ba710a3fe191d9a59ad3c61fe8ead9c68272ba8067b53f709a10980059c6cb4a37f3898a6bc6b0b1f3a
7
+ data.tar.gz: 767ce312e69c381ac91cc6bd4c9cf913b1297ca9d4ee990f38cf8e55f306c8607421dcaf1b0ab9941da41003f20674346512c53595d5d61c6a9866cdb6f5a559
data/README.md CHANGED
@@ -21,7 +21,7 @@ If you are on Rails, please read on!
21
21
  Add this line to your application's Gemfile:
22
22
 
23
23
  ```ruby
24
- gem 'github_webhook', '~> 1.2'
24
+ gem 'github_webhook', '~> 1.4'
25
25
  ```
26
26
 
27
27
  And then execute:
@@ -1,16 +1,12 @@
1
1
  module GithubWebhook::Processor
2
2
  extend ActiveSupport::Concern
3
+ require 'abstract_controller'
3
4
 
4
5
  included do
5
6
  before_action :authenticate_github_request!, only: :create
6
7
  before_action :check_github_event!, only: :create
7
8
  end
8
9
 
9
- class SignatureError < StandardError; end
10
- class UnspecifiedWebhookSecretError < StandardError; end
11
- class UnsupportedGithubEventError < StandardError; end
12
- class UnsupportedContentTypeError < StandardError; end
13
-
14
10
  # To fetch list from https://developer.github.com/v3/activity/events/types
15
11
  # run this little JS code in the console:
16
12
  # document.querySelectorAll('.list-style-none li.lh-condensed a').forEach(e => console.log(e.text))
@@ -75,7 +71,7 @@ module GithubWebhook::Processor
75
71
  self.send event_method, json_body
76
72
  head(:ok)
77
73
  else
78
- raise NoMethodError.new("GithubWebhooksController##{event_method} not implemented")
74
+ raise AbstractController::ActionNotFound.new("GithubWebhooksController##{event_method} not implemented")
79
75
  end
80
76
  end
81
77
 
@@ -89,20 +85,20 @@ module GithubWebhook::Processor
89
85
  HMAC_DIGEST = OpenSSL::Digest.new('sha256')
90
86
 
91
87
  def authenticate_github_request!
92
- raise UnspecifiedWebhookSecretError.new unless respond_to?(:webhook_secret, true)
88
+ raise AbstractController::ActionNotFound.new unless respond_to?(:webhook_secret, true)
93
89
  secret = webhook_secret(json_body)
94
90
 
95
91
  expected_signature = "sha256=#{OpenSSL::HMAC.hexdigest(HMAC_DIGEST, secret, request_body)}"
96
92
  unless ActiveSupport::SecurityUtils.secure_compare(signature_header, expected_signature)
97
93
  GithubWebhook.logger && GithubWebhook.logger.warn("[GithubWebhook::Processor] signature "\
98
94
  "invalid, actual: #{signature_header}, expected: #{expected_signature}")
99
- raise SignatureError
95
+ raise AbstractController::ActionNotFound
100
96
  end
101
97
  end
102
98
 
103
99
  def check_github_event!
104
100
  unless GITHUB_EVENTS.include?(request.headers['X-GitHub-Event'])
105
- raise UnsupportedGithubEventError.new("#{request.headers['X-GitHub-Event']} is not a whitelisted GitHub event. See https://developer.github.com/v3/activity/events/types/")
101
+ raise AbstractController::ActionNotFound.new("#{request.headers['X-GitHub-Event']} is not a whitelisted GitHub event. See https://developer.github.com/v3/activity/events/types/")
106
102
  end
107
103
  end
108
104
 
@@ -123,7 +119,7 @@ module GithubWebhook::Processor
123
119
  when 'application/json'
124
120
  payload = request_body
125
121
  else
126
- raise UnsupportedContentTypeError.new(
122
+ raise AbstractController::ActionNotFound.new(
127
123
  "Content-Type #{content_type} is not supported. Use 'application/x-www-form-urlencoded' or 'application/json")
128
124
  end
129
125
  ActiveSupport::HashWithIndifferentAccess.new(JSON.load(payload))
@@ -1,3 +1,3 @@
1
1
  module GithubWebhook
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -53,9 +53,9 @@ module GithubWebhook
53
53
  context 'when #webhook_secret is not defined' do
54
54
  let(:controller_class) { ControllerWithoutSecret }
55
55
 
56
- it "raises a Processor::UnspecifiedWebhookSecretError" do
56
+ it "raises a AbstractController::ActionNotFound" do
57
57
  expect { controller.send :authenticate_github_request! }
58
- .to raise_error(Processor::UnspecifiedWebhookSecretError)
58
+ .to raise_error(AbstractController::ActionNotFound)
59
59
  end
60
60
  end
61
61
 
@@ -99,19 +99,25 @@ module GithubWebhook
99
99
  controller.request.headers['X-Hub-Signature-256'] = "sha256=FOOBAR"
100
100
  controller.request.headers['X-GitHub-Event'] = 'push'
101
101
  controller.request.headers['Content-Type'] = 'application/json'
102
- expect { controller.send :authenticate_github_request! }.to raise_error(Processor::SignatureError)
102
+ expect { controller.send :authenticate_github_request! }.to raise_error(AbstractController::ActionNotFound)
103
103
  end
104
104
 
105
105
  it "raises an error when the github event method is not implemented" do
106
106
  controller.request.headers['X-GitHub-Event'] = 'deployment'
107
107
  controller.request.headers['Content-Type'] = 'application/json'
108
- expect { controller.create }.to raise_error(NoMethodError)
108
+ expect { controller.create }.to raise_error(
109
+ AbstractController::ActionNotFound,
110
+ "GithubWebhooksController#github_deployment not implemented",
111
+ )
109
112
  end
110
113
 
111
114
  it "raises an error when the github event is not in the whitelist" do
112
115
  controller.request.headers['X-GitHub-Event'] = 'fake_event'
113
116
  controller.request.headers['Content-Type'] = 'application/json'
114
- expect { controller.send :check_github_event! }.to raise_error(Processor::UnsupportedGithubEventError)
117
+ expect { controller.send :check_github_event! }.to raise_error(
118
+ AbstractController::ActionNotFound,
119
+ "fake_event is not a whitelisted GitHub event. See https://developer.github.com/v3/activity/events/types/",
120
+ )
115
121
  end
116
122
 
117
123
  it "raises an error when the content type is not correct" do
@@ -119,14 +125,17 @@ module GithubWebhook
119
125
  controller.request.headers['X-Hub-Signature-256'] = "sha256=3f3ab3986b656abb17af3eb1443ed6c08ef8fff9fea83915909d1b421aec89be"
120
126
  controller.request.headers['X-GitHub-Event'] = 'ping'
121
127
  controller.request.headers['Content-Type'] = 'application/xml'
122
- expect { controller.send :authenticate_github_request! }.to raise_error(Processor::UnsupportedContentTypeError)
128
+ expect { controller.send :authenticate_github_request! }.to raise_error(
129
+ AbstractController::ActionNotFound,
130
+ "Content-Type application/xml is not supported. Use 'application/x-www-form-urlencoded' or 'application/json",
131
+ )
123
132
  end
124
133
 
125
134
  it 'raises SignatureError when the X-Hub-Signature header is missing' do
126
135
  controller.request.body = StringIO.new('{}')
127
136
  controller.request.headers['Content-Type'] = 'application/json'
128
137
  controller.request.headers['X-GitHub-Event'] = 'ping'
129
- expect { controller.send :authenticate_github_request! }.to raise_error(Processor::SignatureError)
138
+ expect { controller.send :authenticate_github_request! }.to raise_error(AbstractController::ActionNotFound)
130
139
  end
131
140
  end
132
141
  end
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.3.0
4
+ version: 1.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: 2021-12-11 00:00:00.000000000 Z
11
+ date: 2021-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack