stripe 5.19.0 → 5.20.0

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
  SHA256:
3
- metadata.gz: 609a42b37282281ebdaea0fa8e0fd74540cdf49b44df5c3d03fc2c9d05a71638
4
- data.tar.gz: 88f0c70adfa171e72d448126300692dfb027165fbb8d5be69e2dbf1eb7c2a9a1
3
+ metadata.gz: 53d5362cf3395da735662c079302a68f77a067db5ed0b33d9049ab47a5d610e6
4
+ data.tar.gz: a33095d14ba39ec3d3a178c5b6a7aaf477f3290a060bc9955d840d30f284d9ad
5
5
  SHA512:
6
- metadata.gz: a800f54e6335291b9ce91a14d715b9432ebaa04a1145b8616470037972b1c8fb83622ad8226fb03e79ce9350c4b132bb776451da25ed3ca10c8624dfebdef778
7
- data.tar.gz: ff25a1a52d03cdf59c16012cacced71952462ef3daff1f7caea9403045a20c8c1343e5252f326ff5182a92075fdfbd92432c4059504b529f5cca41289a110430
6
+ metadata.gz: 5708098cb83cae3806edc15aa7baa946f7e1107e380282e64012b59d849a8e5b1a6c394b23347b20dc94a81922760cdaea7cb6b634c8c2f35f8b8c74694e5bee
7
+ data.tar.gz: 3add4e8a981bf84adabf38d6c6ee98c7dbebb0254709e38e3ee9c4aeddd68c9ce1b78cf594cf1aad7c1bb587767952cba0be15a273bdb6bf31ed215040c5162b
@@ -1,6 +1,9 @@
1
1
  # Changelog
2
2
 
3
- ## - 2020-04-24
3
+ ## 5.20.0 - 2020-04-27
4
+ * [#916](https://github.com/stripe/stripe-ruby/pull/916) Add new `.generate_header` method for webhooks
5
+
6
+ ## 5.19.0 - 2020-04-24
4
7
  * [#915](https://github.com/stripe/stripe-ruby/pull/915) Expose `Stripe::Webhook.compute_signature` publicly
5
8
 
6
9
  ## 5.18.0 - 2020-04-22
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.19.0
1
+ 5.20.0
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stripe
4
- VERSION = "5.19.0"
4
+ VERSION = "5.20.0"
5
5
  end
@@ -39,6 +39,23 @@ module Stripe
39
39
  timestamped_payload)
40
40
  end
41
41
 
42
+ # Generates a value that would be added to a `Stripe-Signature` for a
43
+ # given webhook payload.
44
+ #
45
+ # Note that this isn't needed to verify webhooks in any way, and is
46
+ # mainly here for use in test cases (those that are both within this
47
+ # project and without).
48
+ def self.generate_header(timestamp, signature, scheme: EXPECTED_SCHEME)
49
+ raise ArgumentError, "timestamp should be an instance of Time" \
50
+ unless timestamp.is_a?(Time)
51
+ raise ArgumentError, "signature should be a string" \
52
+ unless signature.is_a?(String)
53
+ raise ArgumentError, "scheme should be a string" \
54
+ unless scheme.is_a?(String)
55
+
56
+ "t=#{timestamp.to_i},#{scheme}=#{signature}"
57
+ end
58
+
42
59
  # Extracts the timestamp and the signature(s) with the desired scheme
43
60
  # from the header
44
61
  def self.get_timestamp_and_signatures(header, scheme)
@@ -22,7 +22,11 @@ module Stripe
22
22
  opts[:payload],
23
23
  opts[:secret]
24
24
  )
25
- "t=#{opts[:timestamp].to_i},#{opts[:scheme]}=#{opts[:signature]}"
25
+ Stripe::Webhook::Signature.generate_header(
26
+ opts[:timestamp],
27
+ opts[:signature],
28
+ scheme: opts[:scheme]
29
+ )
26
30
  end
27
31
 
28
32
  context ".compute_signature" do
@@ -38,6 +42,24 @@ module Stripe
38
42
  end
39
43
  end
40
44
 
45
+ context ".generate_header" do
46
+ should "generate a header in valid format" do
47
+ timestamp = Time.now
48
+ signature = Stripe::Webhook::Signature.compute_signature(
49
+ timestamp,
50
+ EVENT_PAYLOAD,
51
+ SECRET
52
+ )
53
+ scheme = "v1"
54
+ header = Stripe::Webhook::Signature.generate_header(
55
+ timestamp,
56
+ signature,
57
+ scheme: scheme
58
+ )
59
+ assert_equal("t=#{timestamp.to_i},#{scheme}=#{signature}", header)
60
+ end
61
+ end
62
+
41
63
  context ".construct_event" do
42
64
  should "return an Event instance from a valid JSON payload and valid signature header" do
43
65
  header = generate_header
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.19.0
4
+ version: 5.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-24 00:00:00.000000000 Z
11
+ date: 2020-04-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Stripe is the easiest way to accept payments online. See https://stripe.com
14
14
  for details.