fix(client): validate Retry-After header (cap, fallback, edge cases)

- Ajoute try/except autour du float() pour gérer les dates HTTP RFC 7231
- Cap à 30s pour éviter un blocage indéfini sur valeur énorme
- Plancher à _RETRY_DELAY pour Retry-After: 0 ou négatif (FINDING-R2)
- 4 nouveaux tests : date HTTP, valeur zéro, valeur énorme, health check partiel

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
sylvain
2026-03-12 19:44:39 +01:00
parent 15ed533d20
commit 16344bbb3f
3 changed files with 73 additions and 1 deletions

View File

@@ -330,6 +330,25 @@ class TestMainHealth:
assert exc_info.value.code == 1
@patch("gitea_dashboard.cli.GiteaClient")
def test_main_health_version_ok_repos_fail(self, mock_client_cls):
"""--health : get_version reussit mais get_repos leve HTTPError -> exit 1.
Verifie le cas d'un health check partiel : l'instance Gitea repond
sur /version mais l'acces aux repos echoue (ex: token sans permissions).
"""
env = {"GITEA_TOKEN": "test-token"}
mock_client = MagicMock()
mock_client_cls.return_value = mock_client
mock_client.get_version.return_value = {"version": "1.21.0"}
mock_client.get_repos.side_effect = requests.HTTPError("403 Forbidden")
with patch.dict("os.environ", env, clear=True):
with pytest.raises(SystemExit) as exc_info:
main(["--health"])
assert exc_info.value.code == 1
class TestMainNoDesc:
"""Test main() with --no-desc."""