From 1c41db67527b52925aa602585d489d24e0a759ed Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Tue, 13 Aug 2024 16:40:32 -0600 Subject: [PATCH 1/2] chore: use new webhook fixtures in tests --- examples | 2 +- spec/support/fixture.rb | 16 ++++++++++++---- spec/webhook_spec.rb | 9 ++++----- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/examples b/examples index 7bafcddd..9447e72e 160000 --- a/examples +++ b/examples @@ -1 +1 @@ -Subproject commit 7bafcddd4e7e9f11827a734784127773887443b1 +Subproject commit 9447e72e087b823445b8c3e1351d28c070a8e6b1 diff --git a/spec/support/fixture.rb b/spec/support/fixture.rb index c0d00694..e081ce06 100644 --- a/spec/support/fixture.rb +++ b/spec/support/fixture.rb @@ -41,10 +41,6 @@ def self.report_date '2022-06-11' end - def self.webhook_url - read_fixture_data['webhook_url'] - end - def self.ca_address1 read_fixture_data['addresses']['ca_address_1'] end @@ -132,6 +128,18 @@ def self.event_bytes JSON.parse(data).to_json.encode('UTF-8') end + def self.webhook_hmac_signature + read_fixture_data['webhook_hmac_signature'] + end + + def self.webhook_secret + read_fixture_data['webhook_secret'] + end + + def self.webhook_url + read_fixture_data['webhook_url'] + end + # The credit card details below are for a valid proxy card usable # for tests only and cannot be used for real transactions. # DO NOT alter these details with real credit card information. diff --git a/spec/webhook_spec.rb b/spec/webhook_spec.rb index ec7d37d3..fb8261b2 100644 --- a/spec/webhook_spec.rb +++ b/spec/webhook_spec.rb @@ -75,14 +75,13 @@ describe '.validate_webhook' do it 'validate a webhook' do - webhook_secret = 'sécret' - expected_hmac_signature = 'hmac-sha256-hex=e93977c8ccb20363d51a62b3fe1fc402b7829be1152da9e88cf9e8d07115a46b' headers = { - 'X-Hmac-Signature' => expected_hmac_signature, + 'X-Hmac-Signature' => Fixture.webhook_hmac_signature, } - webhook_body = EasyPost::Util.validate_webhook(Fixture.event_bytes, headers, webhook_secret) - expect(webhook_body['description']).to eq('batch.created') + webhook_body = EasyPost::Util.validate_webhook(Fixture.event_bytes, headers, Fixture.webhook_secret) + expect(webhook_body['description']).to eq('tracker.updated') + expect(webhook_body['result']['weight']).to eq(136.0) end it 'validate a webhook with invalid secret' do From 08cb1710f8faa84ee21e0952a064b0f356f8510f Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Tue, 13 Aug 2024 16:41:19 -0600 Subject: [PATCH 2/2] chore: add missing comment --- spec/webhook_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/webhook_spec.rb b/spec/webhook_spec.rb index fb8261b2..70e0d16f 100644 --- a/spec/webhook_spec.rb +++ b/spec/webhook_spec.rb @@ -81,7 +81,7 @@ webhook_body = EasyPost::Util.validate_webhook(Fixture.event_bytes, headers, Fixture.webhook_secret) expect(webhook_body['description']).to eq('tracker.updated') - expect(webhook_body['result']['weight']).to eq(136.0) + expect(webhook_body['result']['weight']).to eq(136.0) # Ensure we convert floats properly end it 'validate a webhook with invalid secret' do