Skip to content

Commit

Permalink
Change behaviour of check_schema_keys to no longer remove unknown keys
Browse files Browse the repository at this point in the history
This commit prevents validation from changing resource and connection_info  hashes passed into RSAPI from removing keys that are not in their schema.
  • Loading branch information
da-ar committed Feb 14, 2019
1 parent 2330c30 commit 9baf1c8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/puppet/resource_api/type_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ def check_schema(resource)
end

# Returns an array of keys that where not found in the type schema
# Modifies the resource passed in, leaving only valid attributes
# No longer modifies the resource passed in
def check_schema_keys(resource)
rejected = []
resource.reject! { |key| rejected << key if key != :title && attributes.key?(key) == false }
resource.reject { |key| rejected << key if key != :title && attributes.key?(key) == false }
rejected
end

Expand Down
10 changes: 8 additions & 2 deletions spec/puppet/resource_api/base_type_definition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@

context 'when resource contains invalid keys' do
let(:resource) { { name: 'test_string', wibble: '1', foo: '2' } }
let(:resource_copy) { { name: 'test_string', wibble: '1', foo: '2' } }

it 'returns an array containing the bad keys' do
expect(type.check_schema_keys(resource)).to eq([:wibble, :foo])
end

it 'does not modify the resource passed in' do
type.check_schema_keys(resource)
expect(resource).to eq(resource_copy)
end
end
end

Expand Down Expand Up @@ -84,7 +90,7 @@
it 'displays up to 100 warnings' do
expect(Puppet).to receive(:warning).with(message).exactly(100).times
110.times do
type.check_schema(resource.dup)
type.check_schema(resource)
end
end
end
Expand Down Expand Up @@ -121,7 +127,7 @@
it 'displays up to 100 warnings' do
expect(Puppet).to receive(:warning).with(message).exactly(100).times
110.times do
type.check_schema(resource.dup)
type.check_schema(resource)
end
end
end
Expand Down

0 comments on commit 9baf1c8

Please sign in to comment.