Skip to content

Commit 22b07ae

Browse files
committed
Merge pull request #602 from theasci/fix-user-validation-regression
Fix regression in username validation
2 parents 89762a7 + 4f0d431 commit 22b07ae

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/puppet/type/mysql_user.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
# Regex should problably be more like this: /^[`'"]?[^`'"]*[`'"]?@[`'"]?[\w%\.]+[`'"]?$/
1414
# If at least one special char is used, string must be quoted
1515
raise(ArgumentError, "Database user #{value} must be quotted as it contains special characters") if value =~ /^[^'`"].*[^0-9a-zA-Z$_].*[^'`"]@[\w%\.:]+/
16-
# If no special char, quoted is not needed, but allowed
17-
# I don't see any case where this could happen, as it should be covered by previous check
18-
raise(ArgumentError, "Invalid database user #{value}") unless value =~ /^['`"]?[0-9a-zA-Z$_]*['`"]?@[\w%\.:]+/
16+
raise(ArgumentError, "Invalid database user #{value}") unless value =~ /^(?:['`"][^'`"]*['`"]|[0-9a-zA-Z$_]*)@[\w%\.:]+/
1917
username = value.split('@')[0]
2018
if username.size > 16
2119
raise ArgumentError, 'MySQL usernames are limited to a maximum of 16 characters'

spec/unit/puppet/type/mysql_user_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@
4949
end
5050
end
5151

52+
context 'using `speci!al#`@localhost' do
53+
before :each do
54+
@user = Puppet::Type.type(:mysql_user).new(:name => '`speci!al#`@localhost', :password_hash => 'pass')
55+
end
56+
57+
it 'should accept a quoted user name with special chatracters' do
58+
expect(@user[:name]).to eq('`speci!al#`@localhost')
59+
end
60+
end
61+
5262
context 'using in-valid@localhost' do
5363
it 'should fail with an unquotted username with special char' do
5464
expect {

0 commit comments

Comments
 (0)