提交优化日志接口关键字和日志接口用例示例

This commit is contained in:
lyf
2021-03-31 18:25:18 +08:00
parent f21b4beb0c
commit df0c0224a6
2 changed files with 199 additions and 82 deletions

View File

@@ -15,11 +15,11 @@ ${url} /${version}/report/url/recommend
*** Test Cases *** *** Test Cases ***
LogApiVerifyCase-001 LogApiVerifyCase-001
[Documentation] 验证api接口 [Documentation] 验证api接口
${logurl} Set Variable http://${host}:${port}/v1/log/list ${Logurl} Set Variable http://${host}:${port}/v1/log/list
${logtype} Set Variable security_event_log ${logType} Set Variable security_event_log
${schemaurl} Set Variable http://${host}:${port}/v1/log/schema?logType=${logtype} ${Schemaurl} Set Variable http://${host}:${port}/v1/log/schema?logType=${logType}
${EndTime} get current date ${EndTime} get current date
@@ -29,16 +29,16 @@ LogApiVerifyCase-001
${StartTime1} Get Substring ${StartTime} \ -4 ${StartTime1} Get Substring ${StartTime} \ -4
logapiverify ${logurl} ${schemaurl} ${token} ${StartTime1} ${EndTime1} ${logtype} logapiverify ${Logurl} ${Schemaurl} ${token} ${StartTime1} ${EndTime1} ${logType}
LogApiVerifyCase-002 LogApiVerifyCase-002
[Documentation] 验证api接口 [Documentation] 验证api接口
${Logurl} Set Variable http://${host}:${port}/v1/log/list ${Logurl} Set Variable http://${host}:${port}/v1/log/list
${Logtype} Set Variable security_event_log ${logType} Set Variable security_event_log
${Schemaurl} Set Variable http://${host}:${port}/v1/log/schema?logType=${logtype} ${Schemaurl} Set Variable http://${host}:${port}/v1/log/schema?logType=${logType}
${EndTime} get current date ${EndTime} get current date
@@ -50,7 +50,97 @@ LogApiVerifyCase-002
${filter} Set Variable common_recv_time = 45535 ${filter} Set Variable common_recv_time = 45535
${responsebody} loglistverify ${logurl} ${schemaurl} ${token} ${StartTime1} ${EndTime1} ${logtype} ${filter} ${responsebody} loglistverify ${Logurl} ${Schemaurl} ${token} ${StartTime1} ${EndTime1} ${logType} ${filter}
log ${responsebody}
LogApiVerifyCase-003
[Documentation] 验证api接口:事件日志和通联日志时间分布查询
${StartTime} Set Variable 2021-03-26 12:27:03
${EndTime} Set Variable 2021-03-29 12:27:03
${granularity} Set Variable PT5M
${logType} Set Variable security_event_hits_log
${urlpath} Set Variable ?logType=${logType}&startTime=${StartTime}&endTime=${EndTime}&granularity=${granularity}
${Logurl} Set Variable http://${host}:${port}/v1/interface/gateway/sql/galaxy/${logType}/timedistribution${urlpath}
${responsebody} distributed_query ${Logurl} ${token}
log ${responsebody}
LogApiVerifyCase-004
[Documentation] 验证api接口:事件日志和通联日志时间分布查询
${StartTime} Set Variable 2021-03-26 12:27:03
${EndTime} Set Variable 2021-03-29 12:27:03
${granularity} Set Variable PT5M
${logType} Set Variable proxy_event_hits_log
${urlpath} Set Variable ?logType=${logType}&startTime=${StartTime}&endTime=${EndTime}&granularity=${granularity}
${Logurl} Set Variable http://${host}:${port}/v1/interface/gateway/sql/galaxy/${logType}/timedistribution${urlpath}
${responsebody} distributed_query ${Logurl} ${token}
log ${responsebody}
LogApiVerifyCase-005
[Documentation] 验证api接口:事件日志和通联日志时间分布查询
${StartTime} Set Variable 2021-03-26 12:27:03
${EndTime} Set Variable 2021-03-29 12:27:03
${granularity} Set Variable PT5M
${logType} Set Variable traffic_summary_log
${urlpath} Set Variable ?logType=${logType}&startTime=${StartTime}&endTime=${EndTime}&granularity=${granularity}
${Logurl} Set Variable http://${host}:${port}/v1/interface/gateway/sql/galaxy/${logType}/timedistribution${urlpath}
${responsebody} distributed_query ${Logurl} ${token}
log ${responsebody}
LogApiVerifyCase-006
[Documentation] 验证api接口:日志检索条件校验filter内容验证
${logType} Set Variable security_event_log
${filter} Set Variable common_recv_time = 45535
${urlpath} Set Variable ?logType=${logType}&filter=${filter}
${Logurl} Set Variable http://${host}:${port}/v1/interface/gateway/sql/galaxy/log/filter/validation${urlpath}
${responsebody} distributed_query ${Logurl} ${token}
log ${responsebody}
LogApiVerifyCase-007
[Documentation] 验证api接口:原始日志根据条件过滤计算时间分布查询
${Logurl} Set Variable http://${host}:${port}/v1/log/timedistribution
${logType} Set Variable security_event_log
${StartTime} Set Variable 2021-03-26 12:27:03
${EndTime} Set Variable 2021-03-29 12:27:03
${granularity} Set Variable PT5M
${filter} Set Variable common_recv_time = 45535
${responsebody} timedistribution ${logurl} ${token} ${StartTime} ${EndTime} ${logType} ${granularity} ${filter}
log ${responsebody} log ${responsebody}

View File

@@ -1,43 +1,53 @@
#/user/bin/python # /user/bin/python
#-*-coding:utf-8-*- # -*-coding:utf-8-*-
import requests import requests
import random import random
import json import json
#import allure
# import allure
list = [] list = []
#请求schema接口得到返回数据用于其他接口
def schema(schemauerl,token):
url = schemauerl #"http://192.168.44.72:8080/v1/log/schema?logType=security_event_log" # 请求schema接口得到返回数据用于其他接口
headers = {"Content-Type":"application/x-www-form-urlencoded","Authorization":token} def schema(schemauerl, token):
response = requests.get(url=url,headers=headers) url = schemauerl # "http://192.168.44.72:8080/v1/log/schema?logType=security_event_log"
headers = {"Content-Type": "application/x-www-form-urlencoded", "Authorization": token}
response = requests.get(url=url, headers=headers)
return response.json() return response.json()
#根据schema接口返回数据得出所有属性所支持的比较类型的列表
#1、根据[doc][allow_query]值为true列支持搜索 # 根据schema接口返回数据得出所有属性所支持的比较类型的列表
#2、如有[doc][constraints][operator_functions]值,操作优先 # 1、根据[doc][allow_query]值为true列支持搜索
#3、如有[doc][data]值则对应属性取值为data所列code值 # 2、如有[doc][constraints][operator_functions]值,操作优先
#4、int和long的范围不一致 # 3、如有[doc][data]值则对应属性取值为data所列code值
#5、string要包含特殊字符 # 4、int和long的范围不一致
#6、给查询条件赋值要给出边界和正常值 # 5、string要包含特殊字符
#7、IPV4、V6和URL要给出专门的方法生成 # 6、给查询条件赋值要给出边界和正常值
# 7、IPV4、V6和URL要给出专门的方法生成
import ipaddress import ipaddress
#生成随机ipv4或ipv6
# 生成随机ipv4或ipv6
MAX_IPV4 = ipaddress.IPv4Address._ALL_ONES # 2 ** 32 - 1 MAX_IPV4 = ipaddress.IPv4Address._ALL_ONES # 2 ** 32 - 1
MAX_IPV6 = ipaddress.IPv6Address._ALL_ONES # 2 ** 128 - 1 MAX_IPV6 = ipaddress.IPv6Address._ALL_ONES # 2 ** 128 - 1
def random_ipv4(): def random_ipv4():
return ipaddress.IPv4Address._string_from_ip_int( return ipaddress.IPv4Address._string_from_ip_int(
random.randint(0, MAX_IPV4) random.randint(0, MAX_IPV4)
) )
def random_ipv6(): def random_ipv6():
return ipaddress.IPv6Address._string_from_ip_int( return ipaddress.IPv6Address._string_from_ip_int(
random.randint(0, MAX_IPV6) random.randint(0, MAX_IPV6)
) )
from random import Random from random import Random
# 生成 12 位随机 URL 地址 # 生成 12 位随机 URL 地址
def randrom_url(): def randrom_url():
str = '' str = ''
@@ -47,29 +57,30 @@ def randrom_url():
length = len(chars) length = len(chars)
length1 = len(chars1) length1 = len(chars1)
random = Random() random = Random()
for x in range(random.randint(8,16)): for x in range(random.randint(8, 16)):
str += chars[random.randint(0,length - 1)] str += chars[random.randint(0, length - 1)]
for pp in range(random.randint(8,16)): for pp in range(random.randint(8, 16)):
str1 += chars1[random.randint(0,length1 - 1)] str1 += chars1[random.randint(0, length1 - 1)]
url = str[0:-5]+"." + str[0:-6] + "." + str[0:-7] + "/" + str1 url = str[0:-5] + "." + str[0:-6] + "." + str[0:-7] + "/" + str1
print(url) print(url)
return url return url
def Filter1(schemauerl,token):
json_str = schema(schemauerl,token) def Filter1(schemauerl, token):
json_str = schema(schemauerl, token)
print(type(json_str)) print(type(json_str))
#获取日志属性定义 # 获取日志属性定义
fields = json_str["data"]["fields"] fields = json_str["data"]["fields"]
#获取不同属性支持的部不同操作 # 获取不同属性支持的部不同操作
operator = json_str["data"]["doc"]["schema_query"]["references"]["operator"] operator = json_str["data"]["doc"]["schema_query"]["references"]["operator"]
for i in fields: for i in fields:
number = random.randint(-2147483648,2147483647) number = random.randint(-2147483648, 2147483647)
maxnumber = 2147483647 maxnumber = 2147483647
minnumber = -2147483648 minnumber = -2147483648
str = random.choice('abcdefghijklmnopqrstuvwxyz!@#$%^&*') str = random.choice('abcdefghijklmnopqrstuvwxyz!@#$%^&*')
name = i["name"] name = i["name"]
doc = i["doc"] doc = i["doc"]
#获取无任何特殊说明列: # 获取无任何特殊说明列:
if doc == None: if doc == None:
type1 = i["type"] type1 = i["type"]
for j in operator: for j in operator:
@@ -79,11 +90,11 @@ def Filter1(schemauerl,token):
functions = j["functions"] functions = j["functions"]
functions1 = functions.split(",") functions1 = functions.split(",")
for v in functions1: for v in functions1:
if v=="in" or v == "not in": if v == "in" or v == "not in":
str1 = name + " "+v + " "+ "(" +f"{value1}" + ")" str1 = name + " " + v + " " + "(" + f"{value1}" + ")"
list.append(str1) list.append(str1)
else: else:
str1 = name + " " + v + " " + f"{value1}" str1 = name + " " + v + " " + f"{value1}"
list.append(str1) list.append(str1)
elif type1 == "string": elif type1 == "string":
value1 = str value1 = str
@@ -97,14 +108,14 @@ def Filter1(schemauerl,token):
str1 = name + " " + v + " " + "(" + " '" + value1 + " '" + ")" str1 = name + " " + v + " " + "(" + " '" + value1 + " '" + ")"
list.append(str1) list.append(str1)
else: else:
str1 = name + " " + v + " " + " '"+ value1 + " '" str1 = name + " " + v + " " + " '" + value1 + " '"
list.append(str1) list.append(str1)
else: else:
if i["doc"]["constraints"]== None: if i["doc"]["constraints"] == None:
type1 = i["type"] type1 = i["type"]
for j in operator: for j in operator:
if type1==j["type"]: if type1 == j["type"]:
if type1=="int" or type1=="long": if type1 == "int" or type1 == "long":
value1 = number value1 = number
functions = j["functions"] functions = j["functions"]
functions1 = functions.split(",") functions1 = functions.split(",")
@@ -115,11 +126,11 @@ def Filter1(schemauerl,token):
else: else:
str1 = name + " " + v + " " + f"{value1}" str1 = name + " " + v + " " + f"{value1}"
list.append(str1) list.append(str1)
elif type1=="string": elif type1 == "string":
value1 = str value1 = str
functions = j["functions"] functions = j["functions"]
functions1 = functions.split(",") functions1 = functions.split(",")
for v in functions1: for v in functions1:
if v == "not empty" or v == "empty": if v == "not empty" or v == "empty":
str1 = v + "(" + " '" + name + " '" + ")" str1 = v + "(" + " '" + name + " '" + ")"
list.append(str1) list.append(str1)
@@ -127,11 +138,11 @@ def Filter1(schemauerl,token):
str1 = name + " " + v + " " + "(" + " '" + value1 + " '" + ")" str1 = name + " " + v + " " + "(" + " '" + value1 + " '" + ")"
list.append(str1) list.append(str1)
else: else:
str1 = name + " " + v + " " + " '" + value1 + " '" str1 = name + " " + v + " " + " '" + value1 + " '"
list.append(str1) list.append(str1)
else: else:
if i["doc"]["constraints"]["operator_functions"]==None: if i["doc"]["constraints"]["operator_functions"] == None:
type1 = i["type"] type1 = i["type"]
for j in operator: for j in operator:
if type1 == j["type"]: if type1 == j["type"]:
@@ -140,7 +151,7 @@ def Filter1(schemauerl,token):
functions = j["functions"] functions = j["functions"]
functions1 = functions.split(",") functions1 = functions.split(",")
for v in functions1: for v in functions1:
if v == "in" or v == "not in" : if v == "in" or v == "not in":
str1 = name + " " + v + " " + "(" + f"{value1}" + ")" str1 = name + " " + v + " " + "(" + f"{value1}" + ")"
list.append(str1) list.append(str1)
else: else:
@@ -165,40 +176,44 @@ def Filter1(schemauerl,token):
operator1 = i["doc"]["constraints"]["operator_functions"] operator1 = i["doc"]["constraints"]["operator_functions"]
operator2 = operator1.split(",") operator2 = operator1.split(",")
data = i["doc"]["data"] data = i["doc"]["data"]
for d in data: for d in data:
code = d["code"] code = d["code"]
if type1 == "int" or type1 == "long": if type1 == "int" or type1 == "long":
for o in operator2: for o in operator2:
str1 = name + " "+ o + " "+ code str1 = name + " " + o + " " + code
list.append(str1) list.append(str1)
else: else:
for o in operator2: for o in operator2:
str1 = name + " "+ o + " "+ " '" + code + " '" str1 = name + " " + o + " " + " '" + code + " '"
list.append(str1) list.append(str1)
print(list) print(list)
return list return list
#根据Filter1方法中的的数据写入log请求接口中来验证log请求接口
def logapiverify(logurl,schemauerl,token,starttime,endtime,logtype):
filter2 = Filter1(schemauerl,token) # 根据Filter1方法中的的数据写入log请求接口中来验证log请求接口
a = schema(schemauerl,token) def logapiverify(logurl, schemauerl, token, starttime, endtime, logtype):
filter2 = Filter1(schemauerl, token)
a = schema(schemauerl, token)
fields = a["data"]["fields"] fields = a["data"]["fields"]
print(fields) print(fields)
str2 = "" str2 = ""
for i in filter2: for i in filter2:
str2 = str2 + i + " " + "and" + " " str2 = str2 + i + " " + "and" + " "
url = logurl #"http://192.168.44.72:8080/v1/log/list" url = logurl # "http://192.168.44.72:8080/v1/log/list"
headers = {"Content-Type": "application/json", headers = {"Content-Type": "application/json",
"Authorization": token} "Authorization": token}
data = { data = {
"start_common_recv_time":starttime, "start_common_recv_time": starttime,
"end_common_recv_time":endtime, "end_common_recv_time": endtime,
"logType":logtype, "logType": logtype,
"fields":fields, "fields": fields,
"filter":i "filter": i
} }
print(data) print(data)
print(json.dumps(data)) print(json.dumps(data))
response1 = requests.post(url=url, data=json.dumps(data),headers=headers) response1 = requests.post(url=url, data=json.dumps(data), headers=headers)
code = response1.json()["code"] code = response1.json()["code"]
assert code == 200 assert code == 200
print(response1.json()["code"]) print(response1.json()["code"])
@@ -224,9 +239,10 @@ def logapiverify(logurl,schemauerl,token,starttime,endtime,logtype):
assert code == 200 assert code == 200
print(response1.json()["code"]) print(response1.json()["code"])
#精确filter请求日志接口
def loglistverify(logurl,schemauerl,token,starttime,endtime,logtype,filtervalue): # 精确filter请求日志接口
a = schema(schemauerl,token) def loglistverify(logurl, schemauerl, token, starttime, endtime, logtype, filtervalue):
a = schema(schemauerl, token)
fields = a["data"]["fields"] fields = a["data"]["fields"]
print(fields) print(fields)
url = logurl # "http://192.168.44.72:8080/v1/log/list" url = logurl # "http://192.168.44.72:8080/v1/log/list"
@@ -247,22 +263,28 @@ def loglistverify(logurl,schemauerl,token,starttime,endtime,logtype,filtervalue)
assert code == 200 assert code == 200
print(response1.json()["code"]) print(response1.json()["code"])
return response1.json() return response1.json()
#事件日志和通联日志时间分布查询 日志检索条件校验filter内容验证
def distributed_query(logurl,token): # 事件日志和通联日志时间分布查询 日志检索条件校验filter内容验证
url = logurl #url示例http://192.168.44.72:8080/v1/interface/gateway/sql/galaxy/security_event_hits_log/timedistribution?logType=security_event_hits_log&startTime=2021-03-26 12:27:03&endTime=2021-03-29 12:27:03&granularity=PT5M def distributed_query(logurl, token):
url = logurl # url示例http://192.168.44.72:8080/v1/interface/gateway/sql/galaxy/security_event_hits_log/timedistribution?logType=security_event_hits_log&startTime=2021-03-26 12:27:03&endTime=2021-03-29 12:27:03&granularity=PT5M
headers = {"Content-Type": "application/json", "Authorization": token} headers = {"Content-Type": "application/json", "Authorization": token}
response = requests.get(url=url, headers=headers) response = requests.get(url=url, headers=headers)
code = response1.json()["code"]
print(response.json())
assert code == 200
print(response.json()["code"])
return response.json() return response.json()
#原始日志检索时间分布计算
def timedistribution(logurl,token,starttime,endtime,logtype,granularity,filtervalue): # 原始日志检索时间分布计算
def timedistribution(logurl, token, starttime, endtime, logtype, granularity, filtervalue):
url = logurl # "http://192.168.44.72:8080/v1/log/timedistribution" url = logurl # "http://192.168.44.72:8080/v1/log/timedistribution"
headers = {"Content-Type": "application/json", headers = {"Content-Type": "application/json",
"Authorization": token} "Authorization": token}
data = { data = {
"start_common_recv_time": starttime, "startTime": starttime,
"end_common_recv_time": endtime, "endTime": endtime,
"logType": logtype, "logType": logtype,
"granularity": granularity, "granularity": granularity,
"filter": filtervalue "filter": filtervalue
@@ -270,5 +292,10 @@ def timedistribution(logurl,token,starttime,endtime,logtype,granularity,filterva
print(data) print(data)
print(json.dumps(data)) print(json.dumps(data))
response1 = requests.post(url=url, data=json.dumps(data), headers=headers) response1 = requests.post(url=url, data=json.dumps(data), headers=headers)
#if __name__ == '__main__': code = response1.json()["code"]
print(response1.json())
print(response1.json()["code"])
assert code == 200
return response1.json()
# if __name__ == '__main__':
# logapiverify("http://192.168.32.59:8080/v1/log/list","http://192.168.32.59:8080/v1/log/schema?logType=security_event_log","d475b20d-e2b8-4f24-87ee-d54af46e6aff&807&",'2021-03-20 16:36:41','2021-03-21 17:36:41',"security_event_log") # logapiverify("http://192.168.32.59:8080/v1/log/list","http://192.168.32.59:8080/v1/log/schema?logType=security_event_log","d475b20d-e2b8-4f24-87ee-d54af46e6aff&807&",'2021-03-20 16:36:41','2021-03-21 17:36:41',"security_event_log")