Skip to content

Commit 09405d4

Browse files
authored
Merge pull request #8432 from joshcooper/merge_master_main
(maint) Merge master to main
2 parents 2117ee2 + 7cef257 commit 09405d4

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

lib/puppet/network/formats.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ def render(instance)
255255
end
256256

257257
def supported?(klass)
258-
klass == Puppet::Resource::Catalog &&
258+
suitable? &&
259+
klass == Puppet::Resource::Catalog &&
259260
Puppet.lookup(:current_environment).rich_data?
260261
end
261262
end

spec/unit/http/service/compiler_spec.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,26 @@
130130
subject.post_catalog(certname, environment: 'production', facts: facts, checksum_type: %w[sha256 sha384])
131131
end
132132

133+
it 'does not accept msgpack by default' do
134+
stub_request(:post, uri)
135+
.with(headers: {'Accept' => 'application/vnd.puppet.rich+json, application/json, text/pson'})
136+
.to_return(**catalog_response)
137+
138+
allow(Puppet.features).to receive(:msgpack?).and_return(false)
139+
140+
subject.post_catalog(certname, environment: environment, facts: facts)
141+
end
142+
143+
it 'accepts msgpack & rich_json_msgpack if the gem is present' do
144+
stub_request(:post, uri)
145+
.with(headers: {'Accept' => 'application/vnd.puppet.rich+json, application/json, application/vnd.puppet.rich+msgpack, application/x-msgpack, text/pson'})
146+
.to_return(**catalog_response)
147+
148+
allow(Puppet.features).to receive(:msgpack?).and_return(true)
149+
150+
subject.post_catalog(certname, environment: environment, facts: facts)
151+
end
152+
133153
it 'returns a deserialized catalog' do
134154
stub_request(:post, uri)
135155
.to_return(**catalog_response)
@@ -139,6 +159,35 @@
139159
expect(cat.name).to eq(certname)
140160
end
141161

162+
it 'deserializes the catalog from msgpack', if: Puppet.features.msgpack? do
163+
body = catalog.to_msgpack
164+
formatter = Puppet::Network::FormatHandler.format(:msgpack)
165+
catalog_response = { body: body, headers: {'Content-Type' => formatter.mime }}
166+
167+
stub_request(:post, uri)
168+
.to_return(**catalog_response)
169+
170+
_, cat = subject.post_catalog(certname, environment: 'production', facts: facts)
171+
expect(cat).to be_a(Puppet::Resource::Catalog)
172+
expect(cat.name).to eq(certname)
173+
end
174+
175+
it 'deserializes the catalog from rich msgpack', if: Puppet.features.msgpack? do
176+
body = Puppet.override(rich_data: true) do
177+
catalog.to_msgpack
178+
end
179+
180+
formatter = Puppet::Network::FormatHandler.format(:rich_data_msgpack)
181+
catalog_response = { body: body, headers: {'Content-Type' => formatter.mime }}
182+
183+
stub_request(:post, uri)
184+
.to_return(**catalog_response)
185+
186+
_, cat = subject.post_catalog(certname, environment: 'production', facts: facts)
187+
expect(cat).to be_a(Puppet::Resource::Catalog)
188+
expect(cat.name).to eq(certname)
189+
end
190+
142191
it 'returns the request response' do
143192
stub_request(:post, uri)
144193
.to_return(**catalog_response)

spec/unit/http/service_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def mime_types(model)
136136
catalog_mimes = if Puppet.features.msgpack?
137137
%w[application/vnd.puppet.rich+json application/json application/vnd.puppet.rich+msgpack application/x-msgpack text/pson]
138138
else
139-
%w[application/vnd.puppet.rich+json application/json application/vnd.puppet.rich+msgpack text/pson]
139+
%w[application/vnd.puppet.rich+json application/json text/pson]
140140
end
141141
expect(service.mime_types(Puppet::Resource::Catalog)).to eq(catalog_mimes)
142142
end

0 commit comments

Comments
 (0)