mirror of
https://github.com/SeedSigner/seedsigner.git
synced 2026-10-05 15:08:25 +00:00
bugfix; caught by @jdlcdl
This commit is contained in:
@@ -87,6 +87,12 @@ class Settings(Singleton):
|
|||||||
values = value
|
values = value
|
||||||
for v in values:
|
for v in values:
|
||||||
if v not in [opt[0] for opt in settings_entry.selection_options]:
|
if v not in [opt[0] for opt in settings_entry.selection_options]:
|
||||||
|
if settings_entry.attr_name == SettingsConstants.SETTING__PERSISTENT_SETTINGS and v == SettingsConstants.OPTION__ENABLED:
|
||||||
|
# Special case: trying to enable Persistent Settings when
|
||||||
|
# DISABLED is the only option allowed (because the SD card is not
|
||||||
|
# inserted. Explicitly set to DISABLED.
|
||||||
|
value = SettingsConstants.OPTION__DISABLED
|
||||||
|
break
|
||||||
raise InvalidSettingsQRData(f"""{abbreviated_name} = '{v}' is not valid""")
|
raise InvalidSettingsQRData(f"""{abbreviated_name} = '{v}' is not valid""")
|
||||||
|
|
||||||
updated_settings[settings_entry.attr_name] = value
|
updated_settings[settings_entry.attr_name] = value
|
||||||
|
|||||||
@@ -196,13 +196,6 @@ class SettingsIngestSettingsQRView(View):
|
|||||||
# May raise an Exception which will bubble up to the Controller to display to the
|
# May raise an Exception which will bubble up to the Controller to display to the
|
||||||
# user.
|
# user.
|
||||||
self.config_name, settings_update_dict = Settings.parse_settingsqr(data)
|
self.config_name, settings_update_dict = Settings.parse_settingsqr(data)
|
||||||
|
|
||||||
persistent_settings = settings_update_dict.get(SettingsConstants.SETTING__PERSISTENT_SETTINGS)
|
|
||||||
if persistent_settings == SettingsConstants.OPTION__ENABLED and not MicroSD.get_instance().is_inserted:
|
|
||||||
# SettingsQR wants to enable persistent settings, but no MicroSD is inserted.
|
|
||||||
# For the sake of simplicity we just ignore that setting for now.
|
|
||||||
# TODO: Can consider a warning screen instead that gives the user some options.
|
|
||||||
del settings_update_dict[SettingsConstants.SETTING__PERSISTENT_SETTINGS]
|
|
||||||
|
|
||||||
self.settings.update(settings_update_dict)
|
self.settings.update(settings_update_dict)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
|
from mock import PropertyMock, patch
|
||||||
|
|
||||||
# Must import test base before the Controller
|
# Must import test base before the Controller
|
||||||
from base import FlowTest, FlowStep
|
from base import FlowTest, FlowStep
|
||||||
|
|
||||||
@@ -116,6 +118,19 @@ class TestSettingsFlows(FlowTest):
|
|||||||
self.mock_microsd.is_inserted = False
|
self.mock_microsd.is_inserted = False
|
||||||
assert MicroSD.get_instance().is_inserted is False
|
assert MicroSD.get_instance().is_inserted is False
|
||||||
|
|
||||||
|
# Have to jump through some hoops to completely simulate the SD card being
|
||||||
|
# removed; we need Settings to restrict Persistent Settings to only allow
|
||||||
|
# DISABLED.
|
||||||
|
with patch('seedsigner.models.settings.Settings.HOSTNAME', new_callable=PropertyMock) as mock_hostname:
|
||||||
|
# Must identify itself as SeedSigner OS to trigger the SD card removal logic
|
||||||
|
mock_hostname.return_value = Settings.SEEDSIGNER_OS
|
||||||
|
Settings.handle_microsd_state_change(MicroSD.ACTION__REMOVED)
|
||||||
|
|
||||||
|
selection_options = SettingsDefinition.get_settings_entry(SettingsConstants.SETTING__PERSISTENT_SETTINGS).selection_options
|
||||||
|
assert len(selection_options) == 1
|
||||||
|
assert selection_options[0][0] == SettingsConstants.OPTION__DISABLED
|
||||||
|
assert self.settings.get_value(SettingsConstants.SETTING__PERSISTENT_SETTINGS) == SettingsConstants.OPTION__DISABLED
|
||||||
|
|
||||||
_run_test(
|
_run_test(
|
||||||
initial_setting_state=SettingsConstants.OPTION__DISABLED,
|
initial_setting_state=SettingsConstants.OPTION__DISABLED,
|
||||||
load_settingsqr_into_decoder=load_persistent_settingsqr_into_decoder,
|
load_settingsqr_into_decoder=load_persistent_settingsqr_into_decoder,
|
||||||
|
|||||||
Reference in New Issue
Block a user