Revision e8fe59f8
Added by Ewoud Kohl van Wijngaarden 3 months ago
test/http_download_test.rb | ||
---|---|---|
"/usr/bin/curl",
|
||
"--insecure",
|
||
"--silent", "--show-error",
|
||
'--fail',
|
||
"--connect-timeout", "10",
|
||
"--retry", "3",
|
||
"--retry-delay", "10",
|
||
... | ... | |
expected = [
|
||
"/usr/bin/curl",
|
||
"--silent", "--show-error",
|
||
'--fail',
|
||
"--connect-timeout", "10",
|
||
"--retry", "3",
|
||
"--retry-delay", "10",
|
||
... | ... | |
end
|
||
end
|
||
end
|
||
|
||
class HttpDownloadsIntegrationTest < Test::Unit::TestCase
|
||
def setup
|
||
@server = WEBrick::HTTPServer.new(Port: 0)
|
||
@server.mount_proc '/200' do |req, res|
|
||
res.body = 'Hello, world!'
|
||
end
|
||
@thread = Thread.new { @server.start }
|
||
end
|
||
|
||
def teardown
|
||
@thread.exit
|
||
@thread.join
|
||
end
|
||
|
||
def test_retrieving_found
|
||
src = "http://localhost:#{@server.config[:Port]}/200"
|
||
|
||
dest = Tempfile.new('found')
|
||
path = dest.path
|
||
dest.unlink
|
||
|
||
thread = Proxy::HttpDownload.new(src, path).start
|
||
thread.join
|
||
|
||
assert File.exist?(path)
|
||
ensure
|
||
FileUtils.rm_f(path)
|
||
end
|
||
|
||
def test_retrieving_not_found
|
||
src = "http://localhost:#{@server.config[:Port]}/404"
|
||
|
||
dest = Tempfile.new('not-found')
|
||
path = dest.path
|
||
dest.unlink
|
||
|
||
thread = Proxy::HttpDownload.new(src, path).start
|
||
thread.join
|
||
|
||
assert !File.exist?(path)
|
||
ensure
|
||
FileUtils.rm_f(path)
|
||
end
|
||
end
|
Also available in: Unified diff
Fixes #37147 - Pass --fail option to curl
This prevents curl from writing out error pages, for example when the
URL returns a HTTP 404.
It still doesn't return any error to Foreman since the TFTP
/fetch_boot_file only starts a thread and there's no way to monitor it.
Fixes: 3d87c6feaa8c ("Refs #2412 - use curl for downloads")