Skip to content

Commit 89dd42c

Browse files
committed
(MODULES-4908) adds support for sensitive data type to pw_hash
1 parent 5a17bf1 commit 89dd42c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/puppet/parser/functions/pw_hash.rb

Lines changed: 7 additions & 0 deletions
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/functions/pw_hash_spec.rb

Lines changed: 8 additions & 0 deletions
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 Gem::Version.new(Puppet.version) >= '4.7.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)