Exemple #1
0
def add_model(model_id=None, value=None):
    from python_moondb.core import ModelManager
    if not value:
        subject_category_id, object_category_id, action_category_id, meta_rule_id = builder.create_new_meta_rule()
        name = "MLS"+uuid4().hex if model_id is None else "MLS " + model_id
        value = {
            "name": name,
            "description": "test",
            "meta_rules": [meta_rule_id]
        }
    return ModelManager.add_model(user_id=None, model_id=model_id, value=value)
Exemple #2
0
def update_model(client, name, model_id):
    subject_category_id, object_category_id, action_category_id, meta_rule_id = builder.create_new_meta_rule(
    )

    data = {
        "name": name,
        "description": "description of {}".format(name),
        "meta_rules": [meta_rule_id]
    }
    req = client.patch("/models/{}".format(model_id),
                       data=json.dumps(data),
                       headers={'Content-Type': 'application/json'})
    models = utilities.get_json(req.data)
    return req, models
Exemple #3
0
def test_delete_data_categories_connected_to_meta_rule():
    subject_category_id, object_category_id, action_category_id, meta_rule_id = data_builder.create_new_meta_rule()
    client = utilities.register_client()
    req = client.delete("/subject_categories/{}".format(subject_category_id))
    assert req.status_code == 400
    assert json.loads(req.data)["message"] == '400: Subject Category With Meta Rule Error'

    req = client.delete("/object_categories/{}".format(object_category_id))
    assert req.status_code == 400
    assert json.loads(req.data)["message"] == '400: Object Category With Meta Rule Error'

    req = client.delete("/action_categories/{}".format(action_category_id))
    assert req.status_code == 400
    assert json.loads(req.data)["message"] == '400: Action Category With Meta Rule Error'
Exemple #4
0
def add_models(client, name, data=None):
    subject_category_id, object_category_id, action_category_id, meta_rule_id = builder.create_new_meta_rule(
    )

    if not data:
        data = {
            "name": name,
            "description": "description of {}".format(name),
            "meta_rules": [meta_rule_id]
        }
    req = client.post("/models",
                      data=json.dumps(data),
                      headers={'Content-Type': 'application/json'})
    models = utilities.get_json(req.data)
    return req, models
Exemple #5
0
def test_update_meta_rules_with_categories_and_one_empty():
    client = utilities.register_client()
    subject_category_id, object_category_id, action_category_id, meta_rule_id = data_builder.create_new_meta_rule(
    )
    data = {
        "name": "testuser",
        "subject_categories": [subject_category_id, ""],
        "object_categories": [object_category_id, ""],
        "action_categories": [action_category_id, ""]
    }
    req_update = update_meta_rules_with_categories(client,
                                                   "testuser",
                                                   data=data,
                                                   meta_rule_id=meta_rule_id)
    assert req_update[0].status_code == 400
    assert req_update[1]['message'] == '400: Subject Category Unknown'
Exemple #6
0
def add_rules_without_policy_id(client):
    subject_category_id, object_category_id, action_category_id, meta_rule_id = builder.create_new_meta_rule(
    )
    data = {
        "meta_rule_id": meta_rule_id,
        "rule": [subject_category_id, object_category_id, action_category_id],
        "instructions": ({
            "decision": "grant"
        }, ),
        "enabled": True
    }
    req = client.post("/policies/{}/rules".format(None),
                      data=json.dumps(data),
                      headers={'Content-Type': 'application/json'})
    rules = utilities.get_json(req.data)
    return req, rules
Exemple #7
0
def update_meta_rules_with_categories(client,
                                      name,
                                      data=None,
                                      meta_rule_id=None):
    if not meta_rule_id:
        subject_category_id, object_category_id, action_category_id, meta_rule_id = data_builder.create_new_meta_rule(
        )
        data = {
            "name": name,
            "subject_categories": [subject_category_id],
            "object_categories": [object_category_id],
            "action_categories": [action_category_id]
        }

    req = client.patch("/meta_rules/{}".format(meta_rule_id),
                       data=json.dumps(data),
                       headers={'Content-Type': 'application/json'})
    meta_rules = utilities.get_json(req.data)
    return req, meta_rules
Exemple #8
0
def test_add_model_with_existed_meta_rules_list():
    clean_models()
    client = utilities.register_client()
    name = uuid4().hex

    subject_category_id, object_category_id, action_category_id, meta_rule_id = builder.create_new_meta_rule(
    )
    data = {
        "name": name,
        "description": "description of {}".format(name),
        "meta_rules": [meta_rule_id]
    }
    name = uuid4().hex
    req, models = add_models(client=client, name=name, data=data)
    assert req.status_code == 200

    data = {
        "name": name,
        "description": "description of {}".format(name),
        "meta_rules": [meta_rule_id]
    }
    req, models = add_models(client=client, name=name, data=data)
    assert req.status_code == 409
    assert json.loads(req.data)["message"] == '409: Model Error'