Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TODO]: Tests(Fail2Ban) - Make failed login test case reliable #3713

Closed
polarathene opened this issue Dec 19, 2023 · 1 comment
Closed

[TODO]: Tests(Fail2Ban) - Make failed login test case reliable #3713

polarathene opened this issue Dec 19, 2023 · 1 comment
Labels
area/tests meta/help wanted The OP requests help from others - chime in! :D service/security/fail2ban stale-bot/ignore Indicates that this issue / PR shall not be closed by our stale-checking CI

Comments

@polarathene
Copy link
Member

polarathene commented Dec 19, 2023

Description

This test case is quite flakey, and fails on PRs that have nothing to do with it.

not ok 52 [Fail2Ban] ban ip on multiple failed login in 132455ms
# (from function `assert_success' in file test/test_helper/bats-assert/src/assert_success.bash, line 42,
#  from function `_send_email' in file test/helper/sending.bash, line 33,
#  in test file test/tests/parallel/set1/spam_virus/fail2ban.bats, line 77)
#   `CONTAINER_NAME=${CONTAINER2_NAME} _send_email 'auth/smtp-auth-login-wrong' "${CONTAINER1_IP} 465"' failed
#
# -- command failed --
# status : 1
# output :
# --
#

Seems like it's something to do with _send_email failing?

CONTAINER_NAME=${CONTAINER2_NAME} _send_email 'auth/smtp-auth-login-wrong' "${CONTAINER1_IP} 465"

# This function will just send the email in an "asynchronous" fashion, i.e. it will
# send the email but it will not make sure the mail queue is empty after the mail
# has been sent.
function _send_email() {
local TEMPLATE_FILE=${1:?Must provide name of template file}
local NC_PARAMETERS=${2:-0.0.0.0 25}
assert_not_equal "${NC_PARAMETERS}" ''
assert_not_equal "${CONTAINER_NAME:-}" ''
_run_in_container_bash "nc ${NC_PARAMETERS} < /tmp/docker-mailserver-test/${TEMPLATE_FILE}.txt"
assert_success
}

Specifically this line:

_run_in_container_bash "nc ${NC_PARAMETERS} < /tmp/docker-mailserver-test/${TEMPLATE_FILE}.txt"


Chances are it's been banned before the test case can check (expects to first succeed with _send_email twice?), then:

# Checking that CONTAINER2_IP is banned in "${CONTAINER1_NAME}"
CONTAINER2_IP=$(_get_container_ip "${CONTAINER2_NAME}")
run _repeat_in_container_until_success_or_timeout 10 "${CONTAINER_NAME}" /bin/bash -c "fail2ban-client status postfix-sasl | grep -F '${CONTAINER2_IP}'"
assert_success
assert_output --partial 'Banned IP list:'

Generally we expect _send_mail to be successful when it's used, but this is a situation where it's non-deterministic, sometimes failing.

@polarathene polarathene added meta/help wanted The OP requests help from others - chime in! :D area/tests service/security/fail2ban stale-bot/ignore Indicates that this issue / PR shall not be closed by our stale-checking CI labels Dec 19, 2023
@georglauterbach
Copy link
Member

Closing this as #3732 has been merged. Please re-open in case this issue still persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/tests meta/help wanted The OP requests help from others - chime in! :D service/security/fail2ban stale-bot/ignore Indicates that this issue / PR shall not be closed by our stale-checking CI
Projects
None yet
Development

No branches or pull requests

2 participants