コード例 #1
0
def test_add_action_multiple_times(db):
    subject_category_id, object_category_id, action_category_id, meta_rule_id, policy_id1 = mock_data.create_new_policy(
        subject_category_name="subject_category1",
        object_category_name="object_category1",
        action_category_name="action_category1",
        meta_rule_name="meta_rule_1",
        model_name="model1")
    value = {
        "name": "test_action",
        "description": "test",
    }
    action = data_helper.add_action(policy_id=policy_id1, value=value)
    logger.info("action : {}".format(action))
    action_id = list(action.keys())[0]
    perimeter_id = action[action_id].get('id')
    assert action
    value = {
        "name": "test_action",
        "description": "test",
        "policy_list": ['policy_id_3', 'policy_id_4']
    }
    subject_category_id, object_category_id, action_category_id, meta_rule_id, policy_id2 = mock_data.create_new_policy(
        subject_category_name="subject_category2",
        object_category_name="object_category2",
        action_category_name="action_category2",
        meta_rule_name="meta_rule_2",
        model_name="model2")
    action = data_helper.add_action(policy_id=policy_id2, perimeter_id=perimeter_id, value=value)
    logger.info("action : {}".format(action))
    assert action
    action_id = list(action.keys())[0]
    assert len(action[action_id].get('policy_list')) == 2
コード例 #2
0
def test_add_action_with_name_space(db):
    policy_id = policies.mock_data.get_policy_id()
    value = {
        "name": "   ",
        "description": "test",
    }
    with pytest.raises(PerimeterContentError) as exception_info:
        data_helper.add_action(policy_id=policy_id, value=value)
    assert str(exception_info.value) == '400: Perimeter content is invalid.'
コード例 #3
0
def test_add_action_twice(db):
    subject_category_id, object_category_id, action_category_id, meta_rule_id, policy_id = mock_data.create_new_policy(
        subject_category_name="subject_category1",
        object_category_name="object_category1",
        action_category_name="action_category1",
        meta_rule_name="meta_rule_1")
    value = {
        "name": "test_action",
        "description": "test",
    }
    data_helper.add_action(policy_id=policy_id, value=value)
    with pytest.raises(PolicyExisting) as exception_info:
        data_helper.add_action(policy_id=policy_id, value=value)
    assert str(exception_info.value) == '409: Policy Already Exists'
コード例 #4
0
def test_delete_policies_with_action_perimeter(db):
    policies = policy_helper.add_policies()
    policy_id1 = list(policies.keys())[0]

    value = {
        "name": "test_act",
        "security_pipeline": [policy_id1],
        "keystone_project_id": "keystone_project_id1",
        "description": "...",
    }
    data_helper.add_action(policy_id=policy_id1, value=value)
    with pytest.raises(DeletePolicyWithPerimeter) as exception_info:
        policy_helper.delete_policies(policy_id1)
    assert '400: Policy With Perimeter Error' == str(exception_info.value)
コード例 #5
0
def test_get_actions(db):
    subject_category_id, object_category_id, action_category_id, meta_rule_id, policy_id = mock_data.create_new_policy(
        subject_category_name="subject_category1",
        object_category_name="object_category1",
        action_category_name="action_category1",
        meta_rule_name="meta_rule_1")
    value = {
        "name": "test_action",
        "description": "test",
    }
    data_helper.add_action(policy_id=policy_id, value=value)
    actions = data_helper.get_actions(policy_id, )
    assert actions
    assert len(actions) == 1
    action_id = list(actions.keys())[0]
    assert actions[action_id].get('policy_list')[0] == policy_id
コード例 #6
0
def test_delete_action(db):
    subject_category_id, object_category_id, action_category_id, meta_rule_id, policy_id = mock_data.create_new_policy(
        subject_category_name="subject_category1",
        object_category_name="object_category1",
        action_category_name="action_category1",
        meta_rule_name="meta_rule_1")
    value = {
        "name": "test_action",
        "description": "test",
    }
    action = data_helper.add_action(policy_id=policy_id, value=value)
    action_id = list(action.keys())[0]
    data_helper.delete_action(policy_id, action_id)
    actions = data_helper.get_actions(policy_id, )
    assert not actions