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.
- data/lib/right_hook/app.rb +3 -0
- data/lib/right_hook/event.rb +1 -0
- data/lib/right_hook/version.rb +1 -1
- data/spec/app_spec.rb +19 -5
- metadata +4 -4
data/lib/right_hook/app.rb
CHANGED
@@ -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)
|
data/lib/right_hook/event.rb
CHANGED
data/lib/right_hook/version.rb
CHANGED
data/spec/app_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe RightHook::App do
|
4
|
-
class BareApp < RightHook::
|
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 '
|
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
|
-
|
38
|
-
|
39
|
-
|
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.
|
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-
|
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:
|
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:
|
218
|
+
hash: 288642712136343718
|
219
219
|
requirements: []
|
220
220
|
rubyforge_project:
|
221
221
|
rubygems_version: 1.8.23
|