diff --git a/lib/pact_broker/api/contracts/webhook_contract.rb b/lib/pact_broker/api/contracts/webhook_contract.rb index 9c220d6d4..7a7215f37 100644 --- a/lib/pact_broker/api/contracts/webhook_contract.rb +++ b/lib/pact_broker/api/contracts/webhook_contract.rb @@ -130,6 +130,8 @@ def self.host_error_message def valid_method?(http_method) Net::HTTP.const_defined?(http_method.capitalize) + rescue StandardError + false end def valid_url?(url) diff --git a/spec/lib/pact_broker/api/contracts/webhook_contract_spec.rb b/spec/lib/pact_broker/api/contracts/webhook_contract_spec.rb index 18b3cbaea..9003e730c 100644 --- a/spec/lib/pact_broker/api/contracts/webhook_contract_spec.rb +++ b/spec/lib/pact_broker/api/contracts/webhook_contract_spec.rb @@ -372,6 +372,18 @@ def valid_webhook_with expect(subject.errors[:enabled]).to eq ["cannot have a template parameter in the host"] end end + + context "with a dodgey method" do + let(:json) do + valid_webhook_with do |hash| + hash["request"]["method"] = "Post%0d%0a" + end + end + + it "contains an error" do + expect(subject.errors[:"request.http_method"]).to eq ["is not a recognised HTTP method"] + end + end end end end