Skip to content

Commit 54af565

Browse files
Fogelholkdavid22swan
authored andcommitted
(MODULES-3539) Allow @ in username
1 parent 8c43386 commit 54af565

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

lib/puppet/provider/mysql.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ def system_database
119119
end
120120

121121
# Take root@localhost and munge it to 'root'@'localhost'
122+
# Take root@id123@localhost and munge it to 'root@id123'@'localhost'
122123
def self.cmd_user(user)
123-
"'#{user.sub('@', "'@'")}'"
124+
"'#{user.reverse.sub('@', "'@'").reverse}'"
124125
end
125126

126127
# Take root.* and return ON `root`.*

lib/puppet/provider/mysql_user/mysql.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def self.prefetch(resources)
5050
end
5151

5252
def create
53-
merged_name = @resource[:name].sub('@', "'@'")
53+
# (MODULES-3539) Allow @ in username
54+
merged_name = @resource[:name].reverse.sub('@', "'@'").reverse
5455
password_hash = @resource.value(:password_hash)
5556
plugin = @resource.value(:plugin)
5657
max_user_connections = @resource.value(:max_user_connections) || 0
@@ -102,7 +103,8 @@ def create
102103
end
103104

104105
def destroy
105-
merged_name = @resource[:name].sub('@', "'@'")
106+
# (MODULES-3539) Allow @ in username
107+
merged_name = @resource[:name].reverse.sub('@', "'@'").reverse
106108
if_exists = if newer_than('mysql' => '5.7', 'percona' => '5.7', 'mariadb' => '10.1.3')
107109
'IF EXISTS '
108110
else

spec/acceptance/types/mysql_user_spec.rb

+24
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,30 @@ class { 'mysql::server': }
104104
end
105105
end
106106

107+
context 'using foo@bar@localhost' do
108+
describe 'adding user' do
109+
pp_three = <<-MANIFEST
110+
mysql_user { 'foo@bar@localhost':
111+
password_hash => '*F9A8E96790775D196D12F53BCC88B8048FF62ED5',
112+
}
113+
MANIFEST
114+
it 'works without errors' do
115+
execute_manifest(pp_three, catch_failures: true)
116+
end
117+
118+
it 'finds the user #stdout' do
119+
shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'foo@bar@localhost'\"") do |r|
120+
expect(r.stdout).to match(%r{^1$})
121+
end
122+
end
123+
it 'finds the user #stderr' do
124+
shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'foo@bar@localhost'\"") do |r|
125+
expect(r.stderr).to be_empty
126+
end
127+
end
128+
end
129+
end
130+
107131
context 'using ashp@LocalHost' do
108132
describe 'adding user' do
109133
pp_four = <<-MANIFEST

0 commit comments

Comments
 (0)