Skip to content

Commit 5fc0563

Browse files
committed
fix(webhooks): add missing validation for event names when creating webhooks
fixes: pact-foundation#324
1 parent 0c490e7 commit 5fc0563

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/pact_broker/api/contracts/webhook_contract.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require 'pact_broker/webhooks/check_host_whitelist'
33
require 'pact_broker/webhooks/render'
44
require 'pact_broker/pacticipants/service'
5+
require 'pact_broker/webhooks/webhook_event'
56

67
module PactBroker
78
module Api
@@ -46,7 +47,6 @@ def pacticipant_exists?(name)
4647

4748
required(:name).filled(:pacticipant_exists?)
4849
end
49-
5050
end
5151

5252
property :provider do
@@ -155,7 +155,7 @@ def parse_uri(uri_string, placeholder = 'placeholder')
155155
property :name
156156

157157
validation do
158-
required(:name).filled
158+
required(:name).filled(included_in?: PactBroker::Webhooks::WebhookEvent::EVENT_NAMES)
159159
end
160160
end
161161
end

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

+12
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ def valid_webhook_with
159159
end
160160
end
161161

162+
context "with an event with an invalid name" do
163+
let(:json) do
164+
valid_webhook_with do |hash|
165+
hash['events'].first['name'] = 'foo'
166+
end
167+
end
168+
169+
it "contains an error" do
170+
expect(subject.errors[:'events.name'].first).to include "must be one of"
171+
end
172+
end
173+
162174
context "with no method" do
163175
let(:json) do
164176
valid_webhook_with do |hash|

0 commit comments

Comments
 (0)