Skip to content

Commit 6b49e5a

Browse files
authored
Warn when stripe-notify header is present (stripe#1866)
1 parent 5b973db commit 6b49e5a

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

lib/stripe/api_requestor.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ def execute_request(method, path, base_address,
201201
)
202202
req_opts = RequestOptions.extract_opts_from_hash(req_opts)
203203

204+
notice = http_resp["stripe-notice"]
205+
warn("WARNING: #{notice}") if notice
206+
204207
resp = interpret_response(http_resp)
205208

206209
# If being called from `APIRequestor#request`, put the last response in

test/stripe/api_requestor_test.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,29 @@ class RequestorTest < Test::Unit::TestCase
13121312
end
13131313

13141314
context "#execute_request" do
1315+
context "Stripe-Notice header" do
1316+
should "emit a warning when the header is present" do
1317+
stub_request(:post, "#{Stripe::DEFAULT_API_BASE}/v1/charges")
1318+
.to_return(
1319+
body: JSON.generate(object: "charge"),
1320+
headers: { "Stripe-Notice" => "This is a notice" }
1321+
)
1322+
1323+
requestor = APIRequestor.new("sk_test_123")
1324+
requestor.expects(:warn).with("WARNING: This is a notice")
1325+
requestor.execute_request(:post, "/v1/charges", :api)
1326+
end
1327+
1328+
should "not emit a warning when the header is absent" do
1329+
stub_request(:post, "#{Stripe::DEFAULT_API_BASE}/v1/charges")
1330+
.to_return(body: JSON.generate(object: "charge"))
1331+
1332+
requestor = APIRequestor.new("sk_test_123")
1333+
requestor.expects(:warn).never
1334+
requestor.execute_request(:post, "/v1/charges", :api)
1335+
end
1336+
end
1337+
13151338
should "handle success response with empty body" do
13161339
stub_request(:post, "#{Stripe::DEFAULT_API_BASE}/v1/charges")
13171340
.to_return(body: "", status: 200)

0 commit comments

Comments
 (0)