Esempio n. 1
0
    def test_show_inactive_policies(self, mocked_get_copy_of_policies):
        """
        test that legacy policy show the inactive policy
        """
        initial_policies = {
            'losttoken_valid_all': {
                'realm': '*',
                'active': 'False',
                'client': '*',
                'user': '******',
                'time': '* * * * * *;',
                'action': 'lostTokenValid=5',
                'scope': 'enrollment'
            },
            'losttoken_valid_hans': {
                'realm': '*',
                'active': 'True',
                'client': '*',
                'user': '******',
                'time': '* * * * * *;',
                'action': 'lostTokenValid=8 d 1m',
                'scope': 'enrollment'
            }
        }

        param = {}

        # ------------------------------------------------------------------ --

        # by default select only active policies

        mocked_get_copy_of_policies.return_value = deepcopy(initial_policies)

        policies = legacy_getPolicy(param)
        assert len(policies) == 1

        # select all policies - active and inactive ones

        mocked_get_copy_of_policies.return_value = deepcopy(initial_policies)

        policies = legacy_getPolicy(param, only_active=False)
        assert len(policies) == 2

        # select only active policies

        mocked_get_copy_of_policies.return_value = deepcopy(initial_policies)

        policies = legacy_getPolicy(param, only_active=True)
        assert len(policies) == 1

        return
Esempio n. 2
0
    def test_show_inactive_policies(self,
                                    mocked_get_copy_of_policies):
        """
        test that legacy policy show the inactive policy
        """
        initial_policies = {
            'losttoken_valid_all': {
                'realm': '*',
                'active': 'False',
                'client': '*',
                'user': '******',
                'time': '* * * * * *;',
                'action': 'lostTokenValid=5',
                'scope': 'enrollment'},
            'losttoken_valid_hans': {
                'realm': '*',
                'active': 'True',
                'client': '*',
                'user': '******',
                'time': '* * * * * *;',
                'action': 'lostTokenValid=8 d 1m',
                'scope': 'enrollment'}}

        param = {}

        # ------------------------------------------------------------------ --

        # by default select only active policies

        mocked_get_copy_of_policies.return_value = deepcopy(initial_policies)

        policies = legacy_getPolicy(param)
        assert len(policies) == 1

        # select all policies - active and inactive ones

        mocked_get_copy_of_policies.return_value = deepcopy(initial_policies)

        policies = legacy_getPolicy(param, only_active=False)
        assert len(policies) == 2

        # select only active policies

        mocked_get_copy_of_policies.return_value = deepcopy(initial_policies)

        policies = legacy_getPolicy(param, only_active=True)
        assert len(policies) == 1

        return
Esempio n. 3
0
def getPolicy(param, only_active=False):
    """
    migration method for the getPolicy old and new
    """

    use_new_one = boolean(context['Config'].get('NewPolicyEvaluation', False))
    compare = boolean(context['Config'].get('NewPolicyEvaluation.compare',
                                            False))

    if use_new_one or compare:

        pols_new = new_getPolicy(param, only_active=only_active)

    if not use_new_one or compare:

        pols_old = legacy_getPolicy(param, only_active=only_active)

    if use_new_one:
        return_policies = pols_new
    else:
        return_policies = pols_old

    if return_policies:
        pass

    if not compare:
        return return_policies

    if not are_the_same(pols_old, pols_new):

        LOG.error('PolicyEvaluation is not the same for params %r', param)
        LOG.error('old: new %r <> %r', pols_old, pols_new)

    return return_policies
Esempio n. 4
0
def search_policy(param, only_active=True):
    """
    migration stub for the new policy engine
    """

    use_new_one = boolean(context['Config'].get('NewPolicyEvaluation', False))
    compare = boolean(context['Config'].get('NewPolicyEvaluation.compare',
                                            False))

    if use_new_one or compare:
        pols_new = new_search_policy(param, only_active=only_active)

    if not use_new_one or compare:
        pols_old = legacy_getPolicy(param, only_active=only_active)

    if use_new_one:
        return_policies = pols_new
    else:
        return_policies = pols_old

    if not compare:
        return return_policies

    if not are_the_same(pols_old, pols_new):

        LOG.error('PolicyEvaluation is not the same for params %r', param)
        LOG.error('old: new %r <> %r', pols_old, pols_new)

    return return_policies
Esempio n. 5
0
def search_policy(param, only_active=True):
    """
    migration stub for the new policy engine
    """

    use_new_one = boolean(context['Config'].get(
                                    'NewPolicyEvaluation', False))
    compare = boolean(context['Config'].get(
                                    'NewPolicyEvaluation.compare', False))

    if use_new_one or compare:
        pols_new = new_search_policy(param,
                                     only_active=only_active)

    if not use_new_one or compare:
        pols_old = legacy_getPolicy(param,
                                    only_active=only_active)

    if use_new_one:
        return_policies = pols_new
    else:
        return_policies = pols_old

    if not compare:
        return return_policies

    if not are_the_same(pols_old, pols_new):

        LOG.error('PolicyEvaluation is not the same for params %r', param)
        LOG.error('old: new %r <> %r', pols_old, pols_new)

    return return_policies