File tree Expand file tree Collapse file tree 5 files changed +65
-10
lines changed Expand file tree Collapse file tree 5 files changed +65
-10
lines changed Original file line number Diff line number Diff line change @@ -70,9 +70,9 @@ def initialize(*args)
70
70
elsif matches = /^([0-9a-zA-Z$_]*)@([\w %\. :\- ]+)/ . match ( value )
71
71
user_part = matches [ 1 ]
72
72
host_part = matches [ 2 ]
73
- elsif matches = /^(?: (?!['`"]).*)( [^0-9a-zA-Z$_]).*@.+ $/ . match ( value )
74
- # does not start with a quote, but contains a special character
75
- raise ( ArgumentError , "Database user #{ value } must be properly quoted, invalid character: ' #{ matches [ 1 ] } '" )
73
+ elsif matches = /^((?!['`"]).*[^0-9a-zA-Z$_].*)@(.+) $/ . match ( value )
74
+ user_part = matches [ 1 ]
75
+ host_part = matches [ 2 ]
76
76
else
77
77
raise ( ArgumentError , "Invalid database user #{ value } " )
78
78
end
Original file line number Diff line number Diff line change 19
19
elsif matches = /^([0-9a-zA-Z$_]*)@([\w %\. :\- ]+)/ . match ( value )
20
20
user_part = matches [ 1 ]
21
21
host_part = matches [ 2 ]
22
- elsif matches = /^(?: (?!['`"]).*)( [^0-9a-zA-Z$_]).*@.+ $/ . match ( value )
23
- # does not start with a quote, but contains a special character
24
- raise ( ArgumentError , "Database user #{ value } must be properly quoted, invalid character: ' #{ matches [ 1 ] } '" )
22
+ elsif matches = /^((?!['`"]).*[^0-9a-zA-Z$_].*)@(.+) $/ . match ( value )
23
+ user_part = matches [ 1 ]
24
+ host_part = matches [ 2 ]
25
25
else
26
26
raise ( ArgumentError , "Invalid database user #{ value } " )
27
27
end
Original file line number Diff line number Diff line change @@ -70,6 +70,28 @@ class { 'mysql::server': }
70
70
end
71
71
end
72
72
73
+ describe 'adding privileges with special character in name' do
74
+ it 'should work without errors' do
75
+ pp = <<-EOS
76
+ mysql_grant { 'test-2@tester/test.*':
77
+ ensure => 'present',
78
+ table => 'test.*',
79
+ user => 'test-2@tester',
80
+ privileges => ['SELECT', 'UPDATE'],
81
+ }
82
+ EOS
83
+
84
+ apply_manifest ( pp , :catch_failures => true )
85
+ end
86
+
87
+ it 'should find the user' do
88
+ shell ( "mysql -NBe \" SHOW GRANTS FOR 'test-2'@tester\" " ) do |r |
89
+ expect ( r . stdout ) . to match ( /GRANT SELECT, UPDATE.*TO 'test-2'@'tester'/ )
90
+ expect ( r . stderr ) . to be_empty
91
+ end
92
+ end
93
+ end
94
+
73
95
describe 'adding privileges with invalid name' do
74
96
it 'should fail' do
75
97
pp = <<-EOS
Original file line number Diff line number Diff line change @@ -32,6 +32,27 @@ class { 'mysql::server': }
32
32
end
33
33
end
34
34
35
+ context 'using ashp-dash@localhost' do
36
+ describe 'adding user' do
37
+ it 'should work without errors' do
38
+ pp = <<-EOS
39
+ mysql_user { 'ashp-dash@localhost':
40
+ password_hash => '6f8c114b58f2ce9e',
41
+ }
42
+ EOS
43
+
44
+ apply_manifest ( pp , :catch_failures => true )
45
+ end
46
+
47
+ it 'should find the user' do
48
+ shell ( "mysql -NBe \" select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp-dash@localhost'\" " ) do |r |
49
+ expect ( r . stdout ) . to match ( /^1$/ )
50
+ expect ( r . stderr ) . to be_empty
51
+ end
52
+ end
53
+ end
54
+ end
55
+
35
56
context 'using ashp@LocalHost' do
36
57
describe 'adding user' do
37
58
it 'should work without errors' do
Original file line number Diff line number Diff line change 49
49
end
50
50
end
51
51
52
+ context 'ensure the default \'debian-sys-main\'@localhost user can be parsed' do
53
+ before :each do
54
+ @user = Puppet ::Type . type ( :mysql_user ) . new ( :name => '\'debian-sys-maint\'@localhost' , :password_hash => 'pass' )
55
+ end
56
+
57
+ it 'should accept a user name' do
58
+ expect ( @user [ :name ] ) . to eq ( '\'debian-sys-maint\'@localhost' )
59
+ end
60
+ end
61
+
52
62
context 'using a quoted 16 char username' do
53
63
before :each do
54
64
@user = Puppet ::Type . type ( :mysql_user ) . new ( :name => '"debian-sys-maint"@localhost' , :password_hash => 'pass' )
78
88
end
79
89
80
90
context 'using in-valid@localhost' do
81
- it 'should fail with an unquotted username with special char' do
82
- expect {
83
- Puppet ::Type . type ( :mysql_user ) . new ( :name => 'in-valid@localhost' , :password_hash => 'pass' )
84
- } . to raise_error /Database user in-valid@localhost must be properly quoted, invalid character: '-'/
91
+ before :each do
92
+ @user = Puppet ::Type . type ( :mysql_user ) . new ( :name => 'in-valid@localhost' , :password_hash => 'pass' )
93
+ end
94
+
95
+ it 'should accept a user name with special chatracters' do
96
+ expect ( @user [ :name ] ) . to eq ( 'in-valid@localhost' )
85
97
end
86
98
end
87
99
You can’t perform that action at this time.
0 commit comments