Skip to content

lowercase hostname values in qualified usernames #505

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

Merged
merged 1 commit into from
Jun 5, 2014
Merged
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
5 changes: 5 additions & 0 deletions lib/puppet/type/database_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
raise ArgumentError, 'MySQL usernames are limited to a maximum of 16 characters'
end
end

munge do |value|
user_part, host_part = value.split('@')
"#{user_part}@#{host_part.downcase}"
end
end

newproperty(:password_hash) do
Expand Down
5 changes: 5 additions & 0 deletions lib/puppet/type/mysql_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
raise ArgumentError, 'MySQL usernames are limited to a maximum of 16 characters'
end
end

munge do |value|
user_part, host_part = value.split('@')
"#{user_part}@#{host_part.downcase}"
end
end

newproperty(:password_hash) do
Expand Down
47 changes: 35 additions & 12 deletions spec/acceptance/types/mysql_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,44 @@ class { 'mysql::server': }
end
end

describe 'adding user' do
it 'should work without errors' do
pp = <<-EOS
mysql_user { 'ashp@localhost':
password_hash => '6f8c114b58f2ce9e',
}
EOS
context 'using ashp@localhost' do
describe 'adding user' do
it 'should work without errors' do
pp = <<-EOS
mysql_user { 'ashp@localhost':
password_hash => '6f8c114b58f2ce9e',
}
EOS

apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_failures => true)
end

it 'should find the user' do
shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r|
expect(r.stdout).to match(/^1$/)
expect(r.stderr).to be_empty
end
end
end
end

context 'using ashp@LocalHost' do
describe 'adding user' do
it 'should work without errors' do
pp = <<-EOS
mysql_user { 'ashp@LocalHost':
password_hash => '6f8c114b58f2ce9e',
}
EOS

apply_manifest(pp, :catch_failures => true)
end

it 'should find the user' do
shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r|
expect(r.stdout).to match(/^1$/)
expect(r.stderr).to be_empty
it 'should find the user' do
shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r|
expect(r.stdout).to match(/^1$/)
expect(r.stderr).to be_empty
end
end
end
end
Expand Down
40 changes: 26 additions & 14 deletions spec/unit/puppet/type/mysql_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,10 @@
require 'puppet/type/mysql_user'
describe Puppet::Type.type(:mysql_user) do

before :each do
@user = Puppet::Type.type(:mysql_user).new(:name => 'foo@localhost', :password_hash => 'pass')
end

it 'should accept a user name' do
@user[:name].should == 'foo@localhost'
end

it 'should fail with a long user name' do
expect {
Puppet::Type.type(:mysql_user).new({:name => '12345678901234567@localhost', :password_hash => 'pass'})
}.to raise_error /MySQL usernames are limited to a maximum of 16 characters/
end

it 'should accept a password' do
@user[:password_hash] = 'foo'
@user[:password_hash].should == 'foo'
}.to raise_error /MySQL usernames are limited to a maximum of 16 characters/
end

it 'should require a name' do
Expand All @@ -27,4 +14,29 @@
}.to raise_error(Puppet::Error, 'Title or name must be provided')
end

context 'using foo@localhost' do
before :each do
@user = Puppet::Type.type(:mysql_user).new(:name => 'foo@localhost', :password_hash => 'pass')
end

it 'should accept a user name' do
@user[:name].should == 'foo@localhost'
end

it 'should accept a password' do
@user[:password_hash] = 'foo'
@user[:password_hash].should == 'foo'
end
end

context 'using foo@LocalHost' do
before :each do
@user = Puppet::Type.type(:mysql_user).new(:name => 'foo@LocalHost', :password_hash => 'pass')
end

it 'should lowercase the user name' do
@user[:name].should == 'foo@localhost'
end

end
end