예제 #1
0
def check_rule_in_dict(rule, in_dict):
    if "rule" not in in_dict:
        raise MoonCliException("Unexpected request result. rule not in result")
    if rule != in_dict["rule"]:
        raise MoonCliException(
            "Unexpected request result. Bad rule in result, expected {}".
            format(rule))
예제 #2
0
def check_policy_id_in_dict(policy_id, in_dict):
    if "policy_id" not in in_dict:
        raise MoonCliException(
            "Unexpected request result. policy_id not in result")
    if policy_id != in_dict["policy_id"]:
        raise MoonCliException(
            "Unexpected request result. Bad policy id in result, expected {}".
            format(policy_id))
예제 #3
0
def check_result(result):
    if type(result) is not dict or "result" not in result:
        raise MoonCliException(
            "Unexpected request result. It should be a dictionnary with a 'result' entry"
        )
    if result["result"] is None:
        raise MoonCliException(
            "Unexpected request result. The 'result' entry shall not be null")
예제 #4
0
def check_meta_rule_id_in_dict(meta_rule_id, in_dict):
    if "meta_rule_id" not in in_dict:
        raise MoonCliException(
            "Unexpected request result. meta_rule_id not in result")
    if meta_rule_id != in_dict["meta_rule_id"]:
        raise MoonCliException(
            "Unexpected request result. Bad meta rule id in result, expected {}"
            .format(meta_rule_id))
예제 #5
0
def check_subject_description(description, in_dict):
    if description is not None:
        if "description" not in in_dict:
            raise MoonCliException(
                "Unexpected request result. The description of the subject shall not be empty"
            )
        if description not in in_dict["description"]:
            raise MoonCliException(
                "Unexpected request result. The description {} shall be in the subject"
                .format(description))
예제 #6
0
def _check_generic_in_result(field, result, check_not_null=False):
    if type(field) is not str or type(
            result) is not dict or field not in result:
        raise MoonCliException(
            "Unexpected request result. It should be a dictionnary with a '{}' entry"
            .format(field))
    if check_not_null is True and result[field] is None:
        raise MoonCliException(
            "Unexpected request result. The '{}' entry shall not be null".
            format(field))
예제 #7
0
def _check_generic_policy_in_dict(field, policy_id, in_dict):
    if type(field) is str:
        if policy_id is not None:
            if "policy_list" not in in_dict:
                raise MoonCliException(
                    "Unexpected request result. The policy list of the {} shall not be empty"
                    .format(field))
            if policy_id not in in_dict["policy_list"]:
                raise MoonCliException(
                    "Unexpected request result. The policy with id {} shall be in the {}"
                    .format(policy_id, field))
예제 #8
0
def check_rule_id_in_list(meta_rule_id, rule_id, rule, in_dict):
    for item in in_dict:
        if "meta_rule_id" not in item:
            raise MoonCliException(
                "Unexpected request result. meta_rule_id field not in result")
        if meta_rule_id == item["meta_rule_id"]:
            if rule_id == item["id"]:
                if rule != item["rule"]:
                    raise MoonCliException(
                        "Unexpected request result. Bad rule in result, expected {}"
                        .format(rule))
예제 #9
0
def check_meta_rules_list_in_model(meta_rule_list, model_id, result):
    if result["models"] is None:
        raise MoonCliException(
            "Unexpected request result. results shall not be empty")
    if model_id not in result['models']:
        raise MoonCliException("Unexpected request result. Unknown Model id")
    if "meta_rules" not in result['models'][model_id]:
        raise MoonCliException(
            "Unexpected request result. Meta rules related to model with id {} are empty"
            .format(model_id))
    if meta_rule_list != result['models'][model_id]["meta_rules"]:
        raise MoonCliException(
            "Unexpected request result. Meta rule of model with id {} are different from those expected"
            .format(model_id))
예제 #10
0
def _check_category_in_generic_data_data(field, category_id, result):
    _check_generic_data_data(field, result)
    for _data in result[field]:
        if category_id != _data["category_id"]:
            raise MoonCliException(
                "Unexpected request result. Category id {} not in {} data".
                format(category_id, field))
예제 #11
0
def _check_id_not_in_generic_data_data(field, data_id, result):
    if type(field) is str:
        _check_generic_data_data(field, result)
        for _data in result[field]:
            if data_id in list(_data['data'].keys()):
                raise MoonCliException(
                    "Unexpected request result. Data id {} shall not be in {}".
                    format(data_id, field))
예제 #12
0
def _check_generic_name(field, name, field_elt_id, result, do_check_name=True):
    if type(field) is str:
        if result[field] is None:
            raise MoonCliException(
                "Unexpected request result : {} shall not be empty".format(
                    field))
        if field_elt_id not in result[field]:
            raise MoonCliException(
                "Unexpected request result. Unknown {} id".format(field))
        if "name" not in result[field][field_elt_id]:
            raise MoonCliException(
                "Unexpected request result : {} with id {} has no name".format(
                    field, field_elt_id))
        if do_check_name and name != result[field][field_elt_id]["name"]:
            raise MoonCliException(
                "Unexpected request result : {} with id {} has a bad name. Expected {}"
                .format(field, field_elt_id, name))
예제 #13
0
def _check_generic_elt_id(field1, field1_id, field2, field2_id, result):
    if type(field1) is str and type(field2) is str:
        if result[field1] is None:
            raise MoonCliException(
                "Unexpected request result: {} shall not be empty".format(
                    field1))
        if field1_id not in result[field1]:
            raise MoonCliException(
                "Unexpected request result. Unknown {} with id".format(field1))
        if field2 not in result[field1][field1_id]:
            raise MoonCliException(
                "Unexpected request result. {} element with id {} has no {} field"
                .format(field1, field1_id, field2))
        if field2_id != result[field1][field1_id][field2]:
            raise MoonCliException(
                "Unexpected request result. {} element with id {} has a bad {} id. Expected {}"
                .format(field1, field1_id, field2, field2_id))
예제 #14
0
def check_rule_id_not_in_list(rule_id, in_dict):
    found_rule = False
    for item in in_dict:
        if rule_id == item["id"]:
            found_rule = True
    if found_rule is True:
        raise MoonCliException(
            "Unexpected request result. Rule with id {} shall not be in result"
            .format(rule_id))
예제 #15
0
def _check_not_generic_assignments(field, field_id_name, field_id,
                                   field_cat_id, field_data_id, result):
    if type(field) is str and type(field_id_name) is str:
        for key in result[field]:
            if field_id_name not in result[field][key]:
                raise MoonCliException(
                    "Unexpected request result. subject_id not in result[{}] data"
                    .format(field))
            if "category_id" not in result[field][key]:
                raise MoonCliException(
                    "Unexpected request result. category_id not in result[{}] data"
                    .format(field))
            if "assignments" not in result[field][key]:
                raise MoonCliException(
                    "Unexpected request result. assignments not in result[{}] data"
                    .format(field))
            if result[field][key]['subject_id'] == field_id and \
                    result[field][key]["category_id"] == field_cat_id:
                if field_data_id in result[field][key]["assignments"]:
                    raise MoonCliException(
                        "Unexpected request result. {} data with id {} shall not be in result[{}][]['assignements'] data"
                        .format(field, field_data_id, field))
예제 #16
0
def check_ocat_id_in_dict(ocat_id, in_dict):
    if ocat_id not in in_dict:
        raise MoonCliException(
            "Unexpected request result. Object category not in result")
예제 #17
0
def check_model_in_result(result, check_not_null=False):
    _check_generic_in_result("models", result)
    if check_not_null is True and result["models"] is None:
        raise MoonCliException(
            "Unexpected request result. The 'models' entry shall not be null")
예제 #18
0
def check_optionnal_result(result):
    if type(result) is not dict:
        raise MoonCliException(
            "Unexpected request result. It should be a dictionnary")
    if "result" in result:
        check_result(result)
예제 #19
0
def check_acat_id_in_dict(acat_id, in_dict):
    if acat_id not in in_dict:
        raise MoonCliException(
            "Unexpected request result. Action category not in result")
예제 #20
0
def check_policy_id_in_pipeline(policy_id, pipeline):
    if policy_id not in pipeline:
        raise MoonCliException(
            "Unexpected request result. The policy id {} shall be in the pipeline"
            .format(policy_id))
예제 #21
0
def check_name_in_slaves(name, slaves):
    if name is None:
        raise MoonCliException("The slave name must be provided !")
    names = map(lambda x: x['name'], slaves)
    if name not in names:
        raise MoonCliException("The slave '{}' was not found !".format(name))
예제 #22
0
def _check_generic_data_data(field, result):
    if type(field) is str:
        if field not in result:
            raise MoonCliException(
                "Unexpected request result. The {} field shall be in result".
                format(field))
예제 #23
0
def check_pdp_id(pdp_id, result):
    check_pdp_in_result(result)
    if pdp_id not in result['pdps']:
        raise MoonCliException("Unexpected request result. Unknown pdp id")
예제 #24
0
def test_authz_request():
    from python_moonclient.core import config
    conf_data = config.get_config_data("consul", 8500)
    if not isinstance(conf_data, dict):
        raise MoonCliException(
            "Unexpected error : the conf data is not a dictionnary")