diff --git a/lib/puppet/parser/functions/postgresql_password.rb b/lib/puppet/parser/functions/postgresql_password.rb index 0689e0e..e5d2620 100644 --- a/lib/puppet/parser/functions/postgresql_password.rb +++ b/lib/puppet/parser/functions/postgresql_password.rb @@ -1,18 +1,18 @@ # hash a string as mysql's "PASSWORD()" function would do it require 'digest/md5' module Puppet::Parser::Functions newfunction(:postgresql_password, :type => :rvalue, :doc => <<-EOS Returns the postgresql password hash from the clear text username / password. EOS ) do |args| raise(Puppet::ParseError, "postgresql_password(): Wrong number of arguments " + "given (#{args.size} for 2)") if args.size != 2 username = args[0] password = args[1] - 'md5' + Digest::MD5.hexdigest(password + username) + 'md5' + Digest::MD5.hexdigest(password.to_s + username.to_s) end end diff --git a/spec/unit/functions/postgresql_password_spec.rb b/spec/unit/functions/postgresql_password_spec.rb index b5aa00b..89699f6 100644 --- a/spec/unit/functions/postgresql_password_spec.rb +++ b/spec/unit/functions/postgresql_password_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe 'postgresql_password', :type => :puppet_function do it { is_expected.to run.with_params('foo', 'bar'). and_return('md596948aad3fcae80c08a35c9b5958cd89') } + it { is_expected.to run.with_params('foo', 1234). + and_return('md539a0e1b308278a8de5e007cd1f795920') } end