Skip to content

Commit

Permalink
fix: gracefully handle scenario where URL supplied in JSON body is no…
Browse files Browse the repository at this point in the history
…t a String
  • Loading branch information
bethesque committed Aug 23, 2018
1 parent bf80867 commit b0bb604
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/pact_broker/api/contracts/request_validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def url_valid?

def uri
URI(url)
rescue URI::InvalidURIError
rescue URI::InvalidURIError, ArgumentError
nil
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/api/contracts/verification_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def not_blank? value

def valid_url? url
URI(url)
rescue URI::InvalidURIError
rescue URI::InvalidURIError, ArgumentError
nil
end

Expand Down
4 changes: 2 additions & 2 deletions lib/pact_broker/api/contracts/webhook_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def valid_method?(http_method)
def valid_url?(url)
uri = parse_uri(url)
uri.scheme && uri.host
rescue URI::InvalidURIError
false
rescue URI::InvalidURIError, ArgumentError
nil
end

def allowed_webhook_method?(http_method)
Expand Down
2 changes: 1 addition & 1 deletion lib/rack/pact_broker/invalid_uri_protection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def valid_uri? env
begin
parse(::Rack::Request.new(env).url)
true
rescue URI::InvalidURIError
rescue URI::InvalidURIError, ArgumentError
false
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ def modify hash, options
its(:errors) { is_expected.to be_empty }
end

context "when the buildURL is not stringable" do
let(:build_url) { {} }

it "has an error" do
expect(subject.errors[:build_url]).to include(match("URL"))
end
end

context "when the providerApplicationVersion is not present" do
let(:params) { modify valid_params, without: :providerApplicationVersion }
it "has an error" do
Expand Down

0 comments on commit b0bb604

Please sign in to comment.