Skip to content

MODULES-1520 fix a wrapping of the username when contains - #633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/puppet/provider/mysql_user/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you introducing a downcasing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because munge does not get fired on resource, we need to ensure the patterns will match.

end
new(:name => name,
:ensure => :present,
:password_hash => @password,
Expand Down
6 changes: 4 additions & 2 deletions spec/unit/puppet/provider/mysql_user/mysql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -126,5 +129,4 @@
end
end
end

end
9 changes: 9 additions & 0 deletions spec/unit/puppet/type/mysql_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down