From 4f6fe904f3d6094972d20e5a0070c2728e2c31a8 Mon Sep 17 00:00:00 2001 From: Tim Wilkinson Date: Tue, 8 Oct 2024 20:59:07 -0700 Subject: [PATCH] Include cookies when testing services. (#1600) * Include cookies when testing services. Some services use various redirects which involve cookies. If we dont include a cookie jar for these tests, they fail when they should pass. * Fix potential file handle leak --- files/usr/lib/lua/aredn/services.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/files/usr/lib/lua/aredn/services.lua b/files/usr/lib/lua/aredn/services.lua index c2830692..9827b822 100755 --- a/files/usr/lib/lua/aredn/services.lua +++ b/files/usr/lib/lua/aredn/services.lua @@ -233,7 +233,10 @@ local function get(validate) hostname = m.hostname port = m.port end - local status, effective_url = io.popen("/usr/bin/curl --max-time 10 --retry 0 --connect-timeout 2 --speed-time 5 --speed-limit 1000 --silent --output /dev/null --location --write-out '%{http_code} %{url_effective}' " .. "http://" .. hostname .. ":" .. port .. path):read("*a"):match("^(%d+) (.*)") + local cf = io.popen("/usr/bin/curl --max-time 10 --retry 0 --connect-timeout 2 --speed-time 5 --speed-limit 1000 --silent --output /dev/null --cookie-jar /tmp/service-test-cookies --location --write-out '%{http_code} %{url_effective}' " .. "http://" .. hostname .. ":" .. port .. path) + local status, effective_url = cf:read("*a"):match("^(%d+) (.*)") + cf:close() + os.remove("/tmp/service-test-cookies") if status == "200" or status == "401" then vstate[service] = last elseif status == "301" or status == "302" or status == "303" or status == "307" or status == "308" then