Skip to content

Commit ed536c8

Browse files
committedJun 16, 2022
Fix webhook request for headers with symbol key
E.g. the clearance session is called `:clearance` and it then fails with the error: ``` ShopifyAPITest::Webhooks::WebhookRequestTest#test_with_symbol_headers: NoMethodError: undefined method `sub' for :clearance:Symbol Did you mean? stub ```
1 parent 09952c4 commit ed536c8

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed
 

‎lib/shopify_api/webhooks/request.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def parsed_body
3535
sig { params(raw_body: String, headers: T::Hash[String, T.untyped]).void }
3636
def initialize(raw_body:, headers:)
3737
# normalize the headers by forcing lowercase, removing any prepended "http"s, and changing underscores to dashes
38-
headers = headers.to_h { |k, v| [k.downcase.sub("http_", "").gsub("_", "-"), v] }
38+
headers = headers.to_h { |k, v| [k.to_s.downcase.sub("http_", "").gsub("_", "-"), v] }
3939

4040
missing_headers = []
4141
[

‎test/webhooks/request_test.rb

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ def test_error_when_headers_missing
2121
ShopifyAPI::Webhooks::Request.new(raw_body: "{}", headers: {})
2222
end
2323
end
24+
25+
def test_with_symbol_headers
26+
headers = {
27+
"HTTP_X_SHOPIFY_TOPIC" => "some/topic",
28+
"HTTP_X_SHOPIFY_HMAC_SHA256" => "some_hmac",
29+
"HTTP_X_SHOPIFY_SHOP_DOMAIN" => "shop.myshopify.com",
30+
:clearance => "session"
31+
}
32+
33+
assert(ShopifyAPI::Webhooks::Request.new(raw_body: "{}", headers: headers))
34+
end
2435
end
2536
end
2637
end

0 commit comments

Comments
 (0)