File tree 2 files changed +11
-3
lines changed
2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change 13
13
# Regex should problably be more like this: /^[`'"]?[^`'"]*[`'"]?@[`'"]?[\w%\.]+[`'"]?$/
14
14
# If at least one special char is used, string must be quoted
15
15
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 %\. :]+/
19
17
username = value . split ( '@' ) [ 0 ]
20
18
if username . size > 16
21
19
raise ArgumentError , 'MySQL usernames are limited to a maximum of 16 characters'
Original file line number Diff line number Diff line change 49
49
end
50
50
end
51
51
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
+
52
62
context 'using in-valid@localhost' do
53
63
it 'should fail with an unquotted username with special char' do
54
64
expect {
You can’t perform that action at this time.
0 commit comments