Пример #1
0
    def get_default_password_policies(self):
        """Get the default password policies.

        :return: a dictionary of policy names and policy data
        """
        return {
            PASSWORD_POLICY_ROOT:
            PasswordPolicy.from_defaults(PASSWORD_POLICY_ROOT),
            PASSWORD_POLICY_USER:
            PasswordPolicy.from_defaults(PASSWORD_POLICY_USER),
            PASSWORD_POLICY_LUKS:
            PasswordPolicy.from_defaults(PASSWORD_POLICY_LUKS),
        }
Пример #2
0
 def test_default_unknown_policy(self):
     """Test the default policy data for unknown policy."""
     policy = PasswordPolicy.from_defaults("test")
     assert policy.min_quality == 0
     assert policy.min_length == 0
     assert policy.allow_empty is True
     assert policy.is_strict is False
Пример #3
0
 def test_default_known_policy(self):
     """Test the default policy data."""
     policy = PasswordPolicy.from_defaults("root")
     assert policy.min_quality == 1
     assert policy.min_length == 6
     assert policy.allow_empty is False
     assert policy.is_strict is False
Пример #4
0
 def default_unknown_policy_test(self):
     """Test the default policy data for unknown policy."""
     policy = PasswordPolicy.from_defaults("test")
     self.assertEqual(policy.min_quality, 0)
     self.assertEqual(policy.min_length, 0)
     self.assertEqual(policy.allow_empty, True)
     self.assertEqual(policy.is_strict, False)
Пример #5
0
 def default_known_policy_test(self):
     """Test the default policy data."""
     policy = PasswordPolicy.from_defaults("root")
     self.assertEqual(policy.min_quality, 1)
     self.assertEqual(policy.min_length, 6)
     self.assertEqual(policy.allow_empty, False)
     self.assertEqual(policy.is_strict, False)
Пример #6
0
    def test_default_password_policies(self):
        """Test the password policies property."""
        policies = PasswordPolicy.from_structure_dict(
            self.interface.PasswordPolicies)

        expected_names = {"root", "user", "luks"}
        assert policies.keys() == expected_names

        for name in expected_names:
            policy = policies[name]
            expected_policy = PasswordPolicy.from_defaults(name)
            assert compare_data(policy, expected_policy)
Пример #7
0
    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))
Пример #8
0
def get_policy(policy_name) -> PasswordPolicy:
    """Get the password policy data.

    :param policy_name: a name of the policy
    :return: a password policy data
    """
    proxy = BOSS.get_proxy(USER_INTERFACE)
    policies = PasswordPolicy.from_structure_dict(proxy.PasswordPolicies)

    if policy_name in policies:
        return policies[policy_name]

    return PasswordPolicy.from_defaults(policy_name)
    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 test_evaluation_passwd_minlen_report_only_not_ignored(
        proxy_getter, rule_data, ksdata_mock, storage_mock):
    password_proxy_mock = USERS.get_proxy()
    password_proxy_mock.IsRootPasswordCrypted = False
    password_proxy_mock.RootPassword = "******"

    rule_data.new_rule("passwd --minlen=8")

    # call eval_rules with report_only=False
    # should set password minimal length to 8
    messages = rule_data.eval_rules(ksdata_mock, storage_mock, report_only=False)

    # Password Policy changed --> no warnings
    assert not messages
    assert rule_data._passwd_rules._orig_minlen == 6
    assert not rule_data._passwd_rules._orig_strict
    assert rule_data._passwd_rules._minlen == 8

    policy = PasswordPolicy.from_defaults(PASSWORD_POLICY_ROOT)
    policy.min_length = 8
    policy.is_strict = True

    policies = {PASSWORD_POLICY_ROOT: policy}

    ui_mock = BOSS.get_proxy(USER_INTERFACE)
    assert ui_mock.PasswordPolicies == \
        PasswordPolicy.to_structure_dict(policies)

    # call of eval_rules with report_only=True
    # should not change anything
    messages = rule_data.eval_rules(ksdata_mock, storage_mock, report_only=True)
    # Password Policy stayed the same --> no warnings
    assert not messages

    assert rule_data._passwd_rules._orig_minlen == 6
    assert not rule_data._passwd_rules._orig_strict
    assert rule_data._passwd_rules._minlen == 8

    assert ui_mock.PasswordPolicies == \
        PasswordPolicy.to_structure_dict(policies)
def get_policy():
    return PasswordPolicy.from_defaults(PASSWORD_POLICY_USER)