Esempio n. 1
0
def test_get_policy_from_meta_rules_with_no_policy_ids(db):
    meta_rule_id = 'meta_rule_id'
    value = {
        "name": "test_pdp",
        "security_pipeline": [],
        "keystone_project_id": "keystone_project_id1",
        "description": "...",
    }
    pdp_helper.add_pdp(value=value)
    matched_policy_id = policy_helper.get_policy_from_meta_rules(meta_rule_id)
    assert not matched_policy_id
Esempio n. 2
0
def test_get_policy_from_meta_rules(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",
        model_name="model1")
    security_pipeline = [policy_id]
    pdp_obj = mock_data.create_pdp(security_pipeline)
    pdp_helper.add_pdp(value=pdp_obj)
    matched_policy_id = policy_helper.get_policy_from_meta_rules(meta_rule_id)
    assert matched_policy_id
    assert policy_id == matched_policy_id
Esempio n. 3
0
def test_delete_policies_with_pdp(db):
    policies = policy_helper.add_policies()
    policy_id1 = list(policies.keys())[0]
    pdp_id = "pdp_id1"
    value = {
        "name": "test_pdp",
        "security_pipeline": [policy_id1],
        "keystone_project_id": "keystone_project_id1",
        "description": "...",
    }
    pdp_helper.add_pdp(pdp_id=pdp_id, value=value)
    with pytest.raises(DeletePolicyWithPdp) as exception_info:
        policy_helper.delete_policies(policy_id1)
    assert str(exception_info.value) == '400: Policy With PDP Error'
    assert 'Cannot delete policy with pdp' == exception_info.value.description
Esempio n. 4
0
def test_update_pdp(db):
    pdp_id = "pdp_id1"
    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",
        model_name="model1")
    value = {
        "name": "test_pdp",
        "security_pipeline": [policy_id],
        "keystone_project_id": "keystone_project_id1",
        "description": "...",
    }
    pdp_helper.add_pdp(pdp_id, value)
    pdp = pdp_helper.update_pdp(pdp_id, value)
    assert pdp
Esempio n. 5
0
def test_add_pdp_twice_with_same_name(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",
        model_name="model1")
    value = {
        "name": "test_pdp",
        "security_pipeline": [policy_id],
        "keystone_project_id": "keystone_project_id1",
        "description": "...",
    }
    pdp_helper.add_pdp(value=value)
    with pytest.raises(Exception) as exception_info:
        pdp_helper.add_pdp(value=value)
    assert str(exception_info.value) == '409: Pdp Error'