Skip to content

Commit 05eb6f5

Browse files
authored
Merge pull request #62 from joshcooper/stringify_process_output
Convert ProcessOutput to String explicitly
2 parents 8990735 + be5ae9b commit 05eb6f5

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

lib/puppet/provider/cron/filetype.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def read
5050
return ''
5151
end
5252

53-
Puppet::Util::Execution.execute("#{cmdbase} -l", failonfail: true, combine: true)
53+
Puppet::Util::Execution.execute("#{cmdbase} -l", failonfail: true, combine: true).to_s
5454
rescue => detail
5555
case detail.to_s
5656
when %r{no crontab for}
@@ -71,7 +71,7 @@ def remove
7171
cmd = "/bin/echo yes | #{cmd}"
7272
end
7373

74-
Puppet::Util::Execution.execute(cmd, failonfail: true, combine: true)
74+
Puppet::Util::Execution.execute(cmd, failonfail: true, combine: true).to_s
7575
end
7676

7777
# Overwrite a specific @path's cron tab; must be passed the @path name
@@ -113,7 +113,7 @@ def read
113113
return ''
114114
end
115115

116-
Puppet::Util::Execution.execute(['crontab', '-l'], cronargs)
116+
Puppet::Util::Execution.execute(['crontab', '-l'], cronargs).to_s
117117
rescue => detail
118118
case detail.to_s
119119
when %r{can't open your crontab}
@@ -129,7 +129,7 @@ def read
129129

130130
# Remove a specific @path's cron tab.
131131
def remove
132-
Puppet::Util::Execution.execute(['crontab', '-r'], cronargs)
132+
Puppet::Util::Execution.execute(['crontab', '-r'], cronargs).to_s
133133
rescue => detail
134134
raise FileReadError, _('Could not remove crontab for %{path}: %{detail}') % { path: @path, detail: detail }, detail.backtrace
135135
end
@@ -144,7 +144,7 @@ def write(text)
144144
output_file.close
145145
# We have to chown the stupid file to the user.
146146
File.chown(Puppet::Util.uid(@path), nil, output_file.path)
147-
Puppet::Util::Execution.execute(['crontab', output_file.path], cronargs)
147+
Puppet::Util::Execution.execute(['crontab', output_file.path], cronargs).to_s
148148
rescue => detail
149149
raise FileReadError, _('Could not write crontab for %{path}: %{detail}') % { path: @path, detail: detail }, detail.backtrace
150150
ensure
@@ -164,7 +164,7 @@ def read
164164
return ''
165165
end
166166

167-
Puppet::Util::Execution.execute(['crontab', '-l'], cronargs)
167+
Puppet::Util::Execution.execute(['crontab', '-l'], cronargs).to_s
168168
rescue => detail
169169
case detail.to_s
170170
when %r{open.*in.*directory}
@@ -180,7 +180,7 @@ def read
180180

181181
# Remove a specific @path's cron tab.
182182
def remove
183-
Puppet::Util::Execution.execute(['crontab', '-r'], cronargs)
183+
Puppet::Util::Execution.execute(['crontab', '-r'], cronargs).to_s
184184
rescue => detail
185185
raise FileReadError, _('Could not remove crontab for %{path}: %{detail}') % { path: @path, detail: detail }, detail.backtrace
186186
end
@@ -196,7 +196,7 @@ def write(text)
196196
output_file.close
197197
# We have to chown the stupid file to the user.
198198
File.chown(Puppet::Util.uid(@path), nil, output_file.path)
199-
Puppet::Util::Execution.execute(['crontab', output_file.path], cronargs)
199+
Puppet::Util::Execution.execute(['crontab', output_file.path], cronargs).to_s
200200
rescue => detail
201201
raise FileReadError, _('Could not write crontab for %{path}: %{detail}') % { path: @path, detail: detail }, detail.backtrace
202202
ensure
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# HEADER: This file was autogenerated at 2023-11-21 12:32:27 -0700 by puppet.
2+
# HEADER: While it can still be managed manually, it is definitely not recommended.
3+
# HEADER: Note particularly that the comments starting with 'Puppet Name' should
4+
# HEADER: not be deleted, as doing so could cause duplicate cron jobs.

spec/unit/provider/cron/filetype_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
shared_examples_for 'crontab provider' do
77
let(:cron) { type.new('no_such_user') }
88
let(:crontab) { File.read(my_fixture(crontab_output)) }
9+
let(:managedtab) { File.read(my_fixture('managed_output')) }
910
let(:options) { { failonfail: true, combine: true } }
1011
let(:uid) { 'no_such_user' }
1112
let(:user_options) { options.merge(uid: uid) }
@@ -30,6 +31,11 @@
3031
expect(cron.read).to eq(crontab)
3132
end
3233

34+
it 'returns a String' do
35+
expect(Puppet::Util::Execution).to receive(:execute).with(['crontab', '-l'], user_options).and_return(Puppet::Util::Execution::ProcessOutput.new(managedtab, 0))
36+
expect(cron.read).to be_an_instance_of(String)
37+
end
38+
3339
it 'does not switch user if current user is the target user' do
3440
expect(Puppet::Util).to receive(:uid).with(uid).twice.and_return 9000
3541
expect(Puppet::Util::SUIDManager).to receive(:uid).and_return 9000

0 commit comments

Comments
 (0)