right_hook 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,6 +16,8 @@ module RightHook
16
16
  halt 404, "Unknown event type" unless Event::KNOWN_TYPES.include?(event_type)
17
17
  halt 501, "Event type not implemented" unless respond_to?("on_#{event_type}")
18
18
 
19
+ return 200 if request.env['HTTP_X_GITHUB_EVENT'] == Event::PING
20
+
19
21
  require_valid_signature(content, owner, repo_name, event_type)
20
22
 
21
23
  json = JSON.parse(params['payload'])
@@ -39,6 +41,7 @@ module RightHook
39
41
  end
40
42
 
41
43
  private
44
+
42
45
  def require_valid_signature(content, owner, repo_name, event_type)
43
46
  s = secret(owner, repo_name, event_type)
44
47
  expected_signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'), s, content)
@@ -18,6 +18,7 @@ module RightHook
18
18
  ISSUE = 'issue'.freeze
19
19
  PULL_REQUEST = 'pull_request'.freeze
20
20
  ISSUE_COMMENT = 'issue_comment'.freeze
21
+ PING = 'ping'.freeze
21
22
 
22
23
  KNOWN_TYPES = [
23
24
  ISSUE,
@@ -1,3 +1,3 @@
1
1
  module RightHook
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe RightHook::App do
4
- class BareApp < RightHook::App
4
+ class BareApp < RightHook::DebugApp
5
5
  def secret(owner, repo_name, event_type)
6
6
  'secret'
7
7
  end
@@ -25,7 +25,7 @@ describe RightHook::App do
25
25
  expect { RightHook::App.new!.secret('owner', 'repo', 'issue') }.to raise_error(NotImplementedError)
26
26
  end
27
27
 
28
- describe 'the status of a request' do
28
+ describe 'when an app implements the hook method' do
29
29
  class WeirdApp < BareApp
30
30
  def on_issue(owner, repo_name, action, issue_json)
31
31
  302
@@ -34,11 +34,25 @@ describe RightHook::App do
34
34
 
35
35
  let(:app) { WeirdApp }
36
36
 
37
- it 'is 200 regardless of what the hook method returns' do
38
- payload = '{}'
39
- WeirdApp.any_instance.should_receive(:on_issue).and_call_original
37
+ let(:payload) { '{}' }
38
+
39
+ it 'responds with a 200 regardless of what the hook method returns' do
40
+ expect_any_instance_of(WeirdApp).to receive(:on_issue).and_call_original
41
+
40
42
  post_with_signature(path: '/hook/mark-rushakoff/right_hook/issue', payload: payload, secret: 'secret')
41
43
  expect(last_response.status).to eq(200)
42
44
  end
45
+
46
+ it 'does not call the hook method when a ping event is received' do
47
+ expect_any_instance_of(WeirdApp).not_to receive(:on_issue)
48
+
49
+ post(
50
+ '/hook/mark-rushakoff/right_hook/issue',
51
+ {payload: payload},
52
+ generate_secret_header('secret', URI.encode_www_form(payload: payload)).merge(
53
+ 'HTTP_X_GITHUB_EVENT' => 'ping'
54
+ ),
55
+ )
56
+ end
43
57
  end
44
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_hook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-28 00:00:00.000000000 Z
12
+ date: 2014-06-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -206,7 +206,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
206
206
  version: '0'
207
207
  segments:
208
208
  - 0
209
- hash: -495302186993546898
209
+ hash: 288642712136343718
210
210
  required_rubygems_version: !ruby/object:Gem::Requirement
211
211
  none: false
212
212
  requirements:
@@ -215,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
215
  version: '0'
216
216
  segments:
217
217
  - 0
218
- hash: -495302186993546898
218
+ hash: 288642712136343718
219
219
  requirements: []
220
220
  rubyforge_project:
221
221
  rubygems_version: 1.8.23