Skip to content
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

Fix regression in username validation #602

Merged
merged 1 commit into from Nov 14, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/puppet/type/mysql_user.rb
Expand Up @@ -13,9 +13,7 @@
# Regex should problably be more like this: /^[`'"]?[^`'"]*[`'"]?@[`'"]?[\w%\.]+[`'"]?$/
# If at least one special char is used, string must be quoted
raise(ArgumentError, "Database user #{value} must be quotted as it contains special characters") if value =~ /^[^'`"].*[^0-9a-zA-Z$_].*[^'`"]@[\w%\.:]+/
# If no special char, quoted is not needed, but allowed
# I don't see any case where this could happen, as it should be covered by previous check
raise(ArgumentError, "Invalid database user #{value}") unless 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
raise ArgumentError, 'MySQL usernames are limited to a maximum of 16 characters'
Expand Down
10 changes: 10 additions & 0 deletions spec/unit/puppet/type/mysql_user_spec.rb
Expand Up @@ -49,6 +49,16 @@
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')
end

it 'should accept a quoted user name with special chatracters' do
expect(@user[:name]).to eq('`speci!al#`@localhost')
end
end

context 'using in-valid@localhost' do
it 'should fail with an unquotted username with special char' do
expect {
Expand Down