diff options
| author | zhaokun <[email protected]> | 2024-11-27 19:18:15 +0800 |
|---|---|---|
| committer | zhaokun <[email protected]> | 2024-11-27 19:18:15 +0800 |
| commit | 3a1440a42ee4438fb5d431959f22063f641d4049 (patch) | |
| tree | e38a70eea213a66ad8d452c1cd4f1966b27b7a4f | |
| parent | f719e3f8edbe5beae3b9c3c58fd23525f54353fa (diff) | |
| parent | 2b8651145c925236cb26e2c740e0e9f8fdf0a160 (diff) | |
merge
562 files changed, 38849 insertions, 20009 deletions
diff --git a/support/api_utils/create_profiles.py b/support/api_utils/create_profiles.py index c39916072..e8a1c805b 100644 --- a/support/api_utils/create_profiles.py +++ b/support/api_utils/create_profiles.py @@ -33,12 +33,14 @@ class CreateProfiles: for sff_profile in policy_configuration["action_parameter"]["sff_profiles"]: sff_profile_list = [] sf_profile_list = [] + policy_configuration["action_parameter"]["sf_configuration"] = [] for sf_profile in sff_profile["service_func_profiles"]: if "connectivity" in sf_profile.keys(): if "int_vlan_tag" in sf_profile["connectivity"].keys() and "random" == sf_profile["connectivity"]["int_vlan_tag"]: sf_profile["connectivity"]["int_vlan_tag"] = self.generate_random_vlan_id() if "ext_vlan_tag" in sf_profile["connectivity"].keys() and "random" == sf_profile["connectivity"]["ext_vlan_tag"]: sf_profile["connectivity"]["ext_vlan_tag"] = self.generate_random_vlan_id() + policy_configuration["action_parameter"]["sf_configuration"].append(sf_profile) profile_type = "service-functions" sf_uuids, sf_temp = self.create_text_profiles(sf_profile, profile_type) sf_profile_list.append(sf_uuids) @@ -56,7 +58,6 @@ class CreateProfiles: sff_uuids_temp_dict["name"] = sff_profile["name"] profile_uuids_list.append(sff_uuids_temp_dict) sff_profile_list.append(sff_uuids) - policy_configuration["action_parameter"]["sff_profiles"] = sff_profile_list elif "html_profile" in policy_configuration["action_parameter"].keys(): profile_type = "response-pages" html_uuids, html_temp = self.create_file_upload_profiles(policy_configuration["action_parameter"]["html_profile"], profile_type, policy_configuration["action_parameter"]["html_profile"]["file_path"]) @@ -88,7 +89,7 @@ class CreateProfiles: profile_uuids_temp_dict["uuid"] = mirroring_uuids profile_uuids_temp_dict["name"] = policy_configuration["action_parameter"]["traffic_mirroring"]["mirroring_profile"]["name"] profile_uuids_list.append(profile_uuids_temp_dict) - policy_configuration["action_parameter"]["traffic_mirroring"]["mirroring_profile"] = mirroring_uuids + # policy_configuration["action_parameter"]["traffic_mirroring"]["mirroring_profile"] = mirroring_uuids elif "replacement_file" in policy_configuration["action_parameter"].keys(): profile_type = "proxy-replacement-files" replacement_uuids, replacement_temp = self.create_file_upload_profiles( diff --git a/support/api_utils/create_rules.py b/support/api_utils/create_rules.py index c6808fc65..ed765a886 100644 --- a/support/api_utils/create_rules.py +++ b/support/api_utils/create_rules.py @@ -18,7 +18,7 @@ class CreateRules: try: self.policy_configuration = policy_configuration object_uuids_list = list(self.object_uuids_tuple) - self.profile_uuids_list = list(self.profile_uuids_tuple) + profile_uuids_list = list(self.profile_uuids_tuple) if len(self.library_uuids_tuple) > 0: library_uuids_list = list(self.library_uuids_tuple) for i in range(len(library_uuids_list)): @@ -89,7 +89,7 @@ class CreateRules: if len(protocol_field_condition_temp_list) > 0: rule_template_json["rule"]["and_conditions"].extend(self.generate_rule_condition_list(protocol_field_condition_temp_list, object_uuids_list)) if ("action_parameter" in policy_configuration.keys() and len(policy_configuration["action_parameter"]) > 0) or (rule_template_json["rule"]["type"] == "proxy_intercept"): - rule_template_json["rule"]["action_parameter"] = self.generate_rule_action_parameter(policy_configuration) + rule_template_json["rule"]["action_parameter"] = self.generate_rule_action_parameter(policy_configuration, profile_uuids_list) if "effective_range" in policy_configuration.keys() and len(policy_configuration["effective_range"]) > 0: rule_template_json["rule"]["effective_range"] = policy_configuration["effective_range"] # if rule_template_json["rule"]["type"] == "proxy_intercept": # 添加action_parameter默认值 @@ -165,7 +165,7 @@ class CreateRules: condition_list.append(temp_dict) return condition_list - def generate_rule_action_parameter(self, policy_configuration): + def generate_rule_action_parameter(self, policy_configuration, profile_uuids_list): action_parameter_dict = {} if policy_configuration["type"] == "security" and policy_configuration["action"] == "deny": action_parameter_dict["sub_action"] = policy_configuration["action_parameter"]["sub_action"] @@ -235,7 +235,7 @@ class CreateRules: if policy_configuration["action_parameter"]["traffic_mirroring"]["enable"] == 1 and "vlanID" in policy_configuration["action_parameter"]["traffic_mirroring"]: action_parameter_dict["traffic_mirroring"]["vlanID"] = policy_configuration["action_parameter"]["traffic_mirroring"]["vlanID"] # action_parameter_dict["traffic_mirroring"]["mirroring_profile"] = policy_configuration["action_parameter"]["traffic_mirroring"]["mirroring_profile"] - action_parameter_dict["traffic_mirroring"]["mirroring_profile"] = self.profile_uuids_list[0]["uuid"] + action_parameter_dict["traffic_mirroring"]["mirroring_profile"] = profile_uuids_list[0]["uuid"] elif policy_configuration["type"] == "statistics": action_parameter_dict = { "template_profile" : policy_configuration["action_parameter"]["template_profile"] @@ -369,9 +369,11 @@ class CreateRules: elif policy_configuration["type"] == "service_chaining": action_parameter_dict = { "targeted_traffic" : policy_configuration["action_parameter"]["targeted_traffic"], - "sff_profiles" : policy_configuration["action_parameter"]["sff_profiles"] + "sff_profiles" : [] } - + for profile in profile_uuids_list: + if profile["type"] == "service-function-forwarders": + action_parameter_dict["sff_profiles"].append(profile["uuid"]) return action_parameter_dict def create_preset_intercept_rules(self, policy_type, source_condition, enabled): diff --git a/support/api_utils/query_rule_log.py b/support/api_utils/query_rule_log.py index c010deb82..87c6d31a8 100644 --- a/support/api_utils/query_rule_log.py +++ b/support/api_utils/query_rule_log.py @@ -16,7 +16,7 @@ class QueryRuleLog: def query_rule_log(self, traffic_generation, verification_result, rule_uuids_tuple, start_time): try: self.rule_type = self.policy_configuration["type"] - if self.rule_type == "security" or self.rule_type == "proxy_intercept" or self.rule_type == "proxy_manipulation" or self.rule_type == "monitor" or self.rule_type == "statistics" or self.rule_type == "service_chaining": + if self.rule_type == "security" or self.rule_type == "proxy_intercept" or self.rule_type == "proxy_manipulation" or self.rule_type == "monitor" or self.rule_type == "statistics" or self.rule_type == "service_chaining" or self.rule_type == "dos_protection": print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Start to verify the effect of the policy rule by api.", flush=True) log_result = None for _ in range(int(90)): @@ -42,7 +42,10 @@ class QueryRuleLog: elif log_result == False: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], 'The log result checked by calling api is failed.', flush=True) elif log_result == None: - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], 'The log result checked by calling api is none.', flush=True) + if not verification_result["expected_log"]: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], 'The log result checked by calling api is passed.', flush=True) + else: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], 'The log result checked by calling api is none.', flush=True) elif log_result == "no_set": print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], 'The log result checked by calling api is no_set.', flush=True) return log_result @@ -101,8 +104,7 @@ class QueryRuleLog: else: if self.traffic_generation["tool"] == "trex": if self.rule_type == "dos_protection": - attack_type = "Custom Network Attack" - log_condition_dict['filter'] = f"destination_ip='{traffic_generation['servers_start_ip']}'AND attack_type='{attack_type}'" + log_condition_dict['filter'] = f"destination_ip='{traffic_generation['servers_start_ip']}'" else: log_filter = f"vsys_id in ({int(self.parameter['vsys'])}) AND client_ip={traffic_generation['clients_start_ip']} AND has({log_query_rule_type}, '{rule_uuid}')" log_condition_dict['filter'] = log_filter @@ -118,6 +120,54 @@ class QueryRuleLog: response = requests.post(url, headers=headers, json=dsl_dict, verify=False) job_dict = json.loads(response.text) job_id = job_dict['data']['job']['job_id'] + """ + {"execution_mode":"oneshot","query_jobs":[{"id":"e9df1ca8-e270-427d-9baf-3c0e8fb13813","is_saved_query":0,"with_result":false}],"vsys":5} + { + "code": 200, + "msg": "Success", + "data": [{ + "reason": null, + "start_time": "2024-11-27T02:27:21Z", + "is_done": true, + "job_id": "e9df1ca8-e270-427d-9baf-3c0e8fb13813", + "is_canceled": false, + "done_progress": 1, + "end_time": "2024-11-27T02:27:21Z", + "links": { + "status": "/v1/query/job/e9df1ca8-e270-427d-9baf-3c0e8fb13813", + "count": "/v1/query/job/e9df1ca8-e270-427d-9baf-3c0e8fb13813/count", + "list": "/v1/query/job/e9df1ca8-e270-427d-9baf-3c0e8fb13813/list", + "timeline": "/v1/query/job/e9df1ca8-e270-427d-9baf-3c0e8fb13813/timeline" + }, + "is_failed": false + }], + "success": true + } + query_job_dict = { + "query_jobs": [{"id": job_id, "is_saved_query":0, "with_result":False}], + "vsys": int(self.parameter["vsys"]), "limit": 20, "offset": 0 + } + response = requests.post(url, headers=headers, json=query_job_dict, verify=False) + if response.status_code == 200: + query_job_dict = json.loads(response.text) + is_done = query_job_dict['data'][0]['is_done'] + is_failed = query_job_dict['data'][0]['is_failed'] + reason = query_job_dict['data'][0]["reason"] + if is_done and not is_failed: + query_list_dict = { + "query_jobs":[{"id": job_id,"query_option":"list"}], + "vsys":int(self.parameter["vsys"]),"limit":20,"offset":0 + } + response = requests.post(url, headers=headers, json=query_list_dict, verify=False) + assert response.status_code == 200 + log_list = json.loads(response.text) + log_list = log_list['data']['list'] + return log_list, "" + elif is_done and is_failed: + return "", reason + else: + return [], "" + """ query_list_dict = { "query_jobs":[{"id": job_id,"query_option":"list"}], "vsys":int(self.parameter["vsys"]),"limit":20,"offset":0 @@ -319,8 +369,8 @@ class QueryRuleLog: else: temp_log_result_list.append(False) elif query_field_key in {"sc_rsp_raw_uuid_list", "sc_rsp_decrypted_uuid_list"}: - query_value = self.policy_configuration["action_parameter"]["sff_profiles"] - if query_value == log_dict[query_field_key]: + query_value = self.policy_configuration["action_parameter"]["sff_profiles"][0]["service_func_profiles"] + if query_value == log[query_field_key]: temp_log_result_list.append(True) else: temp_log_result_list.append(False) @@ -333,7 +383,7 @@ class QueryRuleLog: query_value = self.traffic_result["total_bytes_sent"] elif query_field_key == "received_bytes": query_value = self.traffic_result["total_bytes_received"] - if query_value == log_dict[query_field_key]: + if query_value == log[query_field_key]: temp_log_result_list.append(True) else: temp_log_result_list.append(False) diff --git a/support/api_utils/query_rule_metric.py b/support/api_utils/query_rule_metric.py index 057619c58..c4dfdd9c4 100644 --- a/support/api_utils/query_rule_metric.py +++ b/support/api_utils/query_rule_metric.py @@ -92,21 +92,21 @@ class QueryRuleMetric: active_dst_ip_list = conf.get("sc_active_dst_ip", "ip_list") effective_device_tag_list = ["group-xxg-tsgx", "center-xxg-tsgx"] sff_configuration = self.policy_configuration["action_parameter"]["sff_profiles"] - sf_configuration = self.policy_configuration["action_parameter"]["sff_profiles"][0]["service_func_profiles"] + sf_configuration = self.policy_configuration["action_parameter"]["sf_configuration"] print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Start to verify the effect of the policy rule by api.", flush=True) n = 0 while n <= 4: utc_tz = pytz.timezone('UTC') current_utc_time = datetime.now(utc_tz) end_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') - metic_dict, code = self.get_sc_metric(self.token, rule_uuids_tuple, start_time, end_time) + metric_dict, code = self.get_sc_metric(self.token, rule_uuids_tuple, start_time, end_time) if code == 333 or code == 444: metric_result = code else: if self.policy_configuration["action_parameter"]["targeted_traffic"] == "raw": - metric_result = self.verify_sc_metric(sff_configuration, sf_configuration, active_dst_ip_list, metic_dict, self.traffic_result) + metric_result = self.verify_sc_metric(sff_configuration, sf_configuration, active_dst_ip_list, metric_dict, self.traffic_result) elif self.policy_configuration["action_parameter"]["targeted_traffic"] == "decrypted": - metric_result = self.verify_sc_metric(sff_configuration, sf_configuration, active_dst_ip_list, metic_dict, "") + metric_result = self.verify_sc_metric(sff_configuration, sf_configuration, active_dst_ip_list, metric_dict, "") if metric_result == True: break time.sleep(15) @@ -794,7 +794,7 @@ class QueryRuleMetric: post_data_ori_dict["start_time"] = start_time post_data_ori_dict["end_time"] = end_time rule_uuids_list = list(rule_uuids_tuple) - post_data_ori_dict["rule_uuid"] = rule_uuids_list["uuid"] + post_data_ori_dict["rule_uuid"] = rule_uuids_list[0]["uuid"] post_data_ori_dict["vsys"] = self.parameter["vsys"] response = requests.post(url, json=post_data_ori_dict, headers=headers, verify=False) r_dict = response.json() @@ -802,15 +802,15 @@ class QueryRuleMetric: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Service chaining metric query failed.", flush=True) return "", 444 else: # 返回正常结果 - if r_dict["data"]["result"] == []: # 为空 + if r_dict["data"]["list"] == []: # 为空 print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Service chaining metric is empty.", flush=True) return "", 333 else: # metric不为空时,验证返回结果 - result_list = r_dict["data"]["result"] + result_list = r_dict["data"]["list"] sc_value = copy.deepcopy(result_list[0]) return sc_value, "" - def verify_sc_metric(self, sff_configuration, sf_configuration, active_dst_ip_list, metic_dict, traffic_result): + def verify_sc_metric(self, sff_configuration, sf_configuration, active_dst_ip_list, metric_dict, traffic_result): metric_result = False # 只考虑了一个Application的场景?? application = self.get_application_from_configration() @@ -835,13 +835,13 @@ class QueryRuleMetric: byte_value -= lost_byte traffic_result["total_bytes"] = byte_value + 50 * pkt_value traffic_result["total_packets"] = pkt_value - if sff_configuration["type"] == 1: - if metic_dict["sent_bytes"] == metic_dict["received_bytes"] == traffic_result["total_bytes"] and metic_dict["sent_packets"] == metic_dict["received_packets"] == pkt_value: + if sff_configuration[0]["type"] == 1: + if metric_dict["sent_bytes"] == metric_dict["received_bytes"] == traffic_result["total_bytes"] and metric_dict["sent_packets"] == metric_dict["received_packets"] == pkt_value: metric_result = True else: metric_result = False - elif sff_configuration["type"] == 2: - if metic_dict["sent_bytes"] == traffic_result["total_bytes"] and metic_dict["sent_packets"] == pkt_value and metic_dict["received_bytes"] == metic_dict["received_packets"] == 0: + elif sff_configuration[0]["type"] == 2: + if metric_dict["sent_bytes"] == traffic_result["total_bytes"] and metric_dict["sent_packets"] == pkt_value and metric_dict["received_bytes"] == metric_dict["received_packets"] == 0: metric_result = True else: metric_result = False @@ -865,8 +865,8 @@ class QueryRuleMetric: byte_value -= lost_byte traffic_result["total_bytes"] = byte_value + 4 * pkt_value traffic_result["total_packets"] = pkt_value - if sff_configuration["type"] == 2: - if metic_dict["sent_bytes"] == traffic_result["total_bytes"] and metic_dict["sent_packets"] == pkt_value and metic_dict["received_bytes"] == metic_dict["received_packets"] == 0: + if sff_configuration[0]["type"] == 2: + if metric_dict["sent_bytes"] == traffic_result["total_bytes"] and metric_dict["sent_packets"] == pkt_value and metric_dict["received_bytes"] == metric_dict["received_packets"] == 0: metric_result = True else: metric_result = False @@ -874,21 +874,21 @@ class QueryRuleMetric: metric_result = False elif self.policy_configuration["action_parameter"]["targeted_traffic"] == "decrypted": if sf_configuration[0]["connectivity"]["method"] == "vxlan_g" and sf_configuration[0]["connectivity"]["sf_dest_ip"] in active_dst_ip_list: - if sff_configuration["type"] == 1: - if metic_dict["sent_bytes"] == metic_dict["received_bytes"] and metic_dict["sent_packets"] == metic_dict["received_packets"]: + if sff_configuration[0]["type"] == 1: + if metric_dict["sent_bytes"] == metric_dict["received_bytes"] and metric_dict["sent_packets"] == metric_dict["received_packets"]: metric_result = True else: metric_result = False - elif sff_configuration["type"] == 2: - if metic_dict["sent_bytes"] != 0 and metic_dict["sent_packets"] != 0 and metic_dict["received_bytes"] == metic_dict["received_packets"] == 0: + elif sff_configuration[0]["type"] == 2: + if metric_dict["sent_bytes"] != 0 and metric_dict["sent_packets"] != 0 and metric_dict["received_bytes"] == metric_dict["received_packets"] == 0: metric_result = True else: metric_result = False else: metric_result = False elif sf_configuration[0]["connectivity"]["method"] == "layer2_switch": - if sff_configuration["type"] == 2 and len(metic_dict) != 0: - if metic_dict["sent_bytes"] != 0 and metic_dict["sent_packets"] != 0 and metic_dict["received_bytes"] == metic_dict["received_packets"] == 0: + if sff_configuration[0]["type"] == 2 and len(metric_dict) != 0: + if metric_dict["sent_bytes"] != 0 and metric_dict["sent_packets"] != 0 and metric_dict["received_bytes"] == metric_dict["received_packets"] == 0: metric_result = True else: metric_result = False @@ -897,9 +897,9 @@ class QueryRuleMetric: return metric_result def get_application_from_configration(self): - action_parameter = self.policy_configuration["action_parameter"] - for i in range(len(action_parameter)): - or_conditions = action_parameter[i]["or_conditions"] + and_conditions = self.policy_configuration["and_conditions"] + for i in range(len(and_conditions)): + or_conditions = and_conditions[i]["or_conditions"] for j in range(len(or_conditions)): if or_conditions[j]["attribute_name"] == "ATTR_APP_ID": application = or_conditions[j]["items"] @@ -907,10 +907,10 @@ class QueryRuleMetric: def get_negate_option_from_configration(self): negate_option_list = [] - action_parameter = self.policy_configuration["action_parameter"] - for i in range(len(action_parameter)): - negate_option_list.append(action_parameter[i]["negate_option"]) + and_conditions = self.policy_configuration["and_conditions"] + for i in range(len(and_conditions)): + negate_option_list.append(and_conditions[i]["negate_option"]) for value in negate_option_list: - if value == 1: + if value == True: return 1 return 0
\ No newline at end of file diff --git a/support/configuration_management/profile/test_end_cert_caentitytest.chain.pem b/support/configuration_management/profile/test_end_cert_caentitytest.chain.pem index 730ea47b2..2644a9a68 100644 --- a/support/configuration_management/profile/test_end_cert_caentitytest.chain.pem +++ b/support/configuration_management/profile/test_end_cert_caentitytest.chain.pem @@ -2,92 +2,93 @@ Certificate: Data: Version: 3 (0x2) Serial Number: - 72:cc:5f:e2:55:f6:e6:f6:c4:bc:7c:6b + 85:50:65:36:f7:cf:89:31:ca:64:e4:3b Signature Algorithm: sha256WithRSAEncryption Issuer: C=CN, ST=BJ, L=BJ, O=NT, OU=NT, CN=CA TRUST1 Validity - Not Before: Jul 7 11:39:21 2023 GMT - Not After : Nov 18 11:39:21 2024 GMT + Not Before: Nov 27 08:28:51 2024 GMT + Not After : Aug 24 08:28:51 2027 GMT Subject: C=CN, CN=www.bbc.com Subject Public Key Info: Public Key Algorithm: rsaEncryption Public-Key: (2048 bit) Modulus: - 00:df:ad:1c:bc:ae:44:16:8a:be:bf:eb:69:06:07: - 5e:16:35:3b:e7:41:5d:48:8b:0f:6c:38:ee:7e:97: - 0f:43:de:63:27:84:5e:65:bc:28:7c:57:f1:4c:2a: - 92:98:e2:73:33:be:39:58:f2:7a:cf:55:45:23:16: - f3:c1:e9:fd:3e:f8:a7:a2:02:c6:f1:20:ff:13:dc: - f2:0a:31:29:fc:d8:e7:90:2d:ef:8e:44:6d:65:92: - fa:3a:a2:73:99:26:ee:e8:35:6f:07:dd:2f:49:61: - 11:11:d2:fb:7a:4c:8a:b9:19:ab:e3:99:79:07:ac: - fc:dd:62:7b:7f:de:fe:ff:8b:a7:68:8c:61:f8:49: - 57:67:8d:a8:23:92:a4:3f:e5:69:0a:6a:38:e3:56: - e2:dc:d2:ac:d5:62:6e:16:9e:46:c5:f3:19:c1:85: - 95:f2:5c:99:d0:2a:a6:80:64:2c:d2:7e:06:b6:80: - fc:48:f0:fc:06:57:c0:89:17:6a:4b:06:c9:26:54: - f5:36:59:44:01:89:89:5c:8d:fb:50:d7:10:ca:bc: - 3a:76:2a:f5:fa:4d:dc:0f:bc:bc:49:e0:92:8d:1d: - 7a:33:42:52:83:dc:ce:78:59:86:31:88:c0:4f:25: - f2:4b:7b:6f:18:d8:59:fd:f4:53:1b:fd:b4:95:ad: - 99:d3 + 00:c0:c6:d8:1f:c8:78:95:20:34:d8:6e:c6:c6:b9: + 4c:44:98:ed:50:96:54:d5:67:56:c5:cc:fe:3b:52: + 6b:33:d3:00:cc:05:65:43:8f:4a:fa:3f:92:c0:53: + ac:09:ca:44:77:f3:0d:60:0f:6f:bd:df:24:85:c2: + 90:67:21:50:cc:cf:63:00:20:2c:ec:26:ff:46:9c: + eb:0e:fc:c4:b3:3a:cb:32:c6:15:c6:d9:e5:07:4f: + d3:03:c7:e6:30:94:56:81:68:0e:b3:cd:01:f9:0e: + 2c:80:fe:8a:8d:95:b8:19:e9:b4:11:4e:8e:21:0e: + 4a:04:06:c3:b9:c3:b5:42:5c:03:0d:6c:e6:fe:2d: + 9a:12:d7:d7:ae:ab:7d:bc:9d:22:86:8b:75:b2:14: + f8:9e:95:5a:46:7b:8c:fd:2b:ef:72:12:e0:d0:16: + 88:a0:9c:94:52:45:c1:d3:a0:8e:1f:c5:66:67:97: + e0:a5:27:00:9f:2f:6f:51:4c:fc:77:ce:08:3d:d3: + c7:6f:2a:6f:ed:35:e5:83:96:55:6c:ac:2a:df:01: + 53:b5:ba:ec:7c:ec:40:73:42:41:6e:32:80:07:c5: + 62:4e:fe:7e:0f:ca:c0:20:29:70:00:36:b7:c9:a4: + 07:e3:0b:e1:ef:b3:7f:b7:c8:d2:cd:2b:80:f4:be: + 23:47 Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Subject Alternative Name: - DNS:*.bbc.com, DNS:*.bbc.cn + DNS:*.www.bbc.com.com, DNS:*.www.bbc.com.cn Signature Algorithm: sha256WithRSAEncryption - ba:a0:a4:49:aa:7f:04:9d:eb:df:c1:c6:27:27:2e:52:c1:3a: - 1d:31:73:be:37:d7:17:6e:7f:1d:ca:f6:f8:24:bb:40:e2:08: - aa:13:84:5e:94:c0:e0:7c:80:f2:75:91:2c:cf:b2:31:9c:38: - bf:45:63:81:7c:20:60:d0:23:cf:0c:ca:14:41:b4:95:a0:e2: - 8f:b7:b8:e9:cb:2e:69:19:f0:53:c6:8f:96:1c:94:bd:41:c2: - d6:81:6e:1f:84:45:00:fa:7c:5a:39:3e:fa:14:6d:75:bf:d9: - ad:c9:85:58:10:24:3a:38:2a:85:90:a2:0b:58:06:7d:c8:2f: - 4a:b8:31:92:8e:c8:3d:21:9d:f6:74:2f:29:57:b2:7b:ee:8e: - 90:47:34:69:54:34:af:93:e3:cf:3a:31:56:40:20:03:61:ec: - 38:49:5b:e9:5a:e4:23:41:6e:f1:33:64:7f:d6:44:96:7b:e8: - 14:79:bf:5e:34:03:d0:63:a0:06:bb:c7:b0:24:8b:87:c6:df: - 5e:24:54:2e:35:05:88:f4:36:12:3d:76:8b:92:8f:95:e9:9c: - 14:39:0e:8f:e4:50:70:f6:f7:cf:24:01:7b:30:7d:33:43:b0: - 20:e1:1c:93:64:15:66:f2:4f:b0:2b:ae:48:18:67:fc:86:fa: - b8:f2:5b:ec + 2c:80:a5:99:49:8b:a8:3e:2d:77:a9:b7:aa:9a:66:89:a4:22: + b0:96:ed:d3:4f:5f:56:d5:8d:fe:f4:01:e6:f5:df:04:e3:95: + fb:1a:5b:b9:82:21:cf:96:4f:8c:ca:d6:f9:a5:8b:a5:75:09: + ac:bf:ca:65:87:37:58:83:3e:7b:18:07:7a:d2:ff:ea:55:c2: + 69:c7:fb:c9:ac:1a:5f:41:71:2d:35:96:02:43:2c:c9:63:85: + c0:d5:e3:dc:aa:df:01:31:1d:0f:79:c8:b2:9e:6e:41:99:32: + a7:9b:54:d9:11:01:d9:eb:34:ce:cf:6a:6f:f6:f9:11:3c:d0: + 4a:59:cd:07:77:02:19:47:fb:a7:8f:d1:c6:57:e5:4f:43:90: + ec:80:fd:d1:d6:f9:6d:8c:12:37:20:76:d8:43:ef:83:b8:b3: + 9c:5f:41:0b:fe:c3:33:49:e6:1d:3d:d0:81:19:46:05:b4:dd: + 1c:30:50:57:f3:9e:01:89:a8:3c:d4:19:03:3c:1b:b6:69:75: + c8:0e:6e:f1:b0:a5:f9:60:31:bc:81:db:25:c0:6f:a0:e1:69: + b0:fa:d8:9b:f1:8b:a7:a8:2c:88:87:71:96:10:15:2a:4f:5b: + 01:1d:61:28:e0:c2:62:bd:73:d4:84:97:60:af:3e:ac:12:73: + a7:42:b0:7d -----BEGIN CERTIFICATE----- -MIIDIDCCAgigAwIBAgIMcsxf4lX25vbEvHxrMA0GCSqGSIb3DQEBCwUAMFUxCzAJ -BgNVBAYTAkNOMQswCQYDVQQIDAJCSjELMAkGA1UEBwwCQkoxCzAJBgNVBAoMAk5U -MQswCQYDVQQLDAJOVDESMBAGA1UEAwwJQ0EgVFJVU1QxMB4XDTIzMDcwNzExMzky -MVoXDTI0MTExODExMzkyMVowIzELMAkGA1UEBhMCQ04xFDASBgNVBAMMC3d3dy5i -YmMuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA360cvK5EFoq+ -v+tpBgdeFjU750FdSIsPbDjufpcPQ95jJ4ReZbwofFfxTCqSmOJzM745WPJ6z1VF -Ixbzwen9PvinogLG8SD/E9zyCjEp/NjnkC3vjkRtZZL6OqJzmSbu6DVvB90vSWER -EdL7ekyKuRmr45l5B6z83WJ7f97+/4unaIxh+ElXZ42oI5KkP+VpCmo441bi3NKs -1WJuFp5GxfMZwYWV8lyZ0CqmgGQs0n4GtoD8SPD8BlfAiRdqSwbJJlT1NllEAYmJ -XI37UNcQyrw6dir1+k3cD7y8SeCSjR16M0JSg9zOeFmGMYjATyXyS3tvGNhZ/fRT -G/20la2Z0wIDAQABoyIwIDAeBgNVHREEFzAVggkqLmJiYy5jb22CCCouYmJjLmNu -MA0GCSqGSIb3DQEBCwUAA4IBAQC6oKRJqn8EnevfwcYnJy5SwTodMXO+N9cXbn8d -yvb4JLtA4giqE4RelMDgfIDydZEsz7IxnDi/RWOBfCBg0CPPDMoUQbSVoOKPt7jp -yy5pGfBTxo+WHJS9QcLWgW4fhEUA+nxaOT76FG11v9mtyYVYECQ6OCqFkKILWAZ9 -yC9KuDGSjsg9IZ32dC8pV7J77o6QRzRpVDSvk+PPOjFWQCADYew4SVvpWuQjQW7x -M2R/1kSWe+gUeb9eNAPQY6AGu8ewJIuHxt9eJFQuNQWI9DYSPXaLko+V6ZwUOQ6P -5FBw9vfPJAF7MH0zQ7Ag4RyTZBVm8k+wK65IGGf8hvq48lvs +MIIDMTCCAhmgAwIBAgINAIVQZTb3z4kxymTkOzANBgkqhkiG9w0BAQsFADBVMQsw +CQYDVQQGEwJDTjELMAkGA1UECAwCQkoxCzAJBgNVBAcMAkJKMQswCQYDVQQKDAJO +VDELMAkGA1UECwwCTlQxEjAQBgNVBAMMCUNBIFRSVVNUMTAeFw0yNDExMjcwODI4 +NTFaFw0yNzA4MjQwODI4NTFaMCMxCzAJBgNVBAYTAkNOMRQwEgYDVQQDDAt3d3cu +YmJjLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMDG2B/IeJUg +NNhuxsa5TESY7VCWVNVnVsXM/jtSazPTAMwFZUOPSvo/ksBTrAnKRHfzDWAPb73f +JIXCkGchUMzPYwAgLOwm/0ac6w78xLM6yzLGFcbZ5QdP0wPH5jCUVoFoDrPNAfkO +LID+io2VuBnptBFOjiEOSgQGw7nDtUJcAw1s5v4tmhLX166rfbydIoaLdbIU+J6V +WkZ7jP0r73IS4NAWiKCclFJFwdOgjh/FZmeX4KUnAJ8vb1FM/HfOCD3Tx28qb+01 +5YOWVWysKt8BU7W67HzsQHNCQW4ygAfFYk7+fg/KwCApcAA2t8mkB+ML4e+zf7fI +0s0rgPS+I0cCAwEAAaMyMDAwLgYDVR0RBCcwJYIRKi53d3cuYmJjLmNvbS5jb22C +ECoud3d3LmJiYy5jb20uY24wDQYJKoZIhvcNAQELBQADggEBACyApZlJi6g+LXep +t6qaZomkIrCW7dNPX1bVjf70Aeb13wTjlfsaW7mCIc+WT4zK1vmli6V1Cay/ymWH +N1iDPnsYB3rS/+pVwmnH+8msGl9BcS01lgJDLMljhcDV49yq3wExHQ95yLKebkGZ +MqebVNkRAdnrNM7Pam/2+RE80EpZzQd3AhlH+6eP0cZX5U9DkOyA/dHW+W2MEjcg +dthD74O4s5xfQQv+wzNJ5h090IEZRgW03RwwUFfzngGJqDzUGQM8G7ZpdcgObvGw +pflgMbyB2yXAb6DhabD62Jvxi6eoLIiHcZYQFSpPWwEdYSjgwmK9c9SEl2CvPqwS +c6dCsH0= -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- -MIIDfTCCAmWgAwIBAgIJAJnxzpEq+vIfMA0GCSqGSIb3DQEBCwUAMFUxCzAJBgNV +MIIDfTCCAmWgAwIBAgIJAN1++hbyZpEIMA0GCSqGSIb3DQEBCwUAMFUxCzAJBgNV BAYTAkNOMQswCQYDVQQIDAJCSjELMAkGA1UEBwwCQkoxCzAJBgNVBAoMAk5UMQsw -CQYDVQQLDAJOVDESMBAGA1UEAwwJQ0EgVFJVU1QxMB4XDTIzMDcwNzExMjk1NVoX -DTI0MTExODExMjk1NVowVTELMAkGA1UEBhMCQ04xCzAJBgNVBAgMAkJKMQswCQYD +CQYDVQQLDAJOVDESMBAGA1UEAwwJQ0EgVFJVU1QxMB4XDTI0MTEyNzA4MjgzN1oX +DTI3MDgyNDA4MjgzN1owVTELMAkGA1UEBhMCQ04xCzAJBgNVBAgMAkJKMQswCQYD VQQHDAJCSjELMAkGA1UECgwCTlQxCzAJBgNVBAsMAk5UMRIwEAYDVQQDDAlDQSBU -UlVTVDEwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDO+4rZA65F6tlt -HEnbFG56FyYs/V9XAM6sSSnnFj8H8MNvxiRQXlaevdK8/7xwtN3udX+x4VdSnmi4 -wPGLhrPWvrrv2ZrDbRlBwNmIosmE+dQdqf9OyN44Pw4/TQoh14CWqjqxQXYLevrn -45GH1POUR64U6qO5Uq5B83zimTRWTbXertvrYb4plOKNxvav3IKdNEufRJSqxelf -AUMQnsrH1iO4iMpZHBYSNbfwl6gkgnXxsr8YTZrrQwk9Bcd/0bFQ+v3OiWD5oiYc -XfcIBTeoy6IIICNc7krfnXRpsXO2oimNgMS6nHPKvXYF5jTbKr0A40ElDEIjtt5T -Yb4oWNHfAgMBAAGjUDBOMB0GA1UdDgQWBBSD6d3VXldZQOiVGZC0Y3nuANvG2zAf -BgNVHSMEGDAWgBSD6d3VXldZQOiVGZC0Y3nuANvG2zAMBgNVHRMEBTADAQH/MA0G -CSqGSIb3DQEBCwUAA4IBAQCM3XHUZ1RwpLtF5DpEKDmC4osIiguk7ENF7Bg+LCQt -GzIeBkHPZ0sKbqZr0og6a0r0Qn1Xzr5nku9cuFH1Gc9Wwg82i8zXLgD8//VSNy5k -SLKb7MiAAnUHv6ZkluX8X9bdg32vb+sTwhuFhjbI5LVWvY3dq/Ez+WERFUxgNL3s -dgiJABkslbkjobgB39m/Lr223P6HwG5n6YukKSmwfiion5QYsTbTpd9AYbAD5UTs -A5H5pRdk/mxJ7yYsgosu60wAUI/xVAVvsaUDGa+koiVKPhUg4A7Qd/2oDByb/H9J -atqHkSjkwvhAekC0mOjKh6ED/Nr2tnN5l0GIbwRvj9Xz +UlVTVDEwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDPNPcqcKdr49y/ +/B8lUz7kUblQcD6BwDdFkRMAzsyyC8o7J4HKJ1jwvs5OdCHqCuVqrSgHTm5EeEFi +1SKxrfoHxVZ2gLVg/UA1fVCQ8M/ic54Vw8eOjnwAG0uVlyhCxOZeboc0WBY17zOF +6Gk34SVqlMrss/ZGqkvn2pttLeOKkncPG7CP+sGG2XmvFJo4JwEVisJelYAZepQl +aVEHFmugLQgWlnw2gkB84VAcJVwkj72WwoE+i3Z9CJEo+2P+INcO5/juIrauRjeg +XXuVvH7iprw2WKA/wzX/8RUSPHk7jBNasFLCNwdFH6mRFUcjNQsSRrtJw7r/YhGn +B+wYNIoJAgMBAAGjUDBOMB0GA1UdDgQWBBQ/rnoFWCjR0bpRDdJlYik+11mXCjAf +BgNVHSMEGDAWgBQ/rnoFWCjR0bpRDdJlYik+11mXCjAMBgNVHRMEBTADAQH/MA0G +CSqGSIb3DQEBCwUAA4IBAQDNfultFcA+xQu9RICjWIyjK9OKmbqSCBwoSeAez55X +B0dekd3MU+fkPEm1dfgduMbXPHU1k0bKNi/rCPcV1sAUSkFSbfa7oeOwcTTeCcpr +1KTQurVY8fVEWBAENJzzZSXngSzqP/pWb9jRPPRAcDrw04zhLaqBcZlCDyg8sZTb +6RIsAsx7inacLH64uDv22/2HdGAWcAqpOVh4ekvHmFPrZQy5aF9UFwEcAkFJAzBI +kQ7tjwY6vZx2o8lh0W4eiMeH0mhvQ4Gxst0rWsMEz5QnP4jgNbdcl3nBDbOIYUJk +ZpA+2mhA66vLJhShoRJeRTwZPEkVq025Wi43f4QZ+4H9 -----END CERTIFICATE----- diff --git a/support/configuration_management/profile/test_end_keycaentitytest.key b/support/configuration_management/profile/test_end_keycaentitytest.key index 7683dbe3a..3d497317d 100644 --- a/support/configuration_management/profile/test_end_keycaentitytest.key +++ b/support/configuration_management/profile/test_end_keycaentitytest.key @@ -1,27 +1,27 @@ -----BEGIN RSA PRIVATE KEY----- -MIIEogIBAAKCAQEA360cvK5EFoq+v+tpBgdeFjU750FdSIsPbDjufpcPQ95jJ4Re -ZbwofFfxTCqSmOJzM745WPJ6z1VFIxbzwen9PvinogLG8SD/E9zyCjEp/NjnkC3v -jkRtZZL6OqJzmSbu6DVvB90vSWEREdL7ekyKuRmr45l5B6z83WJ7f97+/4unaIxh -+ElXZ42oI5KkP+VpCmo441bi3NKs1WJuFp5GxfMZwYWV8lyZ0CqmgGQs0n4GtoD8 -SPD8BlfAiRdqSwbJJlT1NllEAYmJXI37UNcQyrw6dir1+k3cD7y8SeCSjR16M0JS -g9zOeFmGMYjATyXyS3tvGNhZ/fRTG/20la2Z0wIDAQABAoIBAFqQNe1zRaA25wq/ -3xMQ0ph9T1bP0Vw46bKwzme08/pPxafPYYUhjObjmJB1QEvkjC5sG74W14CxDsAp -X+Kowd/IP99J7pDdAkphkCJuS4jTrdZjsvXQYNbajrRE6DcfW2XrlJwDg0zbn1Sv -LyEScqyFZ2JM1oM0GGHuqQBaIrcGa6c8LgtaxmgVKMGA5EbSL86eZ8s0UNwiQs8Y -U1GLrb0ecxJxjI7qHkj3e6bzfJ84P+EA97ZwnSEx2xV9ceMYfzo/nUKFo6BZo9Qy -S1vBbHCs6Pv+1jg5rObI4F+w3Q1xkXDtOo8iGsFjIYvAXVw8k8DeI6hgI1OhF8I1 -Xz/azMkCgYEA8N5JE/u8SVZCfvaHj+e2Orlll+hTvI9GWu7lLYEVd9vdfri31n7v -hHrcV98JqSBVPiKO78H29kSYWfmLRGMWKHInFfdVmuEOi7Xq3b4yIUk+y308A4qo -Wx5JppQQ7Ej/9+lO+AF1ru1x4qsvY+XlmfC9l3zYy9G2+TIKe1kzV1UCgYEA7bpW -tA2ocmeCUWP69dxXwLihsrAMkyIww7DWZHcE2tTH1YxfRdQM4AxrlO2st2aDcP6G -P74cF6ooyeijZS3825rnZpxdpIjic0k/MwJnkyD2Rf16qXhvvu82pA46uyZ2TBfk -Z5kFJw2pC6maNhg2OZCHNlWj2Qprr2EdzcdYXIcCgYBvWNK/gifQXyfuOVkBlUQQ -cZQdXTEYgcMsVjNrjbi259TEt++EILnorEMf++MjY+cECkW5YBkiTyN+tHVE7+lW -WS7oYKYaKt/mhfpE95+E868rsoEDwh2BwcaaUuhf0n9Bw4DV9RbJ/soe1rPZonU5 -bKi4VuaBkjjbid5+lwW84QKBgEB1aBEGKwhqPJGpFGEZz8l3xpBW3/H9MU++YUN4 -ah6T12N13ldmud7+PyVwlIZeC4HV4bzi5WcdQlYM+FD0+TzqcZgHCfUVEKHF2JcS -Lddc9qnfoyTUfSg+YIh3O0GHmkfjqpDUkusV7yI0aJYGVp2hLKh07CprgutY3+Xu -CW19AoGAZzRkQeqrdwLEHOMY4p0GNrwDnubfwBzjEHWt3tBCgRQjPiwpdtXIdXgk -LDc2ZRUMw38JDELQ/BnzhXZa7JKJJJY6mNFTP/mUiGW959C8axE8csiPbIbQopY2 -wseDiyumC8r2wkhUfFST115LoShLeK/ZoiIA2ThWxCdbm/1PHVg= +MIIEogIBAAKCAQEAwMbYH8h4lSA02G7GxrlMRJjtUJZU1WdWxcz+O1JrM9MAzAVl +Q49K+j+SwFOsCcpEd/MNYA9vvd8khcKQZyFQzM9jACAs7Cb/RpzrDvzEszrLMsYV +xtnlB0/TA8fmMJRWgWgOs80B+Q4sgP6KjZW4Gem0EU6OIQ5KBAbDucO1QlwDDWzm +/i2aEtfXrqt9vJ0ihot1shT4npVaRnuM/SvvchLg0BaIoJyUUkXB06COH8VmZ5fg +pScAny9vUUz8d84IPdPHbypv7TXlg5ZVbKwq3wFTtbrsfOxAc0JBbjKAB8ViTv5+ +D8rAIClwADa3yaQH4wvh77N/t8jSzSuA9L4jRwIDAQABAoIBACvH/SWavegAXIAb +CIHxa2TY5my696FPyuE5YTPP0BEBBtlPEGR7kqeq8IVFe3jtuwcS6CK83r/cgcrv +GSSS6GrbXryUkh8/7BH5aVkKBxI9dBCf9CopKl6yvlXJfHnj9pGFNHGZSa1qjqjt +JkJpklowPXkAwj63pA+uCZ2S2QOsxQxMWyPyk4YYxA5p3vu8kksHqv18m+vWOKlO +Cm8sqHPIp8xZ/koftX98sG4XpKQHl/dKfLStkN/kHiqP4/eDdaqNcUlVOFDSI3YW +iOMQ5NZbkIC9gIwxfK7jo1qCVxgb2t7uwv2kjdxjNqu7tO1DSJc+QuvYKvR6QUs5 +BvnTi6ECgYEA33zfici1Yuz0/hCPsoNmFQiXQweUH/eQPUHpJXDy0egi7nDHJgZV +bCf4QYv0+D/DxUhUb5V1MmZZlV/+a9yYENp+HR13YsA+f2wpDMbOh+ZHMh2cTruz +lEVFIaR4aSJm2rFGebvV18Q2ZTX4xYzMKis6NA513jfnsNchGA4sAuUCgYEA3NI7 +Fyqjf7gUEqp1jViGr8uGbeHBbI/d47d4imhlA/AnMwaZBe3D5Tzo2ZoFY7n05tWb +TDMWOZd8PXLALUVtvegQCzVy5xhI2gNw4QJwLfU2IEgkGRTqFuFFzksbr+5UxyNd +24X7LUd/aF/WmWbgKKpJE5jPtg8qlEd1Wpw5jrsCgYAHv2yAelTPeSeFJ03UAnon +gIS97iVUdmCpvv82LRQ98q5DVeWRi+aqOTiCDTgQ4yUGUdubgrLtbF7ursVDOAKN +kwWMPNlGsyN3h2hk6P9/9pvBQQWKNTekjEI5SFpkSq0GJ98pmTlwoXzBRX26W4c4 +bwc1hsrPSWDe4JZlHxingQKBgAmyecHUr4VmUgtXzP2+C3wg1fBxX4si7j2XywVY +/Eal/zKwcXvfKyEgAaG8r8vnWKfibYV1IN66lkwkg+f5Co6yaDH10OvxFxHr4MMg +1khOYmgcgulPD9CdZ/FdPwQE1VhBZ1fClHsyjpfIzaXC7MkcYUUpCsYV+Gq2kKLA +BY8NAoGAGQPiWvCOnIFLS9EHCem2QKPDjLZ4hB53FUMdimD6Q2s61F0CCWh74zfO +LIB6v35xo/QCuaeFRYvrNcxNfiPvR4C4tZHEK+vOR/7KBzQyB/aJYZyaviBMAzav +lQUPt5LZjoqRQadySYiyl/b+0oDmA/hYm5kVhT2BZUWHIgUy9U4= -----END RSA PRIVATE KEY----- diff --git a/support/configuration_management/profile/test_mid_cert_camiddletest.chain.pem b/support/configuration_management/profile/test_mid_cert_camiddletest.chain.pem index c13ccf897..2b839c123 100644 --- a/support/configuration_management/profile/test_mid_cert_camiddletest.chain.pem +++ b/support/configuration_management/profile/test_mid_cert_camiddletest.chain.pem @@ -2,99 +2,99 @@ Certificate: Data: Version: 3 (0x2) Serial Number: - 71:d9:ff:18:5a:34:cc:9f:ee:60:0b:bd + ca:ca:55:61:6f:84:02:ea:95:19:b7:1e Signature Algorithm: sha256WithRSAEncryption Issuer: C=CN, ST=BJ, L=BJ, O=NT, OU=NT, CN=CA TRUST1 Validity - Not Before: Jul 7 11:30:01 2023 GMT - Not After : Nov 18 11:30:01 2024 GMT + Not Before: Nov 27 08:28:46 2024 GMT + Not After : Aug 24 08:28:46 2027 GMT Subject: C=CN, ST=BJ, O=NT, OU=NT, CN=camiddle1 Subject Public Key Info: Public Key Algorithm: rsaEncryption Public-Key: (2048 bit) Modulus: - 00:cb:5a:af:94:d2:6a:98:91:f1:13:6e:95:9e:ed: - 50:96:85:0e:8e:0b:fd:7f:f2:20:b6:88:27:34:91: - 9f:b3:c4:27:43:e4:e9:44:80:fd:e2:51:67:d7:f8: - 9b:17:16:2c:36:7e:f4:75:29:63:40:ec:9b:29:a7: - 4e:a2:d9:e1:ca:1a:51:62:43:5e:af:55:8a:64:b5: - 76:ba:a4:78:d6:87:fa:d6:a1:cb:08:67:69:0c:ec: - 5a:d9:7b:78:6f:28:d3:1b:14:63:ee:bd:47:92:e1: - 57:18:33:bc:99:ba:2f:82:cd:45:15:b2:bd:13:fa: - 51:38:bb:2b:68:11:0a:a4:b9:18:88:70:56:5f:89: - e1:10:21:79:e9:b1:f4:15:8b:74:10:6f:d8:36:9e: - 60:4c:1d:61:63:52:7b:b7:3d:63:8b:65:b3:2f:ed: - e7:d4:b5:39:15:32:52:d3:73:ea:c4:85:53:45:ea: - 5a:77:67:4c:3c:bb:0a:b8:0b:63:69:39:38:d3:61: - 78:16:10:48:e6:40:bf:1a:a9:9b:7a:1c:6f:33:45: - c6:f7:71:43:8c:62:27:7b:78:c3:0e:a7:99:c3:46: - b0:9a:1a:57:aa:8d:aa:75:b3:3d:66:dc:6e:c2:a1: - 04:0c:1e:de:0b:47:22:a9:9e:79:f9:77:b0:4f:02: - a4:f9 + 00:b5:9a:0c:81:d7:ad:8e:d3:24:64:6e:99:73:46: + e0:60:ba:13:02:c0:de:21:91:32:fd:0e:cc:42:20: + 96:61:09:7d:2e:b4:d8:8f:c9:bc:7e:6b:60:ba:12: + 45:54:3e:50:9d:19:31:aa:6b:0e:4e:ca:a6:78:7f: + 17:c9:13:ce:d1:b0:95:1b:d8:47:b1:36:74:99:db: + ff:1c:bb:fb:5e:1e:c2:b9:49:82:41:d8:1c:b1:1c: + 9a:e3:a2:c1:d5:f6:74:8e:9a:87:74:81:d5:1f:52: + b5:b0:d1:33:c3:15:e0:58:54:47:02:43:6e:b9:15: + fb:c4:b2:80:93:a2:9b:c2:cc:7f:ec:2a:df:71:8f: + 06:88:c6:bd:ff:1e:7a:18:90:40:f1:d6:b0:7e:29: + 49:5f:73:7b:a4:68:7f:64:52:65:80:5e:73:4e:e3: + dd:a9:b8:1c:f3:6a:8e:a5:b2:48:5c:e3:0c:b3:3c: + a1:d6:92:26:77:a1:58:77:33:54:8c:c7:6e:d4:bc: + 70:84:04:5d:8f:9d:91:a9:8e:c3:28:13:d0:5a:c8: + f8:a7:78:df:36:b2:8d:eb:de:56:93:6c:57:0f:95: + 44:6c:80:4e:5d:db:a1:4a:53:10:a7:09:47:84:10: + 2c:34:16:1a:ab:15:79:36:35:e3:63:e7:a9:0f:58: + 86:cf Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Subject Key Identifier: - 5D:44:58:02:45:8B:00:5A:DC:03:69:84:EE:70:D6:41:3F:17:C6:10 + 64:C3:F6:22:48:A3:43:81:62:D9:7B:77:7F:55:69:64:32:FF:65:D8 X509v3 Authority Key Identifier: - keyid:83:E9:DD:D5:5E:57:59:40:E8:95:19:90:B4:63:79:EE:00:DB:C6:DB + keyid:3F:AE:7A:05:58:28:D1:D1:BA:51:0D:D2:65:62:29:3E:D7:59:97:0A X509v3 Basic Constraints: CA:TRUE Signature Algorithm: sha256WithRSAEncryption - 42:d8:bc:41:ae:5f:f3:3b:49:c0:72:b3:79:d0:68:36:22:82: - 14:d6:71:56:2c:d2:85:39:2c:34:7c:0a:2c:d8:88:2b:0e:04: - 62:b2:5a:0b:ab:03:df:58:a8:ac:a9:16:a4:81:e8:e4:61:45: - 08:2b:82:3c:7c:66:ca:00:04:57:a5:47:7e:15:f4:1b:a8:7d: - c0:02:5d:2e:ad:ee:52:03:38:d4:5b:e2:d8:4e:04:7b:c2:cd: - 7e:0e:ca:9f:b9:e9:43:1c:25:01:60:2b:91:37:de:de:31:cc: - 88:47:88:1f:46:95:49:de:67:35:16:f1:21:77:c3:03:40:56: - 6a:ac:dc:49:4c:ba:b4:5a:13:cb:68:97:59:8d:5c:7e:ca:a2: - fc:5d:21:95:9f:3c:3f:9b:ea:25:b9:8f:30:6d:68:a6:58:6c: - b6:8f:4c:d3:4c:c4:a7:da:04:49:ca:d0:96:81:c3:fb:41:6d: - ba:4d:9a:b2:fd:b2:0b:30:7c:1e:da:90:54:d3:ac:e0:ad:e3: - 48:9f:ef:51:9e:e4:e8:2e:1d:a5:17:cd:8b:40:94:30:44:e0: - 1d:f3:7f:ec:a6:6e:c8:2f:1c:a3:84:17:f9:66:f7:74:f9:8d: - b5:59:86:da:36:31:71:14:0f:af:d9:c3:96:92:e2:54:c6:b4: - 8b:76:f6:08 + 79:d2:c1:88:d3:2f:cd:e1:16:6e:78:98:e1:1a:86:74:ba:92: + 05:dc:6b:05:2a:6f:01:f4:a3:75:68:a8:7e:ea:55:0e:25:6e: + e7:ce:f0:33:a2:16:ea:10:d7:7e:b8:36:6d:f0:4e:3a:7b:c0: + fa:e3:d7:5e:b1:33:01:4a:74:e0:f5:44:8e:07:45:ac:aa:44: + b1:95:7b:a6:14:16:01:9a:8d:c5:44:45:60:94:09:13:c2:ec: + 28:fd:c7:0a:f7:be:1e:b7:5d:6a:97:1d:86:0b:5e:d4:c4:31: + b3:3d:e6:06:e8:a5:c1:4a:57:f1:7d:fb:75:92:e8:89:1f:6b: + 61:8e:8e:86:e2:02:41:85:47:da:53:3f:7c:94:2d:6f:eb:57: + 2d:c6:c8:4d:bb:83:f6:52:aa:a6:0c:e9:63:37:bd:83:6b:c4: + 28:e3:23:a3:f5:ba:7f:cf:69:ed:bc:69:c5:6c:7e:e9:9d:00: + 56:88:90:16:83:e1:5f:1f:8c:92:55:06:43:86:ff:e9:91:0d: + f1:ba:4f:ca:12:e1:a0:d4:11:e6:7f:c5:7d:9a:bc:1c:35:61: + 82:a5:a3:b2:8f:56:3f:e4:9e:7f:5a:9a:52:eb:5e:d3:c7:23: + 9f:40:66:4a:cd:6b:a6:93:a1:c9:85:1e:f0:34:22:f6:d0:98: + 41:d8:62:ff -----BEGIN CERTIFICATE----- -MIIDczCCAlugAwIBAgIMcdn/GFo0zJ/uYAu9MA0GCSqGSIb3DQEBCwUAMFUxCzAJ -BgNVBAYTAkNOMQswCQYDVQQIDAJCSjELMAkGA1UEBwwCQkoxCzAJBgNVBAoMAk5U -MQswCQYDVQQLDAJOVDESMBAGA1UEAwwJQ0EgVFJVU1QxMB4XDTIzMDcwNzExMzAw -MVoXDTI0MTExODExMzAwMVowSDELMAkGA1UEBhMCQ04xCzAJBgNVBAgMAkJKMQsw -CQYDVQQKDAJOVDELMAkGA1UECwwCTlQxEjAQBgNVBAMMCWNhbWlkZGxlMTCCASIw -DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMtar5TSapiR8RNulZ7tUJaFDo4L -/X/yILaIJzSRn7PEJ0Pk6USA/eJRZ9f4mxcWLDZ+9HUpY0DsmymnTqLZ4coaUWJD -Xq9VimS1drqkeNaH+tahywhnaQzsWtl7eG8o0xsUY+69R5LhVxgzvJm6L4LNRRWy -vRP6UTi7K2gRCqS5GIhwVl+J4RAheemx9BWLdBBv2DaeYEwdYWNSe7c9Y4tlsy/t -59S1ORUyUtNz6sSFU0XqWndnTDy7CrgLY2k5ONNheBYQSOZAvxqpm3ocbzNFxvdx -Q4xiJ3t4ww6nmcNGsJoaV6qNqnWzPWbcbsKhBAwe3gtHIqmeefl3sE8CpPkCAwEA -AaNQME4wHQYDVR0OBBYEFF1EWAJFiwBa3ANphO5w1kE/F8YQMB8GA1UdIwQYMBaA -FIPp3dVeV1lA6JUZkLRjee4A28bbMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEL -BQADggEBAELYvEGuX/M7ScBys3nQaDYighTWcVYs0oU5LDR8CizYiCsOBGKyWgur -A99YqKypFqSB6ORhRQgrgjx8ZsoABFelR34V9BuofcACXS6t7lIDONRb4thOBHvC -zX4Oyp+56UMcJQFgK5E33t4xzIhHiB9GlUneZzUW8SF3wwNAVmqs3ElMurRaE8to -l1mNXH7KovxdIZWfPD+b6iW5jzBtaKZYbLaPTNNMxKfaBEnK0JaBw/tBbbpNmrL9 -sgswfB7akFTTrOCt40if71Ge5OguHaUXzYtAlDBE4B3zf+ymbsgvHKOEF/lm93T5 -jbVZhto2MXEUD6/Zw5aS4lTGtIt29gg= +MIIDdDCCAlygAwIBAgINAMrKVWFvhALqlRm3HjANBgkqhkiG9w0BAQsFADBVMQsw +CQYDVQQGEwJDTjELMAkGA1UECAwCQkoxCzAJBgNVBAcMAkJKMQswCQYDVQQKDAJO +VDELMAkGA1UECwwCTlQxEjAQBgNVBAMMCUNBIFRSVVNUMTAeFw0yNDExMjcwODI4 +NDZaFw0yNzA4MjQwODI4NDZaMEgxCzAJBgNVBAYTAkNOMQswCQYDVQQIDAJCSjEL +MAkGA1UECgwCTlQxCzAJBgNVBAsMAk5UMRIwEAYDVQQDDAljYW1pZGRsZTEwggEi +MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC1mgyB162O0yRkbplzRuBguhMC +wN4hkTL9DsxCIJZhCX0utNiPybx+a2C6EkVUPlCdGTGqaw5OyqZ4fxfJE87RsJUb +2EexNnSZ2/8cu/teHsK5SYJB2ByxHJrjosHV9nSOmod0gdUfUrWw0TPDFeBYVEcC +Q265FfvEsoCTopvCzH/sKt9xjwaIxr3/HnoYkEDx1rB+KUlfc3ukaH9kUmWAXnNO +492puBzzao6lskhc4wyzPKHWkiZ3oVh3M1SMx27UvHCEBF2PnZGpjsMoE9BayPin +eN82so3r3laTbFcPlURsgE5d26FKUxCnCUeEECw0FhqrFXk2NeNj56kPWIbPAgMB +AAGjUDBOMB0GA1UdDgQWBBRkw/YiSKNDgWLZe3d/VWlkMv9l2DAfBgNVHSMEGDAW +gBQ/rnoFWCjR0bpRDdJlYik+11mXCjAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEB +CwUAA4IBAQB50sGI0y/N4RZueJjhGoZ0upIF3GsFKm8B9KN1aKh+6lUOJW7nzvAz +ohbqENd+uDZt8E46e8D649desTMBSnTg9USOB0WsqkSxlXumFBYBmo3FREVglAkT +wuwo/ccK974et11qlx2GC17UxDGzPeYG6KXBSlfxfft1kuiJH2thjo6G4gJBhUfa +Uz98lC1v61ctxshNu4P2UqqmDOljN72Da8Qo4yOj9bp/z2ntvGnFbH7pnQBWiJAW +g+FfH4ySVQZDhv/pkQ3xuk/KEuGg1BHmf8V9mrwcNWGCpaOyj1Y/5J5/WppS617T +xyOfQGZKzWumk6HJhR7wNCL20JhB2GL/ -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- -MIIDfTCCAmWgAwIBAgIJAJnxzpEq+vIfMA0GCSqGSIb3DQEBCwUAMFUxCzAJBgNV +MIIDfTCCAmWgAwIBAgIJAN1++hbyZpEIMA0GCSqGSIb3DQEBCwUAMFUxCzAJBgNV BAYTAkNOMQswCQYDVQQIDAJCSjELMAkGA1UEBwwCQkoxCzAJBgNVBAoMAk5UMQsw -CQYDVQQLDAJOVDESMBAGA1UEAwwJQ0EgVFJVU1QxMB4XDTIzMDcwNzExMjk1NVoX -DTI0MTExODExMjk1NVowVTELMAkGA1UEBhMCQ04xCzAJBgNVBAgMAkJKMQswCQYD +CQYDVQQLDAJOVDESMBAGA1UEAwwJQ0EgVFJVU1QxMB4XDTI0MTEyNzA4MjgzN1oX +DTI3MDgyNDA4MjgzN1owVTELMAkGA1UEBhMCQ04xCzAJBgNVBAgMAkJKMQswCQYD VQQHDAJCSjELMAkGA1UECgwCTlQxCzAJBgNVBAsMAk5UMRIwEAYDVQQDDAlDQSBU -UlVTVDEwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDO+4rZA65F6tlt -HEnbFG56FyYs/V9XAM6sSSnnFj8H8MNvxiRQXlaevdK8/7xwtN3udX+x4VdSnmi4 -wPGLhrPWvrrv2ZrDbRlBwNmIosmE+dQdqf9OyN44Pw4/TQoh14CWqjqxQXYLevrn -45GH1POUR64U6qO5Uq5B83zimTRWTbXertvrYb4plOKNxvav3IKdNEufRJSqxelf -AUMQnsrH1iO4iMpZHBYSNbfwl6gkgnXxsr8YTZrrQwk9Bcd/0bFQ+v3OiWD5oiYc -XfcIBTeoy6IIICNc7krfnXRpsXO2oimNgMS6nHPKvXYF5jTbKr0A40ElDEIjtt5T -Yb4oWNHfAgMBAAGjUDBOMB0GA1UdDgQWBBSD6d3VXldZQOiVGZC0Y3nuANvG2zAf -BgNVHSMEGDAWgBSD6d3VXldZQOiVGZC0Y3nuANvG2zAMBgNVHRMEBTADAQH/MA0G -CSqGSIb3DQEBCwUAA4IBAQCM3XHUZ1RwpLtF5DpEKDmC4osIiguk7ENF7Bg+LCQt -GzIeBkHPZ0sKbqZr0og6a0r0Qn1Xzr5nku9cuFH1Gc9Wwg82i8zXLgD8//VSNy5k -SLKb7MiAAnUHv6ZkluX8X9bdg32vb+sTwhuFhjbI5LVWvY3dq/Ez+WERFUxgNL3s -dgiJABkslbkjobgB39m/Lr223P6HwG5n6YukKSmwfiion5QYsTbTpd9AYbAD5UTs -A5H5pRdk/mxJ7yYsgosu60wAUI/xVAVvsaUDGa+koiVKPhUg4A7Qd/2oDByb/H9J -atqHkSjkwvhAekC0mOjKh6ED/Nr2tnN5l0GIbwRvj9Xz +UlVTVDEwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDPNPcqcKdr49y/ +/B8lUz7kUblQcD6BwDdFkRMAzsyyC8o7J4HKJ1jwvs5OdCHqCuVqrSgHTm5EeEFi +1SKxrfoHxVZ2gLVg/UA1fVCQ8M/ic54Vw8eOjnwAG0uVlyhCxOZeboc0WBY17zOF +6Gk34SVqlMrss/ZGqkvn2pttLeOKkncPG7CP+sGG2XmvFJo4JwEVisJelYAZepQl +aVEHFmugLQgWlnw2gkB84VAcJVwkj72WwoE+i3Z9CJEo+2P+INcO5/juIrauRjeg +XXuVvH7iprw2WKA/wzX/8RUSPHk7jBNasFLCNwdFH6mRFUcjNQsSRrtJw7r/YhGn +B+wYNIoJAgMBAAGjUDBOMB0GA1UdDgQWBBQ/rnoFWCjR0bpRDdJlYik+11mXCjAf +BgNVHSMEGDAWgBQ/rnoFWCjR0bpRDdJlYik+11mXCjAMBgNVHRMEBTADAQH/MA0G +CSqGSIb3DQEBCwUAA4IBAQDNfultFcA+xQu9RICjWIyjK9OKmbqSCBwoSeAez55X +B0dekd3MU+fkPEm1dfgduMbXPHU1k0bKNi/rCPcV1sAUSkFSbfa7oeOwcTTeCcpr +1KTQurVY8fVEWBAENJzzZSXngSzqP/pWb9jRPPRAcDrw04zhLaqBcZlCDyg8sZTb +6RIsAsx7inacLH64uDv22/2HdGAWcAqpOVh4ekvHmFPrZQy5aF9UFwEcAkFJAzBI +kQ7tjwY6vZx2o8lh0W4eiMeH0mhvQ4Gxst0rWsMEz5QnP4jgNbdcl3nBDbOIYUJk +ZpA+2mhA66vLJhShoRJeRTwZPEkVq025Wi43f4QZ+4H9 -----END CERTIFICATE----- diff --git a/support/configuration_management/profile/test_mid_key_camiddletest.key b/support/configuration_management/profile/test_mid_key_camiddletest.key index 2060cc7d6..258523fce 100644 --- a/support/configuration_management/profile/test_mid_key_camiddletest.key +++ b/support/configuration_management/profile/test_mid_key_camiddletest.key @@ -1,27 +1,27 @@ -----BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEAy1qvlNJqmJHxE26Vnu1QloUOjgv9f/IgtognNJGfs8QnQ+Tp -RID94lFn1/ibFxYsNn70dSljQOybKadOotnhyhpRYkNer1WKZLV2uqR41of61qHL -CGdpDOxa2Xt4byjTGxRj7r1HkuFXGDO8mbovgs1FFbK9E/pROLsraBEKpLkYiHBW -X4nhECF56bH0FYt0EG/YNp5gTB1hY1J7tz1ji2WzL+3n1LU5FTJS03PqxIVTRepa -d2dMPLsKuAtjaTk402F4FhBI5kC/GqmbehxvM0XG93FDjGIne3jDDqeZw0awmhpX -qo2qdbM9ZtxuwqEEDB7eC0ciqZ55+XewTwKk+QIDAQABAoIBAGHBsaB4WrgHiH3P -7mtdKB2Dz1Bn4TBtpF47K6Wwz7YqeLnBxIWjAOmYOrRvFZdOmGiGNVxRTh5638hx -XnMZDNsMNc1oF49wLrxlI7Nrt49iBSrC0oiytaR5xt6/5VCCrqFY9wVgxpSMcUL4 -NBUulQJrTWe16gE9l2gPSjmX36b5XLG6n3wsMCh8yphwwOBg86DjYWVY+q/AKY+j -emSka2HYNTXOLQw6cBMcx2dKXtz4/XxDEtbhn/Fwd8B4D4n5RsuqDlLe/vLSXoDp -1IDuK+SsprFZg2O6ss6r9hFEpBtTLYlk9RPlCgtvrMhwCULcRhxoIVxfvL9i+75E -WT6KoQECgYEA6J8btSUE/bNVgy3mmcTZ9t/ukagg3DOyAR/cojEZB3G4FocGxfI8 -BRWUYL3X4tTibLh222fWQMiJB2nUGCEstPKC4vBuorq8jdmNS4EvT0v7w0MiELrf -MiBq2vRla74buweIlTO67kXt+2+MsY4H8jkUanj6ajseJYWvPPsEQWECgYEA38qW -qE7Hc32VlgL00uIYjBGkvfEHDRzwROwTiWMtvqea2WpdR/mBfzrWle4rUXiH9c+A -GTSh2aBpfEgIqzR5wDASYk4cbgfyl/PjsG0ibCf/auilMeHJXw9RDSdkWnfPmFd/ -633yzsY6aYNNauaxSuTLI09VxX8rVYXYfp2W0pkCgYEAiXFI67SdyFBnXASI1Z3r -suQIj2MpVzHsIKH0uJgN08orHJRXOimvsMlZS/efUNS7m8U55NTrUIer/wdWW5Nu -WNNY5kFs/RUcRyudQlln3JBmhq5puDzRl0p0GD6CljBTLiR7XLyd3B7RR9hW5qmm -pEV5fJdSTeX0H/Nm4L7nesECgYBbTnnnk7TWzw9gFDa1b+AaDfzMLnH1DLCPPk6+ -SEPavOF2AWqrugX21hfFNlZgODAov4+BOTMr6sH/HhjDWXavTi3CBCKfVgjJrI1i -ZzSbMjqI8QCteHTDnykvl7nfG3EMs+6SM2IEsWYVtKe6jQMbDnw/HNhe6wLQMvrg -tgVaSQKBgQDRLgTP5YxrUMUT3dq1cyXy3DQoMCPjAka07zXBaAAALtnn57SxR1mN -kJ4cl4YjhdhRBvGV7KSB4hDBKks+xRuuuQ+Eq+I68a9uWE/k4Sdh3MZpif57lC+L -edJqQRviqD0xMi+JImb6rUtNCjVJ/OgLc5pGgdeFi/+lRkiX9M8xJA== +MIIEpQIBAAKCAQEAtZoMgdetjtMkZG6Zc0bgYLoTAsDeIZEy/Q7MQiCWYQl9LrTY +j8m8fmtguhJFVD5QnRkxqmsOTsqmeH8XyRPO0bCVG9hHsTZ0mdv/HLv7Xh7CuUmC +QdgcsRya46LB1fZ0jpqHdIHVH1K1sNEzwxXgWFRHAkNuuRX7xLKAk6Kbwsx/7Crf +cY8GiMa9/x56GJBA8dawfilJX3N7pGh/ZFJlgF5zTuPdqbgc82qOpbJIXOMMszyh +1pImd6FYdzNUjMdu1LxwhARdj52RqY7DKBPQWsj4p3jfNrKN695Wk2xXD5VEbIBO +XduhSlMQpwlHhBAsNBYaqxV5NjXjY+epD1iGzwIDAQABAoIBAQCM9mnU88x1u/FY +v/z+3TpX+re9AGasWZ/hjHYCsnboFcyEz732Rtq4qrLnXD1SehhrCV5i8Tym7miv +yb91xplYbSAhAA4OQb3anEj3Tfd9hJUT7Dpez9jdpd2Y6wJZCjhJZSvVxN3gtXvx +J0JtoPKGvcxstlkg9C587S4e6y7K0k/EDtp3HpnJoBRafi5FLrzje3kM77TF52tK +5W3WtS2by3Hd+jtnFEL4yeF5nhlrgUGAuXP3hkEco/kcQR4I/3NDY6yAHWAKTzsO +aGs2we6/xBpiNkXK8nDRb6D3vlske7yHMqodY6Zymc4ccX+d9VLI1gnWYzrI3rth +hL/7suBpAoGBAO8wwuumaNto1JkoRDFkcN3SvNDaitMbMH4ohzG4BFYCC1MZMOQ/ +Gs80zbEdBTgfEEFwNcZekiznK7KfGWIbbEHPlYofdR68iH2II1kF0Ix/QNj8xlJU ++KgrKqvoKk8tOn7369Z40Yx6+CwcUahZuztBJOZs2/UuqOs41ckUhlNbAoGBAMJd +N71qDMFwhjm9n3UJYqyY96QVm5CXv0cgIw/yG77hbmhmy0njEfaLQ3bunkNd85Ri +YOMpzmxbgkZ0fsNvZrLXQJh7tXxANlSaBGOznbQj+6fDxnu+2x36yvl0D8dI7zCh +IA8KZ9mB9iMBy10Av/mrUqgrvZVhZ8yfRqBairidAoGACjY8vC7YnzV0ji1n6+vr +3ayXnxsVfjnU8i3sx7ShisJ/lUaoDbacAGiyt3MTu/enjAOsaBG1j/E2rmOYg9XD +43NnYQRCzdMiyKk9SRm0c6sjK6BvHyi9jQB6y+gXllXJ/426Jef2mlbNraRv4A4k +rjzzxFq1cVxSnehJSFJ2Aa0CgYEAis6wBCI8wdluwsXdn2P4iHMmSJT16Km2/UDC +SZ0Km6O7iev/uuDj70M+By4a8NmkH5CyyQkOVuxzeYWxEjn5CjgX9c5DqlzhcEIe +aGXadtBL5WA33CBNtHdrhgORUS2RRRWNI7C2wevCsPWTGvRyJghom5nBZ3GNA+Gs +OtDuyTECgYEA7vrlbymCeru0WyzfOAEKnU7yGxS4AJlDS2dWu12mfFQRv25vGNXE +C4fPsEeyn2hz7SoCTKroR83v9P7Hn7WO5aSGupuKfNOouCcM6I5uIjqGYHgEuFcC +Wqk1udjv8Q8Lo44NZcCZ5jANE4AbR9aqXBGAd3Qe411l4kxxmLB+HhQ= -----END RSA PRIVATE KEY----- diff --git a/support/configuration_management/profile/test_root_cert_catest.cer b/support/configuration_management/profile/test_root_cert_catest.cer index 0cf1aeb25..c9a13ac54 100644 --- a/support/configuration_management/profile/test_root_cert_catest.cer +++ b/support/configuration_management/profile/test_root_cert_catest.cer @@ -1,16 +1,21 @@ -----BEGIN CERTIFICATE----- -MIICdjCCAd+gAwIBAgIJAMCCplI8N9WIMA0GCSqGSIb3DQEBCwUAMFQxCzAJBgNV +MIIDfTCCAmWgAwIBAgIJAN1++hbyZpEIMA0GCSqGSIb3DQEBCwUAMFUxCzAJBgNV BAYTAkNOMQswCQYDVQQIDAJCSjELMAkGA1UEBwwCQkoxCzAJBgNVBAoMAk5UMQsw -CQYDVQQLDAJOVDERMA8GA1UEAwwIQ0EgVFJVU1QwHhcNMjMwNjI5MDkxMjUwWhcN -MzMwNjI2MDkxMjUwWjBUMQswCQYDVQQGEwJDTjELMAkGA1UECAwCQkoxCzAJBgNV -BAcMAkJKMQswCQYDVQQKDAJOVDELMAkGA1UECwwCTlQxETAPBgNVBAMMCENBIFRS -VVNUMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCkwtYI3qGhpgYpb33lyZAm -X4RDPFm0IuY/7G2XZF1TTfbPW3l/9wkFG6jZNmgmqzUrJ+SadFoZm+/c3nfdFpaT -KDbcb4MdhqSLRJpBnfww5RgM7pC3FZtfVg2xbesJNCW87nYIFr347OUNggUvEaN6 -0brMYcQN3/gpBOIHl9ME+QIDAQABo1AwTjAdBgNVHQ4EFgQUbNxFN0+J9D/uj5K/ -gtWZW7DdCiowHwYDVR0jBBgwFoAUbNxFN0+J9D/uj5K/gtWZW7DdCiowDAYDVR0T -BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOBgQCiz8UJCye6zeqthGzjLFxNS0KX+sEE -oucrUkFkgu5bg2o+4/r4YT+ocWnVK2RIN5cM+t3XYmVbP/UWG5eTHXyR/D/GlVvV -rvBW/fmjRxRhqFY+6zA4o9sRta+UkHgPUIb+FbBOx2/hebTJp4FY5N98w1sFVAQh -1EitkXdSGbnskw== +CQYDVQQLDAJOVDESMBAGA1UEAwwJQ0EgVFJVU1QxMB4XDTI0MTEyNzA4MjgzN1oX +DTI3MDgyNDA4MjgzN1owVTELMAkGA1UEBhMCQ04xCzAJBgNVBAgMAkJKMQswCQYD +VQQHDAJCSjELMAkGA1UECgwCTlQxCzAJBgNVBAsMAk5UMRIwEAYDVQQDDAlDQSBU +UlVTVDEwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDPNPcqcKdr49y/ +/B8lUz7kUblQcD6BwDdFkRMAzsyyC8o7J4HKJ1jwvs5OdCHqCuVqrSgHTm5EeEFi +1SKxrfoHxVZ2gLVg/UA1fVCQ8M/ic54Vw8eOjnwAG0uVlyhCxOZeboc0WBY17zOF +6Gk34SVqlMrss/ZGqkvn2pttLeOKkncPG7CP+sGG2XmvFJo4JwEVisJelYAZepQl +aVEHFmugLQgWlnw2gkB84VAcJVwkj72WwoE+i3Z9CJEo+2P+INcO5/juIrauRjeg +XXuVvH7iprw2WKA/wzX/8RUSPHk7jBNasFLCNwdFH6mRFUcjNQsSRrtJw7r/YhGn +B+wYNIoJAgMBAAGjUDBOMB0GA1UdDgQWBBQ/rnoFWCjR0bpRDdJlYik+11mXCjAf +BgNVHSMEGDAWgBQ/rnoFWCjR0bpRDdJlYik+11mXCjAMBgNVHRMEBTADAQH/MA0G +CSqGSIb3DQEBCwUAA4IBAQDNfultFcA+xQu9RICjWIyjK9OKmbqSCBwoSeAez55X +B0dekd3MU+fkPEm1dfgduMbXPHU1k0bKNi/rCPcV1sAUSkFSbfa7oeOwcTTeCcpr +1KTQurVY8fVEWBAENJzzZSXngSzqP/pWb9jRPPRAcDrw04zhLaqBcZlCDyg8sZTb +6RIsAsx7inacLH64uDv22/2HdGAWcAqpOVh4ekvHmFPrZQy5aF9UFwEcAkFJAzBI +kQ7tjwY6vZx2o8lh0W4eiMeH0mhvQ4Gxst0rWsMEz5QnP4jgNbdcl3nBDbOIYUJk +ZpA+2mhA66vLJhShoRJeRTwZPEkVq025Wi43f4QZ+4H9 -----END CERTIFICATE----- diff --git a/support/configuration_management/profile/test_root_key_catest.key b/support/configuration_management/profile/test_root_key_catest.key index efa1a8dd1..3924a8db4 100644 --- a/support/configuration_management/profile/test_root_key_catest.key +++ b/support/configuration_management/profile/test_root_key_catest.key @@ -1,15 +1,27 @@ -----BEGIN RSA PRIVATE KEY----- -MIICXQIBAAKBgQCkwtYI3qGhpgYpb33lyZAmX4RDPFm0IuY/7G2XZF1TTfbPW3l/ -9wkFG6jZNmgmqzUrJ+SadFoZm+/c3nfdFpaTKDbcb4MdhqSLRJpBnfww5RgM7pC3 -FZtfVg2xbesJNCW87nYIFr347OUNggUvEaN60brMYcQN3/gpBOIHl9ME+QIDAQAB -AoGAAJX0vtlTx8hYU0NjNjLuQUSrqrWHOB27pdSIWzZvIoGvc/NGTk8piAweII+R -9Tk8mietJ2NsgpTMWIOt92pCJMhU5BAqkDYmfTusksz4xWku/ZiPacX8DxjSrr8J -x6bQUiXzu3OfJqHeis9HcS0UMWSMDQpvumvGImf8sartehUCQQDRtOuvwVoZuYyY -ZgWNxnmLAMQD8xg4ma1RQTUTE/nRcc9IhJKvkbPvI9tajuxEpXc014hgOXTZ2hLT -hm4RhgofAkEAySHrMVWsqsZQ5Yy1a9+Yo0N5wNrILWWWrj4gXqgoAPKYv1hLQ1oi -6K/4HmVHuM9ZmRqndA+y11yD7jnrPrm95wJBAIVA3XK0/jfSe9BrI6RPNfRp7CRG -WGG+5S74rG0PCHNaSkjeVQdTIm8W7c/Beci1C+Z7/qCGYgX8WHIovdBMyCkCQQCz -GBTI1TTuy6/09poE+BB+L/MWGrnsUm0dsgw4vRsB3QLOPtylmHlFIIua5Sw8D8YE -YouA+QmSYrrHQaOLMvE5AkAQiQCs0NJl07Px2L4fod0eIeQ1CnJKzRQZpbYt4kIa -UGF8n/kRPtmLUKgNTrdACqPgm57UY6wOUA5K++OhriaP +MIIEogIBAAKCAQEAzzT3KnCna+Pcv/wfJVM+5FG5UHA+gcA3RZETAM7MsgvKOyeB +yidY8L7OTnQh6grlaq0oB05uRHhBYtUisa36B8VWdoC1YP1ANX1QkPDP4nOeFcPH +jo58ABtLlZcoQsTmXm6HNFgWNe8zhehpN+ElapTK7LP2RqpL59qbbS3jipJ3Dxuw +j/rBhtl5rxSaOCcBFYrCXpWAGXqUJWlRBxZroC0IFpZ8NoJAfOFQHCVcJI+9lsKB +Pot2fQiRKPtj/iDXDuf47iK2rkY3oF17lbx+4qa8NligP8M1//EVEjx5O4wTWrBS +wjcHRR+pkRVHIzULEka7ScO6/2IRpwfsGDSKCQIDAQABAoIBACrOU112JnA4g6s5 +x6lrWCvM4k7G0XL2pbR+cwGQt2L04pNz5vE/TbV2haJZhYQXOivel81im48TlNZ5 +F5DDU0r1rpYOounlh7VFLTa0OQ4cOoVei8RclStkeCnwL0YT7U+G3/GlXPlJcEhy +qgH8RkGNeZqK1w7kMYg1djSI7V/74NH4x84fxfCexJVW1Mrq1bLaQyfCXmKhj6kE +hcFgcY3AUnsrvyFmUqApGU8A0YeLVSwMtYHMPNQMq8PF2UigMPe/hGJiLOygDTEY +wvTvDKmEC28dtuS+fBZEbX0MGX93J4tTIAqY/4CIvSMhbjL3ak05AMBVbHPOFeg+ +4W9ERQECgYEA8K0GKKwRgLv0Kmr8sxXheGdcF8FEEFvMtcONODdkgiogc8SkJ5QP +pwaeWrdeaKXS+FEc69/2mKh0oBkWtqWTdgKpJO3T+WrNhhuBKvbTHFNyuJewf+aF +NeVZ+4gLVsiP9EukxruXe3rg/f3Z4zcpAmt5OOSM/+U4+BXl7Uy0k6kCgYEA3GZn +GwlqEwu86uYEPFbwOgvpYttiYCkUXYLQQ7wyW4zki8h6imNhOONPp/ZLF2n/XwIv +IZCxhQzgoyuVF0LuWUcUOaKps5YVG07vVfCTn9l7DcBnwx8vulFgemrLABT/gXe1 +gdITgk6PkPk7U839c00r5niI6RoTIkIs8wMiP2ECgYBJ+tWG0QV8TcoK8+IDZnlt +GlBrmOPEJ4OwZ5DUM+q4PBzHmS1gYRnCnL02Y2Eox7gmzkAWnTxexoE66RtbP2Ap +iT3W9SgQZe0RCQlWXJKeBWShKzd8yS4vV/Wl5LafkXz2ef4HfIhe03GvgUVlm4IG +lWSowVA6JIqzb3/Cxq5HKQKBgFlnrOGZ0w7AzzTWc9dqSO6zEEyKxABQCbPZMdSY +TjE3GSre+16R68lg5Fo1Hcb0t6P5xdau1GQtkh5+um8CNp++pqSuqHpyIkO+pHXP +LoNEfJdaenz7dKf3BNUD5y80VWVWgymTZ1iPt8tOXtOjFvIj1vAZ6yfr7OETyRoX +JlhhAoGAS42nkd98pGgiVpZTJfeOJVru7fLBZfqr1EPoln0S5EAHcjO5EUN/fY6X +GPEy9dCG/t4CTfuS6DdQZh6iN3gxdtGbX44VC3GJ5EmL6F2MHUKxo6ITJC49H/Wr +H8IEFY82mUp17z+ksw6DgVZdmft89zDa57hJUtxlypH1nRQHggE= -----END RSA PRIVATE KEY----- diff --git a/support/ui_utils/common/create_statistics_policy.py b/support/ui_utils/common/create_statistics_policy.py index 0682d42ce..8fd411afd 100644 --- a/support/ui_utils/common/create_statistics_policy.py +++ b/support/ui_utils/common/create_statistics_policy.py @@ -9,9 +9,9 @@ from support.api_utils.log_in import LogIn from support.ui_utils.objects.create_objects import CreateObject from support.ui_utils.objects.search_objects import SearchObject from support.ui_utils.objects.delete_objects import DeleteObject -from support.ui_utils.profiles.create_profile import CreateProfile -from support.ui_utils.profiles.search_profile import SearchProfile -from support.ui_utils.profiles.delete_profile import DeleteProfile +from support.ui_utils.profiles.create_profiles import CreateProfile +from support.ui_utils.profiles.search_profiles import SearchProfile +from support.ui_utils.profiles.delete_profiles import DeleteProfile from support.ui_utils.policies.create_rules import CreateRule from support.ui_utils.policies.search_rules import SearchRule from support.ui_utils.policies.delete_rules import DeleteRule diff --git a/support/ui_utils/profiles/create_profile.py b/support/ui_utils/profiles/create_profiles.py index 2e322730e..709952c46 100644 --- a/support/ui_utils/profiles/create_profile.py +++ b/support/ui_utils/profiles/create_profiles.py @@ -18,11 +18,12 @@ from support.ui_utils.profiles.create_tcp_proxy_profile import CreateTcpProxyPro from support.ui_utils.profiles.create_traffic_mirroring_profile import CreateMonitorProfile from datetime import datetime -class CreateProfile: +class CreateProfiles: def __init__(self, driver): self.driver = driver - def create(self, profile_data, profile_element_position): + def create_profiles(self, policy_configuration): + profile_element_position = {} page_jump_element_position = profile_element_position["page_jump"] create_element_position = profile_element_position["create"] try: @@ -31,24 +32,24 @@ class CreateProfile: page_jump.jump_sub_profile_page(page_jump_element_position) # 点击create self.driver.find_element(By.XPATH, create_element_position["profileListPage_createButton_posXpath"]).click() - if profile_data["profile_type"] == "response_page": # response page创建 - self._create_response_page(profile_data["profile_file"]) - elif profile_data["profile_type"] == "statistics_template": # response page创建 - self._create_statistics_template_page(profile_data) - elif profile_data["profile_type"] == "hijack_file": # hijack file 创建 - self._create_hijack_file(profile_data["profile_file"]) - elif profile_data["profile_type"] == "insert_script": # insert script 创建 - self._create_insert_script(profile_data["profile_file"]) - elif profile_data["profile_type"] == "run_script": # run script 创建 - self._create_run_script(profile_data["profile_file"]) - elif profile_data["profile_type"] == "ssl_keyring": # ssl decrpytion keyring 创建 - self._create_run_ssl_decryption_keyring(profile_data["profile_file"]) - elif profile_data["profile_type"] == "ssl_decryption": # ssl decrpytion profile 创建 - self._create_run_ssl_decryption_profile(profile_data["profile_file"]) - elif profile_data["profile_type"] == "tcp_option": # tcp proxy 创建 - self._create_run_tcp_proxy_profile(profile_data["profile_file"]) - elif profile_data["profile_type"] == "traffic_mirror": # traffic mirror 创建 - self._create_traffic_mirroring_profile(profile_data["profile_file"]) + if policy_configuration["profile_type"] == "response_page": # response page创建 + self._create_response_page(policy_configuration["profile_file"]) + elif policy_configuration["profile_type"] == "statistics_template": # response page创建 + self._create_statistics_template_page(policy_configuration) + elif policy_configuration["profile_type"] == "hijack_file": # hijack file 创建 + self._create_hijack_file(policy_configuration["profile_file"]) + elif policy_configuration["profile_type"] == "insert_script": # insert script 创建 + self._create_insert_script(policy_configuration["profile_file"]) + elif policy_configuration["profile_type"] == "run_script": # run script 创建 + self._create_run_script(policy_configuration["profile_file"]) + elif policy_configuration["profile_type"] == "ssl_keyring": # ssl decrpytion keyring 创建 + self._create_run_ssl_decryption_keyring(policy_configuration["profile_file"]) + elif policy_configuration["profile_type"] == "ssl_decryption": # ssl decrpytion profile 创建 + self._create_run_ssl_decryption_profile(policy_configuration["profile_file"]) + elif policy_configuration["profile_type"] == "tcp_option": # tcp proxy 创建 + self._create_run_tcp_proxy_profile(policy_configuration["profile_file"]) + elif policy_configuration["profile_type"] == "traffic_mirror": # traffic mirror 创建 + self._create_traffic_mirroring_profile(policy_configuration["profile_file"]) # 其它 profile创建 return 200 except Exception as e: diff --git a/support/ui_utils/profiles/delete_profile.py b/support/ui_utils/profiles/delete_profiles.py index 422a45e0f..98c52158f 100644 --- a/support/ui_utils/profiles/delete_profile.py +++ b/support/ui_utils/profiles/delete_profiles.py @@ -5,7 +5,7 @@ from support.ui_utils.element_position.profile_element_position import * from selenium.webdriver.common.by import By from datetime import datetime -class DeleteProfile: +class DeleteProfiles: def __init__(self, driver): self.driver = driver diff --git a/support/ui_utils/profiles/edit_profiles.py b/support/ui_utils/profiles/edit_profiles.py new file mode 100644 index 000000000..eb1dbc4e8 --- /dev/null +++ b/support/ui_utils/profiles/edit_profiles.py @@ -0,0 +1,7 @@ +import os +import sys +import time + +class EditProfiles: + def __init__(self, driver): + self.driver = driver
\ No newline at end of file diff --git a/support/ui_utils/profiles/search_profile.py b/support/ui_utils/profiles/search_profiles.py index 5354dfc6b..8f73005e3 100644 --- a/support/ui_utils/profiles/search_profile.py +++ b/support/ui_utils/profiles/search_profiles.py @@ -4,11 +4,12 @@ from support.ui_utils.element_position.profile_element_position import * from support.ui_utils.profiles.page_jump import PageJump from selenium.webdriver.common.keys import Keys -class SearchProfile: +class SearchProfiles: def __init__(self, driver): self.driver = driver - def search(self, name, profile_element_position, vsys_name=""): + def search_profiles(self, name): + profile_element_position = {} search_element_position = profile_element_position["search"] page_jump_element_position = profile_element_position["page_jump"] # 打开该列表 diff --git a/support/ui_utils/ui_client.py b/support/ui_utils/ui_client.py index 628dfcce8..203944bd0 100644 --- a/support/ui_utils/ui_client.py +++ b/support/ui_utils/ui_client.py @@ -19,6 +19,10 @@ from support.api_utils.delete_rules import DeleteRules as DeleteRulesAPI from support.ui_utils.objects.search_objects_example import SearchObjects from support.ui_utils.objects.delete_objects_example import DeleteObjects from support.ui_utils.objects.edit_objects_example import EditObjects +from support.ui_utils.profiles.create_profiles import CreateProfiles +from support.ui_utils.profiles.search_profiles import SearchProfiles +from support.ui_utils.profiles.edit_profiles import EditProfiles +from support.ui_utils.profiles.delete_profiles import DeleteProfiles class UIClient: def __init__(self, parameter): @@ -46,7 +50,18 @@ class UIClient: def delete_objects(self, objects_tuple): objects = DeleteObjects(self.driver) objects.delete(self.parameter, objects_tuple) - + + def create_profiles(self, policy_configuration): + profiles = CreateProfiles(self.driver) + code = profiles.create_profiles(policy_configuration) + return code + + def search_profiles(self, policy_configuration): + profiles = SearchProfiles(self.driver) + profile_tuple, code = profiles.search_profiles(policy_configuration) + self.profile_tuple = profile_tuple + return profile_tuple, code + def create_rules(self, policy_configuration): self.policy_configuration = policy_configuration rules = CreateRules(self.driver) diff --git a/tests/dos_protection/dos_allow_srcip.py b/tests/dos_protection/dos_allow_srcip.py index 7bf4ab76d..abc75c86b 100644 --- a/tests/dos_protection/dos_allow_srcip.py +++ b/tests/dos_protection/dos_allow_srcip.py @@ -1,6 +1,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -36,7 +38,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -73,6 +75,12 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_deny_srcip.py b/tests/dos_protection/dos_deny_srcip.py index 36db9e885..e154bac0f 100644 --- a/tests/dos_protection/dos_deny_srcip.py +++ b/tests/dos_protection/dos_deny_srcip.py @@ -1,6 +1,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -36,7 +38,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -73,6 +75,12 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_concurrency_srcip_d3_10s.py b/tests/dos_protection/dos_protect_srcip_concurrency_srcip_d3_10s.py index 0c7d485d6..cfdaae2e1 100644 --- a/tests/dos_protection/dos_protect_srcip_concurrency_srcip_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_concurrency_srcip_d3_10s.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -106,6 +108,12 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_concurrency_srcip_d3_1h.py b/tests/dos_protection/dos_protect_srcip_concurrency_srcip_d3_1h.py index 807b03a3e..588f279c2 100644 --- a/tests/dos_protection/dos_protect_srcip_concurrency_srcip_d3_1h.py +++ b/tests/dos_protection/dos_protect_srcip_concurrency_srcip_d3_1h.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -106,6 +108,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_concurrency_srcip_d3_1min.py b/tests/dos_protection/dos_protect_srcip_concurrency_srcip_d3_1min.py index 5fbc1a88c..f483059a2 100644 --- a/tests/dos_protection/dos_protect_srcip_concurrency_srcip_d3_1min.py +++ b/tests/dos_protection/dos_protect_srcip_concurrency_srcip_d3_1min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -106,6 +108,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_concurrency_srcip_d3_2min.py b/tests/dos_protection/dos_protect_srcip_concurrency_srcip_d3_2min.py index 5589af5b7..ffa3e42c4 100644 --- a/tests/dos_protection/dos_protect_srcip_concurrency_srcip_d3_2min.py +++ b/tests/dos_protection/dos_protect_srcip_concurrency_srcip_d3_2min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -106,6 +108,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_concurrency_srcip_d3_5min.py b/tests/dos_protection/dos_protect_srcip_concurrency_srcip_d3_5min.py index efd15e389..1227f3fdc 100644 --- a/tests/dos_protection/dos_protect_srcip_concurrency_srcip_d3_5min.py +++ b/tests/dos_protection/dos_protect_srcip_concurrency_srcip_d3_5min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -106,6 +108,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_10min.py b/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_10min.py index 6d0a77359..47e3dd255 100644 --- a/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_10min.py +++ b/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_10min.py @@ -4,6 +4,8 @@ import sys from support.organize_config import OrganizeConfig +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -39,7 +41,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -119,6 +121,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_10s.py b/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_10s.py index ecb26951a..9227b5752 100644 --- a/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_10s.py @@ -4,6 +4,8 @@ import sys from support.organize_config import OrganizeConfig +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -39,7 +41,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -119,6 +121,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_1h.py b/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_1h.py index 4241f3eff..e93b8bef2 100644 --- a/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_1h.py +++ b/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_1h.py @@ -4,6 +4,8 @@ import sys from support.organize_config import OrganizeConfig +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -39,7 +41,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -119,6 +121,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_1min.py b/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_1min.py index 06ac47c0e..194b79350 100644 --- a/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_1min.py +++ b/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_1min.py @@ -4,6 +4,8 @@ import sys from support.organize_config import OrganizeConfig +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -39,7 +41,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -119,6 +121,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_2min.py b/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_2min.py index 896a206d8..24c5befc2 100644 --- a/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_2min.py +++ b/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_2min.py @@ -4,6 +4,8 @@ import sys from support.organize_config import OrganizeConfig +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -39,7 +41,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -119,6 +121,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_5min.py b/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_5min.py index f87cc770a..7575bba38 100644 --- a/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_5min.py +++ b/tests/dos_protection/dos_protect_srcip_dns_rate_srcip_cperiod_1min_d3_5min.py @@ -4,6 +4,8 @@ import sys from support.organize_config import OrganizeConfig +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -39,7 +41,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -119,6 +121,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_10min.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_10min.py index 20da71b2d..10935934a 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_10min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_10min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -35,7 +37,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -115,6 +117,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_10s.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_10s.py index 8591402ff..4822d6667 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_10s.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_1h.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_1h.py index 9f163c4c2..f707e1e2e 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_1h.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_1h.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_1min.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_1min.py index e97c9824e..9d4a95b37 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_1min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_1min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_2min.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_2min.py index 4a9d99f5e..0217dbe71 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_2min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_2min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_5min.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_5min.py index fb9619d05..729d5e6be 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_5min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_d3_5min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_none.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_none.py index f4c9d6e46..a38e472df 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_none.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10min_none.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_10min.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_10min.py index 0351418fe..c1b3a0041 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_10min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_10min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_10s.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_10s.py index 9369a3361..d6813cf8c 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_10s.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_1h.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_1h.py index 2aee79904..fbdcf0ea7 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_1h.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_1h.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_1min.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_1min.py index 1acfd910b..f450ad100 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_1min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_1min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_2min.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_2min.py index dd3431044..fc671e8fe 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_2min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_2min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_5min.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_5min.py index 63a667880..ac5b390a1 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_5min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_5min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_none.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_none.py index b64af19a5..aa6f49267 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_none.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_10s_d3_none.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_10min.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_10min.py index 72938d129..59abd24c1 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_10min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_10min.py @@ -4,6 +4,8 @@ import sys from support.organize_config import OrganizeConfig +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -39,7 +41,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -125,6 +127,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_10s.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_10s.py index c3ff179d3..5cca1e5be 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_10s.py @@ -4,6 +4,8 @@ import sys from support.organize_config import OrganizeConfig +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -39,7 +41,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -125,6 +127,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_1h.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_1h.py index 7e94fccb3..011669348 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_1h.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_1h.py @@ -4,6 +4,8 @@ import sys from support.organize_config import OrganizeConfig +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -39,7 +41,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -125,6 +127,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_1min.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_1min.py index 2edbe23eb..a0635e299 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_1min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_1min.py @@ -4,6 +4,8 @@ import sys from support.organize_config import OrganizeConfig +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -39,7 +41,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -125,6 +127,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_2min.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_2min.py index 7e94fccb3..011669348 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_2min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_2min.py @@ -4,6 +4,8 @@ import sys from support.organize_config import OrganizeConfig +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -39,7 +41,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -125,6 +127,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_5min.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_5min.py index 3a9eac868..23132a5ee 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_5min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_d3_5min.py @@ -4,6 +4,8 @@ import sys from support.organize_config import OrganizeConfig +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -39,7 +41,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -125,6 +127,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_none.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_none.py index ba7dc7eee..3a7a8f997 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_none.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_1min_none.py @@ -4,6 +4,8 @@ import sys from support.organize_config import OrganizeConfig +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -39,7 +41,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -124,6 +126,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_10min.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_10min.py index 0bf040503..35fd3a988 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_10min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_10min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_10s.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_10s.py index b323bcd6f..24ab7ed05 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_10s.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_1h.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_1h.py index 64183bfcf..19a1f4066 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_1h.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_1h.py @@ -4,6 +4,8 @@ import sys from support.organize_config import OrganizeConfig +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -39,7 +41,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -125,6 +127,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_1min.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_1min.py index b51944842..2fc43cd95 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_1min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_1min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_2min.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_2min.py index 27f85a186..3082778ed 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_2min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_2min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_5min.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_5min.py index eb95cf614..e73415eb3 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_5min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_5min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_none.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_none.py index 34e649982..adf082123 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_none.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_2min_d3_none.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_10min.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_10min.py index 4ccbf4010..e900d9bfa 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_10min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_10min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_10s.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_10s.py index 4948cd6f5..6e8a0d372 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_10s.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_1h.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_1h.py index c040b16f9..4c0a3ad5d 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_1h.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_1h.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_1min.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_1min.py index d6e082ea0..3de1a149f 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_1min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_1min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_2min.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_2min.py index a03e1a03f..1b94e27a0 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_2min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_2min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_5min.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_5min.py index b2570b214..313ee7b24 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_5min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_5min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_none.py b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_none.py index 1b6fe0b0c..3c7526f47 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_none.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_serverfqdn_cperiod_5min_d3_none.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_10min.py b/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_10min.py index 222a0c199..db892b299 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_10min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_10min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_10s.py b/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_10s.py index e8b63d060..427342728 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_10s.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_1h.py b/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_1h.py index f7a22f946..93784adc3 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_1h.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_1h.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_1min.py b/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_1min.py index 477de0467..b3b79c957 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_1min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_1min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_2min.py b/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_2min.py index ab92cda77..325631b6b 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_2min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_2min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_5min.py b/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_5min.py index ef12012fe..dd3159ff0 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_5min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_d3_5min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_none.py b/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_none.py index b24b9c696..19c81e324 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_none.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srcasn_cperiod_1min_none.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_10min.py b/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_10min.py index 51a564f9f..6e3c559b3 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_10min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_10min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_10s.py b/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_10s.py index 7f80f4f8f..9fa00c7bc 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_10s.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_1h.py b/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_1h.py index 2deaf8fe3..be37b1c3f 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_1h.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_1h.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_1min.py b/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_1min.py index 01b30255e..ab8a0cdaa 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_1min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_1min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,7 +118,7 @@ def run(parameter): if len(ui_error) > 0: return ui_error elif parameter["initiation_method"] == "api": - api_client = APIClient(parameter) + api_client = parameter) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_2min.py b/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_2min.py index b534e8e64..28ddd1531 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_2min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_2min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_5min.py b/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_5min.py index dff2f755a..899ff43d3 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_5min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_d3_5min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_none.py b/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_none.py index 5eac824a2..1f8561797 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_none.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srccountry_cperiod_1min_none.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_10min.py b/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_10min.py index 51a564f9f..6e3c559b3 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_10min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_10min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_10s.py b/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_10s.py index 7f80f4f8f..9fa00c7bc 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_10s.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_1h.py b/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_1h.py index 2deaf8fe3..be37b1c3f 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_1h.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_1h.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_1min.py b/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_1min.py index 01b30255e..9716fc614 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_1min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_1min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_2min.py b/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_2min.py index b534e8e64..28ddd1531 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_2min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_2min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_5min.py b/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_5min.py index dff2f755a..899ff43d3 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_5min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_d3_5min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_none.py b/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_none.py index 5eac824a2..1f8561797 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_none.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srcdst_cperiod_1min_none.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_10min.py b/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_10min.py index 51a564f9f..6e3c559b3 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_10min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_10min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_10s.py b/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_10s.py index 7f80f4f8f..9fa00c7bc 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_10s.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_1h.py b/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_1h.py index 2deaf8fe3..be37b1c3f 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_1h.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_1h.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_1min.py b/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_1min.py index 01b30255e..9716fc614 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_1min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_1min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_2min.py b/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_2min.py index 1e8c9d20a..2d4cab425 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_2min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_2min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_5min.py b/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_5min.py index dff2f755a..899ff43d3 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_5min.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_d3_5min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_none.py b/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_none.py index 5eac824a2..1f8561797 100644 --- a/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_none.py +++ b/tests/dos_protection/dos_protect_srcip_http_rate_srcip_cperiod_1min_none.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_serverfqdn_d3_10s.py b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_serverfqdn_d3_10s.py index 99e28ccb2..1b754a106 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_serverfqdn_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_serverfqdn_d3_10s.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_serverfqdn_none.py b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_serverfqdn_none.py index 792a48050..6ba3704fd 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_serverfqdn_none.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_serverfqdn_none.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -115,6 +117,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcasn_d3_10s.py b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcasn_d3_10s.py index d96c2cfb0..23a41f468 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcasn_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcasn_d3_10s.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcasn_none.py b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcasn_none.py index 6bddc09d6..64670c8f7 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcasn_none.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcasn_none.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -115,6 +117,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srccountry_d3_10s.py b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srccountry_d3_10s.py index 5c873f976..0bf7bf0e8 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srccountry_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srccountry_d3_10s.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srccountry_none.py b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srccountry_none.py index 54c67710c..305e7e351 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srccountry_none.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srccountry_none.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -115,6 +117,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcdst_d3_10s.py b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcdst_d3_10s.py index 41c6355d1..5181621ee 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcdst_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcdst_d3_10s.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcdst_none.py b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcdst_none.py index d55db3674..92cbce3b4 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcdst_none.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcdst_none.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -115,6 +117,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_10min.py b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_10min.py index 734eaa7df..76251daa2 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_10min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_10min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_10s.py b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_10s.py index 2147b4b04..605e524aa 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_10s.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_1h.py b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_1h.py index 3677dd9b3..fb4115b5c 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_1h.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_1h.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_1min.py b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_1min.py index cff5dba2c..33ec28e0c 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_1min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_1min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_2min.py b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_2min.py index a256e73ad..0177f8ba5 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_2min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_2min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_5min.py b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_5min.py index 7a262b6bc..ed6777829 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_5min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_d3_5min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_none.py b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_none.py index 3c8b1d822..a82f5c420 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_none.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_concurrency_srcip_none.py @@ -143,6 +143,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -178,7 +180,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -256,6 +258,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_10min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_10min.py index 9baafc921..121880cbc 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_10min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_10min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_10s.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_10s.py index 00d77aae4..39f59c97e 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_10s.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_1h.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_1h.py index 72b7f1d20..7522fa650 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_1h.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_1h.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_1min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_1min.py index 209acbc43..3c59fe9d5 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_1min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_1min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_2min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_2min.py index c6a58d4c8..8af648e3b 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_2min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_2min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_5min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_5min.py index ef361ebb4..b01cd5d4b 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_5min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_d3_5min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_none.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_none.py index 56f0cf8ed..361ccf453 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_none.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10min_none.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: @@ -170,13 +175,12 @@ def run(parameter): elif metric_result == None: test_summary["metric"] = "The failure reason: the returned metric is empty." elif len(metric_result) > 0: - test_summary["metric"] = metric_result + test_summary["metric"] = metric_resul return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "When running test case, the exception error: ", str(e), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) return "When running test case, the exception error: " + str(e) finally: # 删除 diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_10min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_10min.py index 97cca3018..61a65f8e2 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_10min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_10min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,12 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_10s.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_10s.py index 2f78f8016..ce61e1e01 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_10s.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_1h.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_1h.py index dcf5d31c4..7ccad145f 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_1h.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_1h.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_1min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_1min.py index d3165144f..a1bf6c010 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_1min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_1min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_2min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_2min.py index 536d6658f..66e4a451b 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_2min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_2min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_5min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_5min.py index aaeebd330..784a6d507 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_5min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_d3_5min.py @@ -2,6 +2,10 @@ import os import sys +from support.organize_config import OrganizeConfig + +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +41,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +121,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_none.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_none.py index 1bf3aa07e..4756c6e3f 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_none.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_10s_none.py @@ -1,6 +1,11 @@ # -*- coding: UTF-8 -*- import os import sys + +from support.organize_config import OrganizeConfig + +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -34,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -113,6 +118,12 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: @@ -121,6 +132,7 @@ def run(parameter): if len(api_error) > 0: return api_error + # 等待下发配置生效 time.sleep(3) @@ -144,6 +156,11 @@ def run(parameter): if parameter["initiation_method"] == "ui": log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) elif parameter["initiation_method"] == "api": + print(traffic_generation) + print(verification_result) + print(rules_tuple) + print(start_time) + print(traffic_result) log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) if log_result == True: @@ -202,7 +219,7 @@ if __name__ == '__main__': parameter = { "username": "lina2024", "password": "lina2024", - "test_pc_ip": "192.168.64.96", + "test_pc_ip": "192.168.64.136", "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", "initiation_method": "api", @@ -211,6 +228,9 @@ if __name__ == '__main__': "root_path": workdir, "path": workdir + "/tests", "module_name": "dos_protection", - "test_case_name": os.path.basename(__file__)[:-3] + "test_case_name": os.path.basename(__file__)[:-3], + "is_log": 1, + "policy_type":"dos_protection" + } run(parameter)
\ No newline at end of file diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_10min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_10min.py index 0e01d6307..f83660197 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_10min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_10min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_10s.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_10s.py index 99a2da809..8d18156f4 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_10s.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_1h.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_1h.py index 72c50056b..c8f931594 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_1h.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_1h.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_1min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_1min.py index 37495d961..51d9722e3 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_1min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_1min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_2min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_2min.py index dda885780..81423749a 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_2min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_2min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_5min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_5min.py index f7a26971f..6f4cb2815 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_5min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_5min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_none.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_none.py index 9b1e26348..247fd394c 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_none.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1h_d3_none.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_10min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_10min.py index d47a9555f..945021c6d 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_10min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_10min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_10s.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_10s.py index 1c84f64df..c9db2f766 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_10s.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_1h.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_1h.py index d07e1437f..274d4b2a5 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_1h.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_1h.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_1min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_1min.py index 1dbc87722..bdb882cc8 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_1min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_1min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_2min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_2min.py index 4b3106460..1a28a15a1 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_2min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_2min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_5min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_5min.py index a329a050c..f4183467d 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_5min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_d3_5min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_none.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_none.py index bad9dcedb..fab9cb692 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_none.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_1min_none.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_10min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_10min.py index 551776351..4ef6d8d38 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_10min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_10min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_10s.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_10s.py index f9ac04428..3a0b0cb0e 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_10s.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_1h.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_1h.py index d373eb4a6..7ee96f40c 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_1h.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_1h.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_1min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_1min.py index 65ff30cca..b048d2b38 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_1min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_1min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_2min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_2min.py index 23a330952..9493d1008 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_2min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_2min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_5min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_5min.py index 782ffe1de..528b1ff51 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_5min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_d3_5min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_none.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_none.py index e94fe2ee3..adec68d83 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_none.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_2min_none.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_10min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_10min.py index cd8959967..b386ca5de 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_10min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_10min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_10s.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_10s.py index 1a29ff84c..5d6c5213f 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_10s.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_10s.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_1h.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_1h.py index 9e309c12c..b1313bee9 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_1h.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_1h.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_1min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_1min.py index d88accdb7..1135ee59b 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_1min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_1min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_2min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_2min.py index a89a4c15d..41640e46b 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_2min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_2min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_5min.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_5min.py index 282644c6b..ef6923955 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_5min.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_d3_5min.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -117,6 +119,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_none.py b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_none.py index b541aa706..dd1143a88 100644 --- a/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_none.py +++ b/tests/dos_protection/dos_protect_srcip_ssl_rate_srcip_cperiod_5min_none.py @@ -2,6 +2,8 @@ import os import sys +from support.organize_config import OrganizeConfig + sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) import time import pytz @@ -37,7 +39,7 @@ def run(parameter): "attribute_name": "ATTR_SOURCE_IP", "type": "ip", "sub_type": "ip", - "name": "sec_srcip", + "name": "dos_srcip", "items": [ { "op": "add", @@ -116,6 +118,9 @@ def run(parameter): return ui_error elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) # {uuid, type}, i.e., {"12341-232-a21", "ip"} objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: diff --git a/tests/dos_protection/test.py b/tests/dos_protection/test.py index 35d40203b..729e8aac8 100644 --- a/tests/dos_protection/test.py +++ b/tests/dos_protection/test.py @@ -1,5 +1,7 @@ import os import sys + +from support.organize_config import OrganizeConfig import time from datetime import datetime, timedelta import pytz diff --git a/tests/manipulation/111man_allow_srcip_dstip_http.py b/tests/manipulation/111man_allow_srcip_dstip_http.py new file mode 100644 index 000000000..15f7f8a0d --- /dev/null +++ b/tests/manipulation/111man_allow_srcip_dstip_http.py @@ -0,0 +1,434 @@ +# -*- coding: UTF-8 -*- +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz +from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * +from support.report_update import ReportUpdate + + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + + # 参数初始化 + result, exception_result = "", "" + test_summary = {} + + # 脚本启动时间 + script_start_time = time.time() + + policy_configuration = { + "name": parameter["test_case_name"], + "type": "proxy_manipulation", + "action": "allow", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "name": "manipulation_source_ip", + "items": [ + { + "op": "add", + "ip": parameter["test_pc_ip"], + "interval": "0-65535" + }] + }] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "name": "manipulation_destination_ip", + "items": [ + { + "op": "add", + "ip": "192.168.40.206", + "interval": "0-65535" + }] + }] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + }] + }], + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "ssl", # or trex/http + "command": "curl --connect-timeout 30 -m 60 -H \"Content-Type:application/json;charset=UTF-8\" -X POST -d \"{\\\"requestbody\\\":\\\"test_request_body\\\",\\\"setcook\\\":\\\"test_setcook\\\",\\\"contenttype\\\": \\\"test_cont\\\",\\\"responsebody\\\": \\\"test_resbody\\\"}\" -kv --user-agent \"Wget (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36\" https://open.node.com:1443/go" + } + + verification_result = { + "excepted_traffic_result": "test_resbody", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key": "http_host", "query_value": "open.node.com"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"} + ] + } + + # 创建 + objects_tuple, profiles_tuple, libraries_tuple, rules_tuple = None, None, None, None + if parameter["initiation_method"] == "ui": + ui_client = UIClient(parameter) + """ + created_object_code = ui_client.create_objects(policy_configuration) + if created_object_code != 200: + return "Fail to create object." + objects_tuple, searched_object_code = ui_client.search_objects(policy_configuration, "name") + if searched_object_code != 200: + return "Fail to search object." + """ + created_profile_code = ui_client.create_profiles(policy_configuration) + if created_profile_code != 200: + return "Fail to create profile." + profiles_tuple, searched_profile_code = ui_client.search_profiles(policy_configuration) + if searched_profile_code != 200: + return "Fail to search profile." + """ + created_rule_code = ui_client.create_rules(policy_configuration) + if created_rule_code != 200: + return "Fail to create rule." + rules_tuple, searched_rule_code = ui_client.search_rules(policy_configuration, "name") + if searched_rule_code != 200: + return "Fail to search rule." + """ + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + libraries_tuple, api_error = api_client.create_libraries(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, libraries_tuple, profiles_tuple) + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 提取Manipulation_rules用于查询 + tmp_rules_list = [] + for i in range(len(rules_tuple)): + if rules_tuple[i]["type"] == "proxy_manipulation": + tmp_rules_list.append(rules_tuple[i]) + tmp_rules_tuple = tuple(tmp_rules_list) + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, tmp_rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, tmp_rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, tmp_rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) + finally: + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + if objects_tuple: + ui_client.delete_objects(objects_tuple) + if profiles_tuple: + ui_client.delete_profiles(profiles_tuple) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if libraries_tuple: + api_client.delete_libraries(libraries_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + + +if __name__ == '__main__': + from support.ui_utils.element_position.map_element_position_library import replace_paras + + parameter = { + "username": "zcw3", + "password": "qa111111", + "test_pc_ip": "192.168.64.93", + "test_subcriber_id": "test6491", + "api_server": "http://192.168.44.72", + "debug_flag": "local", + "initiation_method": "api", # api ui 空字符串 + "env": "tsgx", + "vsys": 1, + "root_path": workdir, + "path": workdir + "/tests", + "module_name": "manipulation", + "test_case_name": os.path.basename(__file__)[:-3] + } + parameter = replace_paras(parameter) + run(parameter) + + + sc_action = {"action_parameter": { + "targeted_traffic": "raw", + "sff_profiles": [ + { + "name": "autotest", + "type": 2, + "load_balance_method": "hash-int-ip", + "load_balance_localization": "nearby", + "failure_action": "bypass", + "service_func_profiles": [ + { + "name": "autotest", + "admin_status": 1, + "device_group": { + "value": "center-xxg-9140", + "tag": "data_center" + }, + "connectivity": { + "method": "layer2_switch", + "int_vlan_tag": "4090", + "ext_vlan_tag": "4091", + "dest_ip": "110" + }, + "health_check": { + "method": "none", + "interval_ms": 200, + "retires": 5 + } + } + ] + } + ] + }} + Monitor_action = {"action_parameter": { + "traffic_mirroring": { + "enable": 1, + "vlanID": 1, + "mirroring_profile": {"name": "autotest", "vlan_array": ["65", "66"]} + }, + "packet_capture": { + "enable": 0 + } + } + } + html_profile_action = { + "action_parameter": { + "sub_action": "block", + "manipulation_block": "warning_page", + "code": 403, + "html_profile": { + "name": "test", + "format": "html", + "file_path": "Response-Pages_1.html" + } + } + } + replace_rule_action = { + "action_parameter": { + "sub_action": "replace_file", + "replacement_file": { + "name": "test", + "file_path": "hijack_png_1.png", + "content_name": "hijack.png", + "content_type": "application / vnd.android.package - archive" + } + } + } + insert_css_rule_action = { + "action_parameter": { + "sub_action": "inject_css", + "css_file": { + "name": "automanipulation_insert_profile", + "file_path": "insert_css_1.css" + } + } + } + insert_js_rule_action = { + "action_parameter": { + "sub_action": "inject_javascript", + "injection_section": "html_body", + "js_file": { + "name": "manipulation_insert_profile", + "file_path": "insert_js_1.js" + } + } + } + lua_rule_action = { + "action_parameter": { + "lua_script": { + "name": "test", + "file_path": "run_script_replace_reqbody.lua", + "max_exec_time": 100 + } + } + } + intercept_rule_action = { + "action_parameter": { + "keyring_for_trusted": { + "name": "autotestTrust", + "public_file": "tango_ca_v3_trust_ca.cer", + "private_file": "tango_ca_v3_trust_ca.key", + "reissue_expiry_hour": 24, + "keyring_type": "root", + "public_key_algo": "rsa2048", + "include_root": 1 + }, + "keyring_for_untrusted": { + "name": "autotestUNTrust", + "public_file": "tango_ca_v3_untrust_ca.cer", + "private_file": "tango_ca_v3_untrust_ca.key", + "reissue_expiry_hour": 24, + "keyring_type": "root", + "public_key_algo": "rsa1024", + "include_root": 0 + }, + "tcp_option_profile": {"name": "autotest", "tcp_passthrough": 1, "bypass_duplicated_packet": 0, + "client_side_conn_param": {"tcp_maxseg": {"enable": 1, "maxseg": 1460}, "nodelay": 0, + "ttl": 70, "keep_alive": {"enable": 1, "tcp_keepcnt": 222, + "tcp_keepidle": 7200, + "tcp_keepintvl": 75}, + "user_timeout": {"enable": 1, "timeout_ms": 5000}}, + "server_side_conn_param": {"tcp_maxseg": {"enable": 1, "maxseg": 1460}, "nodelay": 0, + "ttl": 75, "keep_alive": {"enable": 1, "tcp_keepcnt": 200, + "tcp_keepidle": 7000, + "tcp_keepintvl": 69}, + "user_timeout": {"enable": 1, "timeout_ms": 5000}}}, + "decryption_profile": { + "name": "autotest", + "decryption": { + "certificate_checks": { + "approach": { + "cn": 1, "issuer": 1, "self-signed": 1, "expiration": 1 + }, + "fail_action": "fail-close" + }, + "dynamic_bypass": { + "ev_cert": 0, + "cert_transparency": 0, + "mutual_authentication": 1, + "protocol_errors": 1, + "cert_pinning": 1, + "trusted_root_cert_is_not_installed_on_client": 0 + }, + "protocol_version": { + "mirror_client": 1, + "allow_http2": 1, + "min": "tls12", + "max": "tls13" + } + } + }, + "traffic_mirroring": { + "enable": 1, + "vlanID": 1, + "mirroring_profile": { + "name": "autotest", + "vlan_array": ["65", "66"] + } + } + } + } + dns_record_action = { + "action_parameter": { + "sub_action": "redirect", + "resolution": [{"qtype": "A", "answer": [ + {"atype": "A", "record_profile": {"name": "test", "type": "A", "description": "test", + "values": [{"value": "192.168.1.2"}, {"value": "192.168.1.1"}]}, + "selected_num": 1, + "ttl": {"min": 300, "max": 300}}]}, {"qtype": "AAAA", "answer": [ + {"atype": "AAAA", "record_profile": {"name": "test", "type": "AAAA", "description": "test", + "values": [{"value": "11::8847"}, {"value": "11::8848"}]}, + "selected_num": 1, + "ttl": {"min": 300, "max": 300}}]}], + "packet_capture": {"enable": 0}, "send_icmp_unreachable": 0, "send_tcp_reset": 0} + } + shaping_action = { + "action_parameter": { + "fair_factor": 1, + "priority": 5, + "profile_chain": [{"name": "test", "type": "generic", "type_argument": "none", + "limits": [{"direction": "incoming", "bandwidth": 50000}, + {"direction": "outgoing", "bandwidth": 100000}], + "aqm_options": {"algorithm": "blue"}}], + "dscp_marking": { + "enabled": 0 + } + } + }
\ No newline at end of file diff --git a/tests/monitor/monit_apn_dns.py b/tests/monitor/monit_apn_dns.py index 130bc4968..264dc1fad 100644 --- a/tests/monitor/monit_apn_dns.py +++ b/tests/monitor/monit_apn_dns.py @@ -84,13 +84,21 @@ def run(parameter): {"query_field_key": "apn", "query_value": parameter['test_apn']} ] } - # 创建 if parameter["initiation_method"] == "ui": - ui_client = UIClient() - rules_tuple, ui_error = ui_client.create_rules(policy_configuration) - if len(ui_error) > 0: - return ui_error + ui_client = UIClient(parameter) + created_object_code = ui_client.create_objects(policy_configuration) + if created_object_code != 200: + return "Fail to create object." + objects_tuple, searched_object_code = ui_client.search_objects(policy_configuration, "name") + if searched_object_code != 200: + return "Fail to search object." + created_rule_code = ui_client.create_rules(policy_configuration) + if created_rule_code != 200: + return "Fail to create rule." + rules_tuple, searched_rule_code = ui_client.search_rules(policy_configuration, "name") + if searched_rule_code != 200: + return "Fail to search rule." elif parameter["initiation_method"] == "api": api_client = APIClient(parameter) # {uuid, type}, i.e., {"12341-232-a21", "ip"} diff --git a/tests/monitor/monit_neg_srcip_ssl_hit_no.py b/tests/monitor/monit_neg_srcip_ssl_hit_no.py index f87b503ff..1a523e3c3 100644 --- a/tests/monitor/monit_neg_srcip_ssl_hit_no.py +++ b/tests/monitor/monit_neg_srcip_ssl_hit_no.py @@ -91,7 +91,7 @@ def run(parameter): traffic_generation = { "tool": "ssl", # or trex/http - "command": "curl -kv https://www.youtube.com" + "command": "curl -kv https://www.youtube.com" } verification_result = { diff --git a/tests/monitor/monit_srcip_appgroup_ssl.py b/tests/monitor/monit_srcip_appgroup_ssl.py index db43a6c42..03dfb4d1b 100644 --- a/tests/monitor/monit_srcip_appgroup_ssl.py +++ b/tests/monitor/monit_srcip_appgroup_ssl.py @@ -52,15 +52,16 @@ def run(parameter): "attribute_name": "ATTR_APP_ID", "type": "application", "statistics_option": "brief", + "member_type": "subordinate", "name": "monitor_application_group", - "included_sub_object_uuids": [ + "included_sub_objects": [ { "attribute_name": "ATTR_APP_ID", "type": "application", "items": ["ssl"], } ], - "excluded_sub_object_uuids": [ + "excluded_sub_objects": [ { "attribute_name": "ATTR_APP_ID", "type": "application", diff --git a/tests/monitor/monit_srcip_appgroup_ssl_verify_exclude_app.py b/tests/monitor/monit_srcip_appgroup_ssl_verify_exclude_app.py index 3111e088e..0a2a7d00b 100644 --- a/tests/monitor/monit_srcip_appgroup_ssl_verify_exclude_app.py +++ b/tests/monitor/monit_srcip_appgroup_ssl_verify_exclude_app.py @@ -52,15 +52,16 @@ def run(parameter): "attribute_name": "ATTR_APP_ID", "type": "application", "statistics_option": "brief", + "member_type": "subordinate", "name": "monitor_application_group", - "included_sub_object_uuids": [ + "included_sub_objects": [ { "attribute_name": "ATTR_APP_ID", "type": "application", "items": ["ssl"], } ], - "excluded_sub_object_uuids": [ + "excluded_sub_objects": [ { "attribute_name": "ATTR_APP_ID", "type": "application", @@ -87,7 +88,7 @@ def run(parameter): } traffic_generation = { - "tool": "ssl", # or trex/http + "tool": "http", # or trex/http "command": "curl -kv http://www.yumi.com" } diff --git a/tests/monitor/monit_srcip_dns_pre_qname_mirror_on.py b/tests/monitor/monit_srcip_dns_pre_qname_mirror_on.py index 8938e918a..48fe55ea2 100644 --- a/tests/monitor/monit_srcip_dns_pre_qname_mirror_on.py +++ b/tests/monitor/monit_srcip_dns_pre_qname_mirror_on.py @@ -136,13 +136,7 @@ def run(parameter): # 获取当前时间 utc_tz = pytz.timezone('UTC') current_utc_time = datetime.now(utc_tz) - # print(current_utc_time) - # 减去 10 秒 - # adjusted_time = current_utc_time - timedelta(seconds=25) - # start_time = adjusted_time.strftime('%Y-%m-%dT%H:%M:%SZ') - # print(start_time) start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') - print(start_time) # 触发流量 traffic_result = generator.run(policy_configuration, traffic_generation) diff --git a/tests/security/sec_allow_subid_ssl_substr_fqdn_substr_cn_substr_san.py b/tests/security/sec_allow_subid_ssl_substr_fqdn_substr_cn_substr_san.py index d2c26cc53..4d6d9b6d1 100644 --- a/tests/security/sec_allow_subid_ssl_substr_fqdn_substr_cn_substr_san.py +++ b/tests/security/sec_allow_subid_ssl_substr_fqdn_substr_cn_substr_san.py @@ -72,7 +72,7 @@ def run(parameter): ] }, { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SSL_CN", @@ -89,7 +89,7 @@ def run(parameter): ] }, { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SSL_SAN", diff --git a/tests/security/sec_deny_extip_substr_fqdn_http_block_403responseprofile.py b/tests/security/sec_deny_extip_substr_fqdn_http_block_403responseprofile.py index c3f42cd6e..2a146165f 100644 --- a/tests/security/sec_deny_extip_substr_fqdn_http_block_403responseprofile.py +++ b/tests/security/sec_deny_extip_substr_fqdn_http_block_403responseprofile.py @@ -74,7 +74,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 403, "html_profile": { "name": "test", diff --git a/tests/security/sec_deny_extip_substr_fqdn_http_block_403responsetext.py b/tests/security/sec_deny_extip_substr_fqdn_http_block_403responsetext.py index e35769502..6852a09e2 100644 --- a/tests/security/sec_deny_extip_substr_fqdn_http_block_403responsetext.py +++ b/tests/security/sec_deny_extip_substr_fqdn_http_block_403responsetext.py @@ -74,7 +74,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 403, "message": "deny_autest_403", "packet_capture": { diff --git a/tests/security/sec_deny_extip_substr_fqdn_http_block_404responseprofile.py b/tests/security/sec_deny_extip_substr_fqdn_http_block_404responseprofile.py index 453b995cd..29cc302fa 100644 --- a/tests/security/sec_deny_extip_substr_fqdn_http_block_404responseprofile.py +++ b/tests/security/sec_deny_extip_substr_fqdn_http_block_404responseprofile.py @@ -74,7 +74,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 404, "html_profile": { "name": "test", diff --git a/tests/security/sec_deny_extip_substr_fqdn_http_block_404responsetext.py b/tests/security/sec_deny_extip_substr_fqdn_http_block_404responsetext.py index f26cb6a3a..eeacc3969 100644 --- a/tests/security/sec_deny_extip_substr_fqdn_http_block_404responsetext.py +++ b/tests/security/sec_deny_extip_substr_fqdn_http_block_404responsetext.py @@ -74,7 +74,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 404, "message": "deny_autest_404", "packet_capture": { diff --git a/tests/security/sec_deny_extip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_403_profile.py b/tests/security/sec_deny_extip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_403_profile.py index a5463f2fa..d8dd88a96 100644 --- a/tests/security/sec_deny_extip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_403_profile.py +++ b/tests/security/sec_deny_extip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_403_profile.py @@ -112,7 +112,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 403, "html_profile": { "name": "test", diff --git a/tests/security/sec_deny_extip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_404_profile.py b/tests/security/sec_deny_extip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_404_profile.py index 701e152c9..7e4802298 100644 --- a/tests/security/sec_deny_extip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_404_profile.py +++ b/tests/security/sec_deny_extip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_404_profile.py @@ -112,7 +112,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 404, "html_profile": { "name": "test", diff --git a/tests/security/sec_deny_intip_substr_fqdn_http_block_403_text.py b/tests/security/sec_deny_intip_substr_fqdn_http_block_403_text.py index 9e818391e..4ae7f5422 100644 --- a/tests/security/sec_deny_intip_substr_fqdn_http_block_403_text.py +++ b/tests/security/sec_deny_intip_substr_fqdn_http_block_403_text.py @@ -74,15 +74,13 @@ def run(parameter): } ], "action_parameter": { - "action_parameter": { - "sub_action": "alert", + "sub_action": "blcok", "code": 403, - "message": "deny_autest_403", + "message": "deny_autest_404", "packet_capture": { "enable": 0 }, "send_icmp_unreachable": 0 - }, }, "is_enabled": 1, "log_option": "metadata", diff --git a/tests/security/sec_deny_intip_substr_fqdn_http_block_404_text.py b/tests/security/sec_deny_intip_substr_fqdn_http_block_404_text.py index c364757e6..2ea10e0ea 100644 --- a/tests/security/sec_deny_intip_substr_fqdn_http_block_404_text.py +++ b/tests/security/sec_deny_intip_substr_fqdn_http_block_404_text.py @@ -74,7 +74,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "blcok", "code": 404, "message": "deny_autest_404", "packet_capture": { diff --git a/tests/security/sec_deny_intip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_403_profile.py b/tests/security/sec_deny_intip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_403_profile.py index fb6706eb7..259a3da40 100644 --- a/tests/security/sec_deny_intip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_403_profile.py +++ b/tests/security/sec_deny_intip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_403_profile.py @@ -112,7 +112,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 403, "html_profile": { "name": "test", diff --git a/tests/security/sec_deny_intip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_403_text.py b/tests/security/sec_deny_intip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_403_text.py index 8f44f370e..c9d4eaf9d 100644 --- a/tests/security/sec_deny_intip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_403_text.py +++ b/tests/security/sec_deny_intip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_403_text.py @@ -112,15 +112,13 @@ def run(parameter): } ], "action_parameter": { - "action_parameter": { - "sub_action": "alert", + "sub_action": "blcok", "code": 403, - "message": "deny_autest_403", + "message": "deny_autest_404", "packet_capture": { "enable": 0 }, "send_icmp_unreachable": 0 - }, }, "is_enabled": 1, "log_option": "metadata", diff --git a/tests/security/sec_deny_intip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_404_profile.py b/tests/security/sec_deny_intip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_404_profile.py index d34ec4a43..bdc08b473 100644 --- a/tests/security/sec_deny_intip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_404_profile.py +++ b/tests/security/sec_deny_intip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_404_profile.py @@ -112,7 +112,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 404, "html_profile": { "name": "test", diff --git a/tests/security/sec_deny_intip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_404_text.py b/tests/security/sec_deny_intip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_404_text.py index 4deab4457..dc1a481fe 100644 --- a/tests/security/sec_deny_intip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_404_text.py +++ b/tests/security/sec_deny_intip_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_404_text.py @@ -112,7 +112,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 404, "message": "deny_autest_404", "packet_capture": { diff --git a/tests/security/sec_deny_negate_srcip_http_block_403_responseprofile_hit_no.py b/tests/security/sec_deny_negate_srcip_http_block_403_responseprofile_hit_no.py index 4115774e3..fabc9f519 100644 --- a/tests/security/sec_deny_negate_srcip_http_block_403_responseprofile_hit_no.py +++ b/tests/security/sec_deny_negate_srcip_http_block_403_responseprofile_hit_no.py @@ -57,7 +57,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 403, "html_profile": { "name": "test", diff --git a/tests/security/sec_deny_negate_srcip_http_block_403_responseprofile_hit_yes.py b/tests/security/sec_deny_negate_srcip_http_block_403_responseprofile_hit_yes.py index 689b42323..099dd8bc4 100644 --- a/tests/security/sec_deny_negate_srcip_http_block_403_responseprofile_hit_yes.py +++ b/tests/security/sec_deny_negate_srcip_http_block_403_responseprofile_hit_yes.py @@ -57,7 +57,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 403, "html_profile": { "name": "test", diff --git a/tests/security/sec_deny_negate_srcip_http_block_403_responsetext_hit_no.py b/tests/security/sec_deny_negate_srcip_http_block_403_responsetext_hit_no.py index 2c2fe7f66..ce9c59d22 100644 --- a/tests/security/sec_deny_negate_srcip_http_block_403_responsetext_hit_no.py +++ b/tests/security/sec_deny_negate_srcip_http_block_403_responsetext_hit_no.py @@ -57,7 +57,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 403, "message": "deny_autest_403", "packet_capture": { diff --git a/tests/security/sec_deny_negate_srcip_http_block_403_responsetext_hit_yes.py b/tests/security/sec_deny_negate_srcip_http_block_403_responsetext_hit_yes.py index dfb0b6e72..c25dc54cb 100644 --- a/tests/security/sec_deny_negate_srcip_http_block_403_responsetext_hit_yes.py +++ b/tests/security/sec_deny_negate_srcip_http_block_403_responsetext_hit_yes.py @@ -57,7 +57,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 403, "message": "deny_autest_403", "packet_capture": { diff --git a/tests/security/sec_deny_negate_srcip_http_block_404_responseprofile_hit_no.py b/tests/security/sec_deny_negate_srcip_http_block_404_responseprofile_hit_no.py index 24c3c56b0..d1c44fc91 100644 --- a/tests/security/sec_deny_negate_srcip_http_block_404_responseprofile_hit_no.py +++ b/tests/security/sec_deny_negate_srcip_http_block_404_responseprofile_hit_no.py @@ -57,7 +57,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 404, "html_profile": { "name": "test", diff --git a/tests/security/sec_deny_negate_srcip_http_block_404_responseprofile_hit_yes.py b/tests/security/sec_deny_negate_srcip_http_block_404_responseprofile_hit_yes.py index cbbbf4fa1..83df3362c 100644 --- a/tests/security/sec_deny_negate_srcip_http_block_404_responseprofile_hit_yes.py +++ b/tests/security/sec_deny_negate_srcip_http_block_404_responseprofile_hit_yes.py @@ -57,7 +57,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 404, "html_profile": { "name": "test", diff --git a/tests/security/sec_deny_negate_srcip_http_block_404_text_hit_no.py b/tests/security/sec_deny_negate_srcip_http_block_404_text_hit_no.py index f25b3d6a4..62f5b841f 100644 --- a/tests/security/sec_deny_negate_srcip_http_block_404_text_hit_no.py +++ b/tests/security/sec_deny_negate_srcip_http_block_404_text_hit_no.py @@ -57,7 +57,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 404, "message": "deny_autest_404", "packet_capture": { diff --git a/tests/security/sec_deny_negate_srcip_http_block_404_text_hit_yes.py b/tests/security/sec_deny_negate_srcip_http_block_404_text_hit_yes.py index 227a05b28..81b8a06ef 100644 --- a/tests/security/sec_deny_negate_srcip_http_block_404_text_hit_yes.py +++ b/tests/security/sec_deny_negate_srcip_http_block_404_text_hit_yes.py @@ -57,7 +57,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 404, "message": "deny_autest_404", "packet_capture": { diff --git a/tests/security/sec_deny_pn_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_403_profile.py b/tests/security/sec_deny_pn_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_403_profile.py index 8e7c0c730..2ba794586 100644 --- a/tests/security/sec_deny_pn_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_403_profile.py +++ b/tests/security/sec_deny_pn_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_403_profile.py @@ -112,7 +112,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 403, "html_profile": { "name": "test", @@ -164,6 +164,10 @@ def run(parameter): objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") if len(api_error) > 0: return api_error diff --git a/tests/security/sec_deny_pn_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_404_profile.py b/tests/security/sec_deny_pn_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_404_profile.py index 8bc7e36a7..aed192917 100644 --- a/tests/security/sec_deny_pn_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_404_profile.py +++ b/tests/security/sec_deny_pn_substr_fqdn_http_substr_url_substr_reqheader_by_ua_block_404_profile.py @@ -112,7 +112,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 404, "html_profile": { "name": "test", @@ -123,7 +123,7 @@ def run(parameter): "enable": 0 }, "send_icmp_unreachable": 0 - }, + }, "is_enabled": 1, "log_option": "metadata", } @@ -164,6 +164,10 @@ def run(parameter): objects_tuple, api_error = api_client.create_objects(policy_configuration) if len(api_error) > 0: return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") if len(api_error) > 0: return api_error diff --git a/tests/security/sec_deny_signature_common_app_id_default.py b/tests/security/sec_deny_signature_common_app_id_default.py index 457722c11..1167e740a 100644 --- a/tests/security/sec_deny_signature_common_app_id_default.py +++ b/tests/security/sec_deny_signature_common_app_id_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_signature_common_port_app_default.py b/tests/security/sec_deny_signature_common_port_app_default.py index 815a2f615..3f27d561a 100644 --- a/tests/security/sec_deny_signature_common_port_app_default.py +++ b/tests/security/sec_deny_signature_common_port_app_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_signature_dns_qry_name_default.py b/tests/security/sec_deny_signature_dns_qry_name_default.py index 82ba05826..c84e73ece 100644 --- a/tests/security/sec_deny_signature_dns_qry_name_default.py +++ b/tests/security/sec_deny_signature_dns_qry_name_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_signature_http_request_full_uri_default.py b/tests/security/sec_deny_signature_http_request_full_uri_default.py index 89dd94011..71e07c8b7 100644 --- a/tests/security/sec_deny_signature_http_request_full_uri_default.py +++ b/tests/security/sec_deny_signature_http_request_full_uri_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_signature_http_request_header_default.py b/tests/security/sec_deny_signature_http_request_header_default.py index 58d5abdaa..376cbc5a8 100644 --- a/tests/security/sec_deny_signature_http_request_header_default.py +++ b/tests/security/sec_deny_signature_http_request_header_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_signature_http_response_header_default.py b/tests/security/sec_deny_signature_http_response_header_default.py index b705071d8..2e7693104 100644 --- a/tests/security/sec_deny_signature_http_response_header_default.py +++ b/tests/security/sec_deny_signature_http_response_header_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_signature_ip_dst_default.py b/tests/security/sec_deny_signature_ip_dst_default.py index 3d85361b1..f64200037 100644 --- a/tests/security/sec_deny_signature_ip_dst_default.py +++ b/tests/security/sec_deny_signature_ip_dst_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_signature_ip_proto_default.py b/tests/security/sec_deny_signature_ip_proto_default.py index 864207bcd..c69a9755e 100644 --- a/tests/security/sec_deny_signature_ip_proto_default.py +++ b/tests/security/sec_deny_signature_ip_proto_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_signature_ip_src_default.py b/tests/security/sec_deny_signature_ip_src_default.py index f4b05f5cd..e65d27f16 100644 --- a/tests/security/sec_deny_signature_ip_src_default.py +++ b/tests/security/sec_deny_signature_ip_src_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_signature_ssl_analysis_ja3_default.py b/tests/security/sec_deny_signature_ssl_analysis_ja3_default.py index 0197ed2e1..3245e0a00 100644 --- a/tests/security/sec_deny_signature_ssl_analysis_ja3_default.py +++ b/tests/security/sec_deny_signature_ssl_analysis_ja3_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_signature_ssl_analysis_ja3s_default.py b/tests/security/sec_deny_signature_ssl_analysis_ja3s_default.py index 35e11ad4d..39753fa8d 100644 --- a/tests/security/sec_deny_signature_ssl_analysis_ja3s_default.py +++ b/tests/security/sec_deny_signature_ssl_analysis_ja3s_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_signature_ssl_analysis_sni_absent_default.py b/tests/security/sec_deny_signature_ssl_analysis_sni_absent_default.py index 0492fe2d5..5af3458ea 100644 --- a/tests/security/sec_deny_signature_ssl_analysis_sni_absent_default.py +++ b/tests/security/sec_deny_signature_ssl_analysis_sni_absent_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_signature_ssl_handshake_certificate_algorithm_id_default.py b/tests/security/sec_deny_signature_ssl_handshake_certificate_algorithm_id_default.py index cdd1e1043..023da3b2b 100644 --- a/tests/security/sec_deny_signature_ssl_handshake_certificate_algorithm_id_default.py +++ b/tests/security/sec_deny_signature_ssl_handshake_certificate_algorithm_id_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_signature_ssl_handshake_certificate_algorithm_identifier_default.py b/tests/security/sec_deny_signature_ssl_handshake_certificate_algorithm_identifier_default.py index b5bac97d3..093137a5f 100644 --- a/tests/security/sec_deny_signature_ssl_handshake_certificate_algorithm_identifier_default.py +++ b/tests/security/sec_deny_signature_ssl_handshake_certificate_algorithm_identifier_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_signature_ssl_handshake_certificate_issuer_common_name_default.py b/tests/security/sec_deny_signature_ssl_handshake_certificate_issuer_common_name_default.py index 394d76db6..efc9df8af 100644 --- a/tests/security/sec_deny_signature_ssl_handshake_certificate_issuer_common_name_default.py +++ b/tests/security/sec_deny_signature_ssl_handshake_certificate_issuer_common_name_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_signature_ssl_handshake_certificate_issuer_country_name_default.py b/tests/security/sec_deny_signature_ssl_handshake_certificate_issuer_country_name_default.py index a3a1dd29a..2d520dfe3 100644 --- a/tests/security/sec_deny_signature_ssl_handshake_certificate_issuer_country_name_default.py +++ b/tests/security/sec_deny_signature_ssl_handshake_certificate_issuer_country_name_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_signature_ssl_handshake_certificate_issuer_organization_name_default.py b/tests/security/sec_deny_signature_ssl_handshake_certificate_issuer_organization_name_default.py index 59a48d8f9..f18eda15a 100644 --- a/tests/security/sec_deny_signature_ssl_handshake_certificate_issuer_organization_name_default.py +++ b/tests/security/sec_deny_signature_ssl_handshake_certificate_issuer_organization_name_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_signature_ssl_handshake_certificate_not_valid_default.py b/tests/security/sec_deny_signature_ssl_handshake_certificate_not_valid_default.py index e9a4d177b..af5aed24b 100644 --- a/tests/security/sec_deny_signature_ssl_handshake_certificate_not_valid_default.py +++ b/tests/security/sec_deny_signature_ssl_handshake_certificate_not_valid_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_signature_ssl_handshake_certificate_subject_common_name_default.py b/tests/security/sec_deny_signature_ssl_handshake_certificate_subject_common_name_default.py index b82948f4f..0378e3738 100644 --- a/tests/security/sec_deny_signature_ssl_handshake_certificate_subject_common_name_default.py +++ b/tests/security/sec_deny_signature_ssl_handshake_certificate_subject_common_name_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_signature_ssl_handshake_certificate_subject_country_name_default.py b/tests/security/sec_deny_signature_ssl_handshake_certificate_subject_country_name_default.py index dac71ffef..4cb33949f 100644 --- a/tests/security/sec_deny_signature_ssl_handshake_certificate_subject_country_name_default.py +++ b/tests/security/sec_deny_signature_ssl_handshake_certificate_subject_country_name_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_signature_ssl_handshake_certificate_subject_organization_name_default.py b/tests/security/sec_deny_signature_ssl_handshake_certificate_subject_organization_name_default.py index 98acbc6d6..0f9a9d3f5 100644 --- a/tests/security/sec_deny_signature_ssl_handshake_certificate_subject_organization_name_default.py +++ b/tests/security/sec_deny_signature_ssl_handshake_certificate_subject_organization_name_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_signature_tcp_payload_signature_default.py b/tests/security/sec_deny_signature_tcp_payload_signature_default.py index 36ee63695..8e3fa48a5 100644 --- a/tests/security/sec_deny_signature_tcp_payload_signature_default.py +++ b/tests/security/sec_deny_signature_tcp_payload_signature_default.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_dns_default.py b/tests/security/sec_deny_srcip_dns_default.py index 636c29074..5edd115a9 100644 --- a/tests/security/sec_deny_srcip_dns_default.py +++ b/tests/security/sec_deny_srcip_dns_default.py @@ -1,145 +1,191 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_redirect_qtype_A_atype_A_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [], - "sub_action_override": False, - "sub_action": [], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + } + ], + "action_parameter": { + "sub_action": "default", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "timed out", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.example.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.example.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "timed out", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_drop.py b/tests/security/sec_deny_srcip_dns_drop.py index d8dd99dde..3bca3f3e9 100644 --- a/tests/security/sec_deny_srcip_dns_drop.py +++ b/tests/security/sec_deny_srcip_dns_drop.py @@ -1,152 +1,193 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": os.path.splitext(os.path.basename(__file__))[0], - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - { - "type": "drop", - "send_tcp_rst": False, - "drop_packet": 0, - "send_icmp_unreachable": False - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 0, + "send_icmp_unreachable": 0, + "after_n_packets": 0 }, - "profile": [], - "expected_return": "timed out", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.example.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.example.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "timed out", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_pre_qname_drop.py b/tests/security/sec_deny_srcip_dns_pre_qname_drop.py index 01e7b134f..71bfbe026 100644 --- a/tests/security/sec_deny_srcip_dns_pre_qname_drop.py +++ b/tests/security/sec_deny_srcip_dns_pre_qname_drop.py @@ -1,168 +1,212 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_pre_qname_drop", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "www.facebook*" - } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "drop", - "send_tcp_rst": False, - "drop_packet": 0, - "send_icmp_unreachable": False - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^www.facebook", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 0, + "send_icmp_unreachable": 0, + "after_n_packets": 0 }, - "profile": [], - "expected_return": "timed out", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "timed out", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_a_atype_a_profile.py b/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_a_atype_a_profile.py index 187646cd8..7fa81e11d 100644 --- a/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_a_atype_a_profile.py +++ b/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_a_atype_a_profile.py @@ -1,184 +1,237 @@ # -*- coding: UTF-8 -*- -import time import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_pre_qname_redirect_qtype_a_atype_a_profile", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^www.facebook", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, + "resolution": [ { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ + "qtype": "A", + "answer": [ { - "item_operation": "add", - "item_type": "qname", - "item_value": "www.facebook*" + "atype": "A", + "record_profile": { + "name": "auto_dns_record", + "type": "A", + "description": "auto_dns_record", + "values": [{"value": "1.1.1.1"}] + }, + "selected_num": 1, + "ttl": { + "min": 300, + "max": 300 } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "A", - "answer":[ - { - "atype": "A", - "answer_value_type": "Profile", - "profile_name": "sec_dns_type_A", - "ttl": "300-333" - } - ] } ] } ], - "packet_capture": [] }, - "profile": [ - { - "name": "sec_dns_type_A", - "type": "A", - "items": ["1.1.1.1"] - } - ], - "expected_return": "1.1.1.1", - "counters": {"hits": 2}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "1.1.1.1", + "expected_metric": {"hits": 2}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_a_atype_a_text.py b/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_a_atype_a_text.py index 76d82e5a3..810b678c7 100644 --- a/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_a_atype_a_text.py +++ b/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_a_atype_a_text.py @@ -1,178 +1,225 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_pre_qname_redirect_qtype_a_atype_a_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^www.facebook", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "resolution":[ { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + "qtype": "A", + "answer":[ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], + "atype": "A", + "value": "1.1.1.1", + "ttl": { + "min":300, + "max":333 + } } ] } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "www.facebook*" - } ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "A", - "answer":[ - { - "atype": "A", - "answer_value_type": "TEXT", - "answer_value": "1.1.1.1", - "ttl": "300-333" - } - ] - } - ] - } - ], - "packet_capture": [] + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "1.1.1.1", - "counters": {"hits": 2}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "1.1.1.1", + "expected_metric": {"hits": 2}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_a_atype_cname_profile.py b/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_a_atype_cname_profile.py index 474bb878b..421ce8cb4 100644 --- a/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_a_atype_cname_profile.py +++ b/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_a_atype_cname_profile.py @@ -1,184 +1,237 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_pre_qname_redirect_qtype_a_atype_cname_profile", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^www.facebook", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, + "resolution": [ { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ + "qtype": "A", + "answer": [ { - "item_operation": "add", - "item_type": "qname", - "item_value": "www.facebook*" + "atype": "CNAME", + "record_profile": { + "name": "auto_dns_record", + "type": "CNAME", + "description": "auto_dns_record", + "values": [{"value": "aaa.bbb.ccc"}] + }, + "selected_num": 1, + "ttl": { + "min": 300, + "max": 300 } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "A", - "answer":[ - { - "atype": "CNAME", - "answer_value_type": "Profile", - "profile_name": "sec_dns_type_cname", - "ttl": "300-333" - } - ] } ] } ], - "packet_capture": [] }, - "profile": [ - { - "name": "sec_dns_type_cname", - "type": "CNAME", - "items": ["aaa.bbb.ccc"] - } - ], - "expected_return": "aaa.bbb.ccc", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "aaa.bbb.ccc", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_a_atype_cname_text.py b/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_a_atype_cname_text.py index 90c72097c..67aa43d48 100644 --- a/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_a_atype_cname_text.py +++ b/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_a_atype_cname_text.py @@ -1,178 +1,225 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_pre_qname_redirect_qtype_a_atype_cname_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^www.facebook", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "resolution":[ { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + "qtype": "A", + "answer":[ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], + "atype": "CNAME", + "value": "aaa.bbb.ccc", + "ttl": { + "min":300, + "max":333 + } } ] } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "www.facebook*" - } ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "A", - "answer":[ - { - "atype": "CNAME", - "answer_value_type": "TEXT", - "answer_value": "aaa.bbb.ccc", - "ttl": "300-333" - } - ] - } - ] - } - ], - "packet_capture": [] + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "aaa.bbb.ccc", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "aaa.bbb.ccc", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_aaaa_atype_aaaa_profile.py b/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_aaaa_atype_aaaa_profile.py index 9bb49acf6..5be9ae1fc 100644 --- a/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_aaaa_atype_aaaa_profile.py +++ b/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_aaaa_atype_aaaa_profile.py @@ -1,184 +1,237 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_aaaa_profile", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^star-mini.c10r.facebook", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, + "resolution": [ { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ + "qtype": "AAAA", + "answer": [ { - "item_operation": "add", - "item_type": "qname", - "item_value": "star-mini.c10r.facebook*" + "atype": "AAAA", + "record_profile": { + "name": "auto_dns_record", + "type": "AAAA", + "description": "auto_dns_record", + "values": [{"value": "1::1:1:1"}] + }, + "selected_num": 1, + "ttl": { + "min": 300, + "max": 300 } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "AAAA", - "answer":[ - { - "atype": "AAAA", - "answer_value_type": "Profile", - "profile_name": "sec_dns_type_AAAA", - "ttl": "300-333" - } - ] } ] } ], - "packet_capture": [] }, - "profile": [ - { - "name": "sec_dns_type_AAAA", - "type": "AAAA", - "items": ["1::1:1:1"] - } - ], - "expected_return": "1::1:1:1", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "1::1:1:1", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_aaaa_atype_aaaa_text.py b/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_aaaa_atype_aaaa_text.py index 5385968f9..5203988f3 100644 --- a/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_aaaa_atype_aaaa_text.py +++ b/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_aaaa_atype_aaaa_text.py @@ -1,178 +1,225 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_aaaa_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^star-mini.c10r.facebook", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "resolution":[ { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + "qtype": "AAAA", + "answer":[ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], + "atype": "AAAA", + "value": "1::1:1:1", + "ttl": { + "min":300, + "max":333 + } } ] } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "star-mini.c10r.facebook*" - } ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "AAAA", - "answer":[ - { - "atype": "AAAA", - "answer_value_type": "TEXT", - "answer_value": "1::1:1:1", - "ttl": "300-333" - } - ] - } - ] - } - ], - "packet_capture": [] + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "1::1:1:1", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "1::1:1:1", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_aaaa_atype_cname_profile.py b/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_aaaa_atype_cname_profile.py index 54a55b620..deb08a427 100644 --- a/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_aaaa_atype_cname_profile.py +++ b/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_aaaa_atype_cname_profile.py @@ -1,184 +1,237 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_cname_profile", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^star-mini.c10r.facebook", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, + "resolution": [ { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ + "qtype": "AAAA", + "answer": [ { - "item_operation": "add", - "item_type": "qname", - "item_value": "star-mini.c10r.facebook*" + "atype": "CNAME", + "record_profile": { + "name": "auto_dns_record", + "type": "CNAME", + "description": "auto_dns_record", + "values": [{"value": "aaa.bbb.ccc"}] + }, + "selected_num": 1, + "ttl": { + "min": 300, + "max": 300 } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "AAAA", - "answer":[ - { - "atype": "CNAME", - "answer_value_type": "Profile", - "profile_name": "sec_dns_type_cname", - "ttl": "300-333" - } - ] } ] } ], - "packet_capture": [] }, - "profile": [ - { - "name": "sec_dns_type_cname", - "type": "CNAME", - "items": ["aaa.bbb.ccc"] - } - ], - "expected_return": "aaa.bbb.ccc", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "aaa.bbb.ccc", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_aaaa_atype_cname_text.py b/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_aaaa_atype_cname_text.py index 9b251ff62..7c53e5b8a 100644 --- a/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_aaaa_atype_cname_text.py +++ b/tests/security/sec_deny_srcip_dns_pre_qname_redirect_qtype_aaaa_atype_cname_text.py @@ -1,178 +1,225 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_pre_qname_redirect_qtype_aaaa_atype_cname_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^star-mini.c10r.facebook", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "resolution":[ { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + "qtype": "AAAA", + "answer":[ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], + "atype": "CNAME", + "value": "aaa.bbb.ccc", + "ttl": { + "min":300, + "max":333 + } } ] } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "star-mini.c10r.facebook*" - } ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "AAAA", - "answer":[ - { - "atype": "CNAME", - "answer_value_type": "TEXT", - "answer_value": "aaa.bbb.ccc", - "ttl": "300-333" - } - ] - } - ] - } - ], - "packet_capture": [] + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "aaa.bbb.ccc", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "aaa.bbb.ccc", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_pre_qname_tamper.py b/tests/security/sec_deny_srcip_dns_pre_qname_tamper.py index be0619834..9146dce9c 100644 --- a/tests/security/sec_deny_srcip_dns_pre_qname_tamper.py +++ b/tests/security/sec_deny_srcip_dns_pre_qname_tamper.py @@ -1,165 +1,211 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_pre_qname_tamper", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "www.facebook*" - } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "tamper" - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^www.facebook", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "tamper", + "packet_capture": { + "enable": 0 + }, + "tamper_mode": "complete", + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "SERVFAIL", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "SERVFAIL", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_rate_high.py b/tests/security/sec_deny_srcip_dns_rate_high.py index 1c250b770..6e7da887d 100644 --- a/tests/security/sec_deny_srcip_dns_rate_high.py +++ b/tests/security/sec_deny_srcip_dns_rate_high.py @@ -1,150 +1,195 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": os.path.splitext(os.path.basename(__file__))[0], - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - { - "type": "rate_limit", - "rate_value": "100000", - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + } + ], + "action_parameter": { + "sub_action": "rate_limit", + "bps": 10000000, + "limitUnit": "Kbps", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 0, + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "www.example.com", - "counters": {"hits": 2}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.example.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.example.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "timed out", + "expected_metric": {"hits": 2}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.example.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_rate_low.py b/tests/security/sec_deny_srcip_dns_rate_low.py index e85f5962a..3582406ed 100644 --- a/tests/security/sec_deny_srcip_dns_rate_low.py +++ b/tests/security/sec_deny_srcip_dns_rate_low.py @@ -1,150 +1,195 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_redirect_qtype_A_atype_A_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - { - "type": "rate_limit", - "rate_value": "0.01", - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + } + ], + "action_parameter": { + "sub_action": "rate_limit", + "bps": 10, + "limitUnit": "Kbps", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 0, + "send_icmp_unreachable": 0 }, - "profile": [], - "expected_return": "timed out", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.example.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "timed out", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_redirect_qtype_a_atype_a_profile.py b/tests/security/sec_deny_srcip_dns_redirect_qtype_a_atype_a_profile.py index da18ed6d6..42a269310 100644 --- a/tests/security/sec_deny_srcip_dns_redirect_qtype_a_atype_a_profile.py +++ b/tests/security/sec_deny_srcip_dns_redirect_qtype_a_atype_a_profile.py @@ -1,168 +1,219 @@ # -*- coding: UTF-8 -*- -import time import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_redirect_qtype_a_atype_a_profile", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, + "resolution": [ { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + "qtype": "A", + "answer": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], + "atype": "A", + "record_profile": { + "name": "auto_dns_record", + "type": "A", + "description": "auto_dns_record", + "values": [{"value": "1.1.1.1"}] + }, + "selected_num": 1, + "ttl": { + "min": 300, + "max": 300 } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "A", - "answer":[ - { - "atype": "A", - "answer_value_type": "Profile", - "profile_name": "sec_dns_type_A", - "ttl": "300-333" - } - ] } ] } ], - "packet_capture": [] - }, - "profile": [ - { - "name": "sec_dns_type_A", - "type": "A", - "items": ["1.1.1.1"] - } - ], - "expected_return": "1.1.1.1", - "counters": {"hits": 2}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.example.com -timeout=1 8.8.8.8" }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "1.1.1.1", + "expected_metric": {"hits": 2}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_redirect_qtype_a_atype_a_text.py b/tests/security/sec_deny_srcip_dns_redirect_qtype_a_atype_a_text.py index 1d736152f..82a6aade2 100644 --- a/tests/security/sec_deny_srcip_dns_redirect_qtype_a_atype_a_text.py +++ b/tests/security/sec_deny_srcip_dns_redirect_qtype_a_atype_a_text.py @@ -1,162 +1,207 @@ # -*- coding: UTF-8 -*- -import time import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_redirect_qtype_a_atype_a_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "resolution":[ { - "type": "redirect", - "resolution":[ + "qtype": "A", + "answer":[ { - "qtype": "A", - "answer":[ - { - "atype": "A", - "answer_value_type": "TEXT", - "answer_value": "1.1.1.1", - "ttl": "300-333" - } - ] + "atype": "A", + "value": "1.1.1.1", + "ttl": { + "min":300, + "max":333 + } } ] } - ], - "packet_capture": [] - }, - "profile": [], - "expected_return": "1.1.1.1", - "counters": {"hits": 2}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.example.com -timeout=1 8.8.8.8" + ], + "send_icmp_unreachable": 0, }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "1.1.1.1", + "expected_metric": {"hits": 2}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_redirect_qtype_a_atype_cname_profile.py b/tests/security/sec_deny_srcip_dns_redirect_qtype_a_atype_cname_profile.py index fae0c8166..7546ee38b 100644 --- a/tests/security/sec_deny_srcip_dns_redirect_qtype_a_atype_cname_profile.py +++ b/tests/security/sec_deny_srcip_dns_redirect_qtype_a_atype_cname_profile.py @@ -1,168 +1,219 @@ # -*- coding: UTF-8 -*- -import time import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_redirect_qtype_a_atype_cname_profile", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, + "resolution": [ { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + "qtype": "A", + "answer": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], + "atype": "CNAME", + "record_profile": { + "name": "auto_dns_record", + "type": "CNAME", + "description": "auto_dns_record", + "values": [{"value": "aaa.bbb.ccc"}] + }, + "selected_num": 1, + "ttl": { + "min": 300, + "max": 300 } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "A", - "answer":[ - { - "atype": "CNAME", - "answer_value_type": "Profile", - "profile_name": "sec_dns_type_cname", - "ttl": "300-333" - } - ] } ] } ], - "packet_capture": [] - }, - "profile": [ - { - "name": "sec_dns_type_cname", - "type": "CNAME", - "items": ["aaa.bbb.ccc"] - } - ], - "expected_return": "aaa.bbb.ccc", - "counters": {"hits": 2}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.example.com -timeout=1 8.8.8.8" }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.example.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "aaa.bbb.ccc", + "expected_metric": {"hits": 2}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.example.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_redirect_qtype_a_atype_cname_text.py b/tests/security/sec_deny_srcip_dns_redirect_qtype_a_atype_cname_text.py index 1011bd377..b746ed138 100644 --- a/tests/security/sec_deny_srcip_dns_redirect_qtype_a_atype_cname_text.py +++ b/tests/security/sec_deny_srcip_dns_redirect_qtype_a_atype_cname_text.py @@ -1,162 +1,207 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_redirect_qtype_a_atype_cname_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "resolution":[ { - "type": "redirect", - "resolution":[ + "qtype": "A", + "answer":[ { - "qtype": "A", - "answer":[ - { - "atype": "CNAME", - "answer_value_type": "TEXT", - "answer_value": "aaa.bbb.ccc", - "ttl": "300-333" - } - ] + "atype": "CNAME", + "value": "aaa.bbb.ccc", + "ttl": { + "min":300, + "max":333 + } } ] } - ], - "packet_capture": [] - }, - "profile": [], - "expected_return": "aaa.bbb.ccc", - "counters": {"hits": 2}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.example.com -timeout=1 8.8.8.8" + ], + "send_icmp_unreachable": 0, }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.example.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "aaa.bbb.ccc", + "expected_metric": {"hits": 2}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.example.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_redirect_qtype_aaaa_atype_aaaa_profile.py b/tests/security/sec_deny_srcip_dns_redirect_qtype_aaaa_atype_aaaa_profile.py index df2bf5eb4..e0d922917 100644 --- a/tests/security/sec_deny_srcip_dns_redirect_qtype_aaaa_atype_aaaa_profile.py +++ b/tests/security/sec_deny_srcip_dns_redirect_qtype_aaaa_atype_aaaa_profile.py @@ -1,168 +1,219 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_redirect_qtype_aaaa_atype_aaaa_profile", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, + "resolution": [ { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + "qtype": "AAAA", + "answer": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], + "atype": "AAAA", + "record_profile": { + "name": "auto_dns_record", + "type": "AAAA", + "description": "auto_dns_record", + "values": [{"value": "1::1:1:1"}] + }, + "selected_num": 1, + "ttl": { + "min": 300, + "max": 300 } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "AAAA", - "answer":[ - { - "atype": "AAAA", - "answer_value_type": "Profile", - "profile_name": "sec_dns_type_AAAA", - "ttl": "300-333" - } - ] } ] } ], - "packet_capture": [] - }, - "profile": [ - { - "name": "sec_dns_type_AAAA", - "type": "AAAA", - "items": ["1::1:1:1"] - } - ], - "expected_return": "1::1:1:1", - "counters": {"hits": 2}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.example.com -timeout=1 8.8.8.8" }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.example.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "1::1:1:1", + "expected_metric": {"hits": 2}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.example.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_redirect_qtype_aaaa_atype_aaaa_text.py b/tests/security/sec_deny_srcip_dns_redirect_qtype_aaaa_atype_aaaa_text.py index 583b5e32f..8397bbbf8 100644 --- a/tests/security/sec_deny_srcip_dns_redirect_qtype_aaaa_atype_aaaa_text.py +++ b/tests/security/sec_deny_srcip_dns_redirect_qtype_aaaa_atype_aaaa_text.py @@ -1,162 +1,207 @@ # -*- coding: UTF-8 -*- -import time import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_redirect_qtype_aaaa_atype_aaaa_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "resolution":[ { - "type": "redirect", - "resolution":[ + "qtype": "AAAA", + "answer":[ { - "qtype": "AAAA", - "answer":[ - { - "atype": "AAAA", - "answer_value_type": "TEXT", - "answer_value": "1::1:1:1", - "ttl": "300-333" - } - ] + "atype": "AAAA", + "value": "1::1:1:1", + "ttl": { + "min":300, + "max":333 + } } ] } - ], - "packet_capture": [] - }, - "profile": [], - "expected_return": "1::1:1:1", - "counters": {"hits": 2}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.example.com -timeout=1 8.8.8.8" + ], + "send_icmp_unreachable": 0, }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.example.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "1::1:1:1", + "expected_metric": {"hits": 2}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.example.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_redirect_qtype_aaaa_atype_cname_profile.py b/tests/security/sec_deny_srcip_dns_redirect_qtype_aaaa_atype_cname_profile.py index 238771b46..770fc35ad 100644 --- a/tests/security/sec_deny_srcip_dns_redirect_qtype_aaaa_atype_cname_profile.py +++ b/tests/security/sec_deny_srcip_dns_redirect_qtype_aaaa_atype_cname_profile.py @@ -1,168 +1,219 @@ # -*- coding: UTF-8 -*- -import time import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_redirect_qtype_aaaa_atype_cname_profile", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, + "resolution": [ { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + "qtype": "AAAA", + "answer": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], + "atype": "CNAME", + "record_profile": { + "name": "auto_dns_record", + "type": "CNAME", + "description": "auto_dns_record", + "values": [{"value": "aaa.bbb.ccc"}] + }, + "selected_num": 1, + "ttl": { + "min": 300, + "max": 300 } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "AAAA", - "answer":[ - { - "atype": "CNAME", - "answer_value_type": "Profile", - "profile_name": "sec_dns_type_cname", - "ttl": "300-333" - } - ] } ] } ], - "packet_capture": [] - }, - "profile": [ - { - "name": "sec_dns_type_cname", - "type": "CNAME", - "items": ["aaa.bbb.ccc"] - } - ], - "expected_return": "aaa.bbb.ccc", - "counters": {"hits": 2}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.example.com -timeout=1 8.8.8.8" }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.example.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "aaa.bbb.ccc", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.example.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_redirect_qtype_aaaa_atype_cname_text.py b/tests/security/sec_deny_srcip_dns_redirect_qtype_aaaa_atype_cname_text.py index 8618e458b..35d877f32 100644 --- a/tests/security/sec_deny_srcip_dns_redirect_qtype_aaaa_atype_cname_text.py +++ b/tests/security/sec_deny_srcip_dns_redirect_qtype_aaaa_atype_cname_text.py @@ -1,162 +1,225 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_redirect_qtype_aaaa_atype_cname_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^star-mini.c10r.facebook", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "resolution":[ { - "type": "redirect", - "resolution":[ + "qtype": "AAAA", + "answer":[ { - "qtype": "AAAA", - "answer":[ - { - "atype": "CNAME", - "answer_value_type": "TEXT", - "answer_value": "aaa.bbb.ccc", - "ttl": "300-333" - } - ] + "atype": "CNAME", + "value": "aaa.bbb.ccc", + "ttl": { + "min":300, + "max":333 + } } ] } - ], - "packet_capture": [] - }, - "profile": [], - "expected_return": "aaa.bbb.ccc", - "counters": {"hits": 2}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.example.com -timeout=1 8.8.8.8" + ], + "send_icmp_unreachable": 0, }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.example.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "aaa.bbb.ccc", + "expected_metric": {"hits": 2}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.example.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_sub_qname_drop.py b/tests/security/sec_deny_srcip_dns_sub_qname_drop.py index 2231e1972..5c6cecd4e 100644 --- a/tests/security/sec_deny_srcip_dns_sub_qname_drop.py +++ b/tests/security/sec_deny_srcip_dns_sub_qname_drop.py @@ -1,168 +1,212 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_sub_qname_drop", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "facebook.com" - } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "drop", - "send_tcp_rst": False, - "drop_packet": 0, - "send_icmp_unreachable": False - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "facebook.com", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 0, + "send_icmp_unreachable": 0, + "after_n_packets": 0 }, - "profile": [], - "expected_return": "timed out", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "timed out", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_a_atype_a_profile.py b/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_a_atype_a_profile.py index 861fc4587..8e80f4990 100644 --- a/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_a_atype_a_profile.py +++ b/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_a_atype_a_profile.py @@ -1,184 +1,237 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_sub_qname_redirect_qtype_a_atype_a_profile", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "facebook.com", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, + "resolution": [ { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ + "qtype": "A", + "answer": [ { - "item_operation": "add", - "item_type": "qname", - "item_value": "facebook.com" + "atype": "A", + "record_profile": { + "name": "auto_dns_record", + "type": "A", + "description": "auto_dns_record", + "values": [{"value": "1.1.1.1"}] + }, + "selected_num": 1, + "ttl": { + "min": 300, + "max": 300 } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "A", - "answer":[ - { - "atype": "A", - "answer_value_type": "Profile", - "profile_name": "sec_dns_type_A", - "ttl": "300-333" - } - ] } ] } ], - "packet_capture": [] }, - "profile": [ - { - "name": "sec_dns_type_A", - "type": "A", - "items": ["1.1.1.1"] - } - ], - "expected_return": "1.1.1.1", - "counters": {"hits": 2}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "1.1.1.1", + "expected_metric": {"hits": 2}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_a_atype_a_text.py b/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_a_atype_a_text.py index 59387e850..8d306951c 100644 --- a/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_a_atype_a_text.py +++ b/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_a_atype_a_text.py @@ -1,178 +1,225 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_sub_qname_redirect_qtype_a_atype_a_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "facebook.com", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "resolution":[ { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + "qtype": "A", + "answer":[ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], + "atype": "A", + "value": "1.1.1.1", + "ttl": { + "min":300, + "max":333 + } } ] } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "facebook.com" - } ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "A", - "answer":[ - { - "atype": "A", - "answer_value_type": "TEXT", - "answer_value": "1.1.1.1", - "ttl": "300-333" - } - ] - } - ] - } - ], - "packet_capture": [] + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "1.1.1.1", - "counters": {"hits": 2}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "1.1.1.1", + "expected_metric": {"hits": 2}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_a_atype_cname_profile.py b/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_a_atype_cname_profile.py index 1564f34d6..1613a843e 100644 --- a/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_a_atype_cname_profile.py +++ b/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_a_atype_cname_profile.py @@ -1,184 +1,237 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_sub_qname_redirect_qtype_a_atype_cname_profile", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "facebook.com", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, + "resolution": [ { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ + "qtype": "A", + "answer": [ { - "item_operation": "add", - "item_type": "qname", - "item_value": "facebook.com" + "atype": "CNAME", + "record_profile": { + "name": "auto_dns_record", + "type": "CNAME", + "description": "auto_dns_record", + "values": [{"value": "aaa.bbb.ccc"}] + }, + "selected_num": 1, + "ttl": { + "min": 300, + "max": 300 } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "A", - "answer":[ - { - "atype": "CNAME", - "answer_value_type": "Profile", - "profile_name": "sec_dns_type_cname", - "ttl": "300-333" - } - ] } ] } ], - "packet_capture": [] }, - "profile": [ - { - "name": "sec_dns_type_cname", - "type": "CNAME", - "items": ["aaa.bbb.ccc"] - } - ], - "expected_return": "aaa.bbb.ccc", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "aaa.bbb.ccc", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_a_atype_cname_text.py b/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_a_atype_cname_text.py index 8fd43946a..20c88d236 100644 --- a/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_a_atype_cname_text.py +++ b/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_a_atype_cname_text.py @@ -1,178 +1,225 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_sub_qname_redirect_qtype_a_atype_cname_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "facebook.com", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "resolution":[ { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + "qtype": "A", + "answer":[ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], + "atype": "CNAME", + "value": "aaa.bbb.ccc", + "ttl": { + "min":300, + "max":333 + } } ] } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "facebook.com" - } ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "A", - "answer":[ - { - "atype": "CNAME", - "answer_value_type": "TEXT", - "answer_value": "aaa.bbb.ccc", - "ttl": "300-333" - } - ] - } - ] - } - ], - "packet_capture": [] + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "aaa.bbb.ccc", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "aaa.bbb.ccc", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_aaaa_profile.py b/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_aaaa_profile.py index 4950cef2d..d717619d3 100644 --- a/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_aaaa_profile.py +++ b/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_aaaa_profile.py @@ -1,184 +1,237 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_aaaa_profile", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "example.com", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, + "resolution": [ { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ + "qtype": "AAAA", + "answer": [ { - "item_operation": "add", - "item_type": "qname", - "item_value": "example.com" + "atype": "AAAA", + "record_profile": { + "name": "auto_dns_record", + "type": "AAAA", + "description": "auto_dns_record", + "values": [{"value": "1::1:1:1"}] + }, + "selected_num": 1, + "ttl": { + "min": 300, + "max": 300 } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "AAAA", - "answer":[ - { - "atype": "AAAA", - "answer_value_type": "Profile", - "profile_name": "sec_dns_type_AAAA", - "ttl": "300-333" - } - ] } ] } ], - "packet_capture": [] }, - "profile": [ - { - "name": "sec_dns_type_AAAA", - "type": "AAAA", - "items": ["1::1:1:1"] - } - ], - "expected_return": "1::1:1:1", - "counters": {"hits": 2}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.example.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.example.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.example.com.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "1::1:1:1", + "expected_metric": {"hits": 2}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.example.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_aaaa_text.py b/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_aaaa_text.py index 7eab37e92..354d47c3c 100644 --- a/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_aaaa_text.py +++ b/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_aaaa_text.py @@ -1,178 +1,231 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_aaaa_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "example.com", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, + "resolution": [ { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + "qtype": "AAAA", + "answer": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], + "atype": "AAAA", + "record_profile": { + "name": "auto_dns_record", + "type": "AAAA", + "description": "auto_dns_record", + "values": [{"value": "1::1:1:1"}] + }, + "selected_num": 1, + "ttl": { + "min": 300, + "max": 300 } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "example.com" - } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "AAAA", - "answer":[ - { - "atype": "AAAA", - "answer_value_type": "TEXT", - "answer_value": "1::1:1:1", - "ttl": "300-333" - } - ] } ] } ], - "packet_capture": [] - }, - "profile": [], - "expected_return": "1::1:1:1", - "counters": {"hits": 2}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.example.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.example.com -timeout=1 8.8.8.8" }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.example.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "1::1:1:1", + "expected_metric": {"hits": 2}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.example.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_cname_profile.py b/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_cname_profile.py index 44d2c43c8..f5e91fd04 100644 --- a/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_cname_profile.py +++ b/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_cname_profile.py @@ -1,184 +1,237 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_cname_profile", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "example.com", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, + "resolution": [ { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ + "qtype": "AAAA", + "answer": [ { - "item_operation": "add", - "item_type": "qname", - "item_value": "example.com" + "atype": "CNAME", + "record_profile": { + "name": "auto_dns_record", + "type": "CNAME", + "description": "auto_dns_record", + "values": [{"value": "aaa.bbb.ccc"}] + }, + "selected_num": 1, + "ttl": { + "min": 300, + "max": 300 } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "AAAA", - "answer":[ - { - "atype": "CNAME", - "answer_value_type": "Profile", - "profile_name": "sec_dns_type_cname", - "ttl": "300-333" - } - ] } ] } ], - "packet_capture": [] }, - "profile": [ - { - "name": "sec_dns_type_cname", - "type": "CNAME", - "items": ["aaa.bbb.ccc"] - } - ], - "expected_return": "aaa.bbb.ccc", - "counters": {"hits": 2}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.example.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.example.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.example.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "aaa.bbb.ccc", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.example.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_cname_text.py b/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_cname_text.py index 454bf72b3..bc974215a 100644 --- a/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_cname_text.py +++ b/tests/security/sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_cname_text.py @@ -1,178 +1,225 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_sub_qname_redirect_qtype_aaaa_atype_cname_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "example.com", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "resolution":[ { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + "qtype": "AAAA", + "answer":[ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], + "atype": "CNAME", + "value": "aaa.bbb.ccc", + "ttl": { + "min":300, + "max":333 + } } ] } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "example.com" - } ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "AAAA", - "answer":[ - { - "atype": "CNAME", - "answer_value_type": "TEXT", - "answer_value": "aaa.bbb.ccc", - "ttl": "300-333" - } - ] - } - ] - } - ], - "packet_capture": [] + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "aaa.bbb.ccc", - "counters": {"hits": 2}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.example.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.example.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.example.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "aaa.bbb.ccc", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.example.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_sub_qname_tamper.py b/tests/security/sec_deny_srcip_dns_sub_qname_tamper.py index 72f25ceb2..9b8428c36 100644 --- a/tests/security/sec_deny_srcip_dns_sub_qname_tamper.py +++ b/tests/security/sec_deny_srcip_dns_sub_qname_tamper.py @@ -1,165 +1,211 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_sub_qname_tamper", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "facebook.com" - } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "tamper" - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "facebook.com", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "tamper", + "packet_capture": { + "enable": 0 + }, + "tamper_mode": "complete", + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "SERVFAIL", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "SERVFAIL", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_suff_qname_drop.py b/tests/security/sec_deny_srcip_dns_suff_qname_drop.py index 653bacfdc..b6edd1406 100644 --- a/tests/security/sec_deny_srcip_dns_suff_qname_drop.py +++ b/tests/security/sec_deny_srcip_dns_suff_qname_drop.py @@ -1,168 +1,212 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_suff_qname_drop", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "*facebook.com" - } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "drop", - "send_tcp_rst": False, - "drop_packet": 0, - "send_icmp_unreachable": False - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "facebook.com$", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 0, + "send_icmp_unreachable": 0, + "after_n_packets": 0 }, - "profile": [], - "expected_return": "timed out", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "timed out", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_a_atype_a_profile.py b/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_a_atype_a_profile.py index f8545aadc..24685f27e 100644 --- a/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_a_atype_a_profile.py +++ b/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_a_atype_a_profile.py @@ -1,184 +1,237 @@ # -*- coding: UTF-8 -*- -import time import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_suff_qname_redirect_qtype_a_atype_a_profile", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "facebook.com$", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, + "resolution": [ { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ + "qtype": "A", + "answer": [ { - "item_operation": "add", - "item_type": "qname", - "item_value": "*facebook.com" + "atype": "A", + "record_profile": { + "name": "auto_dns_record", + "type": "A", + "description": "auto_dns_record", + "values": [{"value": "1.1.1.1"}] + }, + "selected_num": 1, + "ttl": { + "min": 300, + "max": 300 } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "A", - "answer":[ - { - "atype": "A", - "answer_value_type": "Profile", - "profile_name": "sec_dns_type_A", - "ttl": "300-333" - } - ] } ] } ], - "packet_capture": [] }, - "profile": [ - { - "name": "sec_dns_type_A", - "type": "A", - "items": ["1.1.1.1"] - } - ], - "expected_return": "1.1.1.1", - "counters": {"hits": 2}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "1.1.1.1", + "expected_metric": {"hits": 2}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_a_atype_a_text.py b/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_a_atype_a_text.py index fc0273f9a..9f96e9b66 100644 --- a/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_a_atype_a_text.py +++ b/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_a_atype_a_text.py @@ -1,178 +1,225 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_suff_qname_redirect_qtype_a_atype_a_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "facebook.com$", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "resolution":[ { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + "qtype": "A", + "answer":[ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], + "atype": "A", + "value": "1.1.1.1", + "ttl": { + "min":300, + "max":333 + } } ] } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "*facebook.com" - } ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "A", - "answer":[ - { - "atype": "A", - "answer_value_type": "TEXT", - "answer_value": "1.1.1.1", - "ttl": "300-333" - } - ] - } - ] - } - ], - "packet_capture": [] + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "1.1.1.1", - "counters": {"hits": 2}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "1.1.1.1", + "expected_metric": {"hits": 2}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_a_atype_cname_profile.py b/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_a_atype_cname_profile.py index 2c5fa59f2..cd42e5b17 100644 --- a/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_a_atype_cname_profile.py +++ b/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_a_atype_cname_profile.py @@ -1,184 +1,237 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_suff_qname_redirect_qtype_a_atype_cname_profile", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "facebook.com$", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, + "resolution": [ { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ + "qtype": "A", + "answer": [ { - "item_operation": "add", - "item_type": "qname", - "item_value": "*facebook.com" + "atype": "CNAME", + "record_profile": { + "name": "auto_dns_record", + "type": "CNAME", + "description": "auto_dns_record", + "values": [{"value": "aaa.bbb.ccc"}] + }, + "selected_num": 1, + "ttl": { + "min": 300, + "max": 300 } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "A", - "answer":[ - { - "atype": "CNAME", - "answer_value_type": "Profile", - "profile_name": "sec_dns_type_cname", - "ttl": "300-333" - } - ] } ] } ], - "packet_capture": [] }, - "profile": [ - { - "name": "sec_dns_type_cname", - "type": "CNAME", - "items": ["aaa.bbb.ccc"] - } - ], - "expected_return": "aaa.bbb.ccc", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "aaa.bbb.ccc", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_a_atype_cname_text.py b/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_a_atype_cname_text.py index 16a143878..f6a458f9d 100644 --- a/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_a_atype_cname_text.py +++ b/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_a_atype_cname_text.py @@ -1,178 +1,225 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_suff_qname_redirect_qtype_a_atype_cname_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "facebook.com$", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "resolution":[ { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + "qtype": "A", + "answer":[ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], + "atype": "CNAME", + "value": "aaa.bbb.ccc", + "ttl": { + "min":300, + "max":333 + } } ] } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "*facebook.com" - } ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "A", - "answer":[ - { - "atype": "CNAME", - "answer_value_type": "TEXT", - "answer_value": "aaa.bbb.ccc", - "ttl": "300-333" - } - ] - } - ] - } - ], - "packet_capture": [] + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "aaa.bbb.ccc", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "aaa.bbb.ccc", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_aaaa_atype_aaaa_profile.py b/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_aaaa_atype_aaaa_profile.py index d6f6943e7..f3d7c7262 100644 --- a/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_aaaa_atype_aaaa_profile.py +++ b/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_aaaa_atype_aaaa_profile.py @@ -1,184 +1,237 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_suff_qname_redirect_qtype_aaaa_atype_aaaa_profile", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "c10r.facebook.com$", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, + "resolution": [ { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ + "qtype": "AAAA", + "answer": [ { - "item_operation": "add", - "item_type": "qname", - "item_value": "*c10r.facebook.com" + "atype": "AAAA", + "record_profile": { + "name": "auto_dns_record", + "type": "AAAA", + "description": "auto_dns_record", + "values": [{"value": "1::1:1:1"}] + }, + "selected_num": 1, + "ttl": { + "min": 300, + "max": 300 } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "AAAA", - "answer":[ - { - "atype": "AAAA", - "answer_value_type": "Profile", - "profile_name": "sec_dns_type_AAAA", - "ttl": "300-333" - } - ] } ] } ], - "packet_capture": [] }, - "profile": [ - { - "name": "sec_dns_type_AAAA", - "type": "AAAA", - "items": ["1::1:1:1"] - } - ], - "expected_return": "1::1:1:1", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "1::1:1:1", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_aaaa_atype_aaaa_text.py b/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_aaaa_atype_aaaa_text.py index 6bcf34a0f..1f4bd09aa 100644 --- a/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_aaaa_atype_aaaa_text.py +++ b/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_aaaa_atype_aaaa_text.py @@ -1,178 +1,225 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_suff_qname_redirect_qtype_aaaa_atype_aaaa_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "c10r.facebook.com$", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "resolution":[ { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + "qtype": "AAAA", + "answer":[ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], + "atype": "AAAA", + "value": "1::1:1:1", + "ttl": { + "min":300, + "max":333 + } } ] } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "*c10r.facebook.com" - } ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "AAAA", - "answer":[ - { - "atype": "AAAA", - "answer_value_type": "TEXT", - "answer_value": "1::1:1:1", - "ttl": "300-333" - } - ] - } - ] - } - ], - "packet_capture": [] + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "1::1:1:1", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "1::1:1:1", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_aaaa_atype_cname_profile.py b/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_aaaa_atype_cname_profile.py index db99d5dc4..d064cbd18 100644 --- a/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_aaaa_atype_cname_profile.py +++ b/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_aaaa_atype_cname_profile.py @@ -1,184 +1,237 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_suff_qname_redirect_qtype_aaaa_atype_cname_profile", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "c10r.facebook.com$", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, + "resolution": [ { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ + "qtype": "AAAA", + "answer": [ { - "item_operation": "add", - "item_type": "qname", - "item_value": "*c10r.facebook.com" + "atype": "CNAME", + "record_profile": { + "name": "auto_dns_record", + "type": "CNAME", + "description": "auto_dns_record", + "values": [{"value": "aaa.bbb.ccc"}] + }, + "selected_num": 1, + "ttl": { + "min": 300, + "max": 300 } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "AAAA", - "answer":[ - { - "atype": "CNAME", - "answer_value_type": "Profile", - "profile_name": "sec_dns_type_cname", - "ttl": "300-333" - } - ] } ] } ], - "packet_capture": [] }, - "profile": [ - { - "name": "sec_dns_type_cname", - "type": "CNAME", - "items": ["aaa.bbb.ccc"] - } - ], - "expected_return": "aaa.bbb.ccc", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "aaa.bbb.ccc", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_aaaa_atype_cname_text.py b/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_aaaa_atype_cname_text.py index 62dd8d2c0..7aba8f1c9 100644 --- a/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_aaaa_atype_cname_text.py +++ b/tests/security/sec_deny_srcip_dns_suff_qname_redirect_qtype_aaaa_atype_cname_text.py @@ -1,178 +1,225 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_suff_qname_redirect_qtype_aaaa_atype_cname_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "c10r.facebook.com$", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "resolution":[ { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + "qtype": "AAAA", + "answer":[ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], + "atype": "CNAME", + "value": "aaa.bbb.ccc", + "ttl": { + "min":300, + "max":333 + } } ] } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "*c10r.facebook.com" - } ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "AAAA", - "answer":[ - { - "atype": "CNAME", - "answer_value_type": "TEXT", - "answer_value": "aaa.bbb.ccc", - "ttl": "300-333" - } - ] - } - ] - } - ], - "packet_capture": [] + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "aaa.bbb.ccc", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "aaa.bbb.ccc", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_suff_qname_tamper.py b/tests/security/sec_deny_srcip_dns_suff_qname_tamper.py index ceeb695db..8361dd198 100644 --- a/tests/security/sec_deny_srcip_dns_suff_qname_tamper.py +++ b/tests/security/sec_deny_srcip_dns_suff_qname_tamper.py @@ -1,165 +1,211 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_suff_qname_tamper", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "*facebook.com" - } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "tamper" - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "facebook.com$", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "tamper", + "packet_capture": { + "enable": 0 + }, + "tamper_mode": "complete", + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "SERVFAIL", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "SERVFAIL", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_tamper.py b/tests/security/sec_deny_srcip_dns_tamper.py index 56d301c90..20191a276 100644 --- a/tests/security/sec_deny_srcip_dns_tamper.py +++ b/tests/security/sec_deny_srcip_dns_tamper.py @@ -1,149 +1,193 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_tamper", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - { - "type": "tamper" - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + } + ], + "action_parameter": { + "sub_action": "tamper", + "packet_capture": { + "enable": 0 + }, + "tamper_mode": "complete", + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "SERVFAIL", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.example.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "SERVFAIL", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_xly_qname_drop.py b/tests/security/sec_deny_srcip_dns_xly_qname_drop.py index 27f8ff20c..42fecda89 100644 --- a/tests/security/sec_deny_srcip_dns_xly_qname_drop.py +++ b/tests/security/sec_deny_srcip_dns_xly_qname_drop.py @@ -1,168 +1,210 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_xly_qname_drop", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "$www.facebook.com" - } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "drop", - "send_tcp_rst": False, - "drop_packet": 0, - "send_icmp_unreachable": False - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^www.facebook.com$", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "timed out", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "timed out", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_a_atype_a_profile.py b/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_a_atype_a_profile.py index 8e00059b0..bfb2e5a5f 100644 --- a/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_a_atype_a_profile.py +++ b/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_a_atype_a_profile.py @@ -1,184 +1,237 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_xly_qname_redirect_qtype_a_atype_a_profile", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^www.facebook.com$", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, + "resolution": [ { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ + "qtype": "A", + "answer": [ { - "item_operation": "add", - "item_type": "qname", - "item_value": "$www.facebook.com" + "atype": "A", + "record_profile": { + "name": "auto_dns_record", + "type": "A", + "description": "auto_dns_record", + "values": [{"value": "1.1.1.1"}] + }, + "selected_num": 1, + "ttl": { + "min": 300, + "max": 300 } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "A", - "answer":[ - { - "atype": "A", - "answer_value_type": "Profile", - "profile_name": "sec_dns_type_A", - "ttl": "300-333" - } - ] } ] } ], - "packet_capture": [] }, - "profile": [ - { - "name": "sec_dns_type_A", - "type": "A", - "items": ["1.1.1.1"] - } - ], - "expected_return": "1.1.1.1", - "counters": {"hits": 2}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "1.1.1.1", + "expected_metric": {"hits": 2}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_a_atype_a_text.py b/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_a_atype_a_text.py index a53b22e84..b6d5a2ece 100644 --- a/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_a_atype_a_text.py +++ b/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_a_atype_a_text.py @@ -1,178 +1,225 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_xly_qname_redirect_qtype_a_atype_a_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^www.facebook.com$", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "resolution":[ { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + "qtype": "A", + "answer":[ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], + "atype": "A", + "value": "1.1.1.1", + "ttl": { + "min":300, + "max":333 + } } ] } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "$www.facebook.com" - } ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "A", - "answer":[ - { - "atype": "A", - "answer_value_type": "TEXT", - "answer_value": "1.1.1.1", - "ttl": "300-333" - } - ] - } - ] - } - ], - "packet_capture": [] + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "1.1.1.1", - "counters": {"hits": 2}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "1.1.1.1", + "expected_metric": {"hits": 2}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_a_atype_cname_profile.py b/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_a_atype_cname_profile.py index d3500daa7..b397b1ef1 100644 --- a/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_a_atype_cname_profile.py +++ b/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_a_atype_cname_profile.py @@ -1,184 +1,237 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_xly_qname_redirect_qtype_a_atype_cname_profile", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^www.facebook.com$", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, + "resolution": [ { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ + "qtype": "A", + "answer": [ { - "item_operation": "add", - "item_type": "qname", - "item_value": "$www.facebook.com" + "atype": "CNAME", + "record_profile": { + "name": "auto_dns_record", + "type": "CNAME", + "description": "auto_dns_record", + "values": [{"value": "aaa.bbb.ccc"}] + }, + "selected_num": 1, + "ttl": { + "min": 300, + "max": 300 } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "A", - "answer":[ - { - "atype": "CNAME", - "answer_value_type": "Profile", - "profile_name": "sec_dns_type_cname", - "ttl": "300-333" - } - ] } ] } ], - "packet_capture": [] }, - "profile": [ - { - "name": "sec_dns_type_cname", - "type": "CNAME", - "items": ["aaa.bbb.ccc"] - } - ], - "expected_return": "aaa.bbb.ccc", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "aaa.bbb.ccc", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_a_atype_cname_text.py b/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_a_atype_cname_text.py index ca6c88252..a3912e24a 100644 --- a/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_a_atype_cname_text.py +++ b/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_a_atype_cname_text.py @@ -1,178 +1,225 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_xly_qname_redirect_qtype_a_atype_cname_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^www.facebook.com$", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "resolution":[ { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + "qtype": "A", + "answer":[ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], + "atype": "CNAME", + "value": "aaa.bbb.ccc", + "ttl": { + "min":300, + "max":333 + } } ] } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "$www.facebook.com" - } ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "A", - "answer":[ - { - "atype": "CNAME", - "answer_value_type": "TEXT", - "answer_value": "aaa.bbb.ccc", - "ttl": "300-333" - } - ] - } - ] - } - ], - "packet_capture": [] + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "aaa.bbb.ccc", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "aaa.bbb.ccc", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_aaaa_atype_aaaa_profile.py b/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_aaaa_atype_aaaa_profile.py index 5b64282c8..0753214f1 100644 --- a/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_aaaa_atype_aaaa_profile.py +++ b/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_aaaa_atype_aaaa_profile.py @@ -1,184 +1,237 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_xly_qname_redirect_qtype_aaaa_atype_aaaa_profile", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "$star-mini.c10r.facebook.com", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, + "resolution": [ { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ + "qtype": "AAAA", + "answer": [ { - "item_operation": "add", - "item_type": "qname", - "item_value": "$star-mini.c10r.facebook.com" + "atype": "AAAA", + "record_profile": { + "name": "auto_dns_record", + "type": "AAAA", + "description": "auto_dns_record", + "values": [{"value": "1::1:1:1"}] + }, + "selected_num": 1, + "ttl": { + "min": 300, + "max": 300 } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "AAAA", - "answer":[ - { - "atype": "AAAA", - "answer_value_type": "Profile", - "profile_name": "sec_dns_type_AAAA", - "ttl": "300-333" - } - ] } ] } ], - "packet_capture": [] }, - "profile": [ - { - "name": "sec_dns_type_AAAA", - "type": "AAAA", - "items": ["1::1:1:1"] - } - ], - "expected_return": "1::1:1:1", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "1::1:1:1", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_aaaa_atype_aaaa_text.py b/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_aaaa_atype_aaaa_text.py index 65b2ab724..eef4b3e55 100644 --- a/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_aaaa_atype_aaaa_text.py +++ b/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_aaaa_atype_aaaa_text.py @@ -1,178 +1,225 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_xly_qname_redirect_qtype_aaaa_atype_aaaa_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "$star-mini.c10r.facebook.com", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "resolution":[ { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + "qtype": "AAAA", + "answer":[ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], + "atype": "AAAA", + "value": "1::1:1:1", + "ttl": { + "min":300, + "max":333 + } } ] } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "$star-mini.c10r.facebook.com" - } ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "AAAA", - "answer":[ - { - "atype": "AAAA", - "answer_value_type": "TEXT", - "answer_value": "1::1:1:1", - "ttl": "300-333" - } - ] - } - ] - } - ], - "packet_capture": [] + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "1::1:1:1", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "1::1:1:1", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_aaaa_atype_cname_profile.py b/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_aaaa_atype_cname_profile.py index 9ba734815..2c6e14948 100644 --- a/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_aaaa_atype_cname_profile.py +++ b/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_aaaa_atype_cname_profile.py @@ -1,184 +1,237 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_xly_qname_redirect_qtype_aaaa_atype_cname_profile", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "$star-mini.c10r.facebook.com", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "send_icmp_unreachable": 0, + "resolution": [ { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ + "qtype": "AAAA", + "answer": [ { - "item_operation": "add", - "item_type": "qname", - "item_value": "$star-mini.c10r.facebook.com" + "atype": "CNAME", + "record_profile": { + "name": "auto_dns_record", + "type": "CNAME", + "description": "auto_dns_record", + "values": [{"value": "aaa.bbb.ccc"}] + }, + "selected_num": 1, + "ttl": { + "min": 300, + "max": 300 } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "AAAA", - "answer":[ - { - "atype": "CNAME", - "answer_value_type": "Profile", - "profile_name": "sec_dns_type_cname", - "ttl": "300-333" - } - ] } ] } ], - "packet_capture": [] }, - "profile": [ - { - "name": "sec_dns_type_cname", - "type": "CNAME", - "items": ["aaa.bbb.ccc"] - } - ], - "expected_return": "aaa.bbb.ccc", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "aaa.bbb.ccc", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_aaaa_atype_cname_text.py b/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_aaaa_atype_cname_text.py index f901a821a..79d32fc93 100644 --- a/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_aaaa_atype_cname_text.py +++ b/tests/security/sec_deny_srcip_dns_xly_qname_redirect_qtype_aaaa_atype_cname_text.py @@ -1,178 +1,225 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_xly_qname_redirect_qtype_aaaa_atype_cname_text", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "$star-mini.c10r.facebook.com", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "redirect", + "packet_capture": { + "enable": 0 + }, + "resolution":[ { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + "qtype": "AAAA", + "answer":[ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], + "atype": "CNAME", + "value": "aaa.bbb.ccc", + "ttl": { + "min":300, + "max":333 + } } ] } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "$star-mini.c10r.facebook.com" - } ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "redirect", - "resolution":[ - { - "qtype": "AAAA", - "answer":[ - { - "atype": "CNAME", - "answer_value_type": "TEXT", - "answer_value": "aaa.bbb.ccc", - "ttl": "300-333" - } - ] - } - ] - } - ], - "packet_capture": [] + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "aaa.bbb.ccc", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" + } + + verification_result = { + "excepted_traffic_result": "aaa.bbb.ccc", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "star-mini.c10r.facebook.com"} + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 1, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_dns_xly_qname_tamper.py b/tests/security/sec_deny_srcip_dns_xly_qname_tamper.py index 0fee80cf0..27d578af1 100644 --- a/tests/security/sec_deny_srcip_dns_xly_qname_tamper.py +++ b/tests/security/sec_deny_srcip_dns_xly_qname_tamper.py @@ -1,165 +1,211 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": "sec_deny_srcip_dns_xly_qname_tamper", - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dns", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_fqdn", - "object_type": "fqdn", - "item_operation": "add", - "select_type": False, - "negate": False, - "items": [ - { - "item_operation": "add", - "item_type": "qname", - "item_value": "$www.facebook.com" - } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "tamper" - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["dns"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_DNS_QNAME", + "type": "fqdn", + "member_type": "item", + "name": "test_dns_qname", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^www.facebook.com$", + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "tamper", + "packet_capture": { + "enable": 0 + }, + "tamper_mode": "complete", + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "SERVFAIL", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"server_ip", "query_value": "8.8.8.8"}, - {"query_field_key":"decoded_as", "query_value": "DNS"}, - {"query_field_key":"dns_qname", "query_value": "www.facebook.com"}], - "traffic": { - "protocol": "dns", - "type": "nslookup", - "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "dns", # or trex/http + "command": "nslookup www.facebook.com -timeout=1 8.8.8.8" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "SERVFAIL", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"server_ip", "query_value": "8.8.8.8"}, + {"query_field_key":"decoded_as", "query_value": "DNS"}, + {"query_field_key":"dns_qname", "query_value": "www.facebook.com"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_ftp_exactly_account_drop.py b/tests/security/sec_deny_srcip_ftp_exactly_account_drop.py index 21a658f9d..ec94d834d 100644 --- a/tests/security/sec_deny_srcip_ftp_exactly_account_drop.py +++ b/tests/security/sec_deny_srcip_ftp_exactly_account_drop.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_exactly_account_drop_rst.py b/tests/security/sec_deny_srcip_ftp_exactly_account_drop_rst.py index 65ab313fe..bb910b082 100644 --- a/tests/security/sec_deny_srcip_ftp_exactly_account_drop_rst.py +++ b/tests/security/sec_deny_srcip_ftp_exactly_account_drop_rst.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_exactly_account_rate_high.py b/tests/security/sec_deny_srcip_ftp_exactly_account_rate_high.py index a5d00878f..f966c24ea 100644 --- a/tests/security/sec_deny_srcip_ftp_exactly_account_rate_high.py +++ b/tests/security/sec_deny_srcip_ftp_exactly_account_rate_high.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_exactly_account_rate_low.py b/tests/security/sec_deny_srcip_ftp_exactly_account_rate_low.py index 3de3c4514..98ab6db15 100644 --- a/tests/security/sec_deny_srcip_ftp_exactly_account_rate_low.py +++ b/tests/security/sec_deny_srcip_ftp_exactly_account_rate_low.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_exactly_account_tamper.py b/tests/security/sec_deny_srcip_ftp_exactly_account_tamper.py index 9809c1b60..01c4150f5 100644 --- a/tests/security/sec_deny_srcip_ftp_exactly_account_tamper.py +++ b/tests/security/sec_deny_srcip_ftp_exactly_account_tamper.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_exactly_url_drop.py b/tests/security/sec_deny_srcip_ftp_exactly_url_drop.py index 95aa01b33..cf4ab843a 100644 --- a/tests/security/sec_deny_srcip_ftp_exactly_url_drop.py +++ b/tests/security/sec_deny_srcip_ftp_exactly_url_drop.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_exactly_url_drop_rst.py b/tests/security/sec_deny_srcip_ftp_exactly_url_drop_rst.py index 95aa01b33..cf4ab843a 100644 --- a/tests/security/sec_deny_srcip_ftp_exactly_url_drop_rst.py +++ b/tests/security/sec_deny_srcip_ftp_exactly_url_drop_rst.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_exactly_url_rate_high.py b/tests/security/sec_deny_srcip_ftp_exactly_url_rate_high.py index e0beb508e..a929ae9f7 100644 --- a/tests/security/sec_deny_srcip_ftp_exactly_url_rate_high.py +++ b/tests/security/sec_deny_srcip_ftp_exactly_url_rate_high.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_exactly_url_rate_low.py b/tests/security/sec_deny_srcip_ftp_exactly_url_rate_low.py index cb5a37c79..19a6a3bb0 100644 --- a/tests/security/sec_deny_srcip_ftp_exactly_url_rate_low.py +++ b/tests/security/sec_deny_srcip_ftp_exactly_url_rate_low.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_exactly_url_tamper.py b/tests/security/sec_deny_srcip_ftp_exactly_url_tamper.py index 792bf3989..83887a44c 100644 --- a/tests/security/sec_deny_srcip_ftp_exactly_url_tamper.py +++ b/tests/security/sec_deny_srcip_ftp_exactly_url_tamper.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_pre_account_drop.py b/tests/security/sec_deny_srcip_ftp_pre_account_drop.py index 6cfc4cbcd..403b62626 100644 --- a/tests/security/sec_deny_srcip_ftp_pre_account_drop.py +++ b/tests/security/sec_deny_srcip_ftp_pre_account_drop.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_pre_account_drop_rst.py b/tests/security/sec_deny_srcip_ftp_pre_account_drop_rst.py index 88bd0ea12..c27096650 100644 --- a/tests/security/sec_deny_srcip_ftp_pre_account_drop_rst.py +++ b/tests/security/sec_deny_srcip_ftp_pre_account_drop_rst.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_pre_account_rate_high.py b/tests/security/sec_deny_srcip_ftp_pre_account_rate_high.py index 8a273f696..2dde60c05 100644 --- a/tests/security/sec_deny_srcip_ftp_pre_account_rate_high.py +++ b/tests/security/sec_deny_srcip_ftp_pre_account_rate_high.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", @@ -242,7 +242,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_pre_account_rate_low.py b/tests/security/sec_deny_srcip_ftp_pre_account_rate_low.py index 2227a4be3..7ae812f59 100644 --- a/tests/security/sec_deny_srcip_ftp_pre_account_rate_low.py +++ b/tests/security/sec_deny_srcip_ftp_pre_account_rate_low.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_pre_account_tamper.py b/tests/security/sec_deny_srcip_ftp_pre_account_tamper.py index 5280aafb5..7452cbcf4 100644 --- a/tests/security/sec_deny_srcip_ftp_pre_account_tamper.py +++ b/tests/security/sec_deny_srcip_ftp_pre_account_tamper.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_pre_url_drop.py b/tests/security/sec_deny_srcip_ftp_pre_url_drop.py index 798df2832..1379a5321 100644 --- a/tests/security/sec_deny_srcip_ftp_pre_url_drop.py +++ b/tests/security/sec_deny_srcip_ftp_pre_url_drop.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_pre_url_drop_rst.py b/tests/security/sec_deny_srcip_ftp_pre_url_drop_rst.py index 798df2832..1379a5321 100644 --- a/tests/security/sec_deny_srcip_ftp_pre_url_drop_rst.py +++ b/tests/security/sec_deny_srcip_ftp_pre_url_drop_rst.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_pre_url_rate_high.py b/tests/security/sec_deny_srcip_ftp_pre_url_rate_high.py index be76c8562..990b3c0a1 100644 --- a/tests/security/sec_deny_srcip_ftp_pre_url_rate_high.py +++ b/tests/security/sec_deny_srcip_ftp_pre_url_rate_high.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_pre_url_rate_low.py b/tests/security/sec_deny_srcip_ftp_pre_url_rate_low.py index d7bf81092..fac765229 100644 --- a/tests/security/sec_deny_srcip_ftp_pre_url_rate_low.py +++ b/tests/security/sec_deny_srcip_ftp_pre_url_rate_low.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_pre_url_tamper.py b/tests/security/sec_deny_srcip_ftp_pre_url_tamper.py index cac64d96c..9767212c5 100644 --- a/tests/security/sec_deny_srcip_ftp_pre_url_tamper.py +++ b/tests/security/sec_deny_srcip_ftp_pre_url_tamper.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_substr_account_drop.py b/tests/security/sec_deny_srcip_ftp_substr_account_drop.py index 9cdeebb88..28d41b8b1 100644 --- a/tests/security/sec_deny_srcip_ftp_substr_account_drop.py +++ b/tests/security/sec_deny_srcip_ftp_substr_account_drop.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_substr_account_drop_rst.py b/tests/security/sec_deny_srcip_ftp_substr_account_drop_rst.py index be330389f..3dd82cf57 100644 --- a/tests/security/sec_deny_srcip_ftp_substr_account_drop_rst.py +++ b/tests/security/sec_deny_srcip_ftp_substr_account_drop_rst.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_substr_account_rate_high.py b/tests/security/sec_deny_srcip_ftp_substr_account_rate_high.py index beb7c53b6..81272fd53 100644 --- a/tests/security/sec_deny_srcip_ftp_substr_account_rate_high.py +++ b/tests/security/sec_deny_srcip_ftp_substr_account_rate_high.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", @@ -242,7 +242,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_substr_account_rate_low.py b/tests/security/sec_deny_srcip_ftp_substr_account_rate_low.py index ff49c27c5..1d066db8f 100644 --- a/tests/security/sec_deny_srcip_ftp_substr_account_rate_low.py +++ b/tests/security/sec_deny_srcip_ftp_substr_account_rate_low.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_substr_account_tamper.py b/tests/security/sec_deny_srcip_ftp_substr_account_tamper.py index 130331283..88e146b7a 100644 --- a/tests/security/sec_deny_srcip_ftp_substr_account_tamper.py +++ b/tests/security/sec_deny_srcip_ftp_substr_account_tamper.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_substr_content_drop.py b/tests/security/sec_deny_srcip_ftp_substr_content_drop.py index 5e24ac380..2fe7bb01a 100644 --- a/tests/security/sec_deny_srcip_ftp_substr_content_drop.py +++ b/tests/security/sec_deny_srcip_ftp_substr_content_drop.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_substr_content_drop_rst.py b/tests/security/sec_deny_srcip_ftp_substr_content_drop_rst.py index 181c9d0c2..d1ffd568d 100644 --- a/tests/security/sec_deny_srcip_ftp_substr_content_drop_rst.py +++ b/tests/security/sec_deny_srcip_ftp_substr_content_drop_rst.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_substr_content_rate_high.py b/tests/security/sec_deny_srcip_ftp_substr_content_rate_high.py index e85a8090b..91762c967 100644 --- a/tests/security/sec_deny_srcip_ftp_substr_content_rate_high.py +++ b/tests/security/sec_deny_srcip_ftp_substr_content_rate_high.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_substr_content_rate_low.py b/tests/security/sec_deny_srcip_ftp_substr_content_rate_low.py index dc458a6d7..6b2996495 100644 --- a/tests/security/sec_deny_srcip_ftp_substr_content_rate_low.py +++ b/tests/security/sec_deny_srcip_ftp_substr_content_rate_low.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_substr_content_tamper.py b/tests/security/sec_deny_srcip_ftp_substr_content_tamper.py index 339b7f7c8..b3a20ab19 100644 --- a/tests/security/sec_deny_srcip_ftp_substr_content_tamper.py +++ b/tests/security/sec_deny_srcip_ftp_substr_content_tamper.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_substr_url_drop.py b/tests/security/sec_deny_srcip_ftp_substr_url_drop.py index 56956b8d0..52f8212e0 100644 --- a/tests/security/sec_deny_srcip_ftp_substr_url_drop.py +++ b/tests/security/sec_deny_srcip_ftp_substr_url_drop.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_substr_url_drop_rst.py b/tests/security/sec_deny_srcip_ftp_substr_url_drop_rst.py index 56956b8d0..52f8212e0 100644 --- a/tests/security/sec_deny_srcip_ftp_substr_url_drop_rst.py +++ b/tests/security/sec_deny_srcip_ftp_substr_url_drop_rst.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_substr_url_rate_high.py b/tests/security/sec_deny_srcip_ftp_substr_url_rate_high.py index fc945c912..c37bb36cf 100644 --- a/tests/security/sec_deny_srcip_ftp_substr_url_rate_high.py +++ b/tests/security/sec_deny_srcip_ftp_substr_url_rate_high.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_substr_url_rate_low.py b/tests/security/sec_deny_srcip_ftp_substr_url_rate_low.py index e64dca4ea..d64d3f1f7 100644 --- a/tests/security/sec_deny_srcip_ftp_substr_url_rate_low.py +++ b/tests/security/sec_deny_srcip_ftp_substr_url_rate_low.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_substr_url_tamper.py b/tests/security/sec_deny_srcip_ftp_substr_url_tamper.py index 327526f6d..c3c8e9343 100644 --- a/tests/security/sec_deny_srcip_ftp_substr_url_tamper.py +++ b/tests/security/sec_deny_srcip_ftp_substr_url_tamper.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_suff_account_drop.py b/tests/security/sec_deny_srcip_ftp_suff_account_drop.py index c1c302b81..7bec2ca07 100644 --- a/tests/security/sec_deny_srcip_ftp_suff_account_drop.py +++ b/tests/security/sec_deny_srcip_ftp_suff_account_drop.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_suff_account_drop_rst.py b/tests/security/sec_deny_srcip_ftp_suff_account_drop_rst.py index f4d737b22..2a2fc565c 100644 --- a/tests/security/sec_deny_srcip_ftp_suff_account_drop_rst.py +++ b/tests/security/sec_deny_srcip_ftp_suff_account_drop_rst.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_suff_account_rate_high.py b/tests/security/sec_deny_srcip_ftp_suff_account_rate_high.py index 2a107ba4a..ac7d8ec7f 100644 --- a/tests/security/sec_deny_srcip_ftp_suff_account_rate_high.py +++ b/tests/security/sec_deny_srcip_ftp_suff_account_rate_high.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_suff_account_rate_low.py b/tests/security/sec_deny_srcip_ftp_suff_account_rate_low.py index b238839ad..80721f304 100644 --- a/tests/security/sec_deny_srcip_ftp_suff_account_rate_low.py +++ b/tests/security/sec_deny_srcip_ftp_suff_account_rate_low.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_suff_account_tamper.py b/tests/security/sec_deny_srcip_ftp_suff_account_tamper.py index cc6289df4..ba6c5fa2b 100644 --- a/tests/security/sec_deny_srcip_ftp_suff_account_tamper.py +++ b/tests/security/sec_deny_srcip_ftp_suff_account_tamper.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_suff_url_drop.py b/tests/security/sec_deny_srcip_ftp_suff_url_drop.py index 1d166b551..d1daa751f 100644 --- a/tests/security/sec_deny_srcip_ftp_suff_url_drop.py +++ b/tests/security/sec_deny_srcip_ftp_suff_url_drop.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_suff_url_rate_high.py b/tests/security/sec_deny_srcip_ftp_suff_url_rate_high.py index a17c94ec7..4e5b3604f 100644 --- a/tests/security/sec_deny_srcip_ftp_suff_url_rate_high.py +++ b/tests/security/sec_deny_srcip_ftp_suff_url_rate_high.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_suff_url_rate_low.py b/tests/security/sec_deny_srcip_ftp_suff_url_rate_low.py index 89f759d68..b7868dc93 100644 --- a/tests/security/sec_deny_srcip_ftp_suff_url_rate_low.py +++ b/tests/security/sec_deny_srcip_ftp_suff_url_rate_low.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_suff_url_rst.py b/tests/security/sec_deny_srcip_ftp_suff_url_rst.py index 1d166b551..d1daa751f 100644 --- a/tests/security/sec_deny_srcip_ftp_suff_url_rst.py +++ b/tests/security/sec_deny_srcip_ftp_suff_url_rst.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_ftp_suff_url_tamper.py b/tests/security/sec_deny_srcip_ftp_suff_url_tamper.py index 4c3b7a611..d9f8d5f26 100644 --- a/tests/security/sec_deny_srcip_ftp_suff_url_tamper.py +++ b/tests/security/sec_deny_srcip_ftp_suff_url_tamper.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_http_alert_200_profile.py b/tests/security/sec_deny_srcip_http_alert_200_profile.py index 609e72883..66e151288 100644 --- a/tests/security/sec_deny_srcip_http_alert_200_profile.py +++ b/tests/security/sec_deny_srcip_http_alert_200_profile.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_http_alert_200_text.py b/tests/security/sec_deny_srcip_http_alert_200_text.py index 8e0f455b6..c7d3f9cd9 100644 --- a/tests/security/sec_deny_srcip_http_alert_200_text.py +++ b/tests/security/sec_deny_srcip_http_alert_200_text.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_http_alert_204.py b/tests/security/sec_deny_srcip_http_alert_204.py index 7fa2b456e..9dbc51a04 100644 --- a/tests/security/sec_deny_srcip_http_alert_204.py +++ b/tests/security/sec_deny_srcip_http_alert_204.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", diff --git a/tests/security/sec_deny_srcip_http_block_403_profile.py b/tests/security/sec_deny_srcip_http_block_403_profile.py index 7fa2b456e..a2df4abff 100644 --- a/tests/security/sec_deny_srcip_http_block_403_profile.py +++ b/tests/security/sec_deny_srcip_http_block_403_profile.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", @@ -74,8 +74,13 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", - "code": 204, + "sub_action": "block", + "code": 404, + "html_profile": { + "name": "test", + "format": "html", + "file_path": "Response-Pages_1.html" + }, "packet_capture": { "enable": 0 }, @@ -91,7 +96,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "204", + "excepted_traffic_result": "403", "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key":"server_fqdn", "query_value": "www.example.com"}, diff --git a/tests/security/sec_deny_srcip_http_block_403_text.py b/tests/security/sec_deny_srcip_http_block_403_text.py index d855a0055..d569cee41 100644 --- a/tests/security/sec_deny_srcip_http_block_403_text.py +++ b/tests/security/sec_deny_srcip_http_block_403_text.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", @@ -74,7 +74,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 403, "message": "deny_autest_403", "packet_capture": { diff --git a/tests/security/sec_deny_srcip_http_block_404_profile.py b/tests/security/sec_deny_srcip_http_block_404_profile.py index d61c31b94..ee861c486 100644 --- a/tests/security/sec_deny_srcip_http_block_404_profile.py +++ b/tests/security/sec_deny_srcip_http_block_404_profile.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", @@ -74,7 +74,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 404, "html_profile": { "name": "test", diff --git a/tests/security/sec_deny_srcip_http_block_404_text.py b/tests/security/sec_deny_srcip_http_block_404_text.py index 25205a161..f25792f34 100644 --- a/tests/security/sec_deny_srcip_http_block_404_text.py +++ b/tests/security/sec_deny_srcip_http_block_404_text.py @@ -28,7 +28,7 @@ def run(parameter): "action": "deny", "and_conditions": [ { - "negate_option": True, + "negate_option": False, "or_conditions": [ { "attribute_name": "ATTR_SOURCE_IP", @@ -74,7 +74,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 404, "message": "deny_autest_404", "packet_capture": { diff --git a/tests/security/sec_deny_srcip_http_pre_reqbody_drop.py b/tests/security/sec_deny_srcip_http_pre_reqbody_drop.py index 38c4fdf51..b5d70e72b 100644 --- a/tests/security/sec_deny_srcip_http_pre_reqbody_drop.py +++ b/tests/security/sec_deny_srcip_http_pre_reqbody_drop.py @@ -1,103 +1,100 @@ # -*- coding: UTF-8 -*- -import time import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": os.path.splitext(os.path.basename(__file__))[0], - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_keywords_reqbody", - "object_type": "keywords", - "item_operation": "add", - "select_type": False, - "negate": False, - "statistics": "None", - "item": [ - { - "item_operation": "add", - "item_type": "request_body", - "item_value": "TEXT", - "value": [ - "{\"requestbody\":\"test\",\"setcook\":\"\",\"contenttype\":\"\",\"responsebody\":\"\"}*" - ] - } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "drop", - "drop_packet": 0, - "send_tcp_rst": False, - "send_icmp_unreachable": False - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_REQ_BODY", + "type": "keyword", + "name": "sec_keyword", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^{\"requestbody\":\"test\",\"setcook\":\"\",\"contenttype\":\"\",\"responsebody\":\"\"}" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 0, + "send_icmp_unreachable": 0, + "after_n_packets": 0 }, - "profile": [], - "expected_return": "timed out", - "counters": {"hits": 1}, - "log_query_param": [ + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "curl --connect-timeout 10 -m 10 -H \"Content-Type:application/json;charset=UTF-8\" -X POST -d \"{\\\"requestbody\\\":\\\"test\\\",\\\"setcook\\\":\\\"\\\",\\\"contenttype\\\":\\\"\\\",\\\"responsebody\\\":\\\"\\\"}\" -kv --user-agent \"Wget (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36\" http://open.node.com:180/go" + } + + verification_result = { + "excepted_traffic_result": "timed out", + "expected_metric": {"hits": 1}, + "expected_log": [ {"query_field_key":"client_ip", "query_value":parameter['test_pc_ip']}, {"query_field_key":"decoded_as", "query_value": "HTTP"}, {"query_field_key":"security_action", "query_value":"deny"}, @@ -105,74 +102,114 @@ def run(parameter): {"query_field_key":"ip_protocol", "query_value": "tcp"}, {"query_field_key":"http_host", "query_value": "open.node.com"}, {"query_field_key":"http_url", "query_value": "open.node.com:180/go"} - ], - "traffic": { - "protocol": "http", - "type": "curl", - "command": "curl --connect-timeout 10 -m 10 -H \"Content-Type:application/json;charset=UTF-8\" -X POST -d \"{\\\"requestbody\\\":\\\"test\\\",\\\"setcook\\\":\\\"\\\",\\\"contenttype\\\":\\\"\\\",\\\"responsebody\\\":\\\"\\\"}\" -kv --user-agent \"Wget (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36\" http://open.node.com:180/go" - }, - "token": "" + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_pre_reqbody_drop_rst.py b/tests/security/sec_deny_srcip_http_pre_reqbody_drop_rst.py index 8edd45239..7ee9800b5 100644 --- a/tests/security/sec_deny_srcip_http_pre_reqbody_drop_rst.py +++ b/tests/security/sec_deny_srcip_http_pre_reqbody_drop_rst.py @@ -1,103 +1,100 @@ # -*- coding: UTF-8 -*- -import time import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": os.path.splitext(os.path.basename(__file__))[0], - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_keywords_reqbody", - "object_type": "keywords", - "item_operation": "add", - "select_type": False, - "negate": False, - "statistics": "None", - "item": [ - { - "item_operation": "add", - "item_type": "request_body", - "item_value": "TEXT", - "value": [ - "{\"requestbody\":\"test\",\"setcook\":\"\",\"contenttype\":\"\",\"responsebody\":\"\"}*" - ] - } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "drop", - "drop_packet": 0, - "send_tcp_rst": True, - "send_icmp_unreachable": False - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_REQ_BODY", + "type": "keyword", + "name": "sec_keyword", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^{\"requestbody\":\"test\",\"setcook\":\"\",\"contenttype\":\"\",\"responsebody\":\"\"}" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 1, + "send_icmp_unreachable": 0, + "after_n_packets": 0 }, - "profile": [], - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [ + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "curl --connect-timeout 10 -m 10 -H \"Content-Type:application/json;charset=UTF-8\" -X POST -d \"{\\\"requestbody\\\":\\\"test\\\",\\\"setcook\\\":\\\"\\\",\\\"contenttype\\\":\\\"\\\",\\\"responsebody\\\":\\\"\\\"}\" -kv --user-agent \"Wget (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36\" http://open.node.com:180/go" + } + + verification_result = { + "excepted_traffic_result": "reset", + "expected_metric": {"hits": 1}, + "expected_log": [ {"query_field_key":"client_ip", "query_value":parameter['test_pc_ip']}, {"query_field_key":"decoded_as", "query_value": "HTTP"}, {"query_field_key":"security_action", "query_value":"deny"}, @@ -105,74 +102,114 @@ def run(parameter): {"query_field_key":"ip_protocol", "query_value": "tcp"}, {"query_field_key":"http_host", "query_value": "open.node.com"}, {"query_field_key":"http_url", "query_value": "open.node.com:180/go"} - ], - "traffic": { - "protocol": "http", - "type": "curl", - "command": "curl --connect-timeout 10 -m 10 -H \"Content-Type:application/json;charset=UTF-8\" -X POST -d \"{\\\"requestbody\\\":\\\"test\\\",\\\"setcook\\\":\\\"\\\",\\\"contenttype\\\":\\\"\\\",\\\"responsebody\\\":\\\"\\\"}\" -kv --user-agent \"Wget (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36\" http://open.node.com:180/go" - }, - "token": "" + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_pre_reqbody_rate_high.py b/tests/security/sec_deny_srcip_http_pre_reqbody_rate_high.py index 36a751f0b..ecb2abe2e 100644 --- a/tests/security/sec_deny_srcip_http_pre_reqbody_rate_high.py +++ b/tests/security/sec_deny_srcip_http_pre_reqbody_rate_high.py @@ -1,101 +1,101 @@ # -*- coding: UTF-8 -*- -import time import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": os.path.splitext(os.path.basename(__file__))[0], - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_keywords_reqbody", - "object_type": "keywords", - "item_operation": "add", - "select_type": False, - "negate": False, - "statistics": "None", - "item": [ - { - "item_operation": "add", - "item_type": "request_body", - "item_value": "TEXT", - "value": [ - "{\"requestbody\":\"test\",\"setcook\":\"\",\"contenttype\":\"\",\"responsebody\":\"\"}*" - ] - } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "rate_limit", - "rate_value": "100000", - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_REQ_BODY", + "type": "keyword", + "name": "sec_keyword", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^{\"requestbody\":\"test\",\"setcook\":\"\",\"contenttype\":\"\",\"responsebody\":\"\"}" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "rate_limit", + "bps": 10000000, + "limitUnit": "Kbps", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 0, + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "test", - "counters": {"hits": 1}, - "log_query_param": [ + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "curl --connect-timeout 10 -m 10 -H \"Content-Type:application/json;charset=UTF-8\" -X POST -d \"{\\\"requestbody\\\":\\\"test\\\",\\\"setcook\\\":\\\"\\\",\\\"contenttype\\\":\\\"\\\",\\\"responsebody\\\":\\\"\\\"}\" -kv --user-agent \"Wget (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36\" http://open.node.com:180/go" + } + + verification_result = { + "excepted_traffic_result": "test", + "expected_metric": {"hits": 1}, + "expected_log": [ {"query_field_key":"client_ip", "query_value":parameter['test_pc_ip']}, {"query_field_key":"decoded_as", "query_value": "HTTP"}, {"query_field_key":"security_action", "query_value":"deny"}, @@ -103,74 +103,114 @@ def run(parameter): {"query_field_key":"ip_protocol", "query_value": "tcp"}, {"query_field_key":"http_host", "query_value": "open.node.com"}, {"query_field_key":"http_url", "query_value": "open.node.com:180/go"} - ], - "traffic": { - "protocol": "http", - "type": "curl", - "command": "curl --connect-timeout 10 -m 10 -H \"Content-Type:application/json;charset=UTF-8\" -X POST -d \"{\\\"requestbody\\\":\\\"test\\\",\\\"setcook\\\":\\\"\\\",\\\"contenttype\\\":\\\"\\\",\\\"responsebody\\\":\\\"\\\"}\" -kv --user-agent \"Wget (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36\" http://open.node.com:180/go" - }, - "token": "" + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_pre_reqbody_rate_low.py b/tests/security/sec_deny_srcip_http_pre_reqbody_rate_low.py index d84110de3..b8f02d8c6 100644 --- a/tests/security/sec_deny_srcip_http_pre_reqbody_rate_low.py +++ b/tests/security/sec_deny_srcip_http_pre_reqbody_rate_low.py @@ -1,101 +1,101 @@ # -*- coding: UTF-8 -*- -import time import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": os.path.splitext(os.path.basename(__file__))[0], - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_keywords_reqbody", - "object_type": "keywords", - "item_operation": "add", - "select_type": False, - "negate": False, - "statistics": "None", - "item": [ - { - "item_operation": "add", - "item_type": "request_body", - "item_value": "TEXT", - "value": [ - "{\"requestbody\":\"test\",\"setcook\":\"\",\"contenttype\":\"\",\"responsebody\":\"\"}*" - ] - } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "rate_limit", - "rate_value": "0.1", - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_REQ_BODY", + "type": "keyword", + "name": "sec_keyword", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^{\"requestbody\":\"test\",\"setcook\":\"\",\"contenttype\":\"\",\"responsebody\":\"\"}" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "rate_limit", + "bps": 10, + "limitUnit": "Kbps", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 0, + "send_icmp_unreachable": 0 }, - "profile": [], - "expected_return": "timed out", - "counters": {"hits": 1}, - "log_query_param": [ + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "curl --connect-timeout 10 -m 10 -H \"Content-Type:application/json;charset=UTF-8\" -X POST -d \"{\\\"requestbody\\\":\\\"test\\\",\\\"setcook\\\":\\\"\\\",\\\"contenttype\\\":\\\"\\\",\\\"responsebody\\\":\\\"\\\"}\" -kv --user-agent \"Wget (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36\" http://open.node.com:180/go" + } + + verification_result = { + "excepted_traffic_result": "timed out", + "expected_metric": {"hits": 1}, + "expected_log": [ {"query_field_key":"client_ip", "query_value":parameter['test_pc_ip']}, {"query_field_key":"decoded_as", "query_value": "HTTP"}, {"query_field_key":"security_action", "query_value":"deny"}, @@ -103,74 +103,114 @@ def run(parameter): {"query_field_key":"ip_protocol", "query_value": "tcp"}, {"query_field_key":"http_host", "query_value": "open.node.com"}, {"query_field_key":"http_url", "query_value": "open.node.com:180/go"} - ], - "traffic": { - "protocol": "http", - "type": "curl", - "command": "curl --connect-timeout 10 -m 10 -H \"Content-Type:application/json;charset=UTF-8\" -X POST -d \"{\\\"requestbody\\\":\\\"test\\\",\\\"setcook\\\":\\\"\\\",\\\"contenttype\\\":\\\"\\\",\\\"responsebody\\\":\\\"\\\"}\" -kv --user-agent \"Wget (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36\" http://open.node.com:180/go" - }, - "token": "" + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_pre_reqbody_tamper.py b/tests/security/sec_deny_srcip_http_pre_reqbody_tamper.py index 5647b441e..ad17efb6a 100644 --- a/tests/security/sec_deny_srcip_http_pre_reqbody_tamper.py +++ b/tests/security/sec_deny_srcip_http_pre_reqbody_tamper.py @@ -1,100 +1,99 @@ # -*- coding: UTF-8 -*- -import time import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": os.path.splitext(os.path.basename(__file__))[0], - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_keywords_reqbody", - "object_type": "keywords", - "item_operation": "add", - "select_type": False, - "negate": False, - "statistics": "None", - "item": [ - { - "item_operation": "add", - "item_type": "request_body", - "item_value": "TEXT", - "value": [ - "{\"requestbody\":\"test\",\"setcook\":\"\",\"contenttype\":\"\",\"responsebody\":\"\"}*" - ] - } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "tamper" - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_REQ_BODY", + "type": "keyword", + "name": "sec_keyword", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^{\"requestbody\":\"test\",\"setcook\":\"\",\"contenttype\":\"\",\"responsebody\":\"\"}" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "tamper", + "packet_capture": { + "enable": 0 + }, + "tamper_mode": "complete", + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "timed out", - "counters": {"hits": 1}, - "log_query_param": [ + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "curl --connect-timeout 10 -m 10 -H \"Content-Type:application/json;charset=UTF-8\" -X POST -d \"{\\\"requestbody\\\":\\\"test\\\",\\\"setcook\\\":\\\"\\\",\\\"contenttype\\\":\\\"\\\",\\\"responsebody\\\":\\\"\\\"}\" -kv --user-agent \"Wget (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36\" http://open.node.com:180/go" + } + + verification_result = { + "excepted_traffic_result": "timed out", + "expected_metric": {"hits": 1}, + "expected_log": [ {"query_field_key":"client_ip", "query_value":parameter['test_pc_ip']}, {"query_field_key":"decoded_as", "query_value": "HTTP"}, {"query_field_key":"security_action", "query_value":"deny"}, @@ -102,74 +101,114 @@ def run(parameter): {"query_field_key":"ip_protocol", "query_value": "tcp"}, {"query_field_key":"http_host", "query_value": "open.node.com"}, {"query_field_key":"http_url", "query_value": "open.node.com:180/go"} - ], - "traffic": { - "protocol": "http", - "type": "curl", - "command": "curl --connect-timeout 10 -m 10 -H \"Content-Type:application/json;charset=UTF-8\" -X POST -d \"{\\\"requestbody\\\":\\\"test\\\",\\\"setcook\\\":\\\"\\\",\\\"contenttype\\\":\\\"\\\",\\\"responsebody\\\":\\\"\\\"}\" -kv --user-agent \"Wget (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36\" http://open.node.com:180/go" - }, - "token": "" + ] } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_pre_resbody_drop.py b/tests/security/sec_deny_srcip_http_pre_resbody_drop.py index 9409a0546..4f05b1dfc 100644 --- a/tests/security/sec_deny_srcip_http_pre_resbody_drop.py +++ b/tests/security/sec_deny_srcip_http_pre_resbody_drop.py @@ -1,171 +1,215 @@ # -*- coding: UTF-8 -*- -import time import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": os.path.splitext(os.path.basename(__file__))[0], - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_keywords_resbody", - "object_type": "keywords", - "item_operation": "add", - "select_type": False, - "negate": False, - "statistics": "None", - "item": [ - { - "item_operation": "add", - "item_type": "response_body", - "item_value": "TEXT", - "value": [ - "<html*" - ] - } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "drop", - "drop_packet": 0, - "send_tcp_rst": False, - "send_icmp_unreachable": False - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_RES_BODY", + "type": "keyword", + "name": "sec_keyword", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^<html" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 0, + "send_icmp_unreachable": 0, + "after_n_packets": 0 }, - "profile": [], - "expected_return": "timed out", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"imsi", "query_value":parameter['test_imsi']}, - {"query_field_key":"phone_number", "query_value": parameter['test_phone_number']}], - "traffic": { - "protocol": "http", - "type": "curl", - "command": "curl --connect-timeout 10 -m 10 -H \"Content-Type:application/json;charset=UTF-8\" -X POST -d \"{\\\"requestbody\\\":\\\"helloSecurity\\\",\\\"setcook\\\":\\\"test_setcook\\\",\\\"contenttype\\\": \\\"test_cont\\\",\\\"responsebody\\\": \\\"test_resbody\\\"}\" -kv --user-agent \"Wget (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36\" http://192.168.40.206:180/go" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "curl --connect-timeout 10 -m 10 -H \"Content-Type:application/json;charset=UTF-8\" -X POST -d \"{\\\"requestbody\\\":\\\"test\\\",\\\"setcook\\\":\\\"\\\",\\\"contenttype\\\":\\\"\\\",\\\"responsebody\\\":\\\"\\\"}\" -kv --user-agent \"Wget (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36\" http://open.node.com:180/go" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "timed out", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"client_ip", "query_value":parameter['test_pc_ip']}, + {"query_field_key":"decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action", "query_value":"deny"}, + {"query_field_key":"server_port", "query_value": 180}, + {"query_field_key":"ip_protocol", "query_value": "tcp"}, + {"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/go"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_pre_resbody_drop_rst.py b/tests/security/sec_deny_srcip_http_pre_resbody_drop_rst.py index e6273ccf9..5a04ba672 100644 --- a/tests/security/sec_deny_srcip_http_pre_resbody_drop_rst.py +++ b/tests/security/sec_deny_srcip_http_pre_resbody_drop_rst.py @@ -1,171 +1,215 @@ # -*- coding: UTF-8 -*- -import time import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": os.path.splitext(os.path.basename(__file__))[0], - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_keywords_resbody", - "object_type": "keywords", - "item_operation": "add", - "select_type": False, - "negate": False, - "statistics": "None", - "item": [ - { - "item_operation": "add", - "item_type": "response_body", - "item_value": "TEXT", - "value": [ - "<html*" - ] - } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "drop", - "drop_packet": 0, - "send_tcp_rst": True, - "send_icmp_unreachable": False - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_RES_BODY", + "type": "keyword", + "name": "sec_keyword", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^<html" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 1, + "send_icmp_unreachable": 0, + "after_n_packets": 0 }, - "profile": [], - "expected_return": "timed out", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"imsi", "query_value":parameter['test_imsi']}, - {"query_field_key":"phone_number", "query_value": parameter['test_phone_number']}], - "traffic": { - "protocol": "http", - "type": "curl", - "command": "curl --connect-timeout 10 -m 10 -H \"Content-Type:application/json;charset=UTF-8\" -X POST -d \"{\\\"requestbody\\\":\\\"helloSecurity\\\",\\\"setcook\\\":\\\"test_setcook\\\",\\\"contenttype\\\": \\\"test_cont\\\",\\\"responsebody\\\": \\\"test_resbody\\\"}\" -kv --user-agent \"Wget (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36\" http://192.168.40.206:180/go" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "curl --connect-timeout 10 -m 10 -H \"Content-Type:application/json;charset=UTF-8\" -X POST -d \"{\\\"requestbody\\\":\\\"test\\\",\\\"setcook\\\":\\\"\\\",\\\"contenttype\\\":\\\"\\\",\\\"responsebody\\\":\\\"\\\"}\" -kv --user-agent \"Wget (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36\" http://open.node.com:180/go" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "timed out", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"client_ip", "query_value":parameter['test_pc_ip']}, + {"query_field_key":"decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action", "query_value":"deny"}, + {"query_field_key":"server_port", "query_value": 180}, + {"query_field_key":"ip_protocol", "query_value": "tcp"}, + {"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/go"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_pre_resbody_rate_high.py b/tests/security/sec_deny_srcip_http_pre_resbody_rate_high.py index c824eed56..f3f69915c 100644 --- a/tests/security/sec_deny_srcip_http_pre_resbody_rate_high.py +++ b/tests/security/sec_deny_srcip_http_pre_resbody_rate_high.py @@ -1,169 +1,216 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": os.path.splitext(os.path.basename(__file__))[0], - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_keywords_resbody", - "object_type": "keywords", - "item_operation": "add", - "select_type": False, - "negate": False, - "statistics": "None", - "item": [ - { - "item_operation": "add", - "item_type": "response_body", - "item_value": "TEXT", - "value": [ - "<html*" - ] - } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "rate_limit", - "rate_value": "1000000", - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_RES_BODY", + "type": "keyword", + "name": "sec_keyword", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^<html" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "rate_limit", + "bps": 10000000, + "limitUnit": "Kbps", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 0, + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "test_resbody", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"imsi", "query_value":parameter['test_imsi']}, - {"query_field_key":"phone_number", "query_value": parameter['test_phone_number']}], - "traffic": { - "protocol": "http", - "type": "curl", - "command": "curl --connect-timeout 10 -m 10 -H \"Content-Type:application/json;charset=UTF-8\" -X POST -d \"{\\\"requestbody\\\":\\\"helloSecurity\\\",\\\"setcook\\\":\\\"test_setcook\\\",\\\"contenttype\\\": \\\"test_cont\\\",\\\"responsebody\\\": \\\"test_resbody\\\"}\" -kv --user-agent \"Wget (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36\" http://192.168.40.206:180/go" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "curl --connect-timeout 10 -m 10 -H \"Content-Type:application/json;charset=UTF-8\" -X POST -d \"{\\\"requestbody\\\":\\\"test\\\",\\\"setcook\\\":\\\"\\\",\\\"contenttype\\\":\\\"\\\",\\\"responsebody\\\":\\\"\\\"}\" -kv --user-agent \"Wget (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36\" http://open.node.com:180/go" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "test", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"client_ip", "query_value":parameter['test_pc_ip']}, + {"query_field_key":"decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action", "query_value":"deny"}, + {"query_field_key":"server_port", "query_value": 180}, + {"query_field_key":"ip_protocol", "query_value": "tcp"}, + {"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/go"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_pre_resbody_rate_low.py b/tests/security/sec_deny_srcip_http_pre_resbody_rate_low.py index 9983caa95..fab358c2a 100644 --- a/tests/security/sec_deny_srcip_http_pre_resbody_rate_low.py +++ b/tests/security/sec_deny_srcip_http_pre_resbody_rate_low.py @@ -1,169 +1,216 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": os.path.splitext(os.path.basename(__file__))[0], - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_keywords_resbody", - "object_type": "keywords", - "item_operation": "add", - "select_type": False, - "negate": False, - "statistics": "None", - "item": [ - { - "item_operation": "add", - "item_type": "response_body", - "item_value": "TEXT", - "value": [ - "<html*" - ] - } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "rate_limit", - "rate_value": "0.1", - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_RES_BODY", + "type": "keyword", + "name": "sec_keyword", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^<html" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "rate_limit", + "bps": 10, + "limitUnit": "Kbps", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 0, + "send_icmp_unreachable": 0 }, - "profile": [], - "expected_return": "timed out", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"imsi", "query_value":parameter['test_imsi']}, - {"query_field_key":"phone_number", "query_value": parameter['test_phone_number']}], - "traffic": { - "protocol": "http", - "type": "curl", - "command": "curl --connect-timeout 10 -m 10 -H \"Content-Type:application/json;charset=UTF-8\" -X POST -d \"{\\\"requestbody\\\":\\\"helloSecurity\\\",\\\"setcook\\\":\\\"test_setcook\\\",\\\"contenttype\\\": \\\"test_cont\\\",\\\"responsebody\\\": \\\"test_resbody\\\"}\" -kv --user-agent \"Wget (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36\" http://192.168.40.206:180/go" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "curl --connect-timeout 10 -m 10 -H \"Content-Type:application/json;charset=UTF-8\" -X POST -d \"{\\\"requestbody\\\":\\\"test\\\",\\\"setcook\\\":\\\"\\\",\\\"contenttype\\\":\\\"\\\",\\\"responsebody\\\":\\\"\\\"}\" -kv --user-agent \"Wget (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36\" http://open.node.com:180/go" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "timed out", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"client_ip", "query_value":parameter['test_pc_ip']}, + {"query_field_key":"decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action", "query_value":"deny"}, + {"query_field_key":"server_port", "query_value": 180}, + {"query_field_key":"ip_protocol", "query_value": "tcp"}, + {"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/go"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_pre_resbody_tamper.py b/tests/security/sec_deny_srcip_http_pre_resbody_tamper.py index 20934465c..7f8eb89a0 100644 --- a/tests/security/sec_deny_srcip_http_pre_resbody_tamper.py +++ b/tests/security/sec_deny_srcip_http_pre_resbody_tamper.py @@ -1,168 +1,214 @@ # -*- coding: UTF-8 -*- -import time import os import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate -from support.common_utils.create_policy import CreatePolicy def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "security", - "rule_name": os.path.splitext(os.path.basename(__file__))[0], - "rule_action": "deny", - "rule_type": "create", - "condition": { - "source_ip": [ - { - "name": "sec_srcip", - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": parameter['test_pc_ip'], - } - ] - } - ], - "source_port": [], - "destination_ip": [], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [], - "protocol_filed": [ - { - "name": "sec_keywords_resbody", - "object_type": "keywords", - "item_operation": "add", - "select_type": False, - "negate": False, - "statistics": "None", - "item": [ - { - "item_operation": "add", - "item_type": "response_body", - "item_value": "TEXT", - "value": [ - "<html*" - ] - } - ], - } - ], - "sub_action_override": True, - "sub_action": [ - { - "type": "tamper" - } - ], - "packet_capture": [] + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_RES_BODY", + "type": "keyword", + "name": "sec_keyword", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^<html" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "tamper", + "packet_capture": { + "enable": 0 + }, + "tamper_mode": "complete", + "send_icmp_unreachable": 0, }, - "profile": [], - "expected_return": "timed out", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key":"imsi", "query_value":parameter['test_imsi']}, - {"query_field_key":"phone_number", "query_value": parameter['test_phone_number']}], - "traffic": { - "protocol": "http", - "type": "curl", - "command": "curl --connect-timeout 10 -m 10 -H \"Content-Type:application/json;charset=UTF-8\" -X POST -d \"{\\\"requestbody\\\":\\\"helloSecurity\\\",\\\"setcook\\\":\\\"test_setcook\\\",\\\"contenttype\\\": \\\"test_cont\\\",\\\"responsebody\\\": \\\"test_resbody\\\"}\" -kv --user-agent \"Wget (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36\" http://192.168.40.206:180/go" - }, - "token": "" + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "curl --connect-timeout 10 -m 10 -H \"Content-Type:application/json;charset=UTF-8\" -X POST -d \"{\\\"requestbody\\\":\\\"test\\\",\\\"setcook\\\":\\\"\\\",\\\"contenttype\\\":\\\"\\\",\\\"responsebody\\\":\\\"\\\"}\" -kv --user-agent \"Wget (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36\" http://open.node.com:180/go" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - return result + verification_result = { + "excepted_traffic_result": "timed out", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"client_ip", "query_value":parameter['test_pc_ip']}, + {"query_field_key":"decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action", "query_value":"deny"}, + {"query_field_key":"server_port", "query_value": 180}, + {"query_field_key":"ip_protocol", "query_value": "tcp"}, + {"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/go"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境并删除配置 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) - + if __name__ == '__main__': - # ui - # parameter = { - # "username": "hebingning", - # "password": "hbn66AAA", - # "test_pc_ip": "192.168.64.65", - # "test_subcriber_id": "test6776", - # "api_server": "http://192.168.44.72", - # "debug_flag": "local", - # "script_type": "ui", - # "env": "tsgx", - # "vsys_id": 1, - # "is_log": 1, - # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", - # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", - # "module_name": "security", - # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" - # } - # run(parameter) - # api - from support.ui_utils.element_position.map_element_position_library import replace_paras - from support.ui_utils.workpath import workdir - parameter = { - "username": "hebingning", - "password": "hbn66AAA", - "test_pc_ip": "192.168.64.93", - "test_subcriber_id": "test6491", + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", "api_server": "http://192.168.44.72", - "debug_flag": "local", - "script_type": "api", # api ui 空字符串 - "is_log": 1, + "initiation_method": "api", "env": "tsgx", - "vsys_id": 1, + "vsys": 5, "root_path": workdir, - "path": workdir + "/tests/api", + "path": workdir + "/tests", "module_name": "security", "test_case_name": os.path.basename(__file__)[:-3] } - parameter = replace_paras(parameter) run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_pre_url_alert_200_text.py b/tests/security/sec_deny_srcip_http_pre_url_alert_200_text.py index 6a0319586..7ab509173 100644 --- a/tests/security/sec_deny_srcip_http_pre_url_alert_200_text.py +++ b/tests/security/sec_deny_srcip_http_pre_url_alert_200_text.py @@ -166,4 +166,403 @@ if __name__ == '__main__': "test_case_name": os.path.basename(__file__)[:-3] } parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import time +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +from datetime import datetime +from support.report_update import ReportUpdate +from support.common_utils.create_policy import CreatePolicy + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + script_start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "security", + "rule_name": "sec_deny_srcip_http_pre_url_alert_200_profile", + "rule_action": "deny", + "rule_type": "create", + "condition": { + "source_ip": [ + { + "name": "sec_srcip", + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": parameter['test_pc_ip'], + } + ] + } + ], + "source_port": [], + "destination_ip": [], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [], + "protocol_filed": [ + { + "name": "sec_url", + "object_type": "url", + "item_operation": "add", + "select_type": False, + "negate": False, + "items": [ + { + "item_operation": "add", + "item_type": "url", + "item_value": "open.node*" + } + ], + } + ], + "sub_action_override": True, + "sub_action": [ + { + "type": "alert", + "code": 200, + "content_type": "Profile", + "content": "sec_respage" + } + ], + "packet_capture": [] + }, + "action_parameter": { + "response_page": [ + { + "profile_type": "response_page", + "response_code": 200, + "response_content_type": "Profile", + "profile_file": { + "name": "sec_respage", + "model": "create", + "file": "response_testa.html" + }, + } + ] + }, + "profile": [], + "expected_return": "200", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"}], + "traffic": { + "protocol": "http", + "type": "wget", + "command": "wget -q --debug http://open.node.com:180" + }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + return result + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) + return "Error: " + str(e) + finally: + # 清理环境并删除配置 + if isinstance(create, CreatePolicy): + create.clean_up() + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + # ui + # parameter = { + # "username": "hebingning", + # "password": "hbn66AAA", + # "test_pc_ip": "192.168.64.65", + # "test_subcriber_id": "test6776", + # "api_server": "http://192.168.44.72", + # "debug_flag": "local", + # "script_type": "ui", + # "env": "tsgx", + # "vsys_id": 1, + # "is_log": 1, + # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", + # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", + # "module_name": "security", + # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" + # } + # run(parameter) + # api + from support.ui_utils.element_position.map_element_position_library import replace_paras + from support.ui_utils.workpath import workdir + + parameter = { + "username": "hebingning", + "password": "hbn66AAA", + "test_pc_ip": "192.168.64.93", + "test_subcriber_id": "test6491", + "api_server": "http://192.168.44.72", + "debug_flag": "local", + "script_type": "api", # api ui 空字符串 + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, + "root_path": workdir, + "path": workdir + "/tests/api", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } + parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz +from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + + # 参数初始化 + result, exception_result = "", "" + test_summary = {} + + # 脚本启动时间 + script_start_time = time.time() + + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_URL", + "name": "sec_url", + "type": "url", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^open.node" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 1, + "send_icmp_unreachable": 0, + "after_n_packets": 0 + }, + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "wget -q --debug http://open.node.com:180" + } + + verification_result = { + "excepted_traffic_result": "200", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) + finally: + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", + "api_server": "http://192.168.44.72", + "initiation_method": "api", + "env": "tsgx", + "vsys": 5, + "root_path": workdir, + "path": workdir + "/tests", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_pre_url_alert_204.py b/tests/security/sec_deny_srcip_http_pre_url_alert_204.py index 8f071c762..d14ca459f 100644 --- a/tests/security/sec_deny_srcip_http_pre_url_alert_204.py +++ b/tests/security/sec_deny_srcip_http_pre_url_alert_204.py @@ -164,4 +164,403 @@ if __name__ == '__main__': "test_case_name": os.path.basename(__file__)[:-3] } parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import time +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +from datetime import datetime +from support.report_update import ReportUpdate +from support.common_utils.create_policy import CreatePolicy + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + script_start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "security", + "rule_name": "sec_deny_srcip_http_pre_url_alert_200_profile", + "rule_action": "deny", + "rule_type": "create", + "condition": { + "source_ip": [ + { + "name": "sec_srcip", + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": parameter['test_pc_ip'], + } + ] + } + ], + "source_port": [], + "destination_ip": [], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [], + "protocol_filed": [ + { + "name": "sec_url", + "object_type": "url", + "item_operation": "add", + "select_type": False, + "negate": False, + "items": [ + { + "item_operation": "add", + "item_type": "url", + "item_value": "open.node*" + } + ], + } + ], + "sub_action_override": True, + "sub_action": [ + { + "type": "alert", + "code": 200, + "content_type": "Profile", + "content": "sec_respage" + } + ], + "packet_capture": [] + }, + "action_parameter": { + "response_page": [ + { + "profile_type": "response_page", + "response_code": 200, + "response_content_type": "Profile", + "profile_file": { + "name": "sec_respage", + "model": "create", + "file": "response_testa.html" + }, + } + ] + }, + "profile": [], + "expected_return": "200", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"}], + "traffic": { + "protocol": "http", + "type": "wget", + "command": "wget -q --debug http://open.node.com:180" + }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + return result + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) + return "Error: " + str(e) + finally: + # 清理环境并删除配置 + if isinstance(create, CreatePolicy): + create.clean_up() + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + # ui + # parameter = { + # "username": "hebingning", + # "password": "hbn66AAA", + # "test_pc_ip": "192.168.64.65", + # "test_subcriber_id": "test6776", + # "api_server": "http://192.168.44.72", + # "debug_flag": "local", + # "script_type": "ui", + # "env": "tsgx", + # "vsys_id": 1, + # "is_log": 1, + # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", + # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", + # "module_name": "security", + # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" + # } + # run(parameter) + # api + from support.ui_utils.element_position.map_element_position_library import replace_paras + from support.ui_utils.workpath import workdir + + parameter = { + "username": "hebingning", + "password": "hbn66AAA", + "test_pc_ip": "192.168.64.93", + "test_subcriber_id": "test6491", + "api_server": "http://192.168.44.72", + "debug_flag": "local", + "script_type": "api", # api ui 空字符串 + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, + "root_path": workdir, + "path": workdir + "/tests/api", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } + parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz +from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + + # 参数初始化 + result, exception_result = "", "" + test_summary = {} + + # 脚本启动时间 + script_start_time = time.time() + + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_URL", + "name": "sec_url", + "type": "url", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^open.node" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 1, + "send_icmp_unreachable": 0, + "after_n_packets": 0 + }, + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "wget -q --debug http://open.node.com:180" + } + + verification_result = { + "excepted_traffic_result": "200", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) + finally: + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", + "api_server": "http://192.168.44.72", + "initiation_method": "api", + "env": "tsgx", + "vsys": 5, + "root_path": workdir, + "path": workdir + "/tests", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_pre_url_block_403_profile.py b/tests/security/sec_deny_srcip_http_pre_url_block_403_profile.py index 1971c4e9d..138836777 100644 --- a/tests/security/sec_deny_srcip_http_pre_url_block_403_profile.py +++ b/tests/security/sec_deny_srcip_http_pre_url_block_403_profile.py @@ -180,4 +180,403 @@ if __name__ == '__main__': "test_case_name": os.path.basename(__file__)[:-3] } parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import time +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +from datetime import datetime +from support.report_update import ReportUpdate +from support.common_utils.create_policy import CreatePolicy + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + script_start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "security", + "rule_name": "sec_deny_srcip_http_pre_url_alert_200_profile", + "rule_action": "deny", + "rule_type": "create", + "condition": { + "source_ip": [ + { + "name": "sec_srcip", + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": parameter['test_pc_ip'], + } + ] + } + ], + "source_port": [], + "destination_ip": [], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [], + "protocol_filed": [ + { + "name": "sec_url", + "object_type": "url", + "item_operation": "add", + "select_type": False, + "negate": False, + "items": [ + { + "item_operation": "add", + "item_type": "url", + "item_value": "open.node*" + } + ], + } + ], + "sub_action_override": True, + "sub_action": [ + { + "type": "alert", + "code": 200, + "content_type": "Profile", + "content": "sec_respage" + } + ], + "packet_capture": [] + }, + "action_parameter": { + "response_page": [ + { + "profile_type": "response_page", + "response_code": 200, + "response_content_type": "Profile", + "profile_file": { + "name": "sec_respage", + "model": "create", + "file": "response_testa.html" + }, + } + ] + }, + "profile": [], + "expected_return": "200", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"}], + "traffic": { + "protocol": "http", + "type": "wget", + "command": "wget -q --debug http://open.node.com:180" + }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + return result + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) + return "Error: " + str(e) + finally: + # 清理环境并删除配置 + if isinstance(create, CreatePolicy): + create.clean_up() + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + # ui + # parameter = { + # "username": "hebingning", + # "password": "hbn66AAA", + # "test_pc_ip": "192.168.64.65", + # "test_subcriber_id": "test6776", + # "api_server": "http://192.168.44.72", + # "debug_flag": "local", + # "script_type": "ui", + # "env": "tsgx", + # "vsys_id": 1, + # "is_log": 1, + # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", + # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", + # "module_name": "security", + # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" + # } + # run(parameter) + # api + from support.ui_utils.element_position.map_element_position_library import replace_paras + from support.ui_utils.workpath import workdir + + parameter = { + "username": "hebingning", + "password": "hbn66AAA", + "test_pc_ip": "192.168.64.93", + "test_subcriber_id": "test6491", + "api_server": "http://192.168.44.72", + "debug_flag": "local", + "script_type": "api", # api ui 空字符串 + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, + "root_path": workdir, + "path": workdir + "/tests/api", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } + parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz +from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + + # 参数初始化 + result, exception_result = "", "" + test_summary = {} + + # 脚本启动时间 + script_start_time = time.time() + + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_URL", + "name": "sec_url", + "type": "url", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^open.node" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 1, + "send_icmp_unreachable": 0, + "after_n_packets": 0 + }, + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "wget -q --debug http://open.node.com:180" + } + + verification_result = { + "excepted_traffic_result": "200", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) + finally: + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", + "api_server": "http://192.168.44.72", + "initiation_method": "api", + "env": "tsgx", + "vsys": 5, + "root_path": workdir, + "path": workdir + "/tests", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_pre_url_block_403_text.py b/tests/security/sec_deny_srcip_http_pre_url_block_403_text.py index 3e33211c4..1ce8ff8b6 100644 --- a/tests/security/sec_deny_srcip_http_pre_url_block_403_text.py +++ b/tests/security/sec_deny_srcip_http_pre_url_block_403_text.py @@ -166,4 +166,403 @@ if __name__ == '__main__': "test_case_name": os.path.basename(__file__)[:-3] } parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import time +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +from datetime import datetime +from support.report_update import ReportUpdate +from support.common_utils.create_policy import CreatePolicy + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + script_start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "security", + "rule_name": "sec_deny_srcip_http_pre_url_alert_200_profile", + "rule_action": "deny", + "rule_type": "create", + "condition": { + "source_ip": [ + { + "name": "sec_srcip", + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": parameter['test_pc_ip'], + } + ] + } + ], + "source_port": [], + "destination_ip": [], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [], + "protocol_filed": [ + { + "name": "sec_url", + "object_type": "url", + "item_operation": "add", + "select_type": False, + "negate": False, + "items": [ + { + "item_operation": "add", + "item_type": "url", + "item_value": "open.node*" + } + ], + } + ], + "sub_action_override": True, + "sub_action": [ + { + "type": "alert", + "code": 200, + "content_type": "Profile", + "content": "sec_respage" + } + ], + "packet_capture": [] + }, + "action_parameter": { + "response_page": [ + { + "profile_type": "response_page", + "response_code": 200, + "response_content_type": "Profile", + "profile_file": { + "name": "sec_respage", + "model": "create", + "file": "response_testa.html" + }, + } + ] + }, + "profile": [], + "expected_return": "200", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"}], + "traffic": { + "protocol": "http", + "type": "wget", + "command": "wget -q --debug http://open.node.com:180" + }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + return result + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) + return "Error: " + str(e) + finally: + # 清理环境并删除配置 + if isinstance(create, CreatePolicy): + create.clean_up() + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + # ui + # parameter = { + # "username": "hebingning", + # "password": "hbn66AAA", + # "test_pc_ip": "192.168.64.65", + # "test_subcriber_id": "test6776", + # "api_server": "http://192.168.44.72", + # "debug_flag": "local", + # "script_type": "ui", + # "env": "tsgx", + # "vsys_id": 1, + # "is_log": 1, + # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", + # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", + # "module_name": "security", + # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" + # } + # run(parameter) + # api + from support.ui_utils.element_position.map_element_position_library import replace_paras + from support.ui_utils.workpath import workdir + + parameter = { + "username": "hebingning", + "password": "hbn66AAA", + "test_pc_ip": "192.168.64.93", + "test_subcriber_id": "test6491", + "api_server": "http://192.168.44.72", + "debug_flag": "local", + "script_type": "api", # api ui 空字符串 + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, + "root_path": workdir, + "path": workdir + "/tests/api", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } + parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz +from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + + # 参数初始化 + result, exception_result = "", "" + test_summary = {} + + # 脚本启动时间 + script_start_time = time.time() + + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_URL", + "name": "sec_url", + "type": "url", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^open.node" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 1, + "send_icmp_unreachable": 0, + "after_n_packets": 0 + }, + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "wget -q --debug http://open.node.com:180" + } + + verification_result = { + "excepted_traffic_result": "200", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) + finally: + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", + "api_server": "http://192.168.44.72", + "initiation_method": "api", + "env": "tsgx", + "vsys": 5, + "root_path": workdir, + "path": workdir + "/tests", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_pre_url_block_404_profile.py b/tests/security/sec_deny_srcip_http_pre_url_block_404_profile.py index 344a7b94b..6b57f1e28 100644 --- a/tests/security/sec_deny_srcip_http_pre_url_block_404_profile.py +++ b/tests/security/sec_deny_srcip_http_pre_url_block_404_profile.py @@ -180,4 +180,403 @@ if __name__ == '__main__': "test_case_name": os.path.basename(__file__)[:-3] } parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import time +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +from datetime import datetime +from support.report_update import ReportUpdate +from support.common_utils.create_policy import CreatePolicy + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + script_start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "security", + "rule_name": "sec_deny_srcip_http_pre_url_alert_200_profile", + "rule_action": "deny", + "rule_type": "create", + "condition": { + "source_ip": [ + { + "name": "sec_srcip", + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": parameter['test_pc_ip'], + } + ] + } + ], + "source_port": [], + "destination_ip": [], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [], + "protocol_filed": [ + { + "name": "sec_url", + "object_type": "url", + "item_operation": "add", + "select_type": False, + "negate": False, + "items": [ + { + "item_operation": "add", + "item_type": "url", + "item_value": "open.node*" + } + ], + } + ], + "sub_action_override": True, + "sub_action": [ + { + "type": "alert", + "code": 200, + "content_type": "Profile", + "content": "sec_respage" + } + ], + "packet_capture": [] + }, + "action_parameter": { + "response_page": [ + { + "profile_type": "response_page", + "response_code": 200, + "response_content_type": "Profile", + "profile_file": { + "name": "sec_respage", + "model": "create", + "file": "response_testa.html" + }, + } + ] + }, + "profile": [], + "expected_return": "200", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"}], + "traffic": { + "protocol": "http", + "type": "wget", + "command": "wget -q --debug http://open.node.com:180" + }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + return result + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) + return "Error: " + str(e) + finally: + # 清理环境并删除配置 + if isinstance(create, CreatePolicy): + create.clean_up() + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + # ui + # parameter = { + # "username": "hebingning", + # "password": "hbn66AAA", + # "test_pc_ip": "192.168.64.65", + # "test_subcriber_id": "test6776", + # "api_server": "http://192.168.44.72", + # "debug_flag": "local", + # "script_type": "ui", + # "env": "tsgx", + # "vsys_id": 1, + # "is_log": 1, + # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", + # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", + # "module_name": "security", + # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" + # } + # run(parameter) + # api + from support.ui_utils.element_position.map_element_position_library import replace_paras + from support.ui_utils.workpath import workdir + + parameter = { + "username": "hebingning", + "password": "hbn66AAA", + "test_pc_ip": "192.168.64.93", + "test_subcriber_id": "test6491", + "api_server": "http://192.168.44.72", + "debug_flag": "local", + "script_type": "api", # api ui 空字符串 + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, + "root_path": workdir, + "path": workdir + "/tests/api", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } + parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz +from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + + # 参数初始化 + result, exception_result = "", "" + test_summary = {} + + # 脚本启动时间 + script_start_time = time.time() + + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_URL", + "name": "sec_url", + "type": "url", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^open.node" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 1, + "send_icmp_unreachable": 0, + "after_n_packets": 0 + }, + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "wget -q --debug http://open.node.com:180" + } + + verification_result = { + "excepted_traffic_result": "200", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) + finally: + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", + "api_server": "http://192.168.44.72", + "initiation_method": "api", + "env": "tsgx", + "vsys": 5, + "root_path": workdir, + "path": workdir + "/tests", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_pre_url_block_404_text.py b/tests/security/sec_deny_srcip_http_pre_url_block_404_text.py index f625fdd93..ddbbfdb2d 100644 --- a/tests/security/sec_deny_srcip_http_pre_url_block_404_text.py +++ b/tests/security/sec_deny_srcip_http_pre_url_block_404_text.py @@ -166,4 +166,403 @@ if __name__ == '__main__': "test_case_name": os.path.basename(__file__)[:-3] } parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import time +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +from datetime import datetime +from support.report_update import ReportUpdate +from support.common_utils.create_policy import CreatePolicy + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + script_start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "security", + "rule_name": "sec_deny_srcip_http_pre_url_alert_200_profile", + "rule_action": "deny", + "rule_type": "create", + "condition": { + "source_ip": [ + { + "name": "sec_srcip", + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": parameter['test_pc_ip'], + } + ] + } + ], + "source_port": [], + "destination_ip": [], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [], + "protocol_filed": [ + { + "name": "sec_url", + "object_type": "url", + "item_operation": "add", + "select_type": False, + "negate": False, + "items": [ + { + "item_operation": "add", + "item_type": "url", + "item_value": "open.node*" + } + ], + } + ], + "sub_action_override": True, + "sub_action": [ + { + "type": "alert", + "code": 200, + "content_type": "Profile", + "content": "sec_respage" + } + ], + "packet_capture": [] + }, + "action_parameter": { + "response_page": [ + { + "profile_type": "response_page", + "response_code": 200, + "response_content_type": "Profile", + "profile_file": { + "name": "sec_respage", + "model": "create", + "file": "response_testa.html" + }, + } + ] + }, + "profile": [], + "expected_return": "200", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"}], + "traffic": { + "protocol": "http", + "type": "wget", + "command": "wget -q --debug http://open.node.com:180" + }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + return result + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) + return "Error: " + str(e) + finally: + # 清理环境并删除配置 + if isinstance(create, CreatePolicy): + create.clean_up() + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + # ui + # parameter = { + # "username": "hebingning", + # "password": "hbn66AAA", + # "test_pc_ip": "192.168.64.65", + # "test_subcriber_id": "test6776", + # "api_server": "http://192.168.44.72", + # "debug_flag": "local", + # "script_type": "ui", + # "env": "tsgx", + # "vsys_id": 1, + # "is_log": 1, + # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", + # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", + # "module_name": "security", + # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" + # } + # run(parameter) + # api + from support.ui_utils.element_position.map_element_position_library import replace_paras + from support.ui_utils.workpath import workdir + + parameter = { + "username": "hebingning", + "password": "hbn66AAA", + "test_pc_ip": "192.168.64.93", + "test_subcriber_id": "test6491", + "api_server": "http://192.168.44.72", + "debug_flag": "local", + "script_type": "api", # api ui 空字符串 + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, + "root_path": workdir, + "path": workdir + "/tests/api", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } + parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz +from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + + # 参数初始化 + result, exception_result = "", "" + test_summary = {} + + # 脚本启动时间 + script_start_time = time.time() + + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_URL", + "name": "sec_url", + "type": "url", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^open.node" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 1, + "send_icmp_unreachable": 0, + "after_n_packets": 0 + }, + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "wget -q --debug http://open.node.com:180" + } + + verification_result = { + "excepted_traffic_result": "200", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) + finally: + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", + "api_server": "http://192.168.44.72", + "initiation_method": "api", + "env": "tsgx", + "vsys": 5, + "root_path": workdir, + "path": workdir + "/tests", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_pre_url_drop.py b/tests/security/sec_deny_srcip_http_pre_url_drop.py index a03ff02e4..2fc305204 100644 --- a/tests/security/sec_deny_srcip_http_pre_url_drop.py +++ b/tests/security/sec_deny_srcip_http_pre_url_drop.py @@ -166,4 +166,403 @@ if __name__ == '__main__': "test_case_name": os.path.basename(__file__)[:-3] } parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import time +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +from datetime import datetime +from support.report_update import ReportUpdate +from support.common_utils.create_policy import CreatePolicy + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + script_start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "security", + "rule_name": "sec_deny_srcip_http_pre_url_alert_200_profile", + "rule_action": "deny", + "rule_type": "create", + "condition": { + "source_ip": [ + { + "name": "sec_srcip", + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": parameter['test_pc_ip'], + } + ] + } + ], + "source_port": [], + "destination_ip": [], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [], + "protocol_filed": [ + { + "name": "sec_url", + "object_type": "url", + "item_operation": "add", + "select_type": False, + "negate": False, + "items": [ + { + "item_operation": "add", + "item_type": "url", + "item_value": "open.node*" + } + ], + } + ], + "sub_action_override": True, + "sub_action": [ + { + "type": "alert", + "code": 200, + "content_type": "Profile", + "content": "sec_respage" + } + ], + "packet_capture": [] + }, + "action_parameter": { + "response_page": [ + { + "profile_type": "response_page", + "response_code": 200, + "response_content_type": "Profile", + "profile_file": { + "name": "sec_respage", + "model": "create", + "file": "response_testa.html" + }, + } + ] + }, + "profile": [], + "expected_return": "200", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"}], + "traffic": { + "protocol": "http", + "type": "wget", + "command": "wget -q --debug http://open.node.com:180" + }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + return result + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) + return "Error: " + str(e) + finally: + # 清理环境并删除配置 + if isinstance(create, CreatePolicy): + create.clean_up() + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + # ui + # parameter = { + # "username": "hebingning", + # "password": "hbn66AAA", + # "test_pc_ip": "192.168.64.65", + # "test_subcriber_id": "test6776", + # "api_server": "http://192.168.44.72", + # "debug_flag": "local", + # "script_type": "ui", + # "env": "tsgx", + # "vsys_id": 1, + # "is_log": 1, + # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", + # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", + # "module_name": "security", + # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" + # } + # run(parameter) + # api + from support.ui_utils.element_position.map_element_position_library import replace_paras + from support.ui_utils.workpath import workdir + + parameter = { + "username": "hebingning", + "password": "hbn66AAA", + "test_pc_ip": "192.168.64.93", + "test_subcriber_id": "test6491", + "api_server": "http://192.168.44.72", + "debug_flag": "local", + "script_type": "api", # api ui 空字符串 + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, + "root_path": workdir, + "path": workdir + "/tests/api", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } + parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz +from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + + # 参数初始化 + result, exception_result = "", "" + test_summary = {} + + # 脚本启动时间 + script_start_time = time.time() + + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_URL", + "name": "sec_url", + "type": "url", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^open.node" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 1, + "send_icmp_unreachable": 0, + "after_n_packets": 0 + }, + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "wget -q --debug http://open.node.com:180" + } + + verification_result = { + "excepted_traffic_result": "200", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) + finally: + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", + "api_server": "http://192.168.44.72", + "initiation_method": "api", + "env": "tsgx", + "vsys": 5, + "root_path": workdir, + "path": workdir + "/tests", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_pre_url_drop_rst.py b/tests/security/sec_deny_srcip_http_pre_url_drop_rst.py index 76991aec4..28fae375d 100644 --- a/tests/security/sec_deny_srcip_http_pre_url_drop_rst.py +++ b/tests/security/sec_deny_srcip_http_pre_url_drop_rst.py @@ -166,4 +166,403 @@ if __name__ == '__main__': "test_case_name": os.path.basename(__file__)[:-3] } parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import time +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +from datetime import datetime +from support.report_update import ReportUpdate +from support.common_utils.create_policy import CreatePolicy + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + script_start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "security", + "rule_name": "sec_deny_srcip_http_pre_url_alert_200_profile", + "rule_action": "deny", + "rule_type": "create", + "condition": { + "source_ip": [ + { + "name": "sec_srcip", + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": parameter['test_pc_ip'], + } + ] + } + ], + "source_port": [], + "destination_ip": [], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [], + "protocol_filed": [ + { + "name": "sec_url", + "object_type": "url", + "item_operation": "add", + "select_type": False, + "negate": False, + "items": [ + { + "item_operation": "add", + "item_type": "url", + "item_value": "open.node*" + } + ], + } + ], + "sub_action_override": True, + "sub_action": [ + { + "type": "alert", + "code": 200, + "content_type": "Profile", + "content": "sec_respage" + } + ], + "packet_capture": [] + }, + "action_parameter": { + "response_page": [ + { + "profile_type": "response_page", + "response_code": 200, + "response_content_type": "Profile", + "profile_file": { + "name": "sec_respage", + "model": "create", + "file": "response_testa.html" + }, + } + ] + }, + "profile": [], + "expected_return": "200", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"}], + "traffic": { + "protocol": "http", + "type": "wget", + "command": "wget -q --debug http://open.node.com:180" + }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + return result + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) + return "Error: " + str(e) + finally: + # 清理环境并删除配置 + if isinstance(create, CreatePolicy): + create.clean_up() + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + # ui + # parameter = { + # "username": "hebingning", + # "password": "hbn66AAA", + # "test_pc_ip": "192.168.64.65", + # "test_subcriber_id": "test6776", + # "api_server": "http://192.168.44.72", + # "debug_flag": "local", + # "script_type": "ui", + # "env": "tsgx", + # "vsys_id": 1, + # "is_log": 1, + # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", + # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", + # "module_name": "security", + # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" + # } + # run(parameter) + # api + from support.ui_utils.element_position.map_element_position_library import replace_paras + from support.ui_utils.workpath import workdir + + parameter = { + "username": "hebingning", + "password": "hbn66AAA", + "test_pc_ip": "192.168.64.93", + "test_subcriber_id": "test6491", + "api_server": "http://192.168.44.72", + "debug_flag": "local", + "script_type": "api", # api ui 空字符串 + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, + "root_path": workdir, + "path": workdir + "/tests/api", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } + parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz +from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + + # 参数初始化 + result, exception_result = "", "" + test_summary = {} + + # 脚本启动时间 + script_start_time = time.time() + + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_URL", + "name": "sec_url", + "type": "url", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^open.node" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 1, + "send_icmp_unreachable": 0, + "after_n_packets": 0 + }, + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "wget -q --debug http://open.node.com:180" + } + + verification_result = { + "excepted_traffic_result": "200", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) + finally: + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", + "api_server": "http://192.168.44.72", + "initiation_method": "api", + "env": "tsgx", + "vsys": 5, + "root_path": workdir, + "path": workdir + "/tests", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_pre_url_rate_high.py b/tests/security/sec_deny_srcip_http_pre_url_rate_high.py index 5ca2f8283..44637ee8d 100644 --- a/tests/security/sec_deny_srcip_http_pre_url_rate_high.py +++ b/tests/security/sec_deny_srcip_http_pre_url_rate_high.py @@ -164,4 +164,403 @@ if __name__ == '__main__': "test_case_name": os.path.basename(__file__)[:-3] } parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import time +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +from datetime import datetime +from support.report_update import ReportUpdate +from support.common_utils.create_policy import CreatePolicy + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + script_start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "security", + "rule_name": "sec_deny_srcip_http_pre_url_alert_200_profile", + "rule_action": "deny", + "rule_type": "create", + "condition": { + "source_ip": [ + { + "name": "sec_srcip", + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": parameter['test_pc_ip'], + } + ] + } + ], + "source_port": [], + "destination_ip": [], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [], + "protocol_filed": [ + { + "name": "sec_url", + "object_type": "url", + "item_operation": "add", + "select_type": False, + "negate": False, + "items": [ + { + "item_operation": "add", + "item_type": "url", + "item_value": "open.node*" + } + ], + } + ], + "sub_action_override": True, + "sub_action": [ + { + "type": "alert", + "code": 200, + "content_type": "Profile", + "content": "sec_respage" + } + ], + "packet_capture": [] + }, + "action_parameter": { + "response_page": [ + { + "profile_type": "response_page", + "response_code": 200, + "response_content_type": "Profile", + "profile_file": { + "name": "sec_respage", + "model": "create", + "file": "response_testa.html" + }, + } + ] + }, + "profile": [], + "expected_return": "200", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"}], + "traffic": { + "protocol": "http", + "type": "wget", + "command": "wget -q --debug http://open.node.com:180" + }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + return result + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) + return "Error: " + str(e) + finally: + # 清理环境并删除配置 + if isinstance(create, CreatePolicy): + create.clean_up() + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + # ui + # parameter = { + # "username": "hebingning", + # "password": "hbn66AAA", + # "test_pc_ip": "192.168.64.65", + # "test_subcriber_id": "test6776", + # "api_server": "http://192.168.44.72", + # "debug_flag": "local", + # "script_type": "ui", + # "env": "tsgx", + # "vsys_id": 1, + # "is_log": 1, + # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", + # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", + # "module_name": "security", + # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" + # } + # run(parameter) + # api + from support.ui_utils.element_position.map_element_position_library import replace_paras + from support.ui_utils.workpath import workdir + + parameter = { + "username": "hebingning", + "password": "hbn66AAA", + "test_pc_ip": "192.168.64.93", + "test_subcriber_id": "test6491", + "api_server": "http://192.168.44.72", + "debug_flag": "local", + "script_type": "api", # api ui 空字符串 + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, + "root_path": workdir, + "path": workdir + "/tests/api", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } + parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz +from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + + # 参数初始化 + result, exception_result = "", "" + test_summary = {} + + # 脚本启动时间 + script_start_time = time.time() + + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_URL", + "name": "sec_url", + "type": "url", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^open.node" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 1, + "send_icmp_unreachable": 0, + "after_n_packets": 0 + }, + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "wget -q --debug http://open.node.com:180" + } + + verification_result = { + "excepted_traffic_result": "200", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) + finally: + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", + "api_server": "http://192.168.44.72", + "initiation_method": "api", + "env": "tsgx", + "vsys": 5, + "root_path": workdir, + "path": workdir + "/tests", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_pre_url_rate_low.py b/tests/security/sec_deny_srcip_http_pre_url_rate_low.py index 8d813fc51..aa68ebfda 100644 --- a/tests/security/sec_deny_srcip_http_pre_url_rate_low.py +++ b/tests/security/sec_deny_srcip_http_pre_url_rate_low.py @@ -164,4 +164,403 @@ if __name__ == '__main__': "test_case_name": os.path.basename(__file__)[:-3] } parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import time +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +from datetime import datetime +from support.report_update import ReportUpdate +from support.common_utils.create_policy import CreatePolicy + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + script_start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "security", + "rule_name": "sec_deny_srcip_http_pre_url_alert_200_profile", + "rule_action": "deny", + "rule_type": "create", + "condition": { + "source_ip": [ + { + "name": "sec_srcip", + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": parameter['test_pc_ip'], + } + ] + } + ], + "source_port": [], + "destination_ip": [], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [], + "protocol_filed": [ + { + "name": "sec_url", + "object_type": "url", + "item_operation": "add", + "select_type": False, + "negate": False, + "items": [ + { + "item_operation": "add", + "item_type": "url", + "item_value": "open.node*" + } + ], + } + ], + "sub_action_override": True, + "sub_action": [ + { + "type": "alert", + "code": 200, + "content_type": "Profile", + "content": "sec_respage" + } + ], + "packet_capture": [] + }, + "action_parameter": { + "response_page": [ + { + "profile_type": "response_page", + "response_code": 200, + "response_content_type": "Profile", + "profile_file": { + "name": "sec_respage", + "model": "create", + "file": "response_testa.html" + }, + } + ] + }, + "profile": [], + "expected_return": "200", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"}], + "traffic": { + "protocol": "http", + "type": "wget", + "command": "wget -q --debug http://open.node.com:180" + }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + return result + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) + return "Error: " + str(e) + finally: + # 清理环境并删除配置 + if isinstance(create, CreatePolicy): + create.clean_up() + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + # ui + # parameter = { + # "username": "hebingning", + # "password": "hbn66AAA", + # "test_pc_ip": "192.168.64.65", + # "test_subcriber_id": "test6776", + # "api_server": "http://192.168.44.72", + # "debug_flag": "local", + # "script_type": "ui", + # "env": "tsgx", + # "vsys_id": 1, + # "is_log": 1, + # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", + # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", + # "module_name": "security", + # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" + # } + # run(parameter) + # api + from support.ui_utils.element_position.map_element_position_library import replace_paras + from support.ui_utils.workpath import workdir + + parameter = { + "username": "hebingning", + "password": "hbn66AAA", + "test_pc_ip": "192.168.64.93", + "test_subcriber_id": "test6491", + "api_server": "http://192.168.44.72", + "debug_flag": "local", + "script_type": "api", # api ui 空字符串 + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, + "root_path": workdir, + "path": workdir + "/tests/api", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } + parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz +from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + + # 参数初始化 + result, exception_result = "", "" + test_summary = {} + + # 脚本启动时间 + script_start_time = time.time() + + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_URL", + "name": "sec_url", + "type": "url", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^open.node" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 1, + "send_icmp_unreachable": 0, + "after_n_packets": 0 + }, + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "wget -q --debug http://open.node.com:180" + } + + verification_result = { + "excepted_traffic_result": "200", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) + finally: + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", + "api_server": "http://192.168.44.72", + "initiation_method": "api", + "env": "tsgx", + "vsys": 5, + "root_path": workdir, + "path": workdir + "/tests", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_pre_url_redirect.py b/tests/security/sec_deny_srcip_http_pre_url_redirect.py index 566efbb8e..d7d190be3 100644 --- a/tests/security/sec_deny_srcip_http_pre_url_redirect.py +++ b/tests/security/sec_deny_srcip_http_pre_url_redirect.py @@ -167,4 +167,403 @@ if __name__ == '__main__': "test_case_name": os.path.basename(__file__)[:-3] } parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import time +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +from datetime import datetime +from support.report_update import ReportUpdate +from support.common_utils.create_policy import CreatePolicy + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + script_start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "security", + "rule_name": "sec_deny_srcip_http_pre_url_alert_200_profile", + "rule_action": "deny", + "rule_type": "create", + "condition": { + "source_ip": [ + { + "name": "sec_srcip", + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": parameter['test_pc_ip'], + } + ] + } + ], + "source_port": [], + "destination_ip": [], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [], + "protocol_filed": [ + { + "name": "sec_url", + "object_type": "url", + "item_operation": "add", + "select_type": False, + "negate": False, + "items": [ + { + "item_operation": "add", + "item_type": "url", + "item_value": "open.node*" + } + ], + } + ], + "sub_action_override": True, + "sub_action": [ + { + "type": "alert", + "code": 200, + "content_type": "Profile", + "content": "sec_respage" + } + ], + "packet_capture": [] + }, + "action_parameter": { + "response_page": [ + { + "profile_type": "response_page", + "response_code": 200, + "response_content_type": "Profile", + "profile_file": { + "name": "sec_respage", + "model": "create", + "file": "response_testa.html" + }, + } + ] + }, + "profile": [], + "expected_return": "200", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"}], + "traffic": { + "protocol": "http", + "type": "wget", + "command": "wget -q --debug http://open.node.com:180" + }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + return result + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) + return "Error: " + str(e) + finally: + # 清理环境并删除配置 + if isinstance(create, CreatePolicy): + create.clean_up() + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + # ui + # parameter = { + # "username": "hebingning", + # "password": "hbn66AAA", + # "test_pc_ip": "192.168.64.65", + # "test_subcriber_id": "test6776", + # "api_server": "http://192.168.44.72", + # "debug_flag": "local", + # "script_type": "ui", + # "env": "tsgx", + # "vsys_id": 1, + # "is_log": 1, + # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", + # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", + # "module_name": "security", + # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" + # } + # run(parameter) + # api + from support.ui_utils.element_position.map_element_position_library import replace_paras + from support.ui_utils.workpath import workdir + + parameter = { + "username": "hebingning", + "password": "hbn66AAA", + "test_pc_ip": "192.168.64.93", + "test_subcriber_id": "test6491", + "api_server": "http://192.168.44.72", + "debug_flag": "local", + "script_type": "api", # api ui 空字符串 + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, + "root_path": workdir, + "path": workdir + "/tests/api", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } + parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz +from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + + # 参数初始化 + result, exception_result = "", "" + test_summary = {} + + # 脚本启动时间 + script_start_time = time.time() + + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_URL", + "name": "sec_url", + "type": "url", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^open.node" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 1, + "send_icmp_unreachable": 0, + "after_n_packets": 0 + }, + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "wget -q --debug http://open.node.com:180" + } + + verification_result = { + "excepted_traffic_result": "200", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) + finally: + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", + "api_server": "http://192.168.44.72", + "initiation_method": "api", + "env": "tsgx", + "vsys": 5, + "root_path": workdir, + "path": workdir + "/tests", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_pre_url_tamper.py b/tests/security/sec_deny_srcip_http_pre_url_tamper.py index 3e4a40547..894e0372e 100644 --- a/tests/security/sec_deny_srcip_http_pre_url_tamper.py +++ b/tests/security/sec_deny_srcip_http_pre_url_tamper.py @@ -163,4 +163,403 @@ if __name__ == '__main__': "test_case_name": os.path.basename(__file__)[:-3] } parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import time +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +from datetime import datetime +from support.report_update import ReportUpdate +from support.common_utils.create_policy import CreatePolicy + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + script_start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "security", + "rule_name": "sec_deny_srcip_http_pre_url_alert_200_profile", + "rule_action": "deny", + "rule_type": "create", + "condition": { + "source_ip": [ + { + "name": "sec_srcip", + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": parameter['test_pc_ip'], + } + ] + } + ], + "source_port": [], + "destination_ip": [], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [], + "protocol_filed": [ + { + "name": "sec_url", + "object_type": "url", + "item_operation": "add", + "select_type": False, + "negate": False, + "items": [ + { + "item_operation": "add", + "item_type": "url", + "item_value": "open.node*" + } + ], + } + ], + "sub_action_override": True, + "sub_action": [ + { + "type": "alert", + "code": 200, + "content_type": "Profile", + "content": "sec_respage" + } + ], + "packet_capture": [] + }, + "action_parameter": { + "response_page": [ + { + "profile_type": "response_page", + "response_code": 200, + "response_content_type": "Profile", + "profile_file": { + "name": "sec_respage", + "model": "create", + "file": "response_testa.html" + }, + } + ] + }, + "profile": [], + "expected_return": "200", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"}], + "traffic": { + "protocol": "http", + "type": "wget", + "command": "wget -q --debug http://open.node.com:180" + }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + return result + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) + return "Error: " + str(e) + finally: + # 清理环境并删除配置 + if isinstance(create, CreatePolicy): + create.clean_up() + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + # ui + # parameter = { + # "username": "hebingning", + # "password": "hbn66AAA", + # "test_pc_ip": "192.168.64.65", + # "test_subcriber_id": "test6776", + # "api_server": "http://192.168.44.72", + # "debug_flag": "local", + # "script_type": "ui", + # "env": "tsgx", + # "vsys_id": 1, + # "is_log": 1, + # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", + # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", + # "module_name": "security", + # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" + # } + # run(parameter) + # api + from support.ui_utils.element_position.map_element_position_library import replace_paras + from support.ui_utils.workpath import workdir + + parameter = { + "username": "hebingning", + "password": "hbn66AAA", + "test_pc_ip": "192.168.64.93", + "test_subcriber_id": "test6491", + "api_server": "http://192.168.44.72", + "debug_flag": "local", + "script_type": "api", # api ui 空字符串 + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, + "root_path": workdir, + "path": workdir + "/tests/api", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } + parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz +from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + + # 参数初始化 + result, exception_result = "", "" + test_summary = {} + + # 脚本启动时间 + script_start_time = time.time() + + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_URL", + "name": "sec_url", + "type": "url", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^open.node" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 1, + "send_icmp_unreachable": 0, + "after_n_packets": 0 + }, + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "wget -q --debug http://open.node.com:180" + } + + verification_result = { + "excepted_traffic_result": "200", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) + finally: + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", + "api_server": "http://192.168.44.72", + "initiation_method": "api", + "env": "tsgx", + "vsys": 5, + "root_path": workdir, + "path": workdir + "/tests", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_rate_high.py b/tests/security/sec_deny_srcip_http_rate_high.py index 3b339f7d6..2b93f991c 100644 --- a/tests/security/sec_deny_srcip_http_rate_high.py +++ b/tests/security/sec_deny_srcip_http_rate_high.py @@ -146,4 +146,403 @@ if __name__ == '__main__': "test_case_name": os.path.basename(__file__)[:-3] } parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import time +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +from datetime import datetime +from support.report_update import ReportUpdate +from support.common_utils.create_policy import CreatePolicy + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + script_start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "security", + "rule_name": "sec_deny_srcip_http_pre_url_alert_200_profile", + "rule_action": "deny", + "rule_type": "create", + "condition": { + "source_ip": [ + { + "name": "sec_srcip", + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": parameter['test_pc_ip'], + } + ] + } + ], + "source_port": [], + "destination_ip": [], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [], + "protocol_filed": [ + { + "name": "sec_url", + "object_type": "url", + "item_operation": "add", + "select_type": False, + "negate": False, + "items": [ + { + "item_operation": "add", + "item_type": "url", + "item_value": "open.node*" + } + ], + } + ], + "sub_action_override": True, + "sub_action": [ + { + "type": "alert", + "code": 200, + "content_type": "Profile", + "content": "sec_respage" + } + ], + "packet_capture": [] + }, + "action_parameter": { + "response_page": [ + { + "profile_type": "response_page", + "response_code": 200, + "response_content_type": "Profile", + "profile_file": { + "name": "sec_respage", + "model": "create", + "file": "response_testa.html" + }, + } + ] + }, + "profile": [], + "expected_return": "200", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"}], + "traffic": { + "protocol": "http", + "type": "wget", + "command": "wget -q --debug http://open.node.com:180" + }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + return result + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) + return "Error: " + str(e) + finally: + # 清理环境并删除配置 + if isinstance(create, CreatePolicy): + create.clean_up() + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + # ui + # parameter = { + # "username": "hebingning", + # "password": "hbn66AAA", + # "test_pc_ip": "192.168.64.65", + # "test_subcriber_id": "test6776", + # "api_server": "http://192.168.44.72", + # "debug_flag": "local", + # "script_type": "ui", + # "env": "tsgx", + # "vsys_id": 1, + # "is_log": 1, + # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", + # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", + # "module_name": "security", + # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" + # } + # run(parameter) + # api + from support.ui_utils.element_position.map_element_position_library import replace_paras + from support.ui_utils.workpath import workdir + + parameter = { + "username": "hebingning", + "password": "hbn66AAA", + "test_pc_ip": "192.168.64.93", + "test_subcriber_id": "test6491", + "api_server": "http://192.168.44.72", + "debug_flag": "local", + "script_type": "api", # api ui 空字符串 + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, + "root_path": workdir, + "path": workdir + "/tests/api", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } + parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz +from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + + # 参数初始化 + result, exception_result = "", "" + test_summary = {} + + # 脚本启动时间 + script_start_time = time.time() + + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_URL", + "name": "sec_url", + "type": "url", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^open.node" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 1, + "send_icmp_unreachable": 0, + "after_n_packets": 0 + }, + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "wget -q --debug http://open.node.com:180" + } + + verification_result = { + "excepted_traffic_result": "200", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) + finally: + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", + "api_server": "http://192.168.44.72", + "initiation_method": "api", + "env": "tsgx", + "vsys": 5, + "root_path": workdir, + "path": workdir + "/tests", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_http_rate_low.py b/tests/security/sec_deny_srcip_http_rate_low.py index fc06d956d..c78ddd4bc 100644 --- a/tests/security/sec_deny_srcip_http_rate_low.py +++ b/tests/security/sec_deny_srcip_http_rate_low.py @@ -146,4 +146,403 @@ if __name__ == '__main__': "test_case_name": os.path.basename(__file__)[:-3] } parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import time +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +from datetime import datetime +from support.report_update import ReportUpdate +from support.common_utils.create_policy import CreatePolicy + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + script_start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "security", + "rule_name": "sec_deny_srcip_http_pre_url_alert_200_profile", + "rule_action": "deny", + "rule_type": "create", + "condition": { + "source_ip": [ + { + "name": "sec_srcip", + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": parameter['test_pc_ip'], + } + ] + } + ], + "source_port": [], + "destination_ip": [], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [], + "protocol_filed": [ + { + "name": "sec_url", + "object_type": "url", + "item_operation": "add", + "select_type": False, + "negate": False, + "items": [ + { + "item_operation": "add", + "item_type": "url", + "item_value": "open.node*" + } + ], + } + ], + "sub_action_override": True, + "sub_action": [ + { + "type": "alert", + "code": 200, + "content_type": "Profile", + "content": "sec_respage" + } + ], + "packet_capture": [] + }, + "action_parameter": { + "response_page": [ + { + "profile_type": "response_page", + "response_code": 200, + "response_content_type": "Profile", + "profile_file": { + "name": "sec_respage", + "model": "create", + "file": "response_testa.html" + }, + } + ] + }, + "profile": [], + "expected_return": "200", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"}], + "traffic": { + "protocol": "http", + "type": "wget", + "command": "wget -q --debug http://open.node.com:180" + }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + return result + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, flush=True) + return "Error: " + str(e) + finally: + # 清理环境并删除配置 + if isinstance(create, CreatePolicy): + create.clean_up() + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + # ui + # parameter = { + # "username": "hebingning", + # "password": "hbn66AAA", + # "test_pc_ip": "192.168.64.65", + # "test_subcriber_id": "test6776", + # "api_server": "http://192.168.44.72", + # "debug_flag": "local", + # "script_type": "ui", + # "env": "tsgx", + # "vsys_id": 1, + # "is_log": 1, + # "root_path": "D:/Document/Project-TSG/Code/git/tsg_test", + # "path": "D:/Document/Project-TSG/Code/git/tsg_test/tests/ui", + # "module_name": "security", + # "test_case_name": "deny_srcip_fqdn_drop_rst_icmp" + # } + # run(parameter) + # api + from support.ui_utils.element_position.map_element_position_library import replace_paras + from support.ui_utils.workpath import workdir + + parameter = { + "username": "hebingning", + "password": "hbn66AAA", + "test_pc_ip": "192.168.64.93", + "test_subcriber_id": "test6491", + "api_server": "http://192.168.44.72", + "debug_flag": "local", + "script_type": "api", # api ui 空字符串 + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, + "root_path": workdir, + "path": workdir + "/tests/api", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } + parameter = replace_paras(parameter) + run(parameter) + +# -*- coding: UTF-8 -*- +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +import time +import pytz +from datetime import datetime +from support.ui_utils.workpath import workdir +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + + # 参数初始化 + result, exception_result = "", "" + test_summary = {} + + # 脚本启动时间 + script_start_time = time.time() + + policy_configuration = { + "name": os.path.splitext(os.path.basename(__file__))[0], + "type": "security", + "action": "deny", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "sub_type": "ip", + "name": "sec_srcip", + "items": [ + { + "op": "add", + "ip": parameter['test_pc_ip'], + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ], + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_HTTP_URL", + "name": "sec_url", + "type": "url", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "expr_type": "and", + "expression": "^open.node" + } + ] + } + ] + } + ], + "action_parameter": { + "sub_action": "drop", + "packet_capture": { + "enable": 0 + }, + "send_tcp_reset": 1, + "send_icmp_unreachable": 0, + "after_n_packets": 0 + }, + "is_enabled": 1, + "log_option": "metadata", + } + + traffic_generation = { + "tool": "http", # or trex/http + "command": "wget -q --debug http://open.node.com:180" + } + + verification_result = { + "excepted_traffic_result": "200", + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key":"http_host", "query_value": "open.node.com"}, + {"query_field_key":"http_url", "query_value": "open.node.com:180/"}, + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key":"security_action","query_value":"deny"} + ] + } + + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + objects_tuple, ui_error = ui_client.create_objects(policy_configuration) + if len(ui_error) > 0: + return ui_error + rules_tuple, ui_error = ui_client.create_rules(policy_configuration, objects_tuple) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", "") + if len(api_error) > 0: + return api_error + + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + + return test_summary + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) + finally: + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + + # 统计脚本用时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.87", + "test_subcriber_id": "test6776", + "api_server": "http://192.168.44.72", + "initiation_method": "api", + "env": "tsgx", + "vsys": 5, + "root_path": workdir, + "path": workdir + "/tests", + "module_name": "security", + "test_case_name": os.path.basename(__file__)[:-3] + } run(parameter)
\ No newline at end of file diff --git a/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_403_responseprofile_hit_no.py b/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_403_responseprofile_hit_no.py index 0e6215a69..06146c74e 100644 --- a/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_403_responseprofile_hit_no.py +++ b/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_403_responseprofile_hit_no.py @@ -74,7 +74,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 403, "html_profile": { "name": "test", diff --git a/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_403_responseprofile_hit_yes.py b/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_403_responseprofile_hit_yes.py index 4c77e44c5..9e30a2711 100644 --- a/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_403_responseprofile_hit_yes.py +++ b/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_403_responseprofile_hit_yes.py @@ -74,7 +74,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 403, "html_profile": { "name": "test", diff --git a/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_403_responsetext_hit_no.py b/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_403_responsetext_hit_no.py index f7075ac99..27bdd6d32 100644 --- a/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_403_responsetext_hit_no.py +++ b/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_403_responsetext_hit_no.py @@ -74,7 +74,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 403, "message": "deny_autest_403", "packet_capture": { diff --git a/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_403_responsetext_hit_yes.py b/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_403_responsetext_hit_yes.py index c1def4c7b..2515c36f6 100644 --- a/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_403_responsetext_hit_yes.py +++ b/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_403_responsetext_hit_yes.py @@ -74,7 +74,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 403, "message": "deny_autest_403", "packet_capture": { diff --git a/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_404_responseprofile_hit_no.py b/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_404_responseprofile_hit_no.py index 31ca66516..d5e428f93 100644 --- a/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_404_responseprofile_hit_no.py +++ b/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_404_responseprofile_hit_no.py @@ -74,7 +74,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 404, "html_profile": { "name": "test", diff --git a/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_404_responseprofile_hit_yes.py b/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_404_responseprofile_hit_yes.py index 986697c68..7b1f582df 100644 --- a/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_404_responseprofile_hit_yes.py +++ b/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_404_responseprofile_hit_yes.py @@ -74,7 +74,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 404, "html_profile": { "name": "test", diff --git a/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_404_responsetext_hit_no.py b/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_404_responsetext_hit_no.py index d09fa2a5c..3f42d51f5 100644 --- a/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_404_responsetext_hit_no.py +++ b/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_404_responsetext_hit_no.py @@ -74,7 +74,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 404, "message": "deny_autest_404", "packet_capture": { diff --git a/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_404_responsetext_hit_yes.py b/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_404_responsetext_hit_yes.py index bde338215..62d5eaca0 100644 --- a/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_404_responsetext_hit_yes.py +++ b/tests/security/sec_deny_srcip_negate_substr_fqdn_http_block_404_responsetext_hit_yes.py @@ -74,7 +74,7 @@ def run(parameter): } ], "action_parameter": { - "sub_action": "alert", + "sub_action": "block", "code": 404, "message": "deny_autest_404", "packet_capture": { diff --git a/tests/service_chaining/sc_raw_dstip_dstport_range_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_dstip_dstport_range_mirror_bypass_vlan_none.py index c67818e43..70e8ab640 100644 --- a/tests/service_chaining/sc_raw_dstip_dstport_range_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_dstip_dstport_range_mirror_bypass_vlan_none.py @@ -116,7 +116,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, diff --git a/tests/service_chaining/sc_raw_dstip_dstport_range_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_dstip_dstport_range_steer_bypass_vxlan_activeip_bfd.py index cdf67e4a9..0a25a0cd2 100644 --- a/tests/service_chaining/sc_raw_dstip_dstport_range_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_dstip_dstport_range_steer_bypass_vxlan_activeip_bfd.py @@ -115,7 +115,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, diff --git a/tests/service_chaining/sc_raw_dstip_external_port_range_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_dstip_external_port_range_mirror_bypass_vlan_none.py index 785fd3e5c..5331ec39f 100644 --- a/tests/service_chaining/sc_raw_dstip_external_port_range_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_dstip_external_port_range_mirror_bypass_vlan_none.py @@ -136,7 +136,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, diff --git a/tests/service_chaining/sc_raw_dstip_external_port_range_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_dstip_external_port_range_steer_bypass_vxlan_activeip_bfd.py index 2a22584ce..c83d02a8b 100644 --- a/tests/service_chaining/sc_raw_dstip_external_port_range_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_dstip_external_port_range_steer_bypass_vxlan_activeip_bfd.py @@ -115,7 +115,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, diff --git a/tests/service_chaining/sc_raw_multiple_port_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_multiple_port_steer_bypass_vxlan_activeip_bfd.py index a9c854b23..6392bc087 100644 --- a/tests/service_chaining/sc_raw_multiple_port_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_multiple_port_steer_bypass_vxlan_activeip_bfd.py @@ -148,7 +148,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, diff --git a/tests/service_chaining/sc_raw_negate_apn_fqdn_ssl_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_negate_apn_fqdn_ssl_mirror_bypass_vlan_none.py index 1965e39a7..89c6a84ca 100644 --- a/tests/service_chaining/sc_raw_negate_apn_fqdn_ssl_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_negate_apn_fqdn_ssl_mirror_bypass_vlan_none.py @@ -127,7 +127,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 0}, "expected_log": [] } diff --git a/tests/service_chaining/sc_raw_negate_apn_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_negate_apn_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py index ad37a01c8..f072fdfa6 100644 --- a/tests/service_chaining/sc_raw_negate_apn_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_negate_apn_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py @@ -125,7 +125,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 0}, "expected_log": [] } diff --git a/tests/service_chaining/sc_raw_negate_srcip_dstip_fqdn_ssl_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_negate_srcip_dstip_fqdn_ssl_mirror_bypass_vlan_none.py index a0692b7c7..df761e1ac 100644 --- a/tests/service_chaining/sc_raw_negate_srcip_dstip_fqdn_ssl_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_negate_srcip_dstip_fqdn_ssl_mirror_bypass_vlan_none.py @@ -149,7 +149,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 0}, "expected_log": [] } diff --git a/tests/service_chaining/sc_raw_negate_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_negate_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py index 1dd99ed84..34da53491 100644 --- a/tests/service_chaining/sc_raw_negate_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_negate_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py @@ -148,7 +148,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 0}, "expected_log": [] } diff --git a/tests/service_chaining/sc_raw_scrip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_scrip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_none.py index 99e241ef7..4f22f6172 100644 --- a/tests/service_chaining/sc_raw_scrip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_none.py +++ b/tests/service_chaining/sc_raw_scrip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_none.py @@ -147,7 +147,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_http_url_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_http_url_mirror_bypass_vlan_none.py index a234b2f6f..8a3fee1cd 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_http_url_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_http_url_mirror_bypass_vlan_none.py @@ -287,7 +287,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py index 42410fe9d..373d4ba21 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py @@ -286,7 +286,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ipprototcp_http_url_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ipprototcp_http_url_mirror_bypass_vlan_none.py index 08c212a6f..af14713d9 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ipprototcp_http_url_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ipprototcp_http_url_mirror_bypass_vlan_none.py @@ -297,7 +297,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ipprototcp_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ipprototcp_http_url_steer_bypass_vxlan_activeip_bfd.py index b4826c576..df7a765b3 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ipprototcp_http_url_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ipprototcp_http_url_steer_bypass_vxlan_activeip_bfd.py @@ -296,7 +296,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py index f7ca0e546..6f3a71997 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py @@ -302,7 +302,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_extport_ssl_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_extport_ssl_mirror_bypass_vlan_none.py index 107b9a67e..8e8e60ff3 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_extport_ssl_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_extport_ssl_mirror_bypass_vlan_none.py @@ -166,7 +166,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -286,7 +286,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_extport_ssl_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_extport_ssl_steer_bypass_vxlan_activeip_bfd.py index cc89ba115..f90c1160a 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_extport_ssl_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_extport_ssl_steer_bypass_vxlan_activeip_bfd.py @@ -165,7 +165,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -285,7 +285,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_intport_ssl_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_intport_ssl_mirror_bypass_vlan_none.py index 5c82664b2..59066e554 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_intport_ssl_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_intport_ssl_mirror_bypass_vlan_none.py @@ -166,7 +166,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -286,7 +286,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_intport_ssl_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_intport_ssl_steer_bypass_vxlan_activeip_bfd.py index 5c82664b2..59066e554 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_intport_ssl_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_intport_ssl_steer_bypass_vxlan_activeip_bfd.py @@ -166,7 +166,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -286,7 +286,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_quic_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_quic_mirror_bypass_vlan_none.py index b589704fe..a7bd633bd 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_quic_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_quic_mirror_bypass_vlan_none.py @@ -268,7 +268,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_quic_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_quic_steer_bypass_vxlan_activeip_bfd.py index ca55d72f7..1f63550ea 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_quic_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_quic_steer_bypass_vxlan_activeip_bfd.py @@ -267,7 +267,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_true_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_true_mirror_bypass_vlan_none.py index ee3c4c265..725e7c6c9 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_true_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_true_mirror_bypass_vlan_none.py @@ -159,7 +159,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -280,7 +280,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_true_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_true_steer_bypass_vxlan_activeip_bfd.py index 87c5d34d2..cd3f5b783 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_true_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_true_steer_bypass_vxlan_activeip_bfd.py @@ -158,7 +158,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_esni_false_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_esni_false_mirror_bypass_vlan_none.py index dee077156..7361d2658 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_esni_false_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_esni_false_mirror_bypass_vlan_none.py @@ -280,7 +280,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_disabled_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_disabled_vxlan_activeip_bfd.py index 5bcfba02b..93d0c860a 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_disabled_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_disabled_vxlan_activeip_bfd.py @@ -146,7 +146,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -266,7 +266,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_activeip_bfd.py index 979e689bd..d9c17b72a 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_activeip_bfd.py @@ -144,7 +144,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -264,7 +264,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_activeip_none.py index c2c8fbe5f..0c178dde9 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_activeip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_activeip_none.py @@ -146,7 +146,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -266,7 +266,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_inactiveip_bfd.py index d093eeb84..d84019da7 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_inactiveip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_inactiveip_bfd.py @@ -143,7 +143,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -263,7 +263,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_inactiveip_none.py index a5d544c69..4474edd00 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_inactiveip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_inactiveip_none.py @@ -145,7 +145,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -265,7 +265,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vlan_none.py index 6f795c560..8facc0044 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vlan_none.py @@ -149,7 +149,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -269,7 +269,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_activeip_bfd.py index 21be5265e..84db559ec 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_activeip_bfd.py @@ -143,7 +143,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -263,7 +263,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_activeip_none.py index 1e24a07d0..d95e8edfa 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_activeip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_activeip_none.py @@ -148,7 +148,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -268,7 +268,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_inactiveip_none.py index e7139b8b5..94636c274 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_inactiveip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_inactiveip_none.py @@ -146,7 +146,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -266,7 +266,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_bfd.py index 1bc02a4bd..60551a6a9 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_bfd.py @@ -140,7 +140,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -260,7 +260,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_none.py index 9956176f5..f0caac19e 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_none.py @@ -142,7 +142,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -262,7 +262,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_global_bypass_diff_device_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_global_bypass_diff_device_vlan_none.py index ba8c3f7c8..2506c9373 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_global_bypass_diff_device_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_global_bypass_diff_device_vlan_none.py @@ -147,7 +147,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -267,7 +267,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_nearby_bypass_diff_device_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_nearby_bypass_diff_device_vlan_none.py index b1c7bf35f..319586ff9 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_nearby_bypass_diff_device_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_nearby_bypass_diff_device_vlan_none.py @@ -146,7 +146,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -266,7 +266,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_disabled_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_disabled_vxlan_activeip_bfd.py index 286fe4603..2f807f1ec 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_disabled_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_disabled_vxlan_activeip_bfd.py @@ -151,7 +151,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -271,7 +271,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vlan_none.py index 8789bf7df..cd89b1468 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vlan_none.py @@ -273,7 +273,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } parameter = replace_paras(parameter) run(parameter) diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_activeip_bfd.py index b134b258a..4b04ff7b6 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_activeip_bfd.py @@ -151,7 +151,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -271,7 +271,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_activeip_none.py index 6b2fda0c2..45133ec7c 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_activeip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_activeip_none.py @@ -148,7 +148,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -268,7 +268,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_inactiveip_bfd.py index 1d78b0cf7..23c0d5af5 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_inactiveip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_inactiveip_bfd.py @@ -151,7 +151,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -271,7 +271,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_inactiveip_none.py index 7e29ddf43..39bc2eb0e 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_inactiveip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_inactiveip_none.py @@ -151,7 +151,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -271,7 +271,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_unavailableip_bfd.py index 550d79747..2ccc13d1e 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_unavailableip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_unavailableip_bfd.py @@ -144,7 +144,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -264,7 +264,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_unavailableip_none.py index a3999795d..27f19f799 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_unavailableip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_unavailableip_none.py @@ -151,7 +151,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -271,7 +271,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_disabled_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_disabled_vxlan_activeip_bfd.py index c12b5e6ee..c2bf41256 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_disabled_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_disabled_vxlan_activeip_bfd.py @@ -152,7 +152,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -272,7 +272,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vlan_none.py index 8fb9be306..c58e07526 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vlan_none.py @@ -153,7 +153,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -273,7 +273,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_activeip_bfd.py index c36d2b918..5dd773166 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_activeip_bfd.py @@ -152,7 +152,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -272,7 +272,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_activeip_none.py index 686bc5584..4c949b834 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_activeip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_activeip_none.py @@ -152,7 +152,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -272,7 +272,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_inactiveip_bfd.py index ef5df8042..2001cc6eb 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_inactiveip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_inactiveip_bfd.py @@ -152,7 +152,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -272,7 +272,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_inactiveip_none.py index ad346b1b9..8ac4eced1 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_inactiveip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_inactiveip_none.py @@ -152,7 +152,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -272,7 +272,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_unavailableip_bfd.py index e739c59ad..05c1e1106 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_unavailableip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_unavailableip_bfd.py @@ -152,7 +152,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -272,7 +272,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_unavailableip_none.py index 3ad439637..770499b57 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_unavailableip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_unavailableip_none.py @@ -152,7 +152,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -272,7 +272,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_no_sni_false_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_no_sni_false_mirror_bypass_vlan_none.py index 0ec30cdcf..ed24ce224 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_no_sni_false_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_no_sni_false_mirror_bypass_vlan_none.py @@ -159,7 +159,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_no_sni_false_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_no_sni_false_steer_bypass_vxlan_activeip_bfd.py index e3e1adfa5..2d0edcdb9 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_no_sni_false_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_no_sni_false_steer_bypass_vxlan_activeip_bfd.py @@ -158,7 +158,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -278,7 +278,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_activeip_bfd.py index f6918de86..ba8e1aec1 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_activeip_bfd.py @@ -145,7 +145,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -265,7 +265,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_activeip_none.py index 8089010dd..fa1529abf 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_activeip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_activeip_none.py @@ -145,7 +145,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -265,7 +265,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_inactiveip_bfd.py index a4b7fa560..2272a60ae 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_inactiveip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_inactiveip_bfd.py @@ -139,7 +139,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -259,7 +259,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_inactiveip_none.py index ba3772c9c..ffa102077 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_inactiveip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_inactiveip_none.py @@ -145,7 +145,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -265,7 +265,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_unavailableip_bfd.py index a5da461ea..250396e79 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_unavailableip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_unavailableip_bfd.py @@ -138,7 +138,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -258,7 +258,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_unavailableip_none.py index 7507a1dfe..2fdd3de45 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_unavailableip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_unavailableip_none.py @@ -142,7 +142,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -262,7 +262,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py index ada10e58e..e09e66d04 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py @@ -148,7 +148,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -268,7 +268,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_none.py index 84865a088..b12b51c21 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_none.py @@ -145,7 +145,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -265,7 +265,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_inactiveip_bfd.py index 6165972c3..883dda9d4 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_inactiveip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_inactiveip_bfd.py @@ -139,7 +139,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -259,7 +259,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_inactiveip_none.py index c8b79cab6..22f8585ca 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_inactiveip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_inactiveip_none.py @@ -145,7 +145,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -265,7 +265,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_unavailableip_bfd.py index 461c5e6af..0b9ab9c8a 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_unavailableip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_unavailableip_bfd.py @@ -136,7 +136,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -256,7 +256,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_unavailableip_none.py index 9c4fa6e11..a0702d4bc 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_unavailableip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_unavailableip_none.py @@ -143,7 +143,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -263,7 +263,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_activeip_bfd.py index f12829bbd..424d36a87 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_activeip_bfd.py @@ -143,7 +143,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_activeip_none.py index 3b37154e3..75d5d6517 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_activeip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_activeip_none.py @@ -148,7 +148,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_inactiveip_bfd.py index 297484d9e..f9926fb59 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_inactiveip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_inactiveip_bfd.py @@ -142,7 +142,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_inactiveip_none.py index 1ca5ba430..2073e2c40 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_inactiveip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_inactiveip_none.py @@ -148,7 +148,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_unavailableip_bfd.py index b83f51135..8d20ae64c 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_unavailableip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_unavailableip_bfd.py @@ -143,7 +143,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_unavailableip_none.py index b471b8ee2..d9a8368a5 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_unavailableip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_unavailableip_none.py @@ -145,7 +145,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_activeip_bfd.py index 3e53eed90..2c2cc35c4 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_activeip_bfd.py @@ -143,7 +143,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_activeip_none.py index 2356e5504..35f4834d9 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_activeip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_activeip_none.py @@ -149,7 +149,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_inactiveip_bfd.py index dda343cf9..3385f78e3 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_inactiveip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_inactiveip_bfd.py @@ -143,7 +143,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_inactiveip_none.py index 0f3b16063..b064b3dc6 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_inactiveip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_inactiveip_none.py @@ -149,7 +149,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_unavailableip_bfd.py index f54398833..de8b64d7f 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_unavailableip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_unavailableip_bfd.py @@ -145,7 +145,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_unavailableip_none.py index d6b88d164..ae2ef716d 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_unavailableip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_unavailableip_none.py @@ -146,7 +146,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ftp_account_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_ftp_account_steer_bypass_vxlan_activeip_bfd.py index 2e34e626d..b1ec672f9 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_ftp_account_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_ftp_account_steer_bypass_vxlan_activeip_bfd.py @@ -262,7 +262,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ipprotoudp_dns_qname_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_ipprotoudp_dns_qname_steer_bypass_vxlan_activeip_bfd.py index 771d14278..593359190 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_ipprotoudp_dns_qname_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_ipprotoudp_dns_qname_steer_bypass_vxlan_activeip_bfd.py @@ -279,7 +279,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_mail_from_to_account_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_mail_from_to_account_mirror_bypass_vlan_none.py index e7f785395..2432db869 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_mail_from_to_account_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_mail_from_to_account_mirror_bypass_vlan_none.py @@ -305,7 +305,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_mail_from_to_account_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_mail_from_to_account_steer_bypass_vxlan_activeip_bfd.py index f49e555e0..3dfc1e9ea 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_mail_from_to_account_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_mail_from_to_account_steer_bypass_vxlan_activeip_bfd.py @@ -299,7 +299,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_mirror_block_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_mirror_block_vxlan_activeip_none.py index 26560927f..2af4200ef 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_mirror_block_vxlan_activeip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_mirror_block_vxlan_activeip_none.py @@ -117,7 +117,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -237,7 +237,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_disabled_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_disabled_vxlan_activeip_bfd.py index 67b50162d..415ffa441 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_disabled_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_disabled_vxlan_activeip_bfd.py @@ -115,7 +115,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -235,7 +235,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_vxlan_activeip_bfd.py index fa59169c3..6c8ae39e5 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_vxlan_activeip_bfd.py @@ -115,7 +115,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -235,7 +235,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_vxlan_activeip_none.py index 7ff5984ec..36c29d9a7 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_vxlan_activeip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_vxlan_activeip_none.py @@ -117,7 +117,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -237,7 +237,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_multiple_port_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_multiple_port_mirror_bypass_vlan_none.py index 2ab628165..a9f4de271 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_multiple_port_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_multiple_port_mirror_bypass_vlan_none.py @@ -189,7 +189,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -312,7 +312,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_negate_dstport_dns_qname_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_negate_dstport_dns_qname_mirror_bypass_vlan_none.py index a14b03f26..4902733a5 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_negate_dstport_dns_qname_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_negate_dstport_dns_qname_mirror_bypass_vlan_none.py @@ -288,7 +288,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_negate_dstport_dns_qname_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_negate_dstport_dns_qname_steer_bypass_vxlan_activeip_bfd.py index c073fe5c2..32942c60f 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_negate_dstport_dns_qname_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_negate_dstport_dns_qname_steer_bypass_vxlan_activeip_bfd.py @@ -287,7 +287,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_negate_fqdn_ssl_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_negate_fqdn_ssl_mirror_bypass_vlan_none.py index 9124ac688..4178bf6d9 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_negate_fqdn_ssl_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_negate_fqdn_ssl_mirror_bypass_vlan_none.py @@ -149,7 +149,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -269,7 +269,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_negate_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_negate_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py index e0aaac619..8a935e076 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_negate_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_negate_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py @@ -148,7 +148,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -268,7 +268,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_openvpn_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_openvpn_mirror_bypass_vlan_none.py index 0102d174d..4a587659b 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_openvpn_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_openvpn_mirror_bypass_vlan_none.py @@ -251,7 +251,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_openvpn_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_openvpn_steer_bypass_vxlan_activeip_bfd.py index 7ac5b3ef4..34625b1cb 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_openvpn_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_openvpn_steer_bypass_vxlan_activeip_bfd.py @@ -251,7 +251,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_quic_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_quic_mirror_bypass_vlan_none.py index 779024664..d8023a292 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_quic_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_quic_mirror_bypass_vlan_none.py @@ -250,7 +250,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_quic_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_quic_steer_bypass_vxlan_activeip_bfd.py index 0693d3621..661729a03 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_quic_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_quic_steer_bypass_vxlan_activeip_bfd.py @@ -249,7 +249,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_rdp_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_rdp_mirror_bypass_vlan_none.py index 37d679e9e..35b403695 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_rdp_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_rdp_mirror_bypass_vlan_none.py @@ -251,7 +251,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_rdp_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_rdp_steer_bypass_vxlan_activeip_bfd.py index e05723f2e..64ca710b4 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_rdp_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_rdp_steer_bypass_vxlan_activeip_bfd.py @@ -250,7 +250,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_esni_true_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_esni_true_mirror_bypass_vlan_none.py index 0fd95f650..c7340a7b2 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_esni_true_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_esni_true_mirror_bypass_vlan_none.py @@ -262,7 +262,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_esni_true_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_esni_true_steer_bypass_vxlan_activeip_bfd.py index 494ea7d8a..71f372334 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_esni_true_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_esni_true_steer_bypass_vxlan_activeip_bfd.py @@ -261,7 +261,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vlan_none.py index 3ee1d15bb..014ca63e1 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vlan_none.py @@ -129,7 +129,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -249,7 +249,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_activeip_bfd.py index 3dab24267..1de07c348 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_activeip_bfd.py @@ -121,7 +121,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -241,7 +241,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_activeip_none.py index faba9c82b..4f914c6de 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_activeip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_activeip_none.py @@ -127,7 +127,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -247,7 +247,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_inactiveip_bfd.py index 2f4e69439..e78ad2fc1 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_inactiveip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_inactiveip_bfd.py @@ -121,7 +121,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -241,7 +241,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_inactiveip_none.py index 05c750e22..26f351b40 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_inactiveip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_inactiveip_none.py @@ -128,7 +128,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -248,7 +248,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_unavailableip_bfd.py index 6e110572d..6de3bdde2 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_unavailableip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_unavailableip_bfd.py @@ -118,7 +118,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -238,7 +238,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_unavailableip_none.py index e11063b0a..c16934e57 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_unavailableip_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_unavailableip_none.py @@ -124,7 +124,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -244,7 +244,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_bypass_disabled_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_bypass_disabled_vlan_none.py index dc5c7763c..d841f3bd2 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_bypass_disabled_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_bypass_disabled_vlan_none.py @@ -129,7 +129,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -249,7 +249,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_bypass_vlan_none.py index 6c4e8dd27..260f41f87 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_bypass_vlan_none.py @@ -131,7 +131,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -251,7 +251,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_no_sni_true_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_no_sni_true_mirror_bypass_vlan_none.py index 11b497f37..a059aa322 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_no_sni_true_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_no_sni_true_mirror_bypass_vlan_none.py @@ -261,7 +261,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_no_sni_true_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_no_sni_true_steer_bypass_vxlan_activeip_bfd.py index 78cfcfc26..59036acc4 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_no_sni_true_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_no_sni_true_steer_bypass_vxlan_activeip_bfd.py @@ -260,7 +260,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_steer_bypass_disabled_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_steer_bypass_disabled_vxlan_activeip_bfd.py index 4a7d3c108..54a309866 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_steer_bypass_disabled_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_steer_bypass_disabled_vxlan_activeip_bfd.py @@ -114,7 +114,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -234,7 +234,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_steer_bypass_vxlan_activeip_bfd.py index d8b0df209..74e1cdb2c 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_steer_bypass_vxlan_activeip_bfd.py @@ -111,7 +111,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -231,7 +231,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_compliance_risk_library_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_compliance_risk_library_http_url_steer_bypass_vxlan_activeip_bfd.py index d7adfce54..d4d9004eb 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_compliance_risk_library_http_url_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_compliance_risk_library_http_url_steer_bypass_vxlan_activeip_bfd.py @@ -295,7 +295,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_geoip_asn_library_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_geoip_asn_library_http_url_steer_bypass_vxlan_activeip_bfd.py index 551841cce..b13fe4ca5 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_geoip_asn_library_http_url_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_geoip_asn_library_http_url_steer_bypass_vxlan_activeip_bfd.py @@ -302,7 +302,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_internet_geoip_country_library_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_internet_geoip_country_library_http_url_steer_bypass_vxlan_activeip_bfd.py index fc5fc95c2..37c52a5c1 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_internet_geoip_country_library_http_url_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_internet_geoip_country_library_http_url_steer_bypass_vxlan_activeip_bfd.py @@ -296,7 +296,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_internet_service_library_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_internet_service_library_http_url_steer_bypass_vxlan_activeip_bfd.py index 40fd490cf..fd8aa9fb1 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_internet_service_library_http_url_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_internet_service_library_http_url_steer_bypass_vxlan_activeip_bfd.py @@ -295,7 +295,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py index d2f8fd18b..3113380e9 100644 --- a/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py @@ -301,7 +301,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstport_external_port_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstport_external_port_steer_bypass_vxlan_activeip_bfd.py index 453368c88..a6dadf4a6 100644 --- a/tests/service_chaining/sc_raw_srcip_dstport_external_port_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstport_external_port_steer_bypass_vxlan_activeip_bfd.py @@ -134,7 +134,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -256,7 +256,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstport_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstport_mirror_bypass_vlan_none.py index 07bde2d48..2aeeccb2b 100644 --- a/tests/service_chaining/sc_raw_srcip_dstport_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstport_mirror_bypass_vlan_none.py @@ -118,7 +118,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -239,7 +239,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstport_range_external_port_range_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstport_range_external_port_range_mirror_bypass_vlan_none.py index 7b5ea222d..f8beb30db 100644 --- a/tests/service_chaining/sc_raw_srcip_dstport_range_external_port_range_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_dstport_range_external_port_range_mirror_bypass_vlan_none.py @@ -136,7 +136,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -257,7 +257,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dstport_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstport_steer_bypass_vxlan_activeip_bfd.py index c8a5e725e..ba296afe0 100644 --- a/tests/service_chaining/sc_raw_srcip_dstport_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dstport_steer_bypass_vxlan_activeip_bfd.py @@ -117,7 +117,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -239,7 +239,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_dtsip_mirror_bypass_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_dtsip_mirror_bypass_vxlan_inactiveip_bfd.py index 0b8646ea9..fd469bb31 100644 --- a/tests/service_chaining/sc_raw_srcip_dtsip_mirror_bypass_vxlan_inactiveip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_dtsip_mirror_bypass_vxlan_inactiveip_bfd.py @@ -112,7 +112,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -232,7 +232,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_fqdn_ipprototcp_ssl_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_fqdn_ipprototcp_ssl_steer_bypass_vxlan_activeip_bfd.py index 05d1bbb13..d947a6936 100644 --- a/tests/service_chaining/sc_raw_srcip_fqdn_ipprototcp_ssl_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_fqdn_ipprototcp_ssl_steer_bypass_vxlan_activeip_bfd.py @@ -136,7 +136,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -257,7 +257,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_block_disabled_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_block_disabled_vxlan_activeip_bfd.py index 5c16c0c06..d6fac2159 100644 --- a/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_block_disabled_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_block_disabled_vxlan_activeip_bfd.py @@ -127,7 +127,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -247,7 +247,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_bypass_disabled_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_bypass_disabled_vxlan_activeip_bfd.py index 44b06c2f3..c677cc27b 100644 --- a/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_bypass_disabled_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_bypass_disabled_vxlan_activeip_bfd.py @@ -126,7 +126,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -246,7 +246,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_global_bypass_diff_device_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_global_bypass_diff_device_vxlan_activeip_bfd.py index ede174a22..c4f33bdc6 100644 --- a/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_global_bypass_diff_device_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_global_bypass_diff_device_vxlan_activeip_bfd.py @@ -124,7 +124,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -244,7 +244,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_nearby_bypass_diff_device_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_nearby_bypass_diff_device_vxlan_activeip_bfd.py index 833790db6..6c7b64489 100644 --- a/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_nearby_bypass_diff_device_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_nearby_bypass_diff_device_vxlan_activeip_bfd.py @@ -123,7 +123,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -243,7 +243,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_internal_port_range_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_internal_port_range_mirror_bypass_vlan_none.py index b54529c50..b663fbc78 100644 --- a/tests/service_chaining/sc_raw_srcip_internal_port_range_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_internal_port_range_mirror_bypass_vlan_none.py @@ -117,7 +117,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -239,7 +239,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_internal_port_range_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_internal_port_range_steer_bypass_vxlan_activeip_bfd.py index 73789fcb0..5c0d14cc2 100644 --- a/tests/service_chaining/sc_raw_srcip_internal_port_range_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_internal_port_range_steer_bypass_vxlan_activeip_bfd.py @@ -116,7 +116,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -238,7 +238,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_inactiveip_bfd.py index 4c0f01277..9399f36a0 100644 --- a/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_inactiveip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_inactiveip_bfd.py @@ -100,7 +100,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -220,7 +220,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_inactiveip_none.py index 8bf441f9b..b659b5489 100644 --- a/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_inactiveip_none.py +++ b/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_inactiveip_none.py @@ -128,7 +128,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -248,7 +248,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_unavailableip_bfd.py index 4f9a51114..c54271802 100644 --- a/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_unavailableip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_unavailableip_bfd.py @@ -100,7 +100,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -220,7 +220,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_unavailableip_none.py index c21806e70..1d8cd0fbc 100644 --- a/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_unavailableip_none.py +++ b/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_unavailableip_none.py @@ -100,7 +100,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -222,7 +222,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_mirror_bypass_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_mirror_bypass_vxlan_unavailableip_bfd.py index 95e5e69a0..fbd40f2cc 100644 --- a/tests/service_chaining/sc_raw_srcip_mirror_bypass_vxlan_unavailableip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_mirror_bypass_vxlan_unavailableip_bfd.py @@ -98,7 +98,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -218,7 +218,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_mirror_redispatch_block_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_mirror_redispatch_block_vxlan_inactiveip_bfd.py index 13e1e346a..6b3b3dc16 100644 --- a/tests/service_chaining/sc_raw_srcip_mirror_redispatch_block_vxlan_inactiveip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_mirror_redispatch_block_vxlan_inactiveip_bfd.py @@ -103,7 +103,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -223,7 +223,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_negate_dstip_fqdn_ssl_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_negate_dstip_fqdn_ssl_mirror_bypass_vlan_none.py index 8e4757f30..08f94d2b7 100644 --- a/tests/service_chaining/sc_raw_srcip_negate_dstip_fqdn_ssl_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_negate_dstip_fqdn_ssl_mirror_bypass_vlan_none.py @@ -149,7 +149,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -269,7 +269,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_negate_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_negate_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py index dbf7646af..6d2440af8 100644 --- a/tests/service_chaining/sc_raw_srcip_negate_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_negate_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py @@ -148,7 +148,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -268,7 +268,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_negate_srcport_range_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_negate_srcport_range_mirror_bypass_vlan_none.py index ed70c1c9a..89c7121cd 100644 --- a/tests/service_chaining/sc_raw_srcip_negate_srcport_range_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcip_negate_srcport_range_mirror_bypass_vlan_none.py @@ -239,7 +239,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_negate_srcport_range_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_negate_srcport_range_steer_bypass_vxlan_activeip_bfd.py index ed70c1c9a..89c7121cd 100644 --- a/tests/service_chaining/sc_raw_srcip_negate_srcport_range_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_negate_srcport_range_steer_bypass_vxlan_activeip_bfd.py @@ -239,7 +239,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_inactiveip_bfd.py index 128494f5d..21a61fea3 100644 --- a/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_inactiveip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_inactiveip_bfd.py @@ -98,7 +98,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -218,7 +218,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_inactiveip_none.py index 9c2149de2..aa8e93fc2 100644 --- a/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_inactiveip_none.py +++ b/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_inactiveip_none.py @@ -98,7 +98,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -218,7 +218,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_unavailableip_bfd.py index 5d3351a82..2b7cb503a 100644 --- a/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_unavailableip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_unavailableip_bfd.py @@ -98,7 +98,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -218,7 +218,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_unavailableip_none.py index d18a72e8c..d72d67e48 100644 --- a/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_unavailableip_none.py +++ b/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_unavailableip_none.py @@ -98,7 +98,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -218,7 +218,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_inactiveip_bfd.py index 873db94b0..39389ea52 100644 --- a/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_inactiveip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_inactiveip_bfd.py @@ -98,7 +98,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -218,7 +218,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_unavailableip_bfd.py index 569274de6..0f5059adc 100644 --- a/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_unavailableip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_unavailableip_bfd.py @@ -98,7 +98,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -218,7 +218,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_unavailableip_none.py index 4df9270ef..591646d0d 100644 --- a/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_unavailableip_none.py +++ b/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_unavailableip_none.py @@ -98,7 +98,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -218,7 +218,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_steer_redispatch_block_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_steer_redispatch_block_vxlan_inactiveip_bfd.py index 9f0bb3faf..038fe1294 100644 --- a/tests/service_chaining/sc_raw_srcip_steer_redispatch_block_vxlan_inactiveip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_steer_redispatch_block_vxlan_inactiveip_bfd.py @@ -101,7 +101,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -221,7 +221,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcip_steer_redispatch_bypass_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_steer_redispatch_bypass_vxlan_inactiveip_bfd.py index cd03829d5..a0e3952e2 100644 --- a/tests/service_chaining/sc_raw_srcip_steer_redispatch_bypass_vxlan_inactiveip_bfd.py +++ b/tests/service_chaining/sc_raw_srcip_steer_redispatch_bypass_vxlan_inactiveip_bfd.py @@ -102,7 +102,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -222,7 +222,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcport_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcport_mirror_bypass_vlan_none.py index b7d6947c0..2a80fd813 100644 --- a/tests/service_chaining/sc_raw_srcport_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcport_mirror_bypass_vlan_none.py @@ -97,7 +97,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -219,7 +219,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcport_range_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcport_range_mirror_bypass_vlan_none.py index f50478ee2..f760d7088 100644 --- a/tests/service_chaining/sc_raw_srcport_range_mirror_bypass_vlan_none.py +++ b/tests/service_chaining/sc_raw_srcport_range_mirror_bypass_vlan_none.py @@ -97,7 +97,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -219,7 +219,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcport_range_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcport_range_steer_bypass_vxlan_activeip_bfd.py index bf3baa336..7d3eaf4db 100644 --- a/tests/service_chaining/sc_raw_srcport_range_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcport_range_steer_bypass_vxlan_activeip_bfd.py @@ -104,7 +104,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -226,7 +226,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/service_chaining/sc_raw_srcport_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcport_steer_bypass_vxlan_activeip_bfd.py index e66da5ec5..710adad7f 100644 --- a/tests/service_chaining/sc_raw_srcport_steer_bypass_vxlan_activeip_bfd.py +++ b/tests/service_chaining/sc_raw_srcport_steer_bypass_vxlan_activeip_bfd.py @@ -92,7 +92,7 @@ def run(parameter): } verification_result = { - "excepted_traffic_result": "", + "excepted_traffic_result": {'total_packets': 175, 'total_packets_sent': 45, 'total_packets_received': 130, 'total_bytes': 180025, 'total_bytes_sent': 5799, 'total_bytes_received': 174226, 'total_syn_pkt': 1}, "expected_metric": {"hits": 1}, "expected_log": [ {"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""}, @@ -214,7 +214,7 @@ if __name__ == '__main__': "root_path": "C:/automation_project/tsg_test", "path": "C:/automation_project/tsg_test/tests/ui", "module_name": "service_chaining", - "test_case_name": "" + "test_case_name": os.path.basename(__file__)[:-3] } run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_dtls_line_uniq_dtls_handshake_latency_ms.py b/tests/statistics/stats_srcip_dstip_dtls_line_uniq_dtls_handshake_latency_ms.py new file mode 100644 index 000000000..a72ed750a --- /dev/null +++ b/tests/statistics/stats_srcip_dstip_dtls_line_uniq_dtls_handshake_latency_ms.py @@ -0,0 +1,303 @@ +# -*- coding: UTF-8 -*- +import copy +import os +import sys +import time +import pytz + +from support.organize_config import OrganizeConfig +from support.ui_utils.element_position.map_element_position_library import replace_paras +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + + # 参数初始化 + result, exception_result = "", "" + test_summary = {} + + # 脚本启动时间 + script_start_time = time.time() + + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(DTLS Handshake Latency(ms)) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "dtls_handshake_latency_ms" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(DTLS Handshake Latency(ms))", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } + } + ] + }, + "vsys": 1 + } + }, + "is_enabled": 1, + "log_option": "metadata" + } + + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "dtls" + } + verification_result = { + "excepted_traffic_result": {"total_bytes": 71098, "total_bytes_received": 66295, "total_bytes_sent": 4803, "total_packets": 100, "total_packets_received": 63, "total_packets_sent": 37, "total_syn_pkt": 1}, + "expected_metric": {"hits": 1}, + "expected_log": [ + {"query_field_key": "dtls_sni", "query_value": "www.youtube.com"}, + {"query_field_key": "dtls_version", "query_value": "DTLS 1.2"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + source_change_destination = copy.deepcopy(policy_configuration["and_conditions"][0]["or_conditions"][0]) + source_change_destination["attribute_name"] = "ATTR_DESTINATION_IP" + policy_configuration["and_conditions"][1]["or_conditions"].append(source_change_destination) + destination_change_source = copy.deepcopy(policy_configuration["and_conditions"][1]["or_conditions"][0]) + destination_change_source["attribute_name"] = "ATTR_SOURCE_IP" + policy_configuration["and_conditions"][0]["or_conditions"].append(destination_change_source) + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) + finally: + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.73", + "api_server": "http://192.168.44.72", + "is_log": 0, + "env": "tsgx", + "vsys": 1, # 6 + "root_path": "D:/tsgcode/tsg_test", + "path": "tsgcode/tsg_test/testcase/ui", + "module_name": "statistics", + "test_case_name": os.path.basename(__file__)[:-3], + "debug_flag": "local", + "test_subcriber_id": "test6489", + "initiation_method": "api", + "policy_type": "statistics" + } + parameter = replace_paras(parameter) + run(parameter) + """ + # 在测试文件的当前路径执行如下命令执行测试用例: + pytest –cache-clear -v pytest_json.py --alluredir ./allure + + # 执行如下命令生成测试报告(自动打开浏览器): + allure serve allure + """
\ No newline at end of file diff --git a/tests/statistics/stats_srcip_dstip_dtls_table_uniq_dtls_handshake_latency_ms_dim_device_group.py b/tests/statistics/stats_srcip_dstip_dtls_table_uniq_dtls_handshake_latency_ms_dim_device_group.py index 5b5989c49..c6e9afa4b 100644 --- a/tests/statistics/stats_srcip_dstip_dtls_table_uniq_dtls_handshake_latency_ms_dim_device_group.py +++ b/tests/statistics/stats_srcip_dstip_dtls_table_uniq_dtls_handshake_latency_ms_dim_device_group.py @@ -261,21 +261,11 @@ def run(parameter): if not rules_tuple: ui_client.delete_rules(parameter, policy_configuration) elif parameter["initiation_method"] == "api": - if not rules_tuple: - print("No Rules to be delete!") - else: + if rules_tuple: api_client.delete_rules(rules_tuple) - if not objects_tuple: - print("No Objects to be delete!") - else: + if objects_tuple: api_client.delete_objects(objects_tuple) - if not libraries_tuple: - print("No Objects to be delete!") - else: - api_client.delete_libraries(libraries_tuple) - if not profiles_tuple: - print("No Profiles to be delete!") - else: + if profiles_tuple: api_client.delete_profiles(profiles_tuple) # 脚本结束时间和耗时 end_time = time.time() diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_app.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_app.py index c17c5c623..148a32cc2 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_app.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_app.py @@ -1,209 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Application", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "app" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Application", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.28", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Application", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "app" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Application", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["app"], - "order_by": "", - "row_limit": "15", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["app"], - "order_by": "", - "row_limit": "15", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.28", - "clients_end_ip": "10.64.224.28", - "servers_start_ip": "2.1.1.28", - "servers_end_ip": "2.1.1.28", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_appcategory.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_appcategory.py index 2da1b50eb..227ebe457 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_appcategory.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_appcategory.py @@ -1,209 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Application Category", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "app_category" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Application Category", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.28", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Application Category", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "app_category" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Application Category", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["app"], - "order_by": "", - "row_limit": "15", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["app"], - "order_by": "", - "row_limit": "15", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.28", - "clients_end_ip": "10.64.224.28", - "servers_start_ip": "2.1.1.28", - "servers_end_ip": "2.1.1.28", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c2s_link_id.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c2s_link_id.py index 17877592d..081f553cc 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c2s_link_id.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c2s_link_id.py @@ -1,209 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Client-to-Server Link ID", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "c2s_link_id" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Client-to-Server Link ID", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.28", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Client-to-Server Link ID", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "c2s_link_id" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Client-to-Server Link ID", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["c2s_link_id"], - "order_by": "", - "row_limit": "15", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["c2s_link_id"], - "order_by": "", - "row_limit": "15", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.28", - "clients_end_ip": "10.64.224.28", - "servers_start_ip": "2.1.1.28", - "servers_end_ip": "2.1.1.28", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c2s_ttl.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c2s_ttl.py index 84c786f0e..21ab1e0c1 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c2s_ttl.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c2s_ttl.py @@ -1,209 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Client-to-Server TTL", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "c2s_ttl" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Client-to-Server TTL", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.26", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Client-to-Server TTL", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "c2s_ttl" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Client-to-Server TTL", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["c2s_ttl"], - "order_by": "", - "row_limit": "20", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["c2s_ttl"], - "order_by": "", - "row_limit": "10", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.26", - "clients_end_ip": "10.64.224.26", - "servers_start_ip": "2.1.1.26", - "servers_end_ip": "2.1.1.26", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c_country.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c_country.py index 0b40806b2..2841e4a83 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c_country.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c_country.py @@ -1,209 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Client Country", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "client_country" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Client Country", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.26", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Client Country", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "client_country" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Client Country", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["client_country"], - "order_by": "", - "row_limit": "20", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["client_country"], - "order_by": "", - "row_limit": "10", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.26", - "clients_end_ip": "10.64.224.26", - "servers_start_ip": "2.1.1.26", - "servers_end_ip": "2.1.1.26", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c_ip.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c_ip.py index 88cac18a3..e91dc3e5e 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c_ip.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c_ip.py @@ -1,209 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Client IP", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "client_ip" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Client IP", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.26", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Client IP", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "client_ip" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Client IP", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["client_ip"], - "order_by": "", - "row_limit": "20", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["client_ip"], - "order_by": "", - "row_limit": "10", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.26", - "clients_end_ip": "10.64.224.26", - "servers_start_ip": "2.1.1.26", - "servers_end_ip": "2.1.1.26", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c_ip_object.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c_ip_object.py index ce018fbaf..7a529d931 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c_ip_object.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c_ip_object.py @@ -1,210 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "statistics_option": "Brief", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Client IP Object List", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "client_ip_object_list" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Client IP Object List", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.26", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Client IP Object List", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "client_ip_object_list" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Client IP Object List", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["client_ip_object_list"], - "order_by": "", - "row_limit": "20", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["client_ip_object_list"], - "order_by": "", - "row_limit": "10", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.26", - "clients_end_ip": "10.64.224.26", - "servers_start_ip": "2.1.1.26", - "servers_end_ip": "2.1.1.26", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c_port.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c_port.py index abdae0768..64e1ad411 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c_port.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_c_port.py @@ -1,209 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Client Port", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "client_port" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Client Port", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.26", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Client Port", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "client_port" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Client Port", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["client_port"], - "order_by": "", - "row_limit": "20", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["client_port"], - "order_by": "", - "row_limit": "10", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.26", - "clients_end_ip": "10.64.224.26", - "servers_start_ip": "2.1.1.26", - "servers_end_ip": "2.1.1.26", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_decoded_as.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_decoded_as.py index c2adaaddd..bf2875b1e 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_decoded_as.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_decoded_as.py @@ -1,209 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Decoded AS", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "decoded_as" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Decoded AS", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.26", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Decoded AS", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "decoded_as" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Decoded AS", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["decoded_as"], - "order_by": "", - "row_limit": "20", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["decoded_as"], - "order_by": "", - "row_limit": "10", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.26", - "clients_end_ip": "10.64.224.26", - "servers_start_ip": "2.1.1.26", - "servers_end_ip": "2.1.1.26", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_device_group.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_device_group.py index b9c73a38d..d63d385e2 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_device_group.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_device_group.py @@ -1,209 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Device Group", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "device_group" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Device Group", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.29", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Device Group", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "device_group" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Device Group", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["device_group"], - "order_by": "", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["device_group"], - "order_by": "", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.29", - "clients_end_ip": "10.64.224.29", - "servers_start_ip": "2.1.1.29", - "servers_end_ip": "2.1.1.29", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_direction.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_direction.py index 6c66666a5..667f27a24 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_direction.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_direction.py @@ -1,209 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Direction", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "direction" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Direction", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.26", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Direction", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "direction" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Direction", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["direction"], - "order_by": "", - "row_limit": "20", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["direction"], - "order_by": "", - "row_limit": "10", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.26", - "clients_end_ip": "10.64.224.26", - "servers_start_ip": "2.1.1.26", - "servers_end_ip": "2.1.1.26", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_domain.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_domain.py index 3f6c2f4bf..dc8f7e1f3 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_domain.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_domain.py @@ -1,209 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Server Domain", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "server_domain" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server Domain", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.26", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Server Domain", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "server_domain" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server Domain", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["server_domain"], - "order_by": "", - "row_limit": "20", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["server_domain"], - "order_by": "", - "row_limit": "10", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.26", - "clients_end_ip": "10.64.224.26", - "servers_start_ip": "2.1.1.26", - "servers_end_ip": "2.1.1.26", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_flags.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_flags.py index bfd1000a2..47ac0d60c 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_flags.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_flags.py @@ -1,209 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Flags", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "flags" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Flags", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.26", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Flags", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "flags" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Flags", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["flags"], - "order_by": "", - "row_limit": "20", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["flags"], - "order_by": "", - "row_limit": "10", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.26", - "clients_end_ip": "10.64.224.26", - "servers_start_ip": "2.1.1.26", - "servers_end_ip": "2.1.1.26", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_fqdn.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_fqdn.py index b6da6e352..9c00d78f9 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_fqdn.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_fqdn.py @@ -1,209 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Server FQDN", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "server_fqdn" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server FQDN", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.26", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Server FQDN", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "server_fqdn" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server FQDN", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["server_fqdn"], - "order_by": "", - "row_limit": "20", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["server_fqdn"], - "order_by": "", - "row_limit": "10", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.26", - "clients_end_ip": "10.64.224.26", - "servers_start_ip": "2.1.1.26", - "servers_end_ip": "2.1.1.26", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_http_host.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_http_host.py index 9bdbc639e..740c65a5c 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_http_host.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_http_host.py @@ -1,209 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, HTTP Host", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "http_host" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "HTTP Host", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.26", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, HTTP Host", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "http_host" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "HTTP Host", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["http_host"], - "order_by": "", - "row_limit": "20", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["http_host"], - "order_by": "", - "row_limit": "10", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.26", - "clients_end_ip": "10.64.224.26", - "servers_start_ip": "2.1.1.26", - "servers_end_ip": "2.1.1.26", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s2c_link_id.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s2c_link_id.py index fef47528c..842a32874 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s2c_link_id.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s2c_link_id.py @@ -1,209 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Server-to-Client Link ID", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "s2c_link_id" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server-to-Client Link ID", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.28", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Server-to-Client Link ID", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "s2c_link_id" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server-to-Client Link ID", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["s2c_link_id"], - "order_by": "sessions", - "row_limit": "15", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["s2c_link_id"], - "order_by": "sessions", - "row_limit": "15", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.28", - "clients_end_ip": "10.64.224.28", - "servers_start_ip": "2.1.1.28", - "servers_end_ip": "2.1.1.28", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s2c_ttl.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s2c_ttl.py index 6f3f9b682..1955e5385 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s2c_ttl.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s2c_ttl.py @@ -1,209 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Server-to-Client TTL", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "s2c_ttl" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server-to-Client TTL", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.26", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Server-to-Client TTL", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "s2c_ttl" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server-to-Client TTL", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["s2c_ttl"], - "order_by": "", - "row_limit": "5", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["s2c_ttl"], - "order_by": "", - "row_limit": "10", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.26", - "clients_end_ip": "10.64.224.26", - "servers_start_ip": "2.1.1.26", - "servers_end_ip": "2.1.1.26", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s_country.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s_country.py index 0cb5d7d11..80c492187 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s_country.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s_country.py @@ -1,209 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Server Country", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "server_country" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server Country", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.26", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Server Country", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "server_country" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server Country", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["server_country"], - "order_by": "", - "row_limit": "20", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["server_country"], - "order_by": "", - "row_limit": "10", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.26", - "clients_end_ip": "10.64.224.26", - "servers_start_ip": "2.1.1.26", - "servers_end_ip": "2.1.1.26", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s_ip.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s_ip.py index 1c3875a62..ad364cb83 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s_ip.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s_ip.py @@ -1,209 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Server IP", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "server_ip" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server IP", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.26", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Server IP", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "server_ip" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server IP", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["server_ip"], - "order_by": "", - "row_limit": "20", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["server_ip"], - "order_by": "", - "row_limit": "10", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.26", - "clients_end_ip": "10.64.224.26", - "servers_start_ip": "2.1.1.26", - "servers_end_ip": "2.1.1.26", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s_ip_object.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s_ip_object.py index c85359ec1..2d6191f19 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s_ip_object.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s_ip_object.py @@ -1,210 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Server IP Object List", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "server_ip_object_list" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server IP Object List", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "statistics_option": "Brief", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.26", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Server IP Object List", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "server_ip_object_list" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server IP Object List", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["server_ip_object_list"], - "order_by": "", - "row_limit": "20", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["server_ip_object_list"], - "order_by": "", - "row_limit": "10", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.26", - "clients_end_ip": "10.64.224.26", - "servers_start_ip": "2.1.1.26", - "servers_end_ip": "2.1.1.26", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s_port.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s_port.py index c282a7caa..de3558e8d 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s_port.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_s_port.py @@ -1,209 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Server Port", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "server_port" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server Port", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.26", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Server Port", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "server_port" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server Port", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["server_port"], - "order_by": "", - "row_limit": "20", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["server_port"], - "order_by": "", - "row_limit": "10", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.26", - "clients_end_ip": "10.64.224.26", - "servers_start_ip": "2.1.1.26", - "servers_end_ip": "2.1.1.26", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_sled_ip.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_sled_ip.py index dec15d14e..fcffa55e1 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_sled_ip.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_sled_ip.py @@ -1,209 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Sled IP", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "sled_ip" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Sled IP", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.26", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Sled IP", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "sled_ip" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Sled IP", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["sled_ip"], - "order_by": "", - "row_limit": "20", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["sled_ip"], - "order_by": "", - "row_limit": "10", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.26", - "clients_end_ip": "10.64.224.26", - "servers_start_ip": "2.1.1.26", - "servers_end_ip": "2.1.1.26", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_sub_id.py b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_sub_id.py index 603626651..a266d8851 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_sub_id.py +++ b/tests/statistics/stats_srcip_dstip_http_line_sessions_dim_sub_id.py @@ -1,209 +1,376 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(New Sessions) Distributed by Time, Subscriber ID", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "subscriber_id" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Subscriber ID", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(New Sessions)", + "unit": "sps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "15" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.26", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(New Sessions) Distributed by Time, Subscriber ID", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "subscriber_id" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Subscriber ID", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "new_sessions_for_this_rule" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(New Sessions)", + "unit": "sessions" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:RATE:sessions" - ], - "dimensions": ["subscriber_id"], - "order_by": "", - "row_limit": "20", - "min_in_size": "1", - "min_out_size": "1" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "new_sessions_for_this_rule:SUM:sessions" - ], - "dimensions": ["subscriber_id"], - "order_by": "", - "row_limit": "10", - "min_in_size": "1", - "min_out_size": "1" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.26", - "clients_end_ip": "10.64.224.26", - "servers_start_ip": "2.1.1.26", - "servers_end_ip": "2.1.1.26", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts.py index 44919908f..96c3b9892 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts.py @@ -1,209 +1,348 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(SYN Packets) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(SYN Packets)", + "unit": "packets" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "Syn Packets Line", - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" - }, - { - "chart_name": "Syn Packets Line", - "visualization_type": "Line", - "metrics": [ - "syn_pkts:SUM:syn pkts" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_app.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_app.py index b8a90d973..34b4bd7cd 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_app.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_app.py @@ -1,199 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": "stats_http_line_syn_pkts_dim_app", - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "stats_http_line_syn_pkts_dim_app", - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "app" - ], - "order_by": "", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Application", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "app" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Application", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "5" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_appcategory.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_appcategory.py index c1a3e5c9f..6cebc1cd1 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_appcategory.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_appcategory.py @@ -1,199 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "app_category" - ], - "order_by": "syn pkts", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Application Category", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "app_category" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Application Category", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c2s_link_id.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c2s_link_id.py index d4a831fa0..2d45416d3 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c2s_link_id.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c2s_link_id.py @@ -1,199 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "c2s_link_id" - ], - "order_by": "syn pkts", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Client-to-Server Link ID", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "c2s_link_id" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Client-to-Server Link ID", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c2s_ttl.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c2s_ttl.py index 36a7ebf3c..6a0665c8d 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c2s_ttl.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c2s_ttl.py @@ -1,199 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "c2s_ttl" - ], - "order_by": "syn pkts", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Client-to-Server TTL", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "c2s_ttl" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Client-to-Server TTL", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c_country.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c_country.py index 1e17355e5..547cbd633 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c_country.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c_country.py @@ -1,199 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": "stats_http_line_syn_pkts_dim_app", - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "stats_http_line_syn_pkts_dim_app", - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "client_country" - ], - "order_by": "syn pkts", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Client Country", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "client_country" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Client Country", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c_ip.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c_ip.py index a050a6dbc..07093ce1e 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c_ip.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c_ip.py @@ -1,199 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "client_ip" - ], - "order_by": "syn pkts", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Client IP", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "client_ip" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Client IP", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c_ip_object.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c_ip_object.py index b2c150b15..37568a2b7 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c_ip_object.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c_ip_object.py @@ -1,200 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "statistics_option": "Brief", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "client_ip_object_list" - ], - "order_by": "syn pkts", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Server IP Object List", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "server_ip_object_list" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server IP Object List", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c_port.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c_port.py index bc0a2b7ab..0adbc3819 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c_port.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_c_port.py @@ -1,199 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "client_port" - ], - "order_by": "syn pkts", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Client Port", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "client_port" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Client Port", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_decoded_as.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_decoded_as.py index 2cebf0b27..efa8fe516 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_decoded_as.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_decoded_as.py @@ -1,199 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": "stats_http_line_syn_pkts_dim_app", - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "stats_http_line_syn_pkts_dim_app", - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "decoded_as" - ], - "order_by": "", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Decoded AS", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "decoded_as" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Decoded AS", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_device_group.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_device_group.py index 645b573eb..4412f073e 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_device_group.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_device_group.py @@ -1,199 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "device_group" - ], - "order_by": "syn pkts", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Device Group", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "device_group" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Device Group", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_direction.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_direction.py index 72b779c26..b254792dc 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_direction.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_direction.py @@ -1,199 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": "stats_http_line_syn_pkts_dim_app", - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "stats_http_line_syn_pkts_dim_app", - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "direction" - ], - "order_by": "", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Direction", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "direction" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Direction", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_domain.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_domain.py index 32af93626..38c35fbc5 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_domain.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_domain.py @@ -1,199 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "server_domain" - ], - "order_by": "syn pkts", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Server Domain", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "server_domain" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server Domain", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_flags.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_flags.py index 1467d668b..f57dcd4c0 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_flags.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_flags.py @@ -1,199 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": "stats_http_line_syn_pkts_dim_app", - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "stats_http_line_syn_pkts_dim_app", - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "flags" - ], - "order_by": "", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Flags", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "flags" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Flags", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_fqdn.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_fqdn.py index f00a78f1b..307f98d1b 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_fqdn.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_fqdn.py @@ -1,199 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "server_fqdn" - ], - "order_by": "syn pkts", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Server FQDN", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "server_fqdn" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server FQDN", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_http_host.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_http_host.py index 1aa8be0e1..f0a7e99a4 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_http_host.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_http_host.py @@ -1,199 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": "stats_http_line_syn_pkts_dim_app", - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "stats_http_line_syn_pkts_dim_app", - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "http_host" - ], - "order_by": "", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, HTTP Host", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "http_host" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "HTTP Host", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s2c_link_id.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s2c_link_id.py index 297e37615..5a99f6259 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s2c_link_id.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s2c_link_id.py @@ -1,199 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "s2c_link_id" - ], - "order_by": "syn pkts", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Server-to-Client Link ID", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "s2c_link_id" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server-to-Client Link ID", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s2c_ttl.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s2c_ttl.py index f595908b4..df54564b6 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s2c_ttl.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s2c_ttl.py @@ -1,199 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "s2c_ttl" - ], - "order_by": "syn pkts", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Server-to-Client TTL", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "s2c_ttl" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server-to-Client TTL", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s_country.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s_country.py index 1d479b6b5..d2a24600b 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s_country.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s_country.py @@ -1,199 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": "stats_http_line_syn_pkts_dim_app", - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "stats_http_line_syn_pkts_dim_app", - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "server_country" - ], - "order_by": "syn pkts", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Server Country", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "server_country" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server Country", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s_ip.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s_ip.py index 56d02e29f..0deb6180d 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s_ip.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s_ip.py @@ -1,199 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "server_ip" - ], - "order_by": "syn pkts", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Server IP", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "server_ip" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server IP", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s_ip_object.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s_ip_object.py index e091062ae..37568a2b7 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s_ip_object.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s_ip_object.py @@ -1,200 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "statistics_option": "Brief", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "server_ip_object_list" - ], - "order_by": "syn pkts", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Server IP Object List", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "server_ip_object_list" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server IP Object List", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s_port.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s_port.py index 87def82f8..66764a9e3 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s_port.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_s_port.py @@ -1,199 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "server_port" - ], - "order_by": "syn pkts", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Server Port", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "server_port" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Server Port", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_sled_ip.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_sled_ip.py index 5d67956a6..7552cc2ac 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_sled_ip.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_sled_ip.py @@ -1,199 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": "stats_http_line_syn_pkts_dim_app", - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "stats_http_line_syn_pkts_dim_app", - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "sled_ip" - ], - "order_by": "", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Sled IP", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "sled_ip" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Sled IP", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_sub_id.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_sub_id.py index 7489e437e..c4d18ae2b 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_sub_id.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_dim_sub_id.py @@ -1,199 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": "stats_http_line_syn_pkts_dim_app", - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "stats_http_line_syn_pkts_dim_app", - "visualization_type": "Line", - "metrics": [ - "syn_pkts:RATE:syn pkts" - ], - "dimensions": [ - "subscriber_id" - ], - "order_by": "", - "row_limit": "10", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "RATE(SYN Packets) Distributed by Time, Subscriber ID", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "subscriber_id" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Subscriber ID", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "RATE", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "RATE(SYN Packets)", + "unit": "pps" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_sum.py b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_sum.py index 3e9365b24..d507624f7 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_sum.py +++ b/tests/statistics/stats_srcip_dstip_http_line_syn_pkts_sum.py @@ -1,197 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.9", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "Syn Packets Line", - "visualization_type": "Line", - "metrics": [ - "syn_pkts:SUM:syn pkts" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.9", - "clients_end_ip": "10.64.224.9", - "servers_start_ip": "2.1.1.9", - "servers_end_ip": "2.1.1.9", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "SUM(SYN Packets) Distributed by Time, Application", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "app" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Application", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "SUM", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "count", + "metric_name": "count_1", + "label": "SUM(SYN Packets)", + "unit": "packets" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "10" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_uniq_app_category.py b/tests/statistics/stats_srcip_dstip_http_line_uniq_app_category.py index 22f1b5ac8..90dc33b7d 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_uniq_app_category.py +++ b/tests/statistics/stats_srcip_dstip_http_line_uniq_app_category.py @@ -1,198 +1,307 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.4", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "app:UNIQUE_COUNT:Application", - "app_category:UNIQUE_COUNT:Application Category" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.4", - "clients_end_ip": "10.64.224.4", - "servers_start_ip": "2.1.1.4", - "servers_end_ip": "2.1.1.4", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(Application) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "app" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(Application)", + "unit": "" + }, + { + "source_fields": [ + "app_category" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_2", + "label": "UNIQUE_COUNT(Application Category)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_uniq_bytes.py b/tests/statistics/stats_srcip_dstip_http_line_uniq_bytes.py index 247312a45..44be6c3fd 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_uniq_bytes.py +++ b/tests/statistics/stats_srcip_dstip_http_line_uniq_bytes.py @@ -1,213 +1,414 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(Bytes Sent), UNIQUE_COUNT(Bytes Received), UNIQUE_COUNT(Incoming Bytes) and UNIQUE_COUNT(Outgoing Bytes) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "sent_bytes" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(Bytes Sent)", + "unit": "" + }, + { + "source_fields": [ + "received_bytes" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_2", + "label": "UNIQUE_COUNT(Bytes Received)", + "unit": "" + }, + { + "source_fields": [ + "in_bytes" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_3", + "label": "UNIQUE_COUNT(Incoming Bytes)", + "unit": "" + }, + { + "source_fields": [ + "out_bytes" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_4", + "label": "UNIQUE_COUNT(Outgoing Bytes)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.4", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(Bytes Sent, Bytes Received) and UNIQUE_COUNT(Incoming Bytes, Outgoing Bytes) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "sent_bytes", + "received_bytes" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(Bytes Sent, Bytes Received)", + "unit": "" + }, + { + "source_fields": [ + "in_bytes", + "out_bytes" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_2", + "label": "UNIQUE_COUNT(Incoming Bytes, Outgoing Bytes)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "sent_bytes:UNIQUE_COUNT:Bytes Sent", - "received_bytes:UNIQUE_COUNT:Bytes Received", - "in_bytes:UNIQUE_COUNT:Incoming Bytes", - "out_bytes:UNIQUE_COUNT:Outgoing Bytes" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "sent_bytes+received_bytes:UNIQUE_COUNT:Sent Received Bytes", - "in_bytes+out_bytes:UNIQUE_COUNT:In Out Bytes" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.4", - "clients_end_ip": "10.64.224.4", - "servers_start_ip": "2.1.1.4", - "servers_end_ip": "2.1.1.4", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_uniq_c2s_link_id_s2c_link_id.py b/tests/statistics/stats_srcip_dstip_http_line_uniq_c2s_link_id_s2c_link_id.py index efd4b6965..1f8e862ec 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_uniq_c2s_link_id_s2c_link_id.py +++ b/tests/statistics/stats_srcip_dstip_http_line_uniq_c2s_link_id_s2c_link_id.py @@ -1,199 +1,324 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.4", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "c2s_link_id:UNIQUE_COUNT:Client-to-Server Link ID", - "s2c_link_id:UNIQUE_COUNT:Server-to-Client Link ID", - "c2s_link_id+s2c_link_id:UNIQUE_COUNT:Link ID" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.4", - "clients_end_ip": "10.64.224.4", - "servers_start_ip": "2.1.1.4", - "servers_end_ip": "2.1.1.4", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(Client-to-Server Link ID, Server-to-Client Link ID) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "c2s_link_id" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(Client-to-Server Link ID)", + "unit": "" + }, + { + "source_fields": [ + "s2c_link_id" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_2", + "label": "UNIQUE_COUNT(Server-to-Client Link ID)", + "unit": "" + }, + { + "source_fields": [ + "c2s_link_id", + "s2c_link_id" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_3", + "label": "UNIQUE_COUNT(Client-to-Server Link ID, Server-to-Client Link ID)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_uniq_c_country_s_country.py b/tests/statistics/stats_srcip_dstip_http_line_uniq_c_country_s_country.py index 65a21ebc2..2cabddb2d 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_uniq_c_country_s_country.py +++ b/tests/statistics/stats_srcip_dstip_http_line_uniq_c_country_s_country.py @@ -1,199 +1,324 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.4", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "client_country:UNIQUE_COUNT:Client Country", - "server_country:UNIQUE_COUNT:Server Country", - "client_country+server_country:UNIQUE_COUNT:Country" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.4", - "clients_end_ip": "10.64.224.4", - "servers_start_ip": "2.1.1.4", - "servers_end_ip": "2.1.1.4", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(Client Country, Server Country) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "client_country" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(Client Country)", + "unit": "" + }, + { + "source_fields": [ + "server_country" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_2", + "label": "UNIQUE_COUNT(Server Country)", + "unit": "" + }, + { + "source_fields": [ + "client_country", + "server_country" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_3", + "label": "UNIQUE_COUNT(Client Country, Server Country)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_uniq_c_ip_dim_app.py b/tests/statistics/stats_srcip_dstip_http_line_uniq_c_ip_dim_app.py index 98e54961e..e7bee46bd 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_uniq_c_ip_dim_app.py +++ b/tests/statistics/stats_srcip_dstip_http_line_uniq_c_ip_dim_app.py @@ -1,197 +1,305 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.4", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "client_ip:UNIQUE_COUNT:Unique Client IP" - ], - "dimensions": ["app"], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.4", - "clients_end_ip": "10.64.224.4", - "servers_start_ip": "2.1.1.4", - "servers_end_ip": "2.1.1.4", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(Client IP) Distributed by Time, Application", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "app" + ], + "function": { + "name": "", + "expression": "", + "variables": [ + + ] + }, + "label": "Application", + "is_drill_down": 0 + }, + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "client_ip" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(Client IP)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "20" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_uniq_c_ip_object_s_ip_object.py b/tests/statistics/stats_srcip_dstip_http_line_uniq_c_ip_object_s_ip_object.py index 20fbc06b8..3e8f6260d 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_uniq_c_ip_object_s_ip_object.py +++ b/tests/statistics/stats_srcip_dstip_http_line_uniq_c_ip_object_s_ip_object.py @@ -1,201 +1,324 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "statistics_option": "Brief", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "statistics_option": "Brief", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.4", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "client_ip_object_list:UNIQUE_COUNT:Client IP Object List", - "server_ip_object_list:UNIQUE_COUNT:Server IP Object List", - "client_ip_object_list+server_ip_object_list:UNIQUE_COUNT:IP Object List" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.4", - "clients_end_ip": "10.64.224.4", - "servers_start_ip": "2.1.1.4", - "servers_end_ip": "2.1.1.4", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(Client IP Object List, Server IP Object List) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "client_ip_object_list" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(Client IP Object List)", + "unit": "" + }, + { + "source_fields": [ + "server_ip_object_list" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_2", + "label": "UNIQUE_COUNT(Server IP Object List)", + "unit": "" + }, + { + "source_fields": [ + "client_ip_object_list", + "server_ip_object_list" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_3", + "label": "UNIQUE_COUNT(Client IP Object List, Server IP Object List)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_uniq_c_ip_s_ip.py b/tests/statistics/stats_srcip_dstip_http_line_uniq_c_ip_s_ip.py index 1ca52558a..497becb21 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_uniq_c_ip_s_ip.py +++ b/tests/statistics/stats_srcip_dstip_http_line_uniq_c_ip_s_ip.py @@ -1,199 +1,324 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.4", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "client_ip:UNIQUE_COUNT:UNIQUE Client IP", - "server_ip:UNIQUE_COUNT:UNIQUE Server IP", - "client_ip+server_ip:UNIQUE_COUNT:UNIQUE IP" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.4", - "clients_end_ip": "10.64.224.4", - "servers_start_ip": "2.1.1.4", - "servers_end_ip": "2.1.1.4", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(Client IP, Server IP) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "client_ip" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(Client IP)", + "unit": "" + }, + { + "source_fields": [ + "server_ip" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_2", + "label": "UNIQUE_COUNT(Server IP)", + "unit": "" + }, + { + "source_fields": [ + "client_ip", + "server_ip" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_3", + "label": "UNIQUE_COUNT(Client IP, Server IP)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_uniq_c_port_s_port.py b/tests/statistics/stats_srcip_dstip_http_line_uniq_c_port_s_port.py index e03196eb4..7cefc622e 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_uniq_c_port_s_port.py +++ b/tests/statistics/stats_srcip_dstip_http_line_uniq_c_port_s_port.py @@ -1,198 +1,324 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.4", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "client_port:UNIQUE_COUNT:Client Port", - "server_port:UNIQUE_COUNT:Server Port" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.4", - "clients_end_ip": "10.64.224.4", - "servers_start_ip": "2.1.1.4", - "servers_end_ip": "2.1.1.4", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(Client Port, Server Port) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "client_port" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(Client Port)", + "unit": "" + }, + { + "source_fields": [ + "server_port" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_2", + "label": "UNIQUE_COUNT(Server Port)", + "unit": "" + }, + { + "source_fields": [ + "client_port", + "server_port" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_3", + "label": "UNIQUE_COUNT(Client Port, Server Port)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_uniq_c_s_ip_port.py b/tests/statistics/stats_srcip_dstip_http_line_uniq_c_s_ip_port.py index 2bacef6b1..78e5d0521 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_uniq_c_s_ip_port.py +++ b/tests/statistics/stats_srcip_dstip_http_line_uniq_c_s_ip_port.py @@ -1,199 +1,328 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.4", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "client_port:UNIQUE_COUNT:UNIQUE Client Port", - "server_port:UNIQUE_COUNT:UNIQUE Server Port", - "client_ip+client_port+server_ip+server_port:UNIQUE_COUNT:UNIQUE IP Port" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.4", - "clients_end_ip": "10.64.224.4", - "servers_start_ip": "2.1.1.4", - "servers_end_ip": "2.1.1.4", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(Client IP, Client Port, Server IP, Server Port) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "client_ip", + "client_port" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(Client IP, Client Port)", + "unit": "" + }, + { + "source_fields": [ + "client_ip", + "server_port" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_2", + "label": "UNIQUE_COUNT( Server IP, Server Port)", + "unit": "" + }, + { + "source_fields": [ + "client_ip", + "client_port", + "client_ip", + "server_port" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_3", + "label": "UNIQUE_COUNT(Client IP, Client Port, Server IP, Server Port)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_uniq_decoded_as_seld_ip.py b/tests/statistics/stats_srcip_dstip_http_line_uniq_decoded_as_seld_ip.py index 987f71a71..86f055b49 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_uniq_decoded_as_seld_ip.py +++ b/tests/statistics/stats_srcip_dstip_http_line_uniq_decoded_as_seld_ip.py @@ -1,199 +1,307 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.4", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "decoded_as:UNIQUE_COUNT:Decoded AS", - "sled_ip:UNIQUE_COUNT:Sled IP", - "decoded_as+sled_ip:UNIQUE_COUNT:Decoded AS Sled IP" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.4", - "clients_end_ip": "10.64.224.4", - "servers_start_ip": "2.1.1.4", - "servers_end_ip": "2.1.1.4", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(Decoded AS), UNIQUE_COUNT(Sled IP) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "decoded_as" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(Decoded AS)", + "unit": "" + }, + { + "source_fields": [ + "sled_ip" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_2", + "label": "UNIQUE_COUNT(Sled IP)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_uniq_device_group_app.py b/tests/statistics/stats_srcip_dstip_http_line_uniq_device_group_app.py index ad6a60464..2242a5923 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_uniq_device_group_app.py +++ b/tests/statistics/stats_srcip_dstip_http_line_uniq_device_group_app.py @@ -1,199 +1,307 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.4", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "device_group:UNIQUE_COUNT:Application", - "app:UNIQUE_COUNT:Device Group", - "device_group+app:UNIQUE_COUNT:Device Group Application" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.4", - "clients_end_ip": "10.64.224.4", - "servers_start_ip": "2.1.1.4", - "servers_end_ip": "2.1.1.4", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(Device Group), UNIQUE_COUNT(Application) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "device_group" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(Device Group)", + "unit": "" + }, + { + "source_fields": [ + "app" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_2", + "label": "UNIQUE_COUNT(Application)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_uniq_direction_session_id.py b/tests/statistics/stats_srcip_dstip_http_line_uniq_direction_session_id.py index a2ec92eaa..109c3f3fe 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_uniq_direction_session_id.py +++ b/tests/statistics/stats_srcip_dstip_http_line_uniq_direction_session_id.py @@ -1,199 +1,307 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.4", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "direction:UNIQUE_COUNT:Direction", - "session_id:UNIQUE_COUNT:Session ID", - "direction+session_id:UNIQUE_COUNT:Direction Session ID" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.4", - "clients_end_ip": "10.64.224.4", - "servers_start_ip": "2.1.1.4", - "servers_end_ip": "2.1.1.4", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(Direction), UNIQUE_COUNT(Session ID) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "direction" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(Direction)", + "unit": "" + }, + { + "source_fields": [ + "session_id" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_2", + "label": "UNIQUE_COUNT(Session ID)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_uniq_dtls_handshake_latency_ms.py b/tests/statistics/stats_srcip_dstip_http_line_uniq_dtls_handshake_latency_ms.py deleted file mode 100644 index 6463210a7..000000000 --- a/tests/statistics/stats_srcip_dstip_http_line_uniq_dtls_handshake_latency_ms.py +++ /dev/null @@ -1,216 +0,0 @@ -# -*- coding: UTF-8 -*- -import time -import os -import sys - -from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy -from support.report_update import ReportUpdate - -def run(parameter): - try: - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) - # 参数初始化 - exception_result = "" - result = {} - - # 脚本启动时间 - script_start_time = time.time() - - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - },{ - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.4", - }, - ] - },{ - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [] - } - ], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "dtls", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "dtls_handshake_latency_ms:UNIQUE_COUNT:TCP Handshake Latency(ms)" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "dtls_sni", "query_value": "www.youtube.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.4", - "clients_end_ip": "10.64.224.4", - "servers_start_ip": "2.1.1.4", - "servers_end_ip": "2.1.1.4", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "dtls" - }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" - } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result - - except Exception as e: - exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) - finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() - # 生成csv报告 - update = ReportUpdate() - update.write_result(parameter, result, exception_result) - -if __name__ == '__main__': - parameter = { - - "username": "zhaokun", - "password": "zhaokun1", - "test_pc_ip": "192.168.64.73", - "api_server": "http://192.168.44.72", - "is_log": 1, - "env": "tsgx", - "vsys_id": 1, # 6 - "root_path": "D:/tsgcode/tsg_test", - "path": "tsgcode/tsg_test/testcase/ui", - "module_name": "statistics", - "test_case_name": os.path.basename(__file__)[:-3], - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "policy_type": "statistics" - } - parameter = replace_paras(parameter) - run(parameter) - """ - # 在测试文件的当前路径执行如下命令执行测试用例: - pytest –cache-clear -v pytest_json.py --alluredir ./allure - - # 执行如下命令生成测试报告(自动打开浏览器): - allure serve allure - """
\ No newline at end of file diff --git a/tests/statistics/stats_srcip_dstip_http_line_uniq_duration_ms_tcp_rtt_ms.py b/tests/statistics/stats_srcip_dstip_http_line_uniq_duration_ms_tcp_rtt_ms.py index 5fd0053f9..3066fed03 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_uniq_duration_ms_tcp_rtt_ms.py +++ b/tests/statistics/stats_srcip_dstip_http_line_uniq_duration_ms_tcp_rtt_ms.py @@ -1,198 +1,307 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.4", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "duration_ms:UNIQUE_COUNT:Duration", - "tcp_rtt_ms:UNIQUE_COUNT:Round-trip Time" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.4", - "clients_end_ip": "10.64.224.4", - "servers_start_ip": "2.1.1.4", - "servers_end_ip": "2.1.1.4", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(Duration), UNIQUE_COUNT(Round-trip Time) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "duration_ms" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(Duration)", + "unit": "" + }, + { + "source_fields": [ + "tcp_rtt_ms" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_2", + "label": "UNIQUE_COUNT(Round-trip Time)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_uniq_flags.py b/tests/statistics/stats_srcip_dstip_http_line_uniq_flags.py index 681c703c0..0580cad62 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_uniq_flags.py +++ b/tests/statistics/stats_srcip_dstip_http_line_uniq_flags.py @@ -1,197 +1,291 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.4", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "flags:UNIQUE_COUNT:Flags" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.4", - "clients_end_ip": "10.64.224.4", - "servers_start_ip": "2.1.1.4", - "servers_end_ip": "2.1.1.4", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(Flags) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "flags" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(Flags)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_uniq_fqdn_app.py b/tests/statistics/stats_srcip_dstip_http_line_uniq_fqdn_app.py index 9b70c8d96..9d946ceff 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_uniq_fqdn_app.py +++ b/tests/statistics/stats_srcip_dstip_http_line_uniq_fqdn_app.py @@ -1,198 +1,307 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.4", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "server_fqdn:UNIQUE_COUNT:Unique Server Fqdm", - "app:UNIQUE_COUNT:Unique Application" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.4", - "clients_end_ip": "10.64.224.4", - "servers_start_ip": "2.1.1.4", - "servers_end_ip": "2.1.1.4", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(Server FQDN), UNIQUE_COUNT(Application) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "server_fqdn" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(Server FQDN)", + "unit": "" + }, + { + "source_fields": [ + "app" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_2", + "label": "UNIQUE_COUNT(Application)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_uniq_fqdn_domain.py b/tests/statistics/stats_srcip_dstip_http_line_uniq_fqdn_domain.py index a03591678..c35dd3f02 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_uniq_fqdn_domain.py +++ b/tests/statistics/stats_srcip_dstip_http_line_uniq_fqdn_domain.py @@ -1,199 +1,307 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.4", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "server_fqdn:UNIQUE_COUNT:Server FQDN", - "server_domain:UNIQUE_COUNT:Server Domain", - "server_fqdn+server_domain:UNIQUE_COUNT:Server FQDN Domain" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.4", - "clients_end_ip": "10.64.224.4", - "servers_start_ip": "2.1.1.4", - "servers_end_ip": "2.1.1.4", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(Server FQDN), UNIQUE_COUNT(Server Domain) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "server_fqdn" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(Server FQDN)", + "unit": "" + }, + { + "source_fields": [ + "server_domain" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_2", + "label": "UNIQUE_COUNT(Server Domain)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_uniq_http_host_sub_id.py b/tests/statistics/stats_srcip_dstip_http_line_uniq_http_host_sub_id.py index 4c1222ae7..50fac2dd2 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_uniq_http_host_sub_id.py +++ b/tests/statistics/stats_srcip_dstip_http_line_uniq_http_host_sub_id.py @@ -1,198 +1,307 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.4", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "http_host:UNIQUE_COUNT:HTTP Host", - "subscriber_id:UNIQUE_COUNT:Subscriber ID" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.4", - "clients_end_ip": "10.64.224.4", - "servers_start_ip": "2.1.1.4", - "servers_end_ip": "2.1.1.4", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(Subscriber ID), UNIQUE_COUNT(HTTP Host) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "subscriber_id" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(Subscriber ID)", + "unit": "" + }, + { + "source_fields": [ + "http_host" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_2", + "label": "UNIQUE_COUNT(HTTP Host)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_uniq_pkts.py b/tests/statistics/stats_srcip_dstip_http_line_uniq_pkts.py index 4a09dac8e..276edde01 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_uniq_pkts.py +++ b/tests/statistics/stats_srcip_dstip_http_line_uniq_pkts.py @@ -1,213 +1,414 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(Packets Sent Received) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "sent_pkts" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(Packets Sent)", + "unit": "" + }, + { + "source_fields": [ + "received_bytes" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_2", + "label": "UNIQUE_COUNT(Packets Received)", + "unit": "" + }, + { + "source_fields": [ + "sent_pkts", + "received_bytes" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_3", + "label": "UNIQUE_COUNT(Packets Sent Received)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.4", - }, + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(Incoming Outgoing Packets) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "in_pkts" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(Incoming Packets)", + "unit": "" + }, + { + "source_fields": [ + "out_pkts" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_2", + "label": "UNIQUE_COUNT(Outgoing Packets)", + "unit": "" + }, + { + "source_fields": [ + "in_pkts", + "out_pkts" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_3", + "label": "UNIQUE_COUNT(Incoming Outgoing Packets)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } + } ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "sent_pkts:UNIQUE_COUNT:Packets Sent", - "received_pkts:UNIQUE_COUNT:Packets Received", - "sent_pkts+received_pkts:UNIQUE_COUNT:Packets" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" - }, - { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "in_pkts:UNIQUE_COUNT:Incoming Packets", - "out_pkts:UNIQUE_COUNT:Outgoing Packets", - "in_pkts+out_pkts:UNIQUE_COUNT:Packets" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" - } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.4", - "clients_end_ip": "10.64.224.4", - "servers_start_ip": "2.1.1.4", - "servers_end_ip": "2.1.1.4", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_uniq_session_id.py b/tests/statistics/stats_srcip_dstip_http_line_uniq_session_id.py index 979cf49e1..d1a9c6184 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_uniq_session_id.py +++ b/tests/statistics/stats_srcip_dstip_http_line_uniq_session_id.py @@ -1,197 +1,291 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.4", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "session_id:UNIQUE_COUNT:UNIQUE Session ID", - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.4", - "clients_end_ip": "10.64.224.4", - "servers_start_ip": "2.1.1.4", - "servers_end_ip": "2.1.1.4", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(Session ID) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "session_id" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(Session ID)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ diff --git a/tests/statistics/stats_srcip_dstip_http_line_uniq_syn_pkts.py b/tests/statistics/stats_srcip_dstip_http_line_uniq_syn_pkts.py index 487d18715..5d6b5cee6 100644 --- a/tests/statistics/stats_srcip_dstip_http_line_uniq_syn_pkts.py +++ b/tests/statistics/stats_srcip_dstip_http_line_uniq_syn_pkts.py @@ -1,197 +1,291 @@ # -*- coding: UTF-8 -*- -import time import os import sys +import time +import pytz +from support.organize_config import OrganizeConfig from support.ui_utils.element_position.map_element_position_library import replace_paras - -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -import traceback -from datetime import datetime -from support.common_utils.create_policy import CreatePolicy +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +from support.ui_utils.ui_client import UIClient +from support.api_utils.api_client import APIClient +from support.packet_generator.traffic_generator import * from support.report_update import ReportUpdate def run(parameter): try: print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 - exception_result = "" - result = {} + result, exception_result = "", "" + test_summary = {} # 脚本启动时间 script_start_time = time.time() - # 测试数据 - test_data = { - "is_multi_priority": False, - "rule_num": 1, - "policy_type": "statistics", - "rule_name": parameter["test_case_name"], - "rule_action": "statistics", - "rule_type": "create", - "debug_flag": "local", - "test_subcriber_id": "test6489", - "script_type": "ui", - "condition": { - "source_ip": [ - { - "name": parameter["test_case_name"].replace("_dstip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "10.64.224.31", - }, - ] - } - ], - "source_port": [], - "destination_ip": [ - { - "name": parameter["test_case_name"].replace("_srcip", "", 1), - "object_type": "ip", - "select_type": False, - "negate": False, - "item": [ - { - "item_operation": "add", - "item_type": "ipv4", - "item_value": "2.1.1.4", - }, - ] - }], - "destination_port": [], - "internal_ip": [], - "internal_port": [], - "external_ip": [], - "external_port": [], - "source_geography": [], - "destination_geography": [], - "sub_id": [], - "device": [], - "tunnel": [], - "tunnel_level": [], - "flag": [], - "application": [ - { - "name": "http", # - "object_type": "application", - "negate": False - } - ], - "server_fqdn": [ - ], - "protocol_filed": [], - "sub_action_override": True, - "sub_action": [ - ], - "packet_capture": [] - }, - "action_parameter": { - "statistics_template": [{ - "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), - "profile_type": "statistics_template", - "charts": [ + policy_configuration = { + "name": parameter["test_case_name"], + "type": "statistics", + "action": "statistics", + "and_conditions": [ + { + "negate_option": False, + "or_conditions": [ { - "chart_name": "default name", - "visualization_type": "Line", - "metrics": [ - "syn_pkts:UNIQUE_COUNT:UNIQUE SYN Packets" - ], - "dimensions": [], - "order_by": "", - "row_limit": "", - "min_in_size": "0", - "min_out_size": "0" + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "attribute_name": "ATTR_SOURCE_IP", + "type": "ip", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "10.64.224.31", + "interval": "1-65535" + } + ] } - ] - }] - }, - "expected_return": "reset", - "counters": {"hits": 1}, - "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], - "traffic": { - "protocol": "", - "type": "trex", - "clients_start_ip": "10.64.224.4", - "clients_end_ip": "10.64.224.4", - "servers_start_ip": "2.1.1.4", - "servers_end_ip": "2.1.1.4", - "m": 1, - "d": 1, - "yaml_name": "test", - "pcap_name": "http_87pkts" + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "attribute_name": "ATTR_DESTINATION_IP", + "type": "ip", + "sub_type": "ip", + "statistics_option": "none", + "member_type": "item", + "items": [ + { + "op": "add", + "ip": "2.1.1.9", + "interval": "0-65535" + } + ] + } + ] + }, + { + "negate_option": False, + "or_conditions": [ + { + "attribute_name": "ATTR_APP_ID", + "type": "application", + "items": ["http"] + } + ] + }, + ], + "action_parameter": { + "template_profile":{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "uuid": "", + "dataview": { + "charts": [ + { + "id": "", + "display": { + "page_x": None, + "page_y": None, + "height": "", + "width": "", + "type": "line", + "table_type": "" + }, + "uuid": "", + "name": "UNIQUE_COUNT(SYN Packets) Distributed by Time", + "threshold": { + "in_bytes": 0, + "out_bytes": 0 + }, + "query": { + "dimensions": [ + { + "source_fields": [ + "__time" + ], + "function": { + "name": "DATETIME_FLOOR_WITH_FILL", + "expression": "", + "variables": [ + + ] + }, + "label": "Time", + "is_drill_down": 0 + } + ], + "limit": 65536, + "metrics": [ + { + "source_fields": [ + "syn_pkts" + ], + "function": { + "name": "UNIQUE_COUNT", + "expression": "", + "variables": [ + + ] + }, + "metric_type": "unique_count", + "metric_name": "unique_count_1", + "label": "UNIQUE_COUNT(SYN Packets)", + "unit": "" + } + ], + "order_by": "", + "source": "statistics_rule", + "series_limit": "" + } + } + ] + }, + "vsys": 1 + } }, - # "traffic": { - # "type": "trex", - # "clients_start_ip": "192.168.64.86", - # "clients_end_ip": "192.168.64.86", - # "servers_start_ip": "2.1.1.1", - # "servers_end_ip": "2.1.1.2", - # "m": 1, - # "d": 1, - # "yaml_name": "test", - # "pcap_name": "test_https" - # }, - # "traffic": { - # "type": "nslookup", - # "command": "nslookup www.facebook.com" - # }, - # "traffic": { - # "type": "wget", - # "command": "wget -q -O- http://open.node.com:180" - # }, - "token": "" + "is_enabled": 1, + "log_option": "metadata" } - # 测试用例实例化 - create = CreatePolicy(test_data, parameter) - result = create.create_policy() - # 脚本结束时间和耗时 - script_end_time = time.time() - duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) - return result + traffic_generation = { + "tool": "trex", # or trex/http + "clients_start_ip": "10.64.224.9", + "clients_end_ip": "10.64.224.9", + "servers_start_ip": "2.1.1.9", + "servers_end_ip": "2.1.1.9", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + } + + verification_result = { + "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1}, + "expected_query": {"hits": 1}, + "expected_log": [ + {"query_field_key": "decoded_as", "query_value": "HTTP"}, + {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"} + ] + } + # 创建 + if parameter["initiation_method"] == "ui": + ui_client = UIClient() + rules_tuple, ui_error = ui_client.create_rules(policy_configuration) + if len(ui_error) > 0: + return ui_error + elif parameter["initiation_method"] == "api": + api_client = APIClient(parameter) + + organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,()) + organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation) + + # {uuid, type}, i.e., {"12341-232-a21", "ip"} + objects_tuple, api_error = api_client.create_objects(policy_configuration) + if len(api_error) > 0: + return api_error + # 处理Profiles + profiles_tuple, api_error = api_client.create_profiles(policy_configuration) + if len(api_error) > 0: + return api_error + rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple) + if len(api_error) > 0: + return api_error + # 等待下发配置生效 + time.sleep(3) + + # 类实例化 + generator = TrafficGenerator() + # 获取当前时间 + utc_tz = pytz.timezone('UTC') + current_utc_time = datetime.now(utc_tz) + start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + # 触发流量 + traffic_result = generator.run(policy_configuration, traffic_generation) + + # 验证流量生成器的返回值是否符合策略执行的预期 + excepted_traffic_result, error = generator.result(verification_result, traffic_result) + if excepted_traffic_result == False: + return error + + # 验证tsg的日志是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result) + elif parameter["initiation_method"] == "api": + log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result) + if log_result == True: + test_summary["log"] = "Pass." + elif log_result == False: + test_summary["log"] = "The failure reason: the returned log does not match the expected result." + elif log_result == None: + test_summary["log"] = "The failure reason: the returned log is empty." + elif len(log_result) > 0: + test_summary["log"] = log_result + + # 验证tsg的metric是否符合策略执行的预期 + if parameter["initiation_method"] == "ui": + metric_result = ui_client.query_rule_metric(verification_result, traffic_result) + elif parameter["initiation_method"] == "api": + metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result) + if metric_result == True: + test_summary["metric"] = "Pass." + elif metric_result == False: + test_summary["metric"] = "The failure reason: the returned metric does not match the expected result." + elif metric_result == None: + test_summary["metric"] = "The failure reason: the returned metric is empty." + elif len(metric_result) > 0: + test_summary["metric"] = metric_result + #if rules_tuple: + # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True) + return test_summary except Exception as e: exception_result = str(e) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, - flush=True) - traceback.print_exc() - return "Error: " + str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "When running test case, the exception error: ", str(e), flush=True) + return "When running test case, the exception error: " + str(e) finally: - # 清理环境 - if isinstance(create, CreatePolicy): - create.clean_up() + # 删除 + if parameter["initiation_method"] == "ui": + if rules_tuple: + ui_client.delete_rules(parameter, policy_configuration) + elif parameter["initiation_method"] == "api": + if rules_tuple: + api_client.delete_rules(rules_tuple) + if profiles_tuple: + api_client.delete_profiles(profiles_tuple) + if objects_tuple: + api_client.delete_objects(objects_tuple) + # 脚本结束时间和耗时 + script_end_time = time.time() + duration = script_end_time - script_start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) if __name__ == '__main__': parameter = { - "username": "zhaokun", "password": "zhaokun1", "test_pc_ip": "192.168.64.73", "api_server": "http://192.168.44.72", - "is_log": 1, + "is_log": 0, "env": "tsgx", - "vsys_id": 1, # 6 + "vsys": 1, # 6 "root_path": "D:/tsgcode/tsg_test", "path": "tsgcode/tsg_test/testcase/ui", "module_name": "statistics", "test_case_name": os.path.basename(__file__)[:-3], "debug_flag": "local", "test_subcriber_id": "test6489", - "script_type": "ui", + "initiation_method": "api", "policy_type": "statistics" - } + } parameter = replace_paras(parameter) run(parameter) """ |
