diff --git a/lib/pact_broker/configuration.rb b/lib/pact_broker/configuration.rb index f1a2699c8..28c3a5a81 100644 --- a/lib/pact_broker/configuration.rb +++ b/lib/pact_broker/configuration.rb @@ -31,6 +31,7 @@ class Configuration :webhook_http_method_whitelist, :webhook_scheme_whitelist, :webhook_host_whitelist, + :webhook_http_code_success, :base_equality_only_on_content_that_affects_verification_results, :seed_example_data, :badge_provider_mode, diff --git a/lib/pact_broker/webhooks/webhook_execution_result.rb b/lib/pact_broker/webhooks/webhook_execution_result.rb index c01f1830a..1adbaaa6b 100644 --- a/lib/pact_broker/webhooks/webhook_execution_result.rb +++ b/lib/pact_broker/webhooks/webhook_execution_result.rb @@ -14,7 +14,10 @@ def initialize(request, response, logs, error = nil) end def success? - !response.nil? && response.code.to_i < 300 + unless response.nil? + # Response HTTP Code must be in success list otherwise it is false + PactBroker.configuration.webhook_http_code_success.include? response.code.to_i + end end end end diff --git a/spec/lib/pact_broker/api/resources/webhook_execution_result_spec.rb b/spec/lib/pact_broker/api/resources/webhook_execution_result_spec.rb new file mode 100644 index 000000000..b260aedc1 --- /dev/null +++ b/spec/lib/pact_broker/api/resources/webhook_execution_result_spec.rb @@ -0,0 +1,56 @@ +module PactBroker + module Webhooks + describe WebhookExecutionResult do + subject { WebhookExecutionResult::new(request, response, nil) } + let(:request) do + Net::HTTP::Get.new("http://example.org?foo=bar") + end + + context "When 'webhook_http_code_success' has [200, 201]" do + before do + allow(PactBroker.configuration).to receive(:webhook_http_code_success).and_return([200, 201]) + end + + context "and response is '200'" do + let(:response) { double(code: '200') } + + it "then it should be success" do + expect(subject.success?).to be_truthy + end + end + + context "and response is '400'" do + let(:response) { double(code: '400') } + + it "then it should fail" do + expect(subject.success?).to be_falsey + end + end + end + + + context "When 'webhook_http_code_success' has [400, 401]" do + before do + allow(PactBroker.configuration).to receive(:webhook_http_code_success).and_return([400, 401]) + end + + context "and response is '200'" do + let(:response) { double(code: '200') } + + it "then it should fail" do + expect(subject.success?).to be_falsey + end + end + + context "and response is '400'" do + let(:response) { double(code: '400') } + + it "then it should be success" do + expect(subject.success?).to be_truthy + end + end + end + + end + end +end