Module: RightHook::SpecHelpers
- Includes:
- Rack::Test::Methods
- Defined in:
- lib/right_hook/spec_helpers.rb
Overview
Helpers for specs! Typical usage is to include this module into your spec context, just like you would with Rack::Test::Methods.
Instance Method Summary collapse
-
#generate_secret_header(secret, body) ⇒ Object
:nodoc:.
-
#post_with_signature(opts) ⇒ Object
Post to the given path, including the correct signature header based on the payload and secret.
Instance Method Details
#generate_secret_header(secret, body) ⇒ Object
:nodoc:
25 26 27 28 29 |
# File 'lib/right_hook/spec_helpers.rb', line 25 def generate_secret_header(secret, body) sha = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'), secret, body) # GitHub sends it as 'X-Hub-Signature', but Rack provides it as HTTP_X_HUB_SIGNATURE... :/ {'HTTP_X_HUB_SIGNATURE' => "sha1=#{sha}"} end |
#post_with_signature(opts) ⇒ Object
Post to the given path, including the correct signature header based on the payload and secret.
16 17 18 19 20 21 22 |
# File 'lib/right_hook/spec_helpers.rb', line 16 def post_with_signature(opts) path = opts.fetch(:path) payload = opts.fetch(:payload) secret = opts.fetch(:secret) post path, {payload: payload}, generate_secret_header(secret, URI.encode_www_form(payload: payload)) end |