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 <olivier.gayot@canonical.com>
This commit is contained in:
Olivier Gayot 2022-06-24 10:56:25 +02:00
parent add252a42f
commit d63b44c014
7 changed files with 51 additions and 42 deletions

View File

@ -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:

View File

@ -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

View File

@ -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):

View File

@ -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'] = '<REDACTED>'
if 'passphrase' in safe_result:
safe_result['passphrase'] = '<REDACTED>'
log.debug("vg_done: {}".format(safe_result))
self.parent.controller.volgroup_handler(self.existing, result)
self.parent.refresh_model_inputs()

View File

@ -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)

View File

@ -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(

View File

@ -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(