diff --git a/lib/puppet/provider/mysql_user/mysql.rb b/lib/puppet/provider/mysql_user/mysql.rb index 066ea0b00..de892168e 100644 --- a/lib/puppet/provider/mysql_user/mysql.rb +++ b/lib/puppet/provider/mysql_user/mysql.rb @@ -16,6 +16,10 @@ def self.instances @max_user_connections, @max_connections_per_hour, @max_queries_per_hour, @max_updates_per_hour, @password = mysql([defaults_file, "-NBe", query].compact).split(/\s/) + if name.split('@')[0] =~ /^('|"){0}(\w+-){1,}\w+('|"){0}$/ + name_split = name.split('@') + name = "'#{name_split[0]}'@#{name_split[1].downcase}" + end new(:name => name, :ensure => :present, :password_hash => @password, diff --git a/spec/unit/puppet/provider/mysql_user/mysql_spec.rb b/spec/unit/puppet/provider/mysql_user/mysql_spec.rb index dacbae4b0..4bced5f85 100644 --- a/spec/unit/puppet/provider/mysql_user/mysql_spec.rb +++ b/spec/unit/puppet/provider/mysql_user/mysql_spec.rb @@ -18,6 +18,8 @@ let(:parsed_users) { %w(root@127.0.0.1 root@::1 @localhost debian-sys-maint@localhost root@localhost usvn_user@localhost @vagrant-ubuntu-raring-64) } + let(:munged_users) { %w(root@127.0.0.1 root@::1 @localhost 'debian-sys-maint'@localhost root@localhost usvn_user@localhost @vagrant-ubuntu-raring-64)} + let(:resource) { Puppet::Type.type(:mysql_user).new( { :ensure => :present, :password_hash => '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4', @@ -50,8 +52,9 @@ end usernames = provider.class.instances.collect {|x| x.name } - expect(parsed_users).to match_array(usernames) + expect(munged_users).to match_array(usernames) end + end describe 'self.prefetch' do @@ -126,5 +129,4 @@ end end end - end diff --git a/spec/unit/puppet/type/mysql_user_spec.rb b/spec/unit/puppet/type/mysql_user_spec.rb index 52439f468..cce3bac4c 100644 --- a/spec/unit/puppet/type/mysql_user_spec.rb +++ b/spec/unit/puppet/type/mysql_user_spec.rb @@ -58,6 +58,15 @@ expect(@user[:name]).to eq('"debian-sys-maint"@localhost') end end + context 'ensure the default \'debian-sys-main\'@localhost user can be parsed' do + before :each do + @user = Puppet::Type.type(:mysql_user).new(:name => '\'debian-sys-maint\'@localhost', :password_hash => 'pass') + end + + it 'should accept a user name' do + expect(@user[:name]).to eq('\'debian-sys-maint\'@localhost') + end + end context 'using a quoted username that is too long ' do it 'should fail with a size error' do