auth/test: check auth_delay on failed login

This commit is contained in:
Peter Bieringer
2026-03-29 14:48:05 +02:00
parent 9cb1e5e8bd
commit d81dfa8547

View File

@@ -26,6 +26,7 @@ import base64
import logging import logging
import os import os
import sys import sys
import time
from typing import Iterable, Tuple, Union from typing import Iterable, Tuple, Union
import pytest import pytest
@@ -218,6 +219,21 @@ class TestBaseAuthRequests(BaseTest):
if (htpasswd_found is False) or (htpasswd_cached_found is False): if (htpasswd_found is False) or (htpasswd_cached_found is False):
raise ValueError("Logging misses expected log lines") raise ValueError("Logging misses expected log lines")
# login cache failed
def test_htpasswd_login_cache_failed_delay_plain(self, caplog) -> None:
caplog.set_level(logging.INFO)
self.configure({"auth": {"cache_logins": "True"}})
delay = 1
delay_ns = delay * 10**9 * 0.5 # delay minimum jitter
time_ns_begin1 = time.time_ns()
self._test_htpasswd("plain", "tmp:bepo", [("tmp", "bepo1", False)], delay=delay)
time_ns_end1 = time.time_ns()
time_ns_begin2 = time.time_ns()
self._test_htpasswd("plain", "tmp:bepo", [("tmp", "bepo1", False)], delay=delay)
time_ns_end2 = time.time_ns()
assert (time_ns_end1 - time_ns_begin1) > delay_ns
assert (time_ns_end2 - time_ns_begin2) > delay_ns
# htpasswd file cache # htpasswd file cache
def test_htpasswd_file_cache(self, caplog) -> None: def test_htpasswd_file_cache(self, caplog) -> None:
self.configure({"auth": {"htpasswd_cache": "True"}}) self.configure({"auth": {"htpasswd_cache": "True"}})