module-puppetlabs-mysql/spec/unit/puppet/functions/mysql_password_spec.rb
Daniël van Eeden 279c13b5e3 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)
2015-01-28 21:08:29 +01:00

32 lines
994 B
Ruby

require 'spec_helper'
describe 'the mysql_password function' do
before :all do
Puppet::Parser::Functions.autoloader.loadall
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it 'should exist' do
expect(Puppet::Parser::Functions.function('mysql_password')).to eq('function_mysql_password')
end
it 'should raise a ParseError if there is less than 1 arguments' do
expect { scope.function_mysql_password([]) }.to( raise_error(Puppet::ParseError))
end
it 'should raise a ParseError if there is more than 1 arguments' do
expect { scope.function_mysql_password(%w(foo bar)) }.to( raise_error(Puppet::ParseError))
end
it 'should convert password into a hash' 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