Skip to content

Commit e9731a9

Browse files
authored
Merge pull request #161 from da-ar/sensitive_fix
(maint) Fixes sensitive transport values where absent keys are wrapped
2 parents aa3774f + 153a1a6 commit e9731a9

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

lib/puppet/resource_api/transport.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def self.wrap_sensitive(name, connection_info)
8484
transport_schema = @transports[@environment][name]
8585
if transport_schema
8686
transport_schema.definition[:connection_info].each do |attr_name, options|
87-
if options.key?(:sensitive) && (options[:sensitive] == true)
87+
if options.key?(:sensitive) && (options[:sensitive] == true) && connection_info.key?(attr_name)
8888
connection_info[attr_name] = Puppet::Pops::Types::PSensitiveType::Sensitive.new(connection_info[attr_name])
8989
end
9090
end

spec/puppet/resource_api/transport_spec.rb

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -333,32 +333,33 @@ class Wibble; end
333333
end
334334

335335
describe '#wrap_sensitive(name, connection_info)' do
336-
context 'when the connection info contains a `Sensitive` type' do
337-
let(:schema) do
338-
{
339-
name: 'sensitive_transport',
340-
desc: 'a secret',
341-
connection_info: {
342-
secret: {
343-
type: 'String',
344-
desc: 'A secret to protect.',
345-
sensitive: true,
346-
},
336+
let(:schema) do
337+
{
338+
name: 'sensitive_transport',
339+
desc: 'a secret',
340+
connection_info: {
341+
secret: {
342+
type: 'String',
343+
desc: 'A secret to protect.',
344+
sensitive: true,
347345
},
348-
}
349-
end
350-
let(:schema_def) { instance_double('Puppet::ResourceApi::TransportSchemaDef', 'schema_def') }
346+
},
347+
}
348+
end
349+
let(:schema_def) { instance_double('Puppet::ResourceApi::TransportSchemaDef', 'schema_def') }
350+
351+
before(:each) do
352+
allow(Puppet::ResourceApi::TransportSchemaDef).to receive(:new).with(schema).and_return(schema_def)
353+
described_class.register(schema)
354+
end
355+
356+
context 'when the connection info contains a `Sensitive` type' do
351357
let(:connection_info) do
352358
{
353359
secret: 'sup3r_secret_str1ng',
354360
}
355361
end
356362

357-
before(:each) do
358-
allow(Puppet::ResourceApi::TransportSchemaDef).to receive(:new).with(schema).and_return(schema_def)
359-
described_class.register(schema)
360-
end
361-
362363
it 'wraps the value in a PSensitiveType' do
363364
allow(schema_def).to receive(:definition).and_return(schema)
364365

@@ -367,5 +368,16 @@ class Wibble; end
367368
expect(conn_info[:secret].unwrap).to eq('sup3r_secret_str1ng')
368369
end
369370
end
371+
372+
context 'when the connection info does not contain a `Sensitive` type' do
373+
let(:connection_info) { {} }
374+
375+
it 'wraps the value in a PSensitiveType' do
376+
allow(schema_def).to receive(:definition).and_return(schema)
377+
378+
conn_info = described_class.send :wrap_sensitive, 'sensitive_transport', connection_info
379+
expect(conn_info[:secret]).to be_nil
380+
end
381+
end
370382
end
371383
end

0 commit comments

Comments
 (0)