From a57a5ee0053444544b9fcf3675f5daff79ff003c Mon Sep 17 00:00:00 2001 From: msramalho <19508417+msramalho@users.noreply.github.com> Date: Thu, 23 Apr 2026 14:20:07 +0100 Subject: [PATCH] adds an extra check when calling pypi as it's led to uncaught ssl errors --- src/auto_archiver/core/orchestrator.py | 6 ++++- tests/test_orchestrator.py | 32 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/auto_archiver/core/orchestrator.py b/src/auto_archiver/core/orchestrator.py index 9d914d1..2dab76c 100644 --- a/src/auto_archiver/core/orchestrator.py +++ b/src/auto_archiver/core/orchestrator.py @@ -467,7 +467,11 @@ Here's how that would look: \n\nsteps:\n extractors:\n - [your_extractor_name_ return self.setup_complete_parser(basic_config, yaml_config, unused_args) def check_for_updates(self): - response = requests.get("https://pypi.org/pypi/auto-archiver/json").json() + try: + response = requests.get("https://pypi.org/pypi/auto-archiver/json", timeout=10).json() + except Exception as e: + logger.debug(f"Unable to check for updates: {e}") + return latest_version = version.parse(response["info"]["version"]) current_version = version.parse(__version__) # check version compared to current version diff --git a/tests/test_orchestrator.py b/tests/test_orchestrator.py index b87dfa5..3449a20 100644 --- a/tests/test_orchestrator.py +++ b/tests/test_orchestrator.py @@ -1,5 +1,6 @@ import pytest from argparse import ArgumentParser, ArgumentTypeError +from requests.exceptions import SSLError from auto_archiver.core.orchestrator import ArchivingOrchestrator from auto_archiver.version import __version__ from auto_archiver.core.config import read_yaml, store_yaml @@ -256,3 +257,34 @@ def test_load_failed_extractor_cleanup(test_args, mocker, caplog): assert "Error during setup of modules: Test exception" in caplog.text # make sure the 'cleanup' is called assert "cleanup" in caplog.text + + +def test_check_for_updates_ssl_error(orchestrator, mocker): + """check_for_updates should not raise when the HTTP request fails.""" + mocker.patch( + "auto_archiver.core.orchestrator.requests.get", + side_effect=SSLError("SSL handshake failed"), + ) + # should not raise + orchestrator.check_for_updates() + + +def test_check_for_updates_timeout(orchestrator, mocker): + """check_for_updates should not raise on connection timeout.""" + from requests.exceptions import ConnectionError + + mocker.patch( + "auto_archiver.core.orchestrator.requests.get", + side_effect=ConnectionError("Connection refused"), + ) + orchestrator.check_for_updates() + + +def test_check_for_updates_new_version_available(orchestrator, mocker): + """check_for_updates should not raise when a newer version exists.""" + mocker.patch( + "auto_archiver.core.orchestrator.requests.get", + return_value=mocker.Mock(json=lambda: {"info": {"version": "99.0.0"}}), + ) + # should complete without error + orchestrator.check_for_updates()