From e482c768749ef1df1cb2a12b705b38336bd58d60 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 20 Feb 2018 17:08:28 +0100 Subject: [PATCH] YamlConfig: Refuse to read a newer config version --- qutebrowser/config/configfiles.py | 7 ++++++- tests/unit/config/test_configfiles.py | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/qutebrowser/config/configfiles.py b/qutebrowser/config/configfiles.py index 62e4d7970..9d76d4ee5 100644 --- a/qutebrowser/config/configfiles.py +++ b/qutebrowser/config/configfiles.py @@ -172,13 +172,18 @@ class YamlConfig(QObject): raise configexc.ConfigFileErrors('autoconfig.yml', [desc]) config_version = self._pop_object(yaml_data, 'config_version', int) - if config_version == 1: settings = self._load_legacy_settings_object(yaml_data) self._mark_changed() + elif config_version > self.VERSION: + desc = configexc.ConfigErrorDesc( + "While reading", + "Can't read config from incompatible newer version") + raise configexc.ConfigFileErrors('autoconfig.yml', [desc]) else: settings = self._load_settings_object(yaml_data) self._dirty = False + settings = self._handle_migrations(settings) self._validate(settings) self._build_values(settings) diff --git a/tests/unit/config/test_configfiles.py b/tests/unit/config/test_configfiles.py index 29314d87e..eadddf39b 100644 --- a/tests/unit/config/test_configfiles.py +++ b/tests/unit/config/test_configfiles.py @@ -330,6 +330,20 @@ class TestYaml: } } + def test_read_newer_version(self, yaml, autoconfig): + autoconfig.write_toplevel({ + 'config_version': 999, + 'settings': {}, + }) + with pytest.raises(configexc.ConfigFileErrors) as excinfo: + yaml.load() + + assert len(excinfo.value.errors) == 1 + error = excinfo.value.errors[0] + assert error.text == "While reading" + msg = "Can't read config from incompatible newer version" + assert error.exception == msg + def test_oserror(self, yaml, autoconfig): autoconfig.fobj.ensure() autoconfig.fobj.chmod(0)