-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9410 from joshcooper/deferred_sensitive_12050
(PUP-12050) Check for nested Sensitive arguments
- Loading branch information
Showing
3 changed files
with
114 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,98 @@ | ||
require 'spec_helper' | ||
require 'puppet_spec/compiler' | ||
|
||
Puppet::Type.newtype(:test_deferred) do | ||
newparam(:name) | ||
newproperty(:value) | ||
end | ||
|
||
describe Puppet::Pops::Evaluator::DeferredResolver do | ||
include PuppetSpec::Compiler | ||
|
||
let(:environment) { Puppet::Node::Environment.create(:testing, []) } | ||
let(:facts) { Puppet::Node::Facts.new('node.example.com') } | ||
|
||
def compile_and_resolve_catalog(code, preprocess = false) | ||
catalog = compile_to_catalog(code) | ||
described_class.resolve_and_replace(facts, catalog, environment, preprocess) | ||
catalog | ||
end | ||
|
||
it 'resolves deferred values in a catalog' do | ||
catalog = compile_to_catalog(<<~END) | ||
catalog = compile_and_resolve_catalog(<<~END, true) | ||
notify { "deferred": | ||
message => Deferred("join", [[1,2,3], ":"]) | ||
} | ||
END | ||
described_class.resolve_and_replace(facts, catalog) | ||
|
||
expect(catalog.resource(:notify, 'deferred')[:message]).to eq('1:2:3') | ||
end | ||
|
||
it 'lazily resolves deferred values in a catalog' do | ||
catalog = compile_to_catalog(<<~END) | ||
catalog = compile_and_resolve_catalog(<<~END) | ||
notify { "deferred": | ||
message => Deferred("join", [[1,2,3], ":"]) | ||
} | ||
END | ||
described_class.resolve_and_replace(facts, catalog, environment, false) | ||
|
||
deferred = catalog.resource(:notify, 'deferred')[:message] | ||
expect(deferred.resolve).to eq('1:2:3') | ||
end | ||
|
||
it 'lazily resolves nested deferred values in a catalog' do | ||
catalog = compile_to_catalog(<<~END) | ||
catalog = compile_and_resolve_catalog(<<~END) | ||
$args = Deferred("inline_epp", ["<%= 'a,b,c' %>"]) | ||
notify { "deferred": | ||
message => Deferred("split", [$args, ","]) | ||
} | ||
END | ||
described_class.resolve_and_replace(facts, catalog, environment, false) | ||
|
||
deferred = catalog.resource(:notify, 'deferred')[:message] | ||
expect(deferred.resolve).to eq(["a", "b", "c"]) | ||
end | ||
|
||
it 'marks the parameter as sensitive when passed an array containing a Sensitive instance' do | ||
catalog = compile_and_resolve_catalog(<<~END) | ||
test_deferred { "deferred": | ||
value => Deferred('join', [['a', Sensitive('b')], ':']) | ||
} | ||
END | ||
|
||
resource = catalog.resource(:test_deferred, 'deferred') | ||
expect(resource.sensitive_parameters).to eq([:value]) | ||
end | ||
|
||
it 'marks the parameter as sensitive when passed a hash containing a Sensitive key' do | ||
catalog = compile_and_resolve_catalog(<<~END) | ||
test_deferred { "deferred": | ||
value => Deferred('keys', [{Sensitive('key') => 'value'}]) | ||
} | ||
END | ||
|
||
resource = catalog.resource(:test_deferred, 'deferred') | ||
expect(resource.sensitive_parameters).to eq([:value]) | ||
end | ||
|
||
it 'marks the parameter as sensitive when passed a hash containing a Sensitive value' do | ||
catalog = compile_and_resolve_catalog(<<~END) | ||
test_deferred { "deferred": | ||
value => Deferred('values', [{key => Sensitive('value')}]) | ||
} | ||
END | ||
|
||
resource = catalog.resource(:test_deferred, 'deferred') | ||
expect(resource.sensitive_parameters).to eq([:value]) | ||
end | ||
|
||
it 'marks the parameter as sensitive when passed a nested Deferred containing a Sensitive type' do | ||
catalog = compile_and_resolve_catalog(<<~END) | ||
$vars = {'token' => Deferred('new', [Sensitive, "hello"])} | ||
test_deferred { "deferred": | ||
value => Deferred('inline_epp', ['<%= $token %>', $vars]) | ||
} | ||
END | ||
|
||
resource = catalog.resource(:test_deferred, 'deferred') | ||
expect(resource.sensitive_parameters).to eq([:value]) | ||
end | ||
end |