REGTESTS: healthcheckmail: Update the test to be functionnal again

This reg-test is broken since a while. It was simplified to be
functionnal. Now, it only test email alerts.
This commit is contained in:
Christopher Faulet 2022-06-08 11:57:52 +02:00
parent 58e3501910
commit 52912579ee
2 changed files with 44 additions and 95 deletions

View File

@ -4,46 +4,6 @@ local mailsreceived = 0
local mailconnectionsmade = 0
local healthcheckcounter = 0
core.register_action("bug", { "http-res" }, function(txn)
data = txn:get_priv()
if not data then
data = 0
end
data = data + 1
print(string.format("set to %d", data))
txn.http:res_set_status(200 + data)
txn:set_priv(data)
end)
core.register_service("luahttpservice", "http", function(applet)
local response = "?"
local responsestatus = 200
if applet.path == "/setport" then
vtc_port1 = applet.headers["vtcport1"][0]
response = "OK"
end
if applet.path == "/svr_healthcheck" then
healthcheckcounter = healthcheckcounter + 1
if healthcheckcounter < 2 or healthcheckcounter > 6 then
responsestatus = 403
end
end
applet:set_status(responsestatus)
if applet.path == "/checkMailCounters" then
response = "MailCounters"
applet:add_header("mailsreceived", mailsreceived)
applet:add_header("mailconnectionsmade", mailconnectionsmade)
end
applet:start_response()
applet:send(response)
end)
core.register_service("fakeserv", "http", function(applet)
applet:set_status(200)
applet:start_response()
end)
function RecieveAndCheck(applet, expect)
data = applet:getline()
if data:sub(1,expect:len()) ~= expect then
@ -60,20 +20,24 @@ core.register_service("mailservice", "tcp", function(applet)
applet:send("220 Welcome\r\n")
local data
if RecieveAndCheck(applet, "EHLO") == false then
return
if RecieveAndCheck(applet, "HELO") == false then
applet:set_var("txn.result", "ERROR (step: HELO)")
return
end
applet:send("250 OK\r\n")
if RecieveAndCheck(applet, "MAIL FROM:") == false then
return
applet:set_var("txn.result", "ERROR (step: MAIL FROM)")
return
end
applet:send("250 OK\r\n")
if RecieveAndCheck(applet, "RCPT TO:") == false then
return
applet:set_var("txn.result", "ERROR (step: RCPT TO)")
return
end
applet:send("250 OK\r\n")
if RecieveAndCheck(applet, "DATA") == false then
return
applet:set_var("txn.result", "ERROR (step: DATA)")
return
end
applet:send("354 OK\r\n")
core.Info("#### Send your mailbody")
@ -83,7 +47,7 @@ core.register_service("mailservice", "tcp", function(applet)
data = applet:getline() -- BODY CONTENT
--core.Info(data)
if data:sub(1, 9) == "Subject: " then
subject = data
subject = data
end
if (data == "\r\n") then
data = applet:getline() -- BODY CONTENT
@ -97,9 +61,10 @@ core.register_service("mailservice", "tcp", function(applet)
applet:send("250 OK\r\n")
if RecieveAndCheck(applet, "QUIT") == false then
return
applet:set_var("txn.result", "ERROR (step: QUIT)")
return
end
applet:send("221 Mail queued for delivery to /dev/null \r\n")
core.Info("Mail queued for delivery to /dev/null subject: "..subject)
mailsreceived = mailsreceived + 1
applet:set_var("txn.result", "SUCCESS")
end)

View File

@ -1,75 +1,59 @@
varnishtest "Lua: txn:get_priv() scope"
varnishtest "Check health-check email alerts"
#REQUIRE_OPTIONS=LUA
#REGTEST_TYPE=broken
feature ignore_unknown_macro
server s1 {
rxreq
txresp
syslog S1 -level notice {
recv
expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be1/srv1 failed.+reason: Socket error.+info: \"Connection reset by peer\".+check duration: [[:digit:]]+ms.+status: 0/1 DOWN."
recv info
expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Result=SUCCESS Bytes=[[:digit:]]+"
} -start
haproxy h1 -conf {
global
lua-load ${testdir}/healthcheckmail.lua
defaults
frontend femail
mode tcp
bind "fd@${femail}"
tcp-request content use-service lua.mailservice
frontend luahttpservice
mode http
bind "fd@${luahttpservice}"
http-request use-service lua.luahttpservice
defaults
timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
listen lisrv
mode tcp
bind "fd@${lisrv}"
tcp-request connection reject
listen lismtp
mode tcp
bind "fd@${lismtp}"
log ${S1_addr}:${S1_port} daemon
log-format "Result=%[var(txn.result)] Bytes=%B"
tcp-request content use-service lua.mailservice
frontend fe1
mode http
bind "fd@${fe1}"
default_backend b1
default_backend be1
http-response lua.bug
backend b1
backend be1
mode http
option httpchk /svr_healthcheck
log ${S1_addr}:${S1_port} daemon
option httpchk
option log-health-checks
default-server inter 200ms downinter 100ms rise 1 fall 1
email-alert mailers mymailers
email-alert level info
email-alert from from@domain.tld
email-alert to to@domain.tld
server broken 127.0.0.1:65535 check
server srv_lua ${h1_luahttpservice_addr}:${h1_luahttpservice_port} check inter 500
server srv1 ${s1_addr}:${s1_port} check inter 500
server srv1 ${h1_lisrv_addr}:${h1_lisrv_port} check
mailers mymailers
# timeout mail 20s
# timeout mail 200ms
mailer smtp1 ${h1_femail_addr}:${h1_femail_port}
mailer smtp1 ${h1_lismtp_addr}:${h1_lismtp_port}
} -start
# configure port for lua to call feluaservice
client c1 -connect ${h1_luahttpservice_sock} {
timeout 2
txreq -url "/setport" -hdr "vtcport1: ${h1_femail_port}"
rxresp
expect resp.status == 200
expect resp.body == "OK"
} -run
delay 2
server s2 -repeat 5 -start
delay 5
client c2 -connect ${h1_luahttpservice_sock} {
timeout 2
txreq -url "/checkMailCounters"
rxresp
expect resp.status == 200
expect resp.body == "MailCounters"
expect resp.http.mailsreceived == 16
expect resp.http.mailconnectionsmade == 16
} -run
syslog S1 -wait