Skip to content

Commit b0bb604

Browse files
committed
fix: gracefully handle scenario where URL supplied in JSON body is not a String
1 parent bf80867 commit b0bb604

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

lib/pact_broker/api/contracts/request_validations.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def url_valid?
2525

2626
def uri
2727
URI(url)
28-
rescue URI::InvalidURIError
28+
rescue URI::InvalidURIError, ArgumentError
2929
nil
3030
end
3131
end

lib/pact_broker/api/contracts/verification_contract.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def not_blank? value
2121

2222
def valid_url? url
2323
URI(url)
24-
rescue URI::InvalidURIError
24+
rescue URI::InvalidURIError, ArgumentError
2525
nil
2626
end
2727

lib/pact_broker/api/contracts/webhook_contract.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ def valid_method?(http_method)
109109
def valid_url?(url)
110110
uri = parse_uri(url)
111111
uri.scheme && uri.host
112-
rescue URI::InvalidURIError
113-
false
112+
rescue URI::InvalidURIError, ArgumentError
113+
nil
114114
end
115115

116116
def allowed_webhook_method?(http_method)

lib/rack/pact_broker/invalid_uri_protection.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def valid_uri? env
2323
begin
2424
parse(::Rack::Request.new(env).url)
2525
true
26-
rescue URI::InvalidURIError
26+
rescue URI::InvalidURIError, ArgumentError
2727
false
2828
end
2929
end

spec/lib/pact_broker/api/contracts/verification_contract_spec.rb

+8
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ def modify hash, options
6464
its(:errors) { is_expected.to be_empty }
6565
end
6666

67+
context "when the buildURL is not stringable" do
68+
let(:build_url) { {} }
69+
70+
it "has an error" do
71+
expect(subject.errors[:build_url]).to include(match("URL"))
72+
end
73+
end
74+
6775
context "when the providerApplicationVersion is not present" do
6876
let(:params) { modify valid_params, without: :providerApplicationVersion }
6977
it "has an error" do

0 commit comments

Comments
 (0)