loadrunner 0.0.3 → 0.0.4

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: d485cc0bc26a01f141b992aaed25b970e290470c
4
- data.tar.gz: a7b1bacff31b40b289b509c626ef07720146334c
3
+ metadata.gz: b8a007f7920f1973efc60d3795c4cd8dab52cb3d
4
+ data.tar.gz: 0baaf60bb349d17969597985c564bdb68daf1391
5
5
  SHA512:
6
- metadata.gz: e5e7b9da7b9302209943c6c1a08acc43230210d9872fcd3d20817f3af9384076d3cc044c589199e13f52c9680c718b496aadf208e3a9599b112abbf96f0f526b
7
- data.tar.gz: d726f209f0dc7d64c991fc01f546e48d12207b978aaf9bd75ab0676ef14f525938a37addb384dadb4ced30640f6fe186ae3dba81e5865acdd14cd22790105ec7
6
+ metadata.gz: dd2ddfff2c1dfa0522871c2a41c84e60b36934e56d5785e52172d5cc4bccb17c99cde8e58d78b580a4181448ba252b9b99a512ee803e694e390598f38536ef23
7
+ data.tar.gz: 714bea8499b8c53e358dfca0fe09e75cd97455b97729f49bd99f71d15f6e91b51562c60b0c31386ebdb5cd954325eaa2336a5b91de7bce28f8a820dabee645f1
@@ -16,7 +16,7 @@ module LoadRunner
16
16
  send_payload event, payload
17
17
  end
18
18
 
19
- def send_payload(event=:push, payload)
19
+ def send_payload(event, payload)
20
20
  @payload = payload.is_a?(String) ? payload : payload.to_json
21
21
  headers = headers event
22
22
  self.class.post "/payload", body: @payload, headers: headers
@@ -35,7 +35,7 @@ module LoadRunner
35
35
  client = Client.new client_opts
36
36
  response = client.send args['EVENT'], payload_opts
37
37
 
38
- puts "Reesponse code: #{response.code}"
38
+ puts "Reesponse code: #{response.code}" if response.respond_to? :code
39
39
  ap response
40
40
  end
41
41
 
@@ -25,6 +25,14 @@ module LoadRunner
25
25
  end
26
26
  end
27
27
 
28
+ def handlers_dir
29
+ @handlers_dir ||= 'handlers'
30
+ end
31
+
32
+ def handlers_dir=(path)
33
+ @handlers_dir = path
34
+ end
35
+
28
36
  private
29
37
 
30
38
  def locate_handlers
@@ -53,12 +61,12 @@ module LoadRunner
53
61
  end
54
62
 
55
63
  def matching_handlers
56
- base = "handlers/#{opts[:repo]}"
57
- handlers = ["#{base}/#{opts[:event]}"]
64
+ base = "#{handlers_dir}/#{opts[:repo]}/#{opts[:event]}"
65
+ handlers = ["#{base}"]
58
66
 
59
67
  handlers.tap do |h|
60
- h << "#{base}/#{opts[:event]}@branch=#{opts[:branch]}" if opts[:branch]
61
- h << "#{base}/#{opts[:event]}@tag=#{opts[:tag]}" if opts[:tag]
68
+ h << "#{base}@branch=#{opts[:branch]}" if opts[:branch]
69
+ h << "#{base}@tag=#{opts[:tag]}" if opts[:tag]
62
70
  end
63
71
  end
64
72
 
@@ -4,16 +4,23 @@ module LoadRunner
4
4
  class Server < ServerBase
5
5
  include ServerHelper
6
6
 
7
+ get '/' do
8
+ "OK"
9
+ end
10
+
7
11
  post '/payload' do
8
12
  request.body.rewind
9
13
  payload_body = request.body.read
10
14
 
11
- verify_signature payload_body
15
+ signature = request.env['HTTP_X_HUB_SIGNATURE']
16
+ state = verify_signature payload_body, signature
17
+
18
+ halt 401, halt_messages[state] if state != :ok
12
19
 
13
20
  push = ActiveSupport::HashWithIndifferentAccess.new JSON.parse payload_body
14
21
 
15
22
  opts = {}
16
- opts[:repo] = push[:repository][:name]
23
+ opts[:repo] = push.dig(:repository, :name)
17
24
  opts[:event] = request.env['HTTP_X_GITHUB_EVENT']
18
25
  opts[:branch] = push[:ref].sub('refs/heads/', '') if push[:ref] =~ /refs\/heads/
19
26
  opts[:tag] = push[:ref].sub('refs/tags/', '') if push[:ref] =~ /refs\/tags/
@@ -1,25 +1,29 @@
1
1
  module LoadRunner
2
2
  module ServerHelper
3
- def verify_signature(payload_body)
4
- request_signature = request.env['HTTP_X_HUB_SIGNATURE']
3
+ def verify_signature(payload_body, signature)
4
+ return :no_client if secret_token and !signature
5
+ return :no_server if !secret_token and signature
6
+ return :ok if !secret_token and !signature
5
7
 
6
- if secret_token and !request_signature
7
- return halt 401, "Client did not send a signature"
8
- end
9
-
10
- if !secret_token and request_signature
11
- return halt 401, "Server secret token is not configured"
12
- end
8
+ expected_signature = generate_signature payload_body
9
+ signature_match = Rack::Utils.secure_compare(expected_signature, signature)
10
+ return signature_match ? :ok : :mismatch
11
+ end
13
12
 
14
- if secret_token and request_signature
15
- signature = 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), secret_token, payload_body)
16
- signature_match = Rack::Utils.secure_compare(signature, request.env['HTTP_X_HUB_SIGNATURE'])
17
- return halt 401, "Signature mismatch" unless signature_match
18
- end
13
+ def generate_signature(payload_body)
14
+ 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), secret_token, payload_body)
19
15
  end
20
16
 
21
17
  def secret_token
22
18
  ENV['GITHUB_SECRET_TOKEN']
23
19
  end
20
+
21
+ def halt_messages
22
+ {
23
+ no_client: "Client did not send a signature",
24
+ no_server: "Server secret token is not configured",
25
+ mismatch: "Signature mismatch"
26
+ }
27
+ end
24
28
  end
25
29
  end
@@ -1,3 +1,3 @@
1
1
  module LoadRunner
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loadrunner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-13 00:00:00.000000000 Z
11
+ date: 2017-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: '2.0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rack-test
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '0.7'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '0.7'
167
181
  description: Run your GitHub webhook server and Send simulated github events
168
182
  email: db@dannyben.com
169
183
  executables:
@@ -196,7 +210,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
196
210
  requirements:
197
211
  - - ">="
198
212
  - !ruby/object:Gem::Version
199
- version: 2.0.0
213
+ version: 2.3.0
200
214
  required_rubygems_version: !ruby/object:Gem::Requirement
201
215
  requirements:
202
216
  - - ">="