hubspot-api-client 16.1.1 → 16.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab1a325bccd8f06760d9b2f7149517c100ff5e1504df7ebbf46137bfd8076633
4
- data.tar.gz: a7fabc27a9272be1b7750e4f4ff23294bf9a6b927539ef5c1877df42d6f868b1
3
+ metadata.gz: 9a6993298296b428873f8f86f587f92e2b18adf83ee04ac71d9cd86d9afab75b
4
+ data.tar.gz: 5251f556603bd39e792c1ca547ad1579ef49aaff70a16ed5f9c041e0d0cdeeaa
5
5
  SHA512:
6
- metadata.gz: d5ee0a0ed6eb7dd47c14259eaaeea1c1cef382158d85e8467eada47bd7419502c49b3234c5498a1d4c62b0b8101ec948706aedaf99f9b23268c36a61aec7e34f
7
- data.tar.gz: 54946b4829ccde4b96309e02a740f3e86fb907718392e3274157eb237101869ccd94a386def9f89265bc7b2fcba13e126e93f6b131ff3af19312f96bca9a9e14
6
+ metadata.gz: c2c69d897384df239639611305f031c59dfe574c9539f26605e014a140d52276084d6801858dc1676cb984c73e64dd5fd1e5b9adf926c99afd0bcd017f42535a
7
+ data.tar.gz: f65599a6db559b53f46c5125c699736d126568169c12985d4d7667022d94015b6802e625e89fdf812704d05d246ba3f7a0f448efb8a342d4c77ab93f82a13c4d
data/CHANGELOG.md CHANGED
@@ -5,7 +5,17 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [Unreleased](https://github.com/HubSpot/hubspot-api-ruby/compare/v16.1.1...HEAD)
8
+ ## [Unreleased](https://github.com/HubSpot/hubspot-api-ruby/compare/v16.2.0...HEAD)
9
+
10
+
11
+ ## [16.2.0] - 2023-01-09
12
+ ### Added
13
+
14
+ - Signature's util 'HubSpot.utils.signature'
15
+
16
+ ### Deprecated
17
+
18
+ - webhook's util 'HubSpot.utils.webhooks'
9
19
 
10
20
  ## [16.1.1] - 2022-12-23
11
21
  ### Fixed
data/Gemfile CHANGED
@@ -4,4 +4,5 @@ gemspec
4
4
 
5
5
  group :development, :test do
6
6
  gem 'rake', '~> 12.3.3'
7
+ gem 'openssl'
7
8
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hubspot-api-client (16.1.1)
4
+ hubspot-api-client (16.2.0)
5
5
  json (~> 2.1, >= 2.1.0)
6
6
  typhoeus (~> 1.4.0)
7
7
 
@@ -25,6 +25,7 @@ GEM
25
25
  hashdiff (1.0.1)
26
26
  json (2.6.2)
27
27
  method_source (1.0.0)
28
+ openssl (3.1.0)
28
29
  pry (0.14.1)
29
30
  coderay (~> 1.1)
30
31
  method_source (~> 1.0)
@@ -62,6 +63,7 @@ DEPENDENCIES
62
63
  autotest-growl (~> 0.2, >= 0.2.16)
63
64
  autotest-rails-pure (~> 4.1, >= 4.1.2)
64
65
  hubspot-api-client!
66
+ openssl
65
67
  pry (~> 0.14)
66
68
  rake (~> 12.3.3)
67
69
  rake-release (~> 1.3)
@@ -0,0 +1,62 @@
1
+ require 'date'
2
+ require 'openssl'
3
+
4
+ module Hubspot
5
+ module Helpers
6
+ class Signature
7
+ MAX_ALLOWED_TIMESTAMP = 3000
8
+ def is_valid(
9
+ signature: String,
10
+ client_secret: String,
11
+ request_body: String,
12
+ http_uri: nil,
13
+ http_method: 'POST',
14
+ signature_version: 'v2',
15
+ timestamp: nil
16
+ )
17
+ if signature_version == "v3"
18
+ current_time = DateTime.now.strftime("%s").to_i
19
+ if current_time - timestamp.to_i > MAX_ALLOWED_TIMESTAMP
20
+ raise StandardError("Timestamp is invalid, reject request.")
21
+ end
22
+ end
23
+ hashed_signature = get_signature(
24
+ client_secret: client_secret,
25
+ request_body: request_body,
26
+ signature_version: signature_version,
27
+ http_uri: http_uri,
28
+ http_method: http_method,
29
+ timestamp: timestamp
30
+ )
31
+
32
+ signature == hashed_signature
33
+ end
34
+
35
+ def get_signature(
36
+ client_secret: String,
37
+ request_body: String,
38
+ signature_version: String,
39
+ http_uri: nil,
40
+ http_method: "POST",
41
+ timestamp: nil
42
+ )
43
+ case signature_version
44
+ when "v1"
45
+ source_string = "#{client_secret}#{request_body}"
46
+ hash_result = Digest::SHA2.hexdigest(source_string.encode('utf-8'))
47
+ return hash_result
48
+ when "v2"
49
+ source_string = "#{client_secret}#{http_method}#{http_uri}#{request_body}"
50
+ hash_result = Digest::SHA2.hexdigest(source_string.encode('utf-8'))
51
+ return hash_result
52
+ when "v3"
53
+ source_string = "#{http_method}#{http_uri}#{request_body}#{timestamp}"
54
+ hash_result = OpenSSL::HMAC.base64digest('SHA256', client_secret, source_string.encode('utf-8'))
55
+ return hash_result
56
+ else
57
+ raise StandardError("Not supported signature version: #{signature_version}")
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -1,3 +1,4 @@
1
+ # @deprecated
1
2
  module Hubspot
2
3
  module Helpers
3
4
  class WebhooksHelper
@@ -1,3 +1,3 @@
1
- module Hubspot
2
- VERSION = '16.1.1'
3
- end
1
+ module Hubspot
2
+ VERSION = '16.2.0'
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Hubspot::Helpers::CamelCase" do
4
+ subject( :camel_case) { Hubspot::Helpers::CamelCase.new }
5
+
6
+ it "Method 'format' should convert all snake_case strings to CamelCase strings" do
7
+ result = camel_case.format("some_test_text_in_snake_case")
8
+ expect(result).to eql "SomeTestTextInSnakeCase"
9
+ end
10
+
11
+ end
@@ -0,0 +1,117 @@
1
+ require 'date'
2
+ require_relative "../../lib/hubspot/helpers/signature"
3
+
4
+ TEST_DATA = {
5
+ :client_secret=> "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy",
6
+ :request_body=> "{'example_field':'example_value'}",
7
+ :url=> "https://www.example.com/webhook_uri",
8
+ :http_method=> "POST",
9
+ :timestamp=> 15000000,
10
+ :v1_hash=> "69fc6631a867edd4f9e9e627fc5c1148e3fbdd8b21837b6d2b8901c1fa57f750",
11
+ :v2_hash=> "4fe4e3a7d3cf09db53be39d0a58130e2aaba074ec123a9e355b876a689a1c383",
12
+ :v3_hash=> "HPW73RUtKmcYoEDADG0s6MmGFWUzWJKAW07r8RDgcQw=",
13
+ }
14
+
15
+
16
+
17
+ describe "Hubspot::Helpers::Signature.get_signature" do
18
+ subject( :signature) { Hubspot::Helpers::Signature.new }
19
+
20
+ it "should return hashed data for v3 signature version" do
21
+ result = signature.get_signature(
22
+ client_secret: TEST_DATA[:client_secret],
23
+ request_body: TEST_DATA[:request_body],
24
+ signature_version: "v3",
25
+ http_uri: TEST_DATA[:url],
26
+ timestamp: TEST_DATA[:timestamp]
27
+ )
28
+ expect(result).to eql TEST_DATA[:v3_hash]
29
+ end
30
+ it "should return hashed data for v2 signature version" do
31
+ result = signature.get_signature(
32
+ client_secret: TEST_DATA[:client_secret],
33
+ request_body: TEST_DATA[:request_body],
34
+ signature_version: "v2",
35
+ http_uri: TEST_DATA[:url],
36
+ )
37
+ expect(result).to eql TEST_DATA[:v2_hash]
38
+ end
39
+ it "should return hashed data for v1 signature version" do
40
+ result = signature.get_signature(
41
+ client_secret: TEST_DATA[:client_secret],
42
+ request_body: TEST_DATA[:request_body],
43
+ signature_version: "v1"
44
+ )
45
+ expect(result).to eql TEST_DATA[:v1_hash]
46
+ end
47
+ it "should raise exception for wrong signature version" do
48
+ expect{ signature.get_signature(
49
+ client_secret: TEST_DATA[:client_secret],
50
+ request_body: TEST_DATA[:request_body],
51
+ signature_version: "wrong_signature_version"
52
+ ) }.to raise_error(StandardError)
53
+ end
54
+
55
+ end
56
+
57
+ describe "Hubspot::Helpers::Signature.is_valid" do
58
+ subject( :signature) { Hubspot::Helpers::Signature.new }
59
+ it "should return true for v1 signature version" do
60
+ result = signature.is_valid(
61
+ signature: TEST_DATA[:v1_hash],
62
+ client_secret: TEST_DATA[:client_secret],
63
+ request_body: TEST_DATA[:request_body],
64
+ signature_version: "v1"
65
+ )
66
+ expect(result).to be true
67
+ end
68
+ it "should return true for v2 signature version" do
69
+ result = signature.is_valid(
70
+ signature: TEST_DATA[:v2_hash],
71
+ client_secret: TEST_DATA[:client_secret],
72
+ request_body: TEST_DATA[:request_body],
73
+ http_uri: TEST_DATA[:url],
74
+ signature_version: "v2"
75
+ )
76
+ expect(result).to be true
77
+ end
78
+ it "should return true for v3 signature version" do
79
+ test_timestamp = DateTime.now.strftime("%s")
80
+ test_signature = signature.get_signature(
81
+ client_secret: TEST_DATA[:client_secret],
82
+ request_body: TEST_DATA[:request_body],
83
+ http_uri: TEST_DATA[:http_uri],
84
+ timestamp: test_timestamp,
85
+ signature_version: "v3"
86
+ )
87
+
88
+ result = signature.is_valid(
89
+ signature: test_signature,
90
+ client_secret: TEST_DATA[:client_secret],
91
+ request_body: TEST_DATA[:request_body],
92
+ http_uri: TEST_DATA[:http_uri],
93
+ timestamp: test_timestamp,
94
+ signature_version: "v3"
95
+ )
96
+ expect(result).to be true
97
+ end
98
+ it "should raise exception if :signature_version=>v3 and :timestamp=>nil" do
99
+ expect { signature.is_valid(
100
+ signature: TEST_DATA[:v3_hash],
101
+ client_secret: TEST_DATA[:client_secret],
102
+ request_body: TEST_DATA[:request_body],
103
+ http_uri: TEST_DATA[:http_uri],
104
+ signature_version: "v3"
105
+ ) }.to raise_error(StandardError)
106
+ end
107
+ it "should raise exception if :signature_version=>v3 and :timestamp=>wrong_timestamp" do
108
+ expect { signature.is_valid(
109
+ signature: TEST_DATA[:v3_hash],
110
+ client_secret: TEST_DATA[:client_secret],
111
+ request_body: TEST_DATA[:request_body],
112
+ http_uri: TEST_DATA[:http_uri],
113
+ timestamp: "wrong_timestamp",
114
+ signature_version: "v3"
115
+ ) }.to raise_error(StandardError)
116
+ end
117
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hubspot-api-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.1.1
4
+ version: 16.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - HubSpot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-23 00:00:00.000000000 Z
11
+ date: 2023-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -1655,6 +1655,7 @@ files:
1655
1655
  - lib/hubspot/helpers/camel_case.rb
1656
1656
  - lib/hubspot/helpers/get_all_helper.rb
1657
1657
  - lib/hubspot/helpers/path.rb
1658
+ - lib/hubspot/helpers/signature.rb
1658
1659
  - lib/hubspot/helpers/snake_case.rb
1659
1660
  - lib/hubspot/helpers/webhooks_helper.rb
1660
1661
  - lib/hubspot/oauth_helper.rb
@@ -1805,6 +1806,8 @@ files:
1805
1806
  - spec/discovery/settings/users/users_api_spec.rb
1806
1807
  - spec/discovery/webhooks/settings_api_spec.rb
1807
1808
  - spec/discovery/webhooks/subscriptions_api_spec.rb
1809
+ - spec/helpers/camel_case_spec.rb
1810
+ - spec/helpers/signature_spec.rb
1808
1811
  - spec/spec_helper.rb
1809
1812
  homepage: https://github.com/HubSpot/hubspot-api-ruby
1810
1813
  licenses:
@@ -1976,4 +1979,6 @@ test_files:
1976
1979
  - spec/discovery/events/events_api_spec.rb
1977
1980
  - spec/discovery/webhooks/settings_api_spec.rb
1978
1981
  - spec/discovery/webhooks/subscriptions_api_spec.rb
1982
+ - spec/helpers/signature_spec.rb
1983
+ - spec/helpers/camel_case_spec.rb
1979
1984
  - spec/spec_helper.rb