Skip to content

Commit b39ebdc

Browse files
committed
Merge pull request #505 from larsks/bz/1093367
lowercase hostname values in qualified usernames
2 parents 50ff0a9 + 0afb8f0 commit b39ebdc

File tree

4 files changed

+71
-26
lines changed

4 files changed

+71
-26
lines changed

lib/puppet/type/database_user.rb

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
raise ArgumentError, 'MySQL usernames are limited to a maximum of 16 characters'
1717
end
1818
end
19+
20+
munge do |value|
21+
user_part, host_part = value.split('@')
22+
"#{user_part}@#{host_part.downcase}"
23+
end
1924
end
2025

2126
newproperty(:password_hash) do

lib/puppet/type/mysql_user.rb

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
raise ArgumentError, 'MySQL usernames are limited to a maximum of 16 characters'
1616
end
1717
end
18+
19+
munge do |value|
20+
user_part, host_part = value.split('@')
21+
"#{user_part}@#{host_part.downcase}"
22+
end
1823
end
1924

2025
newproperty(:password_hash) do

spec/acceptance/types/mysql_user_spec.rb

+35-12
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,44 @@ class { 'mysql::server': }
1111
end
1212
end
1313

14-
describe 'adding user' do
15-
it 'should work without errors' do
16-
pp = <<-EOS
17-
mysql_user { 'ashp@localhost':
18-
password_hash => '6f8c114b58f2ce9e',
19-
}
20-
EOS
14+
context 'using ashp@localhost' do
15+
describe 'adding user' do
16+
it 'should work without errors' do
17+
pp = <<-EOS
18+
mysql_user { 'ashp@localhost':
19+
password_hash => '6f8c114b58f2ce9e',
20+
}
21+
EOS
2122

22-
apply_manifest(pp, :catch_failures => true)
23+
apply_manifest(pp, :catch_failures => true)
24+
end
25+
26+
it 'should find the user' do
27+
shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r|
28+
expect(r.stdout).to match(/^1$/)
29+
expect(r.stderr).to be_empty
30+
end
31+
end
2332
end
33+
end
34+
35+
context 'using ashp@LocalHost' do
36+
describe 'adding user' do
37+
it 'should work without errors' do
38+
pp = <<-EOS
39+
mysql_user { 'ashp@LocalHost':
40+
password_hash => '6f8c114b58f2ce9e',
41+
}
42+
EOS
43+
44+
apply_manifest(pp, :catch_failures => true)
45+
end
2446

25-
it 'should find the user' do
26-
shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r|
27-
expect(r.stdout).to match(/^1$/)
28-
expect(r.stderr).to be_empty
47+
it 'should find the user' do
48+
shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r|
49+
expect(r.stdout).to match(/^1$/)
50+
expect(r.stderr).to be_empty
51+
end
2952
end
3053
end
3154
end

spec/unit/puppet/type/mysql_user_spec.rb

+26-14
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,10 @@
22
require 'puppet/type/mysql_user'
33
describe Puppet::Type.type(:mysql_user) do
44

5-
before :each do
6-
@user = Puppet::Type.type(:mysql_user).new(:name => 'foo@localhost', :password_hash => 'pass')
7-
end
8-
9-
it 'should accept a user name' do
10-
@user[:name].should == 'foo@localhost'
11-
end
12-
135
it 'should fail with a long user name' do
146
expect {
157
Puppet::Type.type(:mysql_user).new({:name => '12345678901234567@localhost', :password_hash => 'pass'})
16-
}.to raise_error /MySQL usernames are limited to a maximum of 16 characters/
17-
end
18-
19-
it 'should accept a password' do
20-
@user[:password_hash] = 'foo'
21-
@user[:password_hash].should == 'foo'
8+
}.to raise_error /MySQL usernames are limited to a maximum of 16 characters/
229
end
2310

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

17+
context 'using foo@localhost' do
18+
before :each do
19+
@user = Puppet::Type.type(:mysql_user).new(:name => 'foo@localhost', :password_hash => 'pass')
20+
end
21+
22+
it 'should accept a user name' do
23+
@user[:name].should == 'foo@localhost'
24+
end
25+
26+
it 'should accept a password' do
27+
@user[:password_hash] = 'foo'
28+
@user[:password_hash].should == 'foo'
29+
end
30+
end
31+
32+
context 'using foo@LocalHost' do
33+
before :each do
34+
@user = Puppet::Type.type(:mysql_user).new(:name => 'foo@LocalHost', :password_hash => 'pass')
35+
end
36+
37+
it 'should lowercase the user name' do
38+
@user[:name].should == 'foo@localhost'
39+
end
40+
41+
end
3042
end

0 commit comments

Comments
 (0)