Skip to content

Commit 42d4ea7

Browse files
committed
(MODULES-4908) adds support for sensitive data type to pw_hash
Also includes a small fix to integer_spec so tests pass.
1 parent 596878a commit 42d4ea7

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

lib/puppet/parser/functions/pw_hash.rb

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
environment contains several different operating systems, ensure that they
2828
are compatible before using this function.") do |args|
2929
raise ArgumentError, "pw_hash(): wrong number of arguments (#{args.size} for 3)" if args.size != 3
30+
args.map! do |arg|
31+
if arg.is_a? Puppet::Pops::Types::PSensitiveType::Sensitive
32+
arg.unwrap
33+
else
34+
arg
35+
end
36+
end
3037
raise ArgumentError, "pw_hash(): first argument must be a string" unless args[0].is_a? String or args[0].nil?
3138
raise ArgumentError, "pw_hash(): second argument must be a string" unless args[1].is_a? String
3239
hashes = { 'md5' => '1',

spec/aliases/integer_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
[ "foo\nbar", true, 'true', false, 'false', 'iAmAString', '1test', '1 test', 'test 1', 'test 1 test', {}, { 'key' => 'value' }, { 1=> 2 }, '', :undef , 'x', 3.7, '3.7',-3.7, '-342.2315e-12' ].each do |value|
2323
describe value.inspect do
2424
let(:params) {{ value: value }}
25-
if Gem::Version.new(Puppet.version) >= Gem::Version.new('5.0.0')
25+
if Puppet::Util::Package.versioncmp(Puppet.version, '5.0.0') >= 0
2626
it { is_expected.to compile.and_raise_error(/parameter 'value' expects a Stdlib::Compat::Integer = Variant\[Integer, Pattern\[.*\], Array\[.*\]\] value/) }
2727
else
2828
it { is_expected.to compile.and_raise_error(/parameter 'value' expects a value of type Integer, Pattern(\[.*\]+)?, or Array/) }

spec/functions/pw_hash_spec.rb

+8
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,13 @@
6565
it { is_expected.to run.with_params('password', 'sha-256', 'salt').and_return('$5$salt$Gcm6FsVtF/Qa77ZKD.iwsJlCVPY0XSMgLJL0Hnww/c1') }
6666
it { is_expected.to run.with_params('password', 'sha-512', 'salt').and_return('$6$salt$IxDD3jeSOb5eB1CX5LBsqZFVkJdido3OUILO5Ifz5iwMuTS4XMS130MTSuDDl3aCI6WouIL9AjRbLCelDCy.g.') }
6767
end
68+
69+
if Puppet::Util::Package.versioncmp(Puppet.version, '4.7.0') >= 0
70+
describe 'when arguments are sensitive' do
71+
it { is_expected.to run.with_params(Puppet::Pops::Types::PSensitiveType::Sensitive.new('password'), 'md5', 'salt').and_return('$1$salt$qJH7.N4xYta3aEG/dfqo/0') }
72+
it { is_expected.to run.with_params(Puppet::Pops::Types::PSensitiveType::Sensitive.new('password'), 'md5', Puppet::Pops::Types::PSensitiveType::Sensitive.new('salt')).and_return('$1$salt$qJH7.N4xYta3aEG/dfqo/0') }
73+
it { is_expected.to run.with_params('password', 'md5', Puppet::Pops::Types::PSensitiveType::Sensitive.new('salt')).and_return('$1$salt$qJH7.N4xYta3aEG/dfqo/0') }
74+
end
75+
end
6876
end
6977
end

0 commit comments

Comments
 (0)