Skip to content

Commit

Permalink
fix(webhooks): correctly validate HTTP method when the given method i…
Browse files Browse the repository at this point in the history
…s not a valid class name
  • Loading branch information
bethesque committed Nov 4, 2022
1 parent 88b7df4 commit 6da5a4f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/pact_broker/api/contracts/webhook_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/pact_broker/api/contracts/webhook_contract_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6da5a4f

Please sign in to comment.