Skip to content

Commit

Permalink
fix(webhooks): add missing validation for event names when creating w…
Browse files Browse the repository at this point in the history
…ebhooks

fixes: #324
  • Loading branch information
bethesque committed May 12, 2020
1 parent 0c490e7 commit 5fc0563
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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 @@ -2,6 +2,7 @@
require 'pact_broker/webhooks/check_host_whitelist'
require 'pact_broker/webhooks/render'
require 'pact_broker/pacticipants/service'
require 'pact_broker/webhooks/webhook_event'

module PactBroker
module Api
Expand Down Expand Up @@ -46,7 +47,6 @@ def pacticipant_exists?(name)

required(:name).filled(:pacticipant_exists?)
end

end

property :provider do
Expand Down Expand Up @@ -155,7 +155,7 @@ def parse_uri(uri_string, placeholder = 'placeholder')
property :name

validation do
required(:name).filled
required(:name).filled(included_in?: PactBroker::Webhooks::WebhookEvent::EVENT_NAMES)
end
end
end
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 @@ -159,6 +159,18 @@ def valid_webhook_with
end
end

context "with an event with an invalid name" do
let(:json) do
valid_webhook_with do |hash|
hash['events'].first['name'] = 'foo'
end
end

it "contains an error" do
expect(subject.errors[:'events.name'].first).to include "must be one of"
end
end

context "with no method" do
let(:json) do
valid_webhook_with do |hash|
Expand Down

0 comments on commit 5fc0563

Please sign in to comment.