diff --git a/src/auto_update_setup.py b/src/auto_update_setup.py index d4033791..bd814c8e 100644 --- a/src/auto_update_setup.py +++ b/src/auto_update_setup.py @@ -195,7 +195,12 @@ class UpdateHelperSetup: json.dump(result, f, indent=2) os.chmod(tmp, 0o644) if self._web_ids and hasattr(os, 'chown'): - os.chown(tmp, *self._web_ids) + # Only root can give the file away; the result is readable + # (0644) either way, so a failed chown must not lose it. + try: + os.chown(tmp, *self._web_ids) + except OSError: + pass os.replace(tmp, self.result_file) except OSError as e: logger.warning("Could not record automatic update setup result: %s", e) diff --git a/test/fixtures/api_v3_url_map.json b/test/fixtures/api_v3_url_map.json index 22291e85..c5f496ac 100644 --- a/test/fixtures/api_v3_url_map.json +++ b/test/fixtures/api_v3_url_map.json @@ -841,6 +841,23 @@ "POST" ] ], + [ + "/api/v3/system/auto-update", + "api_v3.get_auto_update_status", + [ + "GET", + "HEAD", + "OPTIONS" + ] + ], + [ + "/api/v3/system/auto-update/dismiss", + "api_v3.dismiss_auto_update_alert", + [ + "OPTIONS", + "POST" + ] + ], [ "/api/v3/system/check-update", "api_v3.check_for_update", diff --git a/test/test_auto_update_setup.py b/test/test_auto_update_setup.py index e7b868ea..866c2ee7 100644 --- a/test/test_auto_update_setup.py +++ b/test/test_auto_update_setup.py @@ -167,3 +167,16 @@ def test_not_a_systemd_host_is_left_alone(tmp_path): systemctl = FakeSystemctl() assert setup(root, tmp_path / 'no-etc', systemctl).ensure(ON) is None assert systemctl.calls == [] + + +def test_the_result_is_kept_when_it_cannot_be_given_to_the_web_user(tmp_path, monkeypatch): + """Caught by CI, which runs as a non-root Linux user: chown needs root, and + a failed chown used to discard the result, so the General tab never + learned whether setup worked.""" + def refuse(*args): + raise PermissionError('Operation not permitted') + monkeypatch.setattr(aus.os, 'chown', refuse, raising=False) + root, etc = project(tmp_path) + out = setup(root, etc, FakeSystemctl()).ensure(ON) + assert out['status'] == 'installed' + assert result(root) == out diff --git a/web_interface/templates/v3/partials/general.html b/web_interface/templates/v3/partials/general.html index 8eed237a..9627269a 100644 --- a/web_interface/templates/v3/partials/general.html +++ b/web_interface/templates/v3/partials/general.html @@ -70,7 +70,7 @@

An update was just installed and its health check is running.

{% endif %} {% if auto_update_status and (auto_update_status.last_run or auto_update_status.next_due) %} -
+
{% if auto_update_status.last_run %}

Last automatic update: {{ auto_update_status.last_run }} — {{ auto_update_status.summary }}

diff --git a/web_interface/templates/v3/partials/overview.html b/web_interface/templates/v3/partials/overview.html index 3a3469a6..a0a54fc6 100644 --- a/web_interface/templates/v3/partials/overview.html +++ b/web_interface/templates/v3/partials/overview.html @@ -8,7 +8,7 @@

Details are under Automatic Updates on the General tab.

-