Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Forward the event's signature in the HandleRequest

Stefan Vermaas7861641684fd
diff --git a/api/app/services/spree/webhooks/subscribers/handle_request.rb b/api/app/services/spree/webhooks/subscribers/handle_request.rb
index 59a7a58c9f..6d38e334e4 100644
--- a/api/app/services/spree/webhooks/subscribers/handle_request.rb
+++ b/api/app/services/spree/webhooks/subscribers/handle_request.rb
@@ -39,7 +39,11 @@ module Spree
def request
@request ||=
- Spree::Webhooks::Subscribers::MakeRequest.new(webhook_payload_body: body_with_event_metadata, url: url)
+ Spree::Webhooks::Subscribers::MakeRequest.new(
+ signature: event.signature_for(body_with_event_metadata),
+ url: url,
+ webhook_payload_body: body_with_event_metadata
+ )
end
alias make_request request
diff --git a/api/spec/services/spree/webhooks/subscribers/handle_request_spec.rb b/api/spec/services/spree/webhooks/subscribers/handle_request_spec.rb
index be38c99239..503ec3426c 100644
--- a/api/spec/services/spree/webhooks/subscribers/handle_request_spec.rb
+++ b/api/spec/services/spree/webhooks/subscribers/handle_request_spec.rb
@@ -35,6 +35,10 @@ describe Spree::Webhooks::Subscribers::HandleRequest do
).to_json
end
+ let(:event_signature) do
+ Spree::Webhooks::EventSignature.new(event, body_with_event_metadata).computed_signature
+ end
+
it 'debug logs' do
allow(Rails.logger).to receive(:debug)
allow(Spree::Webhooks::Subscribers::MakeRequest).to receive(:new).and_call_original
@@ -43,9 +47,14 @@ describe Spree::Webhooks::Subscribers::HandleRequest do
message_snd = "[SPREE WEBHOOKS] 'order.canceled' webhook_payload_body: #{body_with_event_metadata}"
expect(Rails.logger).to have_received(:debug).with(message_fst)
expect(Rails.logger).to have_received(:debug).with(message_snd)
- expect(Spree::Webhooks::Subscribers::MakeRequest).to(
- have_received(:new).with(webhook_payload_body: body_with_event_metadata, url: url)
- )
+
+ expect(Spree::Webhooks::Subscribers::MakeRequest).to \
+ have_received(:new).
+ with(
+ signature: event_signature,
+ url: url,
+ webhook_payload_body: body_with_event_metadata
+ )
end
it "#{with_log_level} logs" do
@@ -171,13 +180,21 @@ describe Spree::Webhooks::Subscribers::HandleRequest do
).to_json
end
+ let(:event_signature) do
+ Spree::Webhooks::EventSignature.new(event, body_with_event_metadata).computed_signature
+ end
+
it 'adds the event data to the body' do
with_webhooks_enabled do
allow(Spree::Webhooks::Subscribers::MakeRequest).to receive(:new).and_call_original
order.finalize!
- expect(Spree::Webhooks::Subscribers::MakeRequest).to(
- have_received(:new).with(webhook_payload_body: body_with_event_metadata, url: url)
- )
+ expect(Spree::Webhooks::Subscribers::MakeRequest).to \
+ have_received(:new).
+ with(
+ signature: event_signature,
+ url: url,
+ webhook_payload_body: body_with_event_metadata
+ )
end
end
end