diff --git a/tests/libraries/common/bodyRequests.py b/tests/libraries/common/bodyRequests.py index 1d4ec14f60759bfb221b686ba84df23b1386fa6c..71fc9b956ce9a95fc77a480a9187ad065bae2dcf 100644 --- a/tests/libraries/common/bodyRequests.py +++ b/tests/libraries/common/bodyRequests.py @@ -32,7 +32,7 @@ def check_variable(input, data_type): else: raise Exception("variable is not integer type") elif data_type == "URI": - check_uri(input,data_type) + check_uri(input, data_type) return True elif data_type == "URI_reference": check_uri(input, data_type) @@ -70,13 +70,29 @@ def check_variable(input, data_type): def check_attributes_dict(body, data_type): mandatory_attributes = capif_types[data_type]["mandatory_attributes"] optional_parameters = capif_types[data_type]["optional_attributes"] + regex_attributes = capif_types[data_type]["regex_attributes"] + all_attributes = mandatory_attributes | optional_parameters # Check if body has not allowed attributes for body_key in body.keys(): + print(body_key) if body_key not in all_attributes.keys(): - raise Exception('Attribute "' + body_key + - '" is not present as a mandatory or optional key (' + ','.join(all_attributes.keys()) + ')') + print(body_key + " NOT IN ALL ATTRIBUTES") + present = False + if regex_attributes is not None: + print("REGEX ATTRIBUTES PRESENT") + print(regex_attributes) + for regex_key, regex_data_type in regex_attributes.items(): + print(regex_key + ":" + regex_data_type) + if check_regex(body_key, regex_key): + print("MATCH with " + body_key) + present = True + all_attributes[body_key] = regex_data_type + break + if not present: + raise Exception('Attribute "' + body_key + + '" is not present as a mandatory or optional key (' + ','.join(all_attributes.keys()) + ')') if mandatory_attributes: for mandatory_key in mandatory_attributes.keys(): @@ -110,16 +126,18 @@ def sign_csr_body(username, public_key): return data -def check_uri(input,rule): +def check_uri(input, rule): if rfc3987.match(input, rule=rule) is not None: return input else: raise Exception(rule + " is not accomplish rfc3986 rule ("+input+")") + def check_regex(input, regex): matched = re.match(regex, input) is_match = bool(matched) if is_match: print("Regex match") + return True else: raise Exception("Input(" + input + ") not match regex (" + regex + ")") diff --git a/tests/libraries/common/types.json b/tests/libraries/common/types.json index 220dd0f5710796fd875ddda8d05dfb3e39a272cd..85a27adf41c1e9731e1c76df730d4247cb04623c 100644 --- a/tests/libraries/common/types.json +++ b/tests/libraries/common/types.json @@ -83,8 +83,14 @@ "apiSuppFeats": "SupportedFeatures", "pubApiPath": "PublishedApiPath", "ccfId": "string" + }, + "regex_attributes": { + "^vendorSpecific-(.*)": "VendorSpecificObject" } }, + "VendorSpecificObject": { + "Check": false + }, "AefProfile": { "mandatory_attributes": { "aefId": "string",