Skip to content

Commit b60b76c

Browse files
committed
Add spec tests
This commit adds spec tests for the changes made in the previous commit.
1 parent 66479fb commit b60b76c

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

spec/classes/mysql_server_spec.rb

+40
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,46 @@
9595
)
9696
end
9797
end
98+
99+
context 'with an invalid install_secret_file path' do
100+
let(:params) { {} }
101+
102+
[
103+
'|| ls -la ||',
104+
'|| touch /tmp/foo.txt ||',
105+
'/tmp/foo.txt;echo',
106+
'myPath;',
107+
'\\myPath\\',
108+
'//myPath has spaces//',
109+
'/',
110+
'.secret_file',
111+
].each do |path|
112+
it do
113+
params['install_secret_file'] = path
114+
is_expected.to raise_error(Puppet::PreformattedError, %r{'#{Regexp.escape(path)}' is not a valid path.})
115+
end
116+
end
117+
end
118+
end
119+
120+
context 'with a valid install_secret_file path' do
121+
let(:params) { {} }
122+
123+
[
124+
'/tmp/foo.txt',
125+
'/foo.txt',
126+
'/.secret_file',
127+
].each do |path|
128+
it do
129+
params['install_secret_file'] = path
130+
is_expected.to contain_exec('remove install pass')
131+
.with(
132+
command: "mysqladmin -u root --password=$(grep -o \'[^ ]\\+$\' #{path}) password \'\' && rm -f #{path}",
133+
onlyif: "test -f #{path}",
134+
path: '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin',
135+
)
136+
end
137+
end
98138
end
99139

100140
context 'mysql::server::service' do

0 commit comments

Comments
 (0)