def from_structure_dict_test(self): """Test the from_structure_dict method.""" s1 = {"min-quality": get_variant(Int, 1)} s2 = {"min-quality": get_variant(Int, 2)} s3 = {"min-quality": get_variant(Int, 3)} # Test an invalid argument. with self.assertRaises(TypeError): PasswordPolicy.from_structure_dict([]) # Test a valid argument. objects = PasswordPolicy.from_structure_dict({ "s1": s1, "s2": s2, "s3": s3 }) self.assertEqual(objects.keys(), {"s1", "s2", "s3"}) self.assertEqual(objects["s1"].min_quality, 1) self.assertEqual(objects["s2"].min_quality, 2) self.assertEqual(objects["s3"].min_quality, 3)
def default_password_policies_test(self): """Test the password policies property.""" policies = PasswordPolicy.from_structure_dict( self.interface.PasswordPolicies) expected_names = {"root", "user", "luks"} self.assertEqual(policies.keys(), expected_names) for name in expected_names: policy = policies[name] expected_policy = PasswordPolicy.from_defaults(name) self.assertTrue(compare_data(policy, expected_policy))
def _get_password_policies(self): """Get the password policies from the installer. :return: a dictionary of password policies """ proxy = BOSS.get_proxy(USER_INTERFACE) policies = PasswordPolicy.from_structure_dict(proxy.PasswordPolicies) if PASSWORD_POLICY_ROOT not in policies: policy = PasswordPolicy.from_defaults(PASSWORD_POLICY_ROOT) policies[PASSWORD_POLICY_ROOT] = policy return policies
def SetPasswordPolicies(self, policies: Dict[Str, Structure]): """Set the password policies. Default policy names: root The policy for the root password. user The policy for the user password. luks The policy for the LUKS passphrase. :param policies: a dictionary of policy names and policy data """ self.implementation.set_password_policies( PasswordPolicy.from_structure_dict(policies))