From 5cce75f6446cb77528dfb2cde4a7f100775b0c77 Mon Sep 17 00:00:00 2001 From: Steven Pritchard Date: Sun, 22 Feb 2026 00:04:05 +0000 Subject: [PATCH] Remove PSON fallback paths PSON serialization support has been fully removed. JSON is now the only supported serialization format. Co-Authored-By: Claude Sonnet 4.6 Signed-off-by: Steven Pritchard --- lib/puppet/configurer/fact_handler.rb | 6 +- lib/puppet/defaults.rb | 15 ---- lib/puppet/feature/pson.rb | 4 +- lib/puppet/http/service/compiler.rb | 10 +-- lib/puppet/indirector/catalog/compiler.rb | 4 - lib/puppet/indirector/catalog/json.rb | 18 +--- lib/puppet/network/format_support.rb | 5 -- lib/puppet/network/formats.rb | 34 -------- .../network/http/api/indirected_routes.rb | 7 +- spec/integration/network/formats_spec.rb | 72 ---------------- spec/unit/configurer/fact_handler_spec.rb | 30 ------- spec/unit/defaults_spec.rb | 7 -- spec/unit/http/service/compiler_spec.rb | 12 --- spec/unit/indirector/catalog/compiler_spec.rb | 9 +- spec/unit/network/formats_spec.rb | 84 ------------------- .../http/api/indirected_routes_spec.rb | 46 ++-------- spec/unit/network/http/request_spec.rb | 11 ++- 17 files changed, 21 insertions(+), 353 deletions(-) diff --git a/lib/puppet/configurer/fact_handler.rb b/lib/puppet/configurer/fact_handler.rb index 64f8fb9da9..e89d694b61 100644 --- a/lib/puppet/configurer/fact_handler.rb +++ b/lib/puppet/configurer/fact_handler.rb @@ -42,10 +42,6 @@ def encode_facts(facts) # > 1024 characters sent in POST data, additionally x-www-form-urlencoded # so it's only important that encoding method here return original values # correctly when CGI.unescape called against it (in compiler code) - if Puppet[:preferred_serialization_format] == "pson" - { :facts_format => :pson, :facts => Puppet::Util.uri_query_encode(facts.render(:pson)) } - else - { :facts_format => 'application/json', :facts => Puppet::Util.uri_query_encode(facts.render(:json)) } - end + { :facts_format => 'application/json', :facts => Puppet::Util.uri_query_encode(facts.render(:json)) } end end diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index bd3ad6b23d..6477298a8d 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -1744,21 +1744,6 @@ def self.initialize_default_settings!(settings) instances will be serialized using this method, since not all classes can be guaranteed to support this format, but it will be used for all classes that support it.", - :hook => proc { |value| - if value == "pson" && !Puppet.features.pson? - raise(Puppet::Settings::ValidationError, "The 'puppet-pson' gem must be installed to use the PSON serialization format.") - end - } - }, - :allow_pson_serialization => { - :default => false, - :type => :boolean, - :desc => "Whether to allow PSON serialization. When unable to serialize to - JSON or other formats, Puppet falls back to PSON. This option affects the - configuration management service responses of Puppet Server and the process by - which the agent saves its cached catalog. With a default value of `false`, this - option is useful in preventing the loss of data because rich data cannot be - serialized via PSON.", }, :agent_catalog_run_lockfile => { :default => "$statedir/agent_catalog_run.lock", diff --git a/lib/puppet/feature/pson.rb b/lib/puppet/feature/pson.rb index 4a2511b6d1..40933e8212 100644 --- a/lib/puppet/feature/pson.rb +++ b/lib/puppet/feature/pson.rb @@ -2,5 +2,5 @@ require_relative '../../puppet/util/feature' -# PSON is deprecated, use JSON instead -Puppet.features.add(:pson, :libs => ['puppet/external/pson']) +# PSON has been removed. This feature is always false. +Puppet.features.add(:pson) { false } diff --git a/lib/puppet/http/service/compiler.rb b/lib/puppet/http/service/compiler.rb index 3bf2d12dff..fed801f176 100644 --- a/lib/puppet/http/service/compiler.rb +++ b/lib/puppet/http/service/compiler.rb @@ -82,14 +82,8 @@ def get_node(name, environment:, configured_environment: nil, transaction_uuid: # # @api public def post_catalog(name, facts:, environment:, configured_environment: nil, check_environment: false, transaction_uuid: nil, job_uuid: nil, static_catalog: true, checksum_type: Puppet[:supported_checksum_types]) - if Puppet[:preferred_serialization_format] == "pson" - formatter = Puppet::Network::FormatHandler.format_for(:pson) - # must use 'pson' instead of 'text/pson' - facts_format = 'pson' - else - formatter = Puppet::Network::FormatHandler.format_for(:json) - facts_format = formatter.mime - end + formatter = Puppet::Network::FormatHandler.format_for(:json) + facts_format = formatter.mime facts_as_string = serialize(formatter, facts) diff --git a/lib/puppet/indirector/catalog/compiler.rb b/lib/puppet/indirector/catalog/compiler.rb index 9bae9e0922..73de55c3ca 100644 --- a/lib/puppet/indirector/catalog/compiler.rb +++ b/lib/puppet/indirector/catalog/compiler.rb @@ -118,10 +118,6 @@ def require_environment? # @api private def convert_wire_facts(facts, format) case format - when 'pson' - # We unescape here because the corresponding code in Puppet::Configurer::FactHandler encodes with Puppet::Util.uri_query_encode - # PSON is deprecated, but continue to accept from older agents - Puppet::Node::Facts.convert_from('pson', CGI.unescape(facts)) when 'application/json' Puppet::Node::Facts.convert_from('json', CGI.unescape(facts)) else diff --git a/lib/puppet/indirector/catalog/json.rb b/lib/puppet/indirector/catalog/json.rb index 4deb7892e0..12e0fa6e3f 100644 --- a/lib/puppet/indirector/catalog/json.rb +++ b/lib/puppet/indirector/catalog/json.rb @@ -7,27 +7,11 @@ class Puppet::Resource::Catalog::Json < Puppet::Indirector::JSON desc "Store catalogs as flat files, serialized using JSON." def from_json(text) - utf8 = text.force_encoding(Encoding::UTF_8) - - if utf8.valid_encoding? - model.convert_from(json_format, utf8) - else - Puppet.info(_("Unable to deserialize catalog from json, retrying with pson")) - model.convert_from('pson', text.force_encoding(Encoding::BINARY)) - end + model.convert_from(json_format, text.force_encoding(Encoding::UTF_8)) end def to_json(object) object.render(json_format) - rescue Puppet::Network::FormatHandler::FormatError => err - if Puppet[:allow_pson_serialization] - Puppet.info(_("Unable to serialize catalog to json, retrying with pson. PSON is deprecated and will be removed in a future release")) - Puppet.log_exception(err, err.message, level: :debug) - object.render('pson').force_encoding(Encoding::BINARY) - else - Puppet.info(_("Unable to serialize catalog to json, no other acceptable format")) - Puppet.log_exception(err, err.message, level: :err) - end end private diff --git a/lib/puppet/network/format_support.rb b/lib/puppet/network/format_support.rb index b59bbe7f80..cab3999920 100644 --- a/lib/puppet/network/format_support.rb +++ b/lib/puppet/network/format_support.rb @@ -98,11 +98,6 @@ def to_msgpack(*args) to_data_hash.to_msgpack(*args) end - # @deprecated, use to_json - def to_pson(*args) - to_data_hash.to_pson(*args) - end - def to_json(*args) Puppet::Util::Json.dump(to_data_hash, *args) end diff --git a/lib/puppet/network/formats.rb b/lib/puppet/network/formats.rb index f3960256d0..87435b7a26 100644 --- a/lib/puppet/network/formats.rb +++ b/lib/puppet/network/formats.rb @@ -87,38 +87,6 @@ def supported?(klass) :required_methods => [:render_method, :intern_method]) do end -# PSON is deprecated -Puppet::Network::FormatHandler.create_serialized_formats(:pson, :weight => 10, :required_methods => [:render_method, :intern_method], :intern_method => :from_data_hash) do - confine :feature => :pson - - def intern(klass, text) - data_to_instance(klass, PSON.parse(text)) - end - - def intern_multiple(klass, text) - PSON.parse(text).collect do |data| - data_to_instance(klass, data) - end - end - - # PSON monkey-patches Array, so this works. - def render_multiple(instances) - instances.to_pson - end - - # If they pass class information, we want to ignore it. - # This is required for compatibility with Puppet 3.x - def data_to_instance(klass, data) - d = data['data'] if data.is_a?(Hash) - if d - data = d - end - return data if data.is_a?(klass) - - klass.from_data_hash(data) - end -end - Puppet::Network::FormatHandler.create_serialized_formats(:json, :mime => 'application/json', :charset => Encoding::UTF_8, :weight => 15, :required_methods => [:render_method, :intern_method], :intern_method => :from_data_hash) do def intern(klass, text) data_to_instance(klass, Puppet::Util::Json.load(text)) @@ -134,8 +102,6 @@ def render_multiple(instances) Puppet::Util::Json.dump(instances) end - # Unlike PSON, we do not need to unwrap the data envelope, because legacy 3.x agents - # have never supported JSON def data_to_instance(klass, data) return data if data.is_a?(klass) diff --git a/lib/puppet/network/http/api/indirected_routes.rb b/lib/puppet/network/http/api/indirected_routes.rb index 3d0055ffb5..8a7a1593c1 100644 --- a/lib/puppet/network/http/api/indirected_routes.rb +++ b/lib/puppet/network/http/api/indirected_routes.rb @@ -189,12 +189,7 @@ def first_response_formatter_for(model, request, key, &block) rescue Puppet::Network::FormatHandler::FormatError => err msg = _("Failed to serialize %{model} for '%{key}': %{detail}") % { model: model, key: key, detail: err } - if Puppet[:allow_pson_serialization] - Puppet.warning(msg) - else - raise Puppet::Network::FormatHandler::FormatError, msg - end - false + raise Puppet::Network::FormatHandler::FormatError, msg end return formatter if formatter diff --git a/spec/integration/network/formats_spec.rb b/spec/integration/network/formats_spec.rb index ee2d87c7b8..755d169343 100644 --- a/spec/integration/network/formats_spec.rb +++ b/spec/integration/network/formats_spec.rb @@ -2,33 +2,6 @@ require 'puppet/network/formats' -class PsonIntTest - attr_accessor :string - def ==(other) - other.class == self.class and string == other.string - end - - def self.from_data_hash(data) - new(data[0]) - end - - def initialize(string) - @string = string - end - - def to_pson(*args) - { - 'type' => self.class.name, - 'data' => [@string] - }.to_pson(*args) - end - - def self.canonical_order(s) - s.gsub(/\{"data":\[(.*?)\],"type":"PsonIntTest"\}/,'{"type":"PsonIntTest","data":[\1]}') - end - -end - describe Puppet::Network::FormatHandler.format(:s) do before do @format = Puppet::Network::FormatHandler.format(:s) @@ -43,48 +16,3 @@ def self.canonical_order(s) end end -describe Puppet::Network::FormatHandler.format(:pson), if: Puppet.features.pson? do - before do - @pson = Puppet::Network::FormatHandler.format(:pson) - end - - it "should be able to render an instance to pson" do - instance = PsonIntTest.new("foo") - expect(PsonIntTest.canonical_order(@pson.render(instance))).to eq(PsonIntTest.canonical_order('{"type":"PsonIntTest","data":["foo"]}' )) - end - - it "should be able to render arrays to pson" do - expect(@pson.render([1,2])).to eq('[1,2]') - end - - it "should be able to render arrays containing hashes to pson" do - expect(@pson.render([{"one"=>1},{"two"=>2}])).to eq('[{"one":1},{"two":2}]') - end - - it "should be able to render multiple instances to pson" do - one = PsonIntTest.new("one") - two = PsonIntTest.new("two") - - expect(PsonIntTest.canonical_order(@pson.render([one,two]))).to eq(PsonIntTest.canonical_order('[{"type":"PsonIntTest","data":["one"]},{"type":"PsonIntTest","data":["two"]}]')) - end - - it "should be able to intern pson into an instance" do - expect(@pson.intern(PsonIntTest, '{"type":"PsonIntTest","data":["foo"]}')).to eq(PsonIntTest.new("foo")) - end - - it "should be able to intern pson with no class information into an instance" do - expect(@pson.intern(PsonIntTest, '["foo"]')).to eq(PsonIntTest.new("foo")) - end - - it "should be able to intern multiple instances from pson" do - expect(@pson.intern_multiple(PsonIntTest, '[{"type": "PsonIntTest", "data": ["one"]},{"type": "PsonIntTest", "data": ["two"]}]')).to eq([ - PsonIntTest.new("one"), PsonIntTest.new("two") - ]) - end - - it "should be able to intern multiple instances from pson with no class information" do - expect(@pson.intern_multiple(PsonIntTest, '[["one"],["two"]]')).to eq([ - PsonIntTest.new("one"), PsonIntTest.new("two") - ]) - end -end diff --git a/spec/unit/configurer/fact_handler_spec.rb b/spec/unit/configurer/fact_handler_spec.rb index 1acf49c30a..2192878a90 100644 --- a/spec/unit/configurer/fact_handler_spec.rb +++ b/spec/unit/configurer/fact_handler_spec.rb @@ -79,36 +79,6 @@ def reload_facter { :hash => { 'afact' => "A\u06FF\u16A0\u{2070E}" }, :encoded => '%22values%22%3A%7B%22afact%22%3A%22' + 'A%DB%BF%E1%9A%A0%F0%A0%9C%8E' + '%22%7D' }, ] - context "as pson", if: Puppet.features.pson? do - before :each do - Puppet[:preferred_serialization_format] = 'pson' - end - - it "should serialize and CGI escape the fact values for uploading" do - facts = Puppet::Node::Facts.new(Puppet[:node_name_value], 'my_name_fact' => 'other_node_name') - Puppet::Node::Facts.indirection.save(facts) - text = Puppet::Util.uri_query_encode(facthandler.find_facts.render(:pson)) - - expect(text).to include('%22values%22%3A%7B%22my_name_fact%22%3A%22other_node_name%22%7D') - expect(facthandler.facts_for_uploading).to eq({:facts_format => :pson, :facts => text}) - end - - facts_with_special_characters.each do |test_fact| - it "should properly accept the fact #{test_fact[:hash]}" do - facts = Puppet::Node::Facts.new(Puppet[:node_name_value], test_fact[:hash]) - Puppet::Node::Facts.indirection.save(facts) - text = Puppet::Util.uri_query_encode(facthandler.find_facts.render(:pson)) - - to_upload = facthandler.facts_for_uploading - expect(to_upload).to eq({:facts_format => :pson, :facts => text}) - expect(text).to include(test_fact[:encoded]) - - # this is not sufficient to test whether these values are sent via HTTP GET or HTTP POST in actual catalog request - expect(JSON.parse(Puppet::Util.uri_unescape(to_upload[:facts]))['values']).to eq(test_fact[:hash]) - end - end - end - context "as json" do it "should serialize and CGI escape the fact values for uploading" do facts = Puppet::Node::Facts.new(Puppet[:node_name_value], 'my_name_fact' => 'other_node_name') diff --git a/spec/unit/defaults_spec.rb b/spec/unit/defaults_spec.rb index 9f322b38ec..5563648f76 100644 --- a/spec/unit/defaults_spec.rb +++ b/spec/unit/defaults_spec.rb @@ -172,11 +172,4 @@ end end - describe "#preferred_serialization_format" do - it 'raises if PSON is not available', unless: Puppet.features.pson? do - expect { - Puppet.settings[:preferred_serialization_format] = "pson" - }.to raise_error(Puppet::Settings::ValidationError, "The 'puppet-pson' gem must be installed to use the PSON serialization format.") - end - end end diff --git a/spec/unit/http/service/compiler_spec.rb b/spec/unit/http/service/compiler_spec.rb index ba07a2901c..cf3bd9b3a2 100644 --- a/spec/unit/http/service/compiler_spec.rb +++ b/spec/unit/http/service/compiler_spec.rb @@ -68,16 +68,6 @@ subject.post_catalog(certname, environment: environment, facts: facts) end - it 'submits facts as pson if set as the preferred format', if: Puppet.features.pson? do - Puppet[:preferred_serialization_format] = "pson" - - stub_request(:post, uri) - .with(body: hash_including("facts_format" => /pson/)) - .to_return(**catalog_response) - - subject.post_catalog(certname, environment: environment, facts: facts) - end - it 'includes environment as a query parameter AND in the POST body' do stub_request(:post, uri) .with(query: {"environment" => "outerspace"}, @@ -145,7 +135,6 @@ .to_return(**catalog_response) allow(Puppet.features).to receive(:msgpack?).and_return(false) - allow(Puppet.features).to receive(:pson?).and_return(false) subject.post_catalog(certname, environment: environment, facts: facts) end @@ -156,7 +145,6 @@ .to_return(**catalog_response) allow(Puppet.features).to receive(:msgpack?).and_return(true) - allow(Puppet.features).to receive(:pson?).and_return(false) subject.post_catalog(certname, environment: environment, facts: facts) end diff --git a/spec/unit/indirector/catalog/compiler_spec.rb b/spec/unit/indirector/catalog/compiler_spec.rb index a0fa4fd3b1..354b482fc2 100644 --- a/spec/unit/indirector/catalog/compiler_spec.rb +++ b/spec/unit/indirector/catalog/compiler_spec.rb @@ -306,7 +306,7 @@ def set_facts(fact_hash) Puppet::Node::Facts.indirection.save(facts) end - def a_legacy_request_that_contains(facts, format = :pson) + def a_legacy_request_that_contains(facts, format = :yaml) request = Puppet::Indirector::Request.new(:catalog, :find, "hostname", nil) request.options[:facts_format] = format.to_s request.options[:facts] = Puppet::Util.uri_query_encode(facts.render(format)) @@ -338,13 +338,6 @@ def a_request_that_contains(facts) expect(facts.timestamp).to eq(time) end - it "accepts PSON facts from older agents", :if => Puppet.features.pson? do - request = a_legacy_request_that_contains(facts) - - facts = compiler.extract_facts_from_request(request) - expect(facts).to eq(facts) - end - it "rejects YAML facts" do request = a_legacy_request_that_contains(facts, :yaml) diff --git a/spec/unit/network/formats_spec.rb b/spec/unit/network/formats_spec.rb index 4f53c611db..68e570585c 100644 --- a/spec/unit/network/formats_spec.rb +++ b/spec/unit/network/formats_spec.rb @@ -247,90 +247,6 @@ def self.from_binary(data) end end - describe "pson", :if => Puppet.features.pson? do - let(:pson) { Puppet::Network::FormatHandler.format(:pson) } - - it "should include a pson format" do - expect(pson).not_to be_nil - end - - it "should have its mime type set to text/pson" do - expect(pson.mime).to eq("text/pson") - end - - it "should have a nil charset" do - expect(pson.charset).to be_nil - end - - it "should require the :render_method" do - expect(pson.required_methods).to be_include(:render_method) - end - - it "should require the :intern_method" do - expect(pson.required_methods).to be_include(:intern_method) - end - - it "should have a weight of 10" do - expect(pson.weight).to eq(10) - end - - it "should render an instance as pson" do - instance = FormatsTest.new("foo") - expect(pson.render(instance)).to eq({"string" => "foo"}.to_pson) - end - - it "should render multiple instances as pson" do - instances = [FormatsTest.new("foo")] - expect(pson.render_multiple(instances)).to eq([{"string" => "foo"}].to_pson) - end - - it "should intern an instance from a pson hash" do - text = PSON.dump({"string" => "parsed_pson"}) - instance = pson.intern(FormatsTest, text) - expect(instance.string).to eq("parsed_pson") - end - - it "should skip data_to_hash if data is already an instance of the specified class" do - # The rest terminus for the report indirected type relies on this behavior - data = PSON.dump([1, 2]) - instance = pson.intern(Array, data) - expect(instance).to eq([1, 2]) - end - - it "should intern multiple instances from a pson array" do - text = PSON.dump( - [ - { - "string" => "BAR" - }, - { - "string" => "BAZ" - } - ] - ) - expect(pson.intern_multiple(FormatsTest, text)).to eq([FormatsTest.new('BAR'), FormatsTest.new('BAZ')]) - end - - it "should unwrap the data from legacy clients" do - text = PSON.dump( - { - "type" => "FormatsTest", - "data" => { - "string" => "parsed_json" - } - } - ) - instance = pson.intern(FormatsTest, text) - expect(instance.string).to eq("parsed_json") - end - - it "fails intelligibly when given invalid data" do - expect do - pson.intern(Puppet::Node, '') - end.to raise_error(PSON::ParserError, /source did not contain any PSON/) - end - end - describe "json" do let(:json) { Puppet::Network::FormatHandler.format(:json) } diff --git a/spec/unit/network/http/api/indirected_routes_spec.rb b/spec/unit/network/http/api/indirected_routes_spec.rb index 2d15aeae27..731bb80015 100644 --- a/spec/unit/network/http/api/indirected_routes_spec.rb +++ b/spec/unit/network/http/api/indirected_routes_spec.rb @@ -177,20 +177,6 @@ expect(response.type).to eq(Puppet::Network::FormatHandler.format(:json)) end - it "falls back to the next supported format", if: Puppet.features.pson? do - Puppet[:allow_pson_serialization] = true - data = Puppet::IndirectorTesting.new("my data") - indirection.save(data, "my data") - request = a_request_that_finds(data, :accept_header => "application/json, text/pson") - allow(data).to receive(:to_json).and_raise(Puppet::Network::FormatHandler::FormatError, 'Could not render to Puppet::Network::Format[json]: source sequence is illegal/malformed utf-8') - expect(Puppet).to receive(:warning).with(/Failed to serialize Puppet::IndirectorTesting for 'my data': Could not render to Puppet::Network::Format\[json\]/) - - handler.call(request, response) - - expect(response.body).to eq(data.render(:pson)) - expect(response.type).to eq(Puppet::Network::FormatHandler.format(:pson)) - end - it "should pass the result through without rendering it if the result is a string" do data = Puppet::IndirectorTesting.new("my data") data_string = "my data string" @@ -212,17 +198,16 @@ }.to raise_error(not_found_error) end - it "should raise FormatError if tries to fallback" do + it "should raise FormatError if serialization fails" do data = Puppet::IndirectorTesting.new("my data") indirection.save(data, "my data") - request = a_request_that_finds(data, :accept_header => "unknown, text/pson") - allow(Puppet.features).to receive(:pson?).and_return(true) - allow(data).to receive(:to_pson).and_raise(Puppet::Network::FormatHandler::FormatError, 'Could not render to Puppet::Network::Format[pson]: source sequence is illegal/malformed utf-8') + request = a_request_that_finds(data, :accept_header => "application/json") + allow(data).to receive(:to_json).and_raise(Puppet::Network::FormatHandler::FormatError, 'Could not render to Puppet::Network::Format[json]: source sequence is illegal/malformed utf-8') expect { handler.call(request, response) }.to raise_error(Puppet::Network::FormatHandler::FormatError, - %r{Failed to serialize Puppet::IndirectorTesting for 'my data': Could not render to Puppet::Network::Format\[pson\]}) + %r{Failed to serialize Puppet::IndirectorTesting for 'my data': Could not render to Puppet::Network::Format\[json\]}) end end @@ -238,20 +223,6 @@ expect(response.body).to eq(Puppet::IndirectorTesting.render_multiple(:json, [data])) end - it "falls back to the next supported format", if: Puppet.features.pson? do - Puppet[:allow_pson_serialization] = true - data = Puppet::IndirectorTesting.new("my data") - indirection.save(data, "my data") - request = a_request_that_searches(Puppet::IndirectorTesting.new("my"), :accept_header => "application/json, text/pson") - allow(data).to receive(:to_json).and_raise(Puppet::Network::FormatHandler::FormatError, 'Could not render to Puppet::Network::Format[json]: source sequence is illegal/malformed utf-8') - expect(Puppet).to receive(:warning).with(/Failed to serialize Puppet::IndirectorTesting for 'my': Could not render_multiple to Puppet::Network::Format\[json\]/) - - handler.call(request, response) - - expect(response.type).to eq(Puppet::Network::FormatHandler.format(:pson)) - expect(response.body).to eq(Puppet::IndirectorTesting.render_multiple(:pson, [data])) - end - it "raises 406 not acceptable if no formats are accceptable" do data = Puppet::IndirectorTesting.new("my data") indirection.save(data, "my data") @@ -263,17 +234,16 @@ %r{No supported formats are acceptable \(Accept: unknown\)}) end - it "raises FormatError if tries to fallback" do + it "raises FormatError if serialization fails" do data = Puppet::IndirectorTesting.new("my data") indirection.save(data, "my data") - request = a_request_that_searches(Puppet::IndirectorTesting.new("my"), :accept_header => "unknown, text/pson") - allow(Puppet.features).to receive(:pson?).and_return(true) - allow(data).to receive(:to_pson).and_raise(Puppet::Network::FormatHandler::FormatError, 'Could not render to Puppet::Network::Format[pson]: source sequence is illegal/malformed utf-8') + request = a_request_that_searches(Puppet::IndirectorTesting.new("my"), :accept_header => "application/json") + allow(data).to receive(:to_json).and_raise(Puppet::Network::FormatHandler::FormatError, 'Could not render to Puppet::Network::Format[json]: source sequence is illegal/malformed utf-8') expect { handler.call(request, response) }.to raise_error(Puppet::Network::FormatHandler::FormatError, - %r{Failed to serialize Puppet::IndirectorTesting for 'my': Could not render_multiple to Puppet::Network::Format\[pson\]}) + %r{Failed to serialize Puppet::IndirectorTesting for 'my': Could not render_multiple to Puppet::Network::Format\[json\]}) end it "should return [] when searching returns an empty array" do diff --git a/spec/unit/network/http/request_spec.rb b/spec/unit/network/http/request_spec.rb index f18e93f687..1e6811ff07 100644 --- a/spec/unit/network/http/request_spec.rb +++ b/spec/unit/network/http/request_spec.rb @@ -6,7 +6,6 @@ include PuppetSpec::Network let(:json_formatter) { Puppet::Network::FormatHandler.format(:json) } - let(:pson_formatter) { Puppet::Network::FormatHandler.format(:pson) } def headers { @@ -75,13 +74,13 @@ def a_request(headers, body = "") end it "returns accepted and supported formats, in the accepted order" do - request = a_request(headers.merge('accept' => 'application/json, application/x-msgpack, text/pson')) - expect(request.response_formatters_for([:pson, :json])).to eq([json_formatter, pson_formatter]) + request = a_request(headers.merge('accept' => 'application/json, text/yaml')) + expect(request.response_formatters_for([:json])).to eq([json_formatter]) end - it "selects the second format if the first one isn't supported by the server" do - request = a_request(headers.merge('accept' => 'application/json, text/pson')) - expect(request.response_formatters_for([:pson])).to eq([pson_formatter]) + it "selects the first matching format between accepted and server-supported" do + request = a_request(headers.merge('accept' => 'text/yaml, application/json')) + expect(request.response_formatters_for([:json])).to eq([json_formatter]) end it "raises HTTP 406 if Accept doesn't include any server-supported formats" do