Fixed regex of database user.

The incorrect regex did not all for the anonymous mysql users to be
removed via the mysql::server::account_security class.  The regex is now
increased to cover for @localhost and @%.
This commit is contained in:
Michael Arnold 2012-05-06 23:17:49 -07:00
parent 7890f79547
commit eaf9ee50f6

View file

@ -7,7 +7,9 @@ Puppet::Type.newtype(:database_user) do
newparam(:name, :namevar=>true) do
desc "The name of the user. This uses the 'username@hostname' or username@hostname."
validate do |value|
raise(ArgumentError, "Invalid database user #{value}") unless value =~ /\w+@[\w%]+/
# https://dev.mysql.com/doc/refman/5.1/en/account-names.html
# Regex should problably be more like this: /^[`'"]?[^`'"]*[`'"]?@[`'"]?[\w%\.]+[`'"]?$/
raise(ArgumentError, "Invalid database user #{value}") unless value =~ /[\w-]*@[\w%\.]+/
username = value.split('@')[0]
if username.size > 16
raise ArgumentError, "MySQL usernames are limited to a maximum of 16 characters"