Skip to content

Commit c526351

Browse files
committed
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)
1 parent 23c192d commit c526351

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

lib/puppet/parser/functions/mysql_password.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Puppet::Parser::Functions
1010
raise(Puppet::ParseError, 'mysql_password(): Wrong number of arguments ' +
1111
"given (#{args.size} for 1)") if args.size != 1
1212

13-
'*' + Digest::SHA1.hexdigest(Digest::SHA1.digest(args[0])).upcase
13+
# Return the hash or an empty string for an empty argument
14+
args[0].length > 0 ? '*' + Digest::SHA1.hexdigest(Digest::SHA1.digest(args[0])).upcase : ''
1415
end
1516
end

lib/puppet/type/mysql_user.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
newproperty(:password_hash) do
3939
desc 'The password hash of the user. Use mysql_password() for creating such a hash.'
40-
newvalue(/\w+/)
40+
newvalue(/\w*/)
4141
end
4242

4343
newproperty(:max_user_connections) do

spec/unit/puppet/functions/mysql_password_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,10 @@
2323
result = scope.function_mysql_password(%w(password))
2424
expect(result).to(eq('*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19'))
2525
end
26+
27+
it 'should convert an empty password into a empty string' do
28+
result = scope.function_mysql_password([""])
29+
expect(result).to(eq(''))
30+
end
2631

2732
end

0 commit comments

Comments
 (0)