From d63b44c014ebaa2831f683f7397cdf141e2641b4 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Fri, 24 Jun 2022 10:56:25 +0200 Subject: [PATCH] storage: use fields named passphrase for passphrases Because the storage views lean on the implementation of setup_password_validation from the identity screen, we were forced to use a form with fields named "password" and "password_confirm". This makes the code confusing because we use the "passphrase" terminology in the storage forms. We now leave up to the caller to specify which fields he wants to be part of the validation ; instead of making him provide the full form. Signed-off-by: Olivier Gayot --- examples/answers-lvm-dmcrypt.yaml | 8 ++--- subiquity/client/controllers/filesystem.py | 4 +-- subiquity/ui/views/filesystem/guided.py | 16 ++++----- subiquity/ui/views/filesystem/lvm.py | 36 ++++++++++--------- .../ui/views/filesystem/tests/test_lvm.py | 6 ++-- subiquity/ui/views/identity.py | 19 ++++++---- system_setup/ui/views/identity.py | 4 ++- 7 files changed, 51 insertions(+), 42 deletions(-) diff --git a/examples/answers-lvm-dmcrypt.yaml b/examples/answers-lvm-dmcrypt.yaml index 455205fe..672a0823 100644 --- a/examples/answers-lvm-dmcrypt.yaml +++ b/examples/answers-lvm-dmcrypt.yaml @@ -40,8 +40,8 @@ Filesystem: - [disk index 0, part 1] - [disk index 0, part 2] encrypt: true - password: "passw0rd" - confirm_password: "passw0rd" + passphrase: "passw0rd" + confirm_passphrase: "passw0rd" - obj: [volgroup name vg-1] action: EDIT data: @@ -50,8 +50,8 @@ Filesystem: action: EDIT data: encrypt: true - password: "passw0rd" - confirm_password: "passw0rd" + passphrase: "passw0rd" + confirm_passphrase: "passw0rd" - obj: [volgroup name vg-1] action: CREATE_LV data: diff --git a/subiquity/client/controllers/filesystem.py b/subiquity/client/controllers/filesystem.py index 02c120f8..f0006ab3 100644 --- a/subiquity/client/controllers/filesystem.py +++ b/subiquity/client/controllers/filesystem.py @@ -114,8 +114,8 @@ class FilesystemController(SubiquityTuiController, FilesystemManipulator): value['lvm_options'] = { 'encrypt': True, 'luks_options': { - 'password': passphrase, - 'confirm_password': passphrase, + 'passphrase': passphrase, + 'confirm_passphrase': passphrase, } } self.ui.body.form.guided_choice.value = value diff --git a/subiquity/ui/views/filesystem/guided.py b/subiquity/ui/views/filesystem/guided.py index 4a087999..bb6212c6 100644 --- a/subiquity/ui/views/filesystem/guided.py +++ b/subiquity/ui/views/filesystem/guided.py @@ -59,15 +59,15 @@ subtitle = _("Configure a guided storage layout, or create a custom one:") class LUKSOptionsForm(SubForm): - password = PasswordField(_("Passphrase:")) - confirm_password = PasswordField(_("Confirm passphrase:")) + passphrase = PasswordField(_("Passphrase:")) + confirm_passphrase = PasswordField(_("Confirm passphrase:")) - def validate_password(self): - if len(self.password.value) < 1: + def validate_passphrase(self): + if len(self.passphrase.value) < 1: return _("Passphrase must be set") - def validate_confirm_password(self): - if self.password.value != self.confirm_password.value: + def validate_confirm_passphrase(self): + if self.passphrase.value != self.confirm_passphrase.value: return _("Passphrases do not match") @@ -185,7 +185,7 @@ can easily be enlarged with standard LVM command line tools (or on the next screen). You can also choose to encrypt LVM volume group. This will require -setting a password, that one will need to type on every boot before +setting a passphrase, that one will need to type on every boot before the system boots. If you do not choose to use LVM, a single partition is created covering the @@ -252,7 +252,7 @@ class GuidedDiskSelectionView(BaseView): use_lvm=results['guided_choice']['use_lvm']) opts = results['guided_choice'].get('lvm_options', {}) if opts.get('encrypt', False): - choice.password = opts['luks_options']['password'] + choice.password = opts['luks_options']['passphrase'] self.controller.guided_choice(choice) def manual(self, sender): diff --git a/subiquity/ui/views/filesystem/lvm.py b/subiquity/ui/views/filesystem/lvm.py index f24bc0fe..6ec28c4b 100644 --- a/subiquity/ui/views/filesystem/lvm.py +++ b/subiquity/ui/views/filesystem/lvm.py @@ -83,22 +83,24 @@ class VolGroupForm(CompoundDiskForm): self.deleted_vg_names = deleted_vg_names super().__init__(model, possible_components, initial) connect_signal(self.encrypt.widget, 'change', self._change_encrypt) - setup_password_validation(self, _("Passphrases")) + setup_password_validation(field=self.passphrase, + field_confirm=self.confirm_passphrase, + desc=_("Passphrases")) self._change_encrypt(None, self.encrypt.value) name = VGNameField(_("Name:")) devices = MultiDeviceField(_("Devices:")) size = ReadOnlyField(_("Size:")) encrypt = BooleanField(_("Create encrypted volume")) - password = PasswordField(_("Passphrase:")) - confirm_password = PasswordField(_("Confirm passphrase:")) + passphrase = PasswordField(_("Passphrase:")) + confirm_passphrase = PasswordField(_("Confirm passphrase:")) def _change_encrypt(self, sender, new_value): - self.password.enabled = new_value - self.confirm_password.enabled = new_value + self.passphrase.enabled = new_value + self.confirm_passphrase.enabled = new_value if not new_value: - self.password.validate() - self.confirm_password.validate() + self.passphrase.validate() + self.confirm_passphrase.validate() def validate_devices(self): if len(self.devices.value) < 1: @@ -119,13 +121,13 @@ class VolGroupForm(CompoundDiskForm): return _("{name} is not a valid name for a volume " "group").format(name=v) - def validate_password(self): - if self.encrypt.value and len(self.password.value) < 1: + def validate_passphrase(self): + if self.encrypt.value and len(self.passphrase.value) < 1: return _("Passphrase must be set") - def validate_confirm_password(self): + def validate_confirm_passphrase(self): if self.encrypt.value and \ - self.password.value != self.confirm_password.value: + self.passphrase.value != self.confirm_passphrase.value: return _("Passphrases do not match") @@ -167,8 +169,8 @@ class VolGroupStretchy(Stretchy): 'devices': devices, 'name': existing.name, 'encrypt': bool(key), - 'password': key, - 'confirm_password': key, + 'passphrase': key, + 'confirm_passphrase': key, } possible_components = get_possible_components( @@ -205,11 +207,11 @@ class VolGroupStretchy(Stretchy): del result['size'] mdc = self.form.devices.widget result['devices'] = mdc.active_devices - if 'confirm_password' in result: - del result['confirm_password'] + if 'confirm_passphrase' in result: + del result['confirm_passphrase'] safe_result = result.copy() - if 'password' in safe_result: - safe_result['password'] = '' + if 'passphrase' in safe_result: + safe_result['passphrase'] = '' log.debug("vg_done: {}".format(safe_result)) self.parent.controller.volgroup_handler(self.existing, result) self.parent.refresh_model_inputs() diff --git a/subiquity/ui/views/filesystem/tests/test_lvm.py b/subiquity/ui/views/filesystem/tests/test_lvm.py index ee459b43..e3191d29 100644 --- a/subiquity/ui/views/filesystem/tests/test_lvm.py +++ b/subiquity/ui/views/filesystem/tests/test_lvm.py @@ -69,14 +69,14 @@ class LVMViewTests(unittest.TestCase): 'name': 'vg1', 'devices': {part1: 'active', part2: 'active'}, 'encrypt': True, - 'password': 'passw0rd', - 'confirm_password': 'passw0rd', + 'passphrase': 'passw0rd', + 'confirm_passphrase': 'passw0rd', } expected_data = { 'name': 'vg1', 'devices': {part1, part2}, 'encrypt': True, - 'password': 'passw0rd', + 'passphrase': 'passw0rd', } view_helpers.enter_data(stretchy.form, form_data) view_helpers.click(stretchy.form.done_btn.base_widget) diff --git a/subiquity/ui/views/identity.py b/subiquity/ui/views/identity.py index 115152fe..b75a3727 100644 --- a/subiquity/ui/views/identity.py +++ b/subiquity/ui/views/identity.py @@ -27,6 +27,7 @@ from subiquitycore.ui.interactive import ( StringEditor, ) from subiquitycore.ui.form import ( + BoundFormField, Form, simple_field, WantsToKnowFormField, @@ -186,17 +187,19 @@ class IdentityForm(Form): return _("Passwords do not match") -def setup_password_validation(form, desc): +def setup_password_validation(field: BoundFormField, + field_confirm: BoundFormField, + desc: str) -> None: + """ Set up an automatic check for password vs password confirmation. """ def _check_password(sender, new_text): - password = form.password.value + password = field.value if not password.startswith(new_text): - form.confirm_password.show_extra( + field_confirm.show_extra( # desc is "Passwords" or "Passphrases" ("info_error", _("{desc} do not match").format(desc=desc))) else: - form.confirm_password.show_extra('') - connect_signal( - form.confirm_password.widget, 'change', _check_password) + field_confirm.show_extra('') + connect_signal(field_confirm.widget, 'change', _check_password) class IdentityView(BaseView): @@ -229,7 +232,9 @@ class IdentityView(BaseView): self.form = IdentityForm(controller, initial) connect_signal(self.form, 'submit', self.done) - setup_password_validation(self.form, _("Passwords")) + setup_password_validation(field=self.form.password, + field_confirm=self.form.confirm_password, + desc=_("Passwords")) super().__init__( screen( diff --git a/system_setup/ui/views/identity.py b/system_setup/ui/views/identity.py index e914444e..a4dc2395 100644 --- a/system_setup/ui/views/identity.py +++ b/system_setup/ui/views/identity.py @@ -72,7 +72,9 @@ class WSLIdentityView(BaseView): self.form = WSLIdentityForm(controller, initial) connect_signal(self.form, 'submit', self.done) - setup_password_validation(self.form, _("passwords")) + setup_password_validation(field=self.form.password, + field_confirm=self.form.confirm_password, + desc=_("passwords")) super().__init__( screen(