def apply_policies_to_module_test(self, proxy_getter): ui_module = Mock() proxy_getter.return_value = ui_module ks_in = """ %anaconda pwpolicy root --minlen=1 --minquality=10 --notempty --strict pwpolicy user --minlen=2 --minquality=20 --emptyok --notstrict pwpolicy luks --minlen=3 --minquality=30 --emptyok --strict %end """ self.ksparser.readKickstartFromString(dedent(ks_in)) apply_password_policy_from_kickstart(self.handler) root_policy = PasswordPolicy() root_policy.min_length = 1 root_policy.min_quality = 10 root_policy.is_strict = True root_policy.allow_empty = False user_policy = PasswordPolicy() user_policy.min_length = 2 user_policy.min_quality = 20 user_policy.is_strict = False user_policy.allow_empty = True luks_policy = PasswordPolicy() luks_policy.min_length = 3 luks_policy.min_quality = 30 luks_policy.is_strict = True luks_policy.allow_empty = True policies = { PASSWORD_POLICY_ROOT: root_policy, PASSWORD_POLICY_USER: user_policy, PASSWORD_POLICY_LUKS: luks_policy } ui_module.SetPasswordPolicies.assert_called_once_with( PasswordPolicy.to_structure_dict(policies))
def apply_password_policy_from_kickstart(data): """Apply the password policy specified in the kickstart file. FIXME: This is a temporary workaround. Remove the pwpolicy kickstart command in the next major release. :param data: a kickstart data handler """ if not data.anaconda.pwpolicy.seen: log.debug("Using the password policy from the configuration.") return # Set up the UI DBus module. ui_module = BOSS.get_proxy(USER_INTERFACE) policies = {} for pwdata in data.anaconda.pwpolicy.policyList: policy = PasswordPolicy() policy_name = pwdata.name policy.min_quality = pwdata.minquality policy.min_length = pwdata.minlen policy.is_strict = pwdata.strict policy.allow_empty = pwdata.emptyok policies[policy_name] = policy ui_module.SetPasswordPolicies(PasswordPolicy.to_structure_dict(policies)) # Set up the Anaconda configuration. This change will affect only the main # process with UI, because the DBus modules are already running. pwdata = data.anaconda.pwpolicy.get_policy(PASSWORD_POLICY_ROOT, fallback_to_default=True) conf.ui._set_option("can_change_root", pwdata.changesok) pwdata = data.anaconda.pwpolicy.get_policy(PASSWORD_POLICY_USER, fallback_to_default=True) conf.ui._set_option("can_change_users", pwdata.changesok) log.debug("Using the password policy from the kickstart file.")