lib/pact_broker/api/resources/pact.rb in pact_broker-2.81.0 vs lib/pact_broker/api/resources/pact.rb in pact_broker-2.82.0
- old
+ new
@@ -1,11 +1,11 @@
require "cgi"
require "pact_broker/api/resources/base_resource"
require "pact_broker/api/resources/pacticipant_resource_methods"
require "pact_broker/api/decorators/pact_decorator"
require "pact_broker/api/decorators/extended_pact_decorator"
-require "pact_broker/json"
+require "pact_broker/messages"
require "pact_broker/pacts/pact_params"
require "pact_broker/api/contracts/put_pact_params_contract"
require "pact_broker/webhooks/execution_configuration"
require "pact_broker/api/resources/webhook_execution_methods"
require "pact_broker/api/resources/pact_resource_methods"
@@ -15,10 +15,11 @@
module Resources
class Pact < BaseResource
include PacticipantResourceMethods
include WebhookExecutionMethods
include PactResourceMethods
+ include PactBroker::Messages
def content_types_provided
[
["application/hal+json", :to_json],
["application/json", :to_json],
@@ -34,20 +35,18 @@
def allowed_methods
["GET", "PUT", "DELETE", "PATCH", "OPTIONS"]
end
def is_conflict?
- merge_conflict = request.patch? && resource_exists? &&
- Pacts::Merger.conflict?(pact.json_content, pact_params.json_content)
+ merge_conflict = request.patch? && resource_exists? && Pacts::Merger.conflict?(pact.json_content, pact_params.json_content)
- potential_duplicate_pacticipants?(pact_params.pacticipant_names) || merge_conflict
+ potential_duplicate_pacticipants?(pact_params.pacticipant_names) || merge_conflict || disallowed_modification?
end
def malformed_request?
if request.patch? || request.put?
- invalid_json? ||
- contract_validation_errors?(Contracts::PutPactParamsContract.new(pact_params), pact_params)
+ invalid_json? || contract_validation_errors?(Contracts::PutPactParamsContract.new(pact_params), pact_params)
else
false
end
end
@@ -105,9 +104,19 @@
private
def pact
@pact ||= pact_service.find_pact(pact_params)
+ end
+
+ def disallowed_modification?
+ if request.really_put? && pact_service.disallowed_modification?(pact, pact_params.json_content)
+ message_params = { consumer_name: pact_params.consumer_name, consumer_version_number: pact_params.consumer_version_number }
+ set_json_error_message(message("errors.validation.pact_content_modification_not_allowed", message_params))
+ true
+ else
+ false
+ end
end
end
end
end
end