From 3aea3a0e5fd38cb7f9a4e9012d5f0f003ace491b Mon Sep 17 00:00:00 2001 From: Chris Gaffney Date: Tue, 12 May 2020 12:56:08 -0400 Subject: [PATCH] Fixes tests for Stripe 5.19.0 As of 5.19.0, the compute_signature method was made public and they split the timestamp into a separate param (which must be a Time). This version checks compute_signature based on the number of params it takes since doing a version check felt odd. Now that it is public, the method shouldn't change it's API. 1: https://github.com/stripe/stripe-ruby/pull/915 --- spec/controllers/webhook_controller_spec.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/spec/controllers/webhook_controller_spec.rb b/spec/controllers/webhook_controller_spec.rb index a6089f1..ebb395e 100644 --- a/spec/controllers/webhook_controller_spec.rb +++ b/spec/controllers/webhook_controller_spec.rb @@ -12,10 +12,19 @@ def stub_event(identifier) def generate_signature(params, secret) payload = params.to_json - timestamp = Time.now.to_i - signature = Stripe::Webhook::Signature.send(:compute_signature, "#{timestamp}.#{payload}", secret) - - "t=#{timestamp},v1=#{signature}" + timestamp = Time.now + + # compute_signature was private until version 5.19.0 when it was made + # public and had it's API changed to split timestamp to a separate field. + signer = Stripe::Webhook::Signature.method(:compute_signature) + signature = + if signer.arity == 3 + signer.call(timestamp, payload, secret) + else + signer.call("#{timestamp.to_i}.#{payload}", secret) + end + + "t=#{timestamp.to_i},v1=#{signature}" end def webhook(signature, params)