From ac5e08903120b66a54c0c0a6f3654ea0913bcd37 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Wed, 18 Aug 2021 10:55:39 +1000 Subject: [PATCH] fix: validate matrix query limit --- lib/pact_broker/locale/en.yml | 1 + lib/pact_broker/matrix/service.rb | 4 ++++ spec/lib/pact_broker/matrix/service_spec.rb | 11 ++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/pact_broker/locale/en.yml b/lib/pact_broker/locale/en.yml index d70a8b547..468cca69a 100644 --- a/lib/pact_broker/locale/en.yml +++ b/lib/pact_broker/locale/en.yml @@ -87,6 +87,7 @@ en: invalid_content_for_content_type: "The content could not be parsed as %{content_type}" cannot_set_currently_deployed_true: The currentlyDeployed property cannot be set back to true. Please record a new deployment. cannot_set_currently_supported_true: The currentlySupported property cannot be set back to true. Please record a new deployment. + invalid_limit: The limit must be 1 or greater. duplicate_pacticipant: | This is the first time a pact has been published for "%{new_name}". The name "%{new_name}" is very similar to the following existing consumers/providers: diff --git a/lib/pact_broker/matrix/service.rb b/lib/pact_broker/matrix/service.rb index 6e0672bb0..b1680dd78 100644 --- a/lib/pact_broker/matrix/service.rb +++ b/lib/pact_broker/matrix/service.rb @@ -100,6 +100,10 @@ def validate_selectors selectors, options = {} error_messages << message("errors.validation.environment_with_name_not_found", name: options[:environment_name]) end + if options[:limit] && options[:limit].to_i < 1 + error_messages << message("errors.validation.invalid_limit") + end + error_messages end # rubocop: enable Metrics/CyclomaticComplexity, Metrics/MethodLength diff --git a/spec/lib/pact_broker/matrix/service_spec.rb b/spec/lib/pact_broker/matrix/service_spec.rb index 9147f579f..260c42b71 100644 --- a/spec/lib/pact_broker/matrix/service_spec.rb +++ b/spec/lib/pact_broker/matrix/service_spec.rb @@ -12,7 +12,7 @@ module Matrix subject { Service.validate_selectors(selectors, options) } - let(:options) { {} } + let(:options) { { limit: "1" } } context "when there are no selectors" do let(:selectors) { [] } @@ -145,6 +145,15 @@ module Matrix expect(subject.last).to include "Please specify the pacticipant name to ignore" end end + + context "with an invalid limit" do + let(:options) { { limit: "limit" } } + let(:selectors) { [] } + + it "returns an error message" do + expect(subject.last).to include "The limit" + end + end end describe "find_for_consumer_and_provider_with_tags integration test" do