From 279c13b5e372c76b75a0f15c78980c6adfb0cdd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Sun, 25 Jan 2015 12:11:26 +0100 Subject: [PATCH] Return an empty string for an empty input. https://tickets.puppetlabs.com/browse/MODULES-1676 This is identical to what PASSWORD('') in MySQL does: 5.6.22-debug-log> CREATE USER 'testpwd'@'localhost' IDENTIFIED BY 'foo'; Query OK, 0 rows affected (0.03 sec) 5.6.22-debug-log> SELECT User,Host,Password FROM mysql.user WHERE User='testpwd'; +---------+-----------+-------------------------------------------+ | User | Host | Password | +---------+-----------+-------------------------------------------+ | testpwd | localhost | *F3A2A51A9B0F2BE2468926B4132313728C250DBF | +---------+-----------+-------------------------------------------+ 1 row in set (0.01 sec) 5.6.22-debug-log> SET PASSWORD FOR 'testpwd'@'localhost' = PASSWORD(''); Query OK, 0 rows affected (0.00 sec) 5.6.22-debug-log> SELECT User,Host,Password FROM mysql.user WHERE User='testpwd'; +---------+-----------+----------+ | User | Host | Password | +---------+-----------+----------+ | testpwd | localhost | | +---------+-----------+----------+ 1 row in set (0.00 sec) --- lib/puppet/parser/functions/mysql_password.rb | 1 + lib/puppet/type/mysql_user.rb | 2 +- spec/unit/puppet/functions/mysql_password_spec.rb | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/mysql_password.rb b/lib/puppet/parser/functions/mysql_password.rb index f057a31..b8a6cda 100644 --- a/lib/puppet/parser/functions/mysql_password.rb +++ b/lib/puppet/parser/functions/mysql_password.rb @@ -10,6 +10,7 @@ module Puppet::Parser::Functions raise(Puppet::ParseError, 'mysql_password(): Wrong number of arguments ' + "given (#{args.size} for 1)") if args.size != 1 + return '' if args[0].empty? '*' + Digest::SHA1.hexdigest(Digest::SHA1.digest(args[0])).upcase end end diff --git a/lib/puppet/type/mysql_user.rb b/lib/puppet/type/mysql_user.rb index c408ccd..dbff3da 100644 --- a/lib/puppet/type/mysql_user.rb +++ b/lib/puppet/type/mysql_user.rb @@ -37,7 +37,7 @@ Puppet::Type.newtype(:mysql_user) do newproperty(:password_hash) do desc 'The password hash of the user. Use mysql_password() for creating such a hash.' - newvalue(/\w+/) + newvalue(/\w*/) end newproperty(:max_user_connections) do diff --git a/spec/unit/puppet/functions/mysql_password_spec.rb b/spec/unit/puppet/functions/mysql_password_spec.rb index 77726d1..14aebd9 100644 --- a/spec/unit/puppet/functions/mysql_password_spec.rb +++ b/spec/unit/puppet/functions/mysql_password_spec.rb @@ -23,5 +23,10 @@ describe 'the mysql_password function' do result = scope.function_mysql_password(%w(password)) expect(result).to(eq('*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19')) end + + it 'should convert an empty password into a empty string' do + result = scope.function_mysql_password([""]) + expect(result).to(eq('')) + end end