Skip to content

Commit

Permalink
Merge pull request #606 from michaeltchapman/usernameregex
Browse files Browse the repository at this point in the history
Support size 15 and 16 quoted usernames
  • Loading branch information
igalic committed Nov 21, 2014
2 parents 31191b6 + fe0365e commit 790305b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/puppet/type/mysql_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
raise(ArgumentError, "Database user #{value} must be quotted as it contains special characters") if value =~ /^[^'`"].*[^0-9a-zA-Z$_].*[^'`"]@[\w%\.:]+/
raise(ArgumentError, "Invalid database user #{value}") unless value =~ /^(?:['`"][^'`"]*['`"]|[0-9a-zA-Z$_]*)@[\w%\.:]+/
username = value.split('@')[0]
if username.size > 16
if not ((username =~ /['"`]*['"`]$/ and username.size <= 18) or username.size <= 16)
raise ArgumentError, 'MySQL usernames are limited to a maximum of 16 characters'
end
end
Expand Down
18 changes: 18 additions & 0 deletions spec/unit/puppet/type/mysql_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@
end
end

context 'using a quoted 16 char username' 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
expect {
Puppet::Type.type(:mysql_user).new(:name => '"debian-sys-maint2"@localhost', :password_hash => 'pass')
}.to raise_error /MySQL usernames are limited to a maximum of 16 characters/
end
end

context 'using `speci!al#`@localhost' do
before :each do
@user = Puppet::Type.type(:mysql_user).new(:name => '`speci!al#`@localhost', :password_hash => 'pass')
Expand Down

0 comments on commit 790305b

Please sign in to comment.