提交 日志接口关键字
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
*** Settings ***
|
||||
Library Collections
|
||||
Library json
|
||||
Library RequestsLibrary
|
||||
Resource ../../03-Variable/BifangApiVariable.txt
|
||||
|
||||
@@ -8,6 +9,7 @@ Post-Request
|
||||
[Arguments] ${url} ${data}
|
||||
${header} Create Dictionary Content-Type=application/json Authorization=${token}
|
||||
Create Session api http://${host}:${port} headers=${header}
|
||||
#${data1} json.dumps ${data}
|
||||
${remoteResponse} Post Request api ${url} data=${data} headers=${header}
|
||||
${response} to json ${remoteResponse.content}
|
||||
Should Be Equal As Strings ${remoteResponse.status_code} 200
|
||||
|
||||
@@ -29,7 +29,7 @@ ManageApistr
|
||||
BasePostRequest
|
||||
[Arguments] ${apistr} ${body}
|
||||
Set Headers {"Authorization":"${token}","Content-Type":"application/json"}
|
||||
log 111111111111111111111111${apistr}
|
||||
log ${apistr}
|
||||
&{httpResponse} Post ${apistr} ${body}
|
||||
#Output response body
|
||||
Object response body
|
||||
|
||||
@@ -4,9 +4,23 @@ Library OperatingSystem
|
||||
Library Selenium2Library
|
||||
Library RequestsLibrary
|
||||
Library Collections
|
||||
Library DateTime
|
||||
Library String
|
||||
Library HttpLibrary.HTTP
|
||||
Resource ../tsg_bfapi/ApiRequest.robot
|
||||
Resource Log_schema.robot
|
||||
Resource ../tsg_bfapi/Common.robot
|
||||
Library ../../04-CustomLibrary/Custometest/Schema.py
|
||||
|
||||
*** Test Cases ***
|
||||
Apitext
|
||||
${EndTime} get current date
|
||||
${EndTime1} Get Substring ${EndTime} \ -4
|
||||
${StartTime} add time to date ${EndTime} -01:00:00
|
||||
${StartTime1} Get Substring ${StartTime} \ -4
|
||||
log ${StartTime1}
|
||||
log ${EndTime1}
|
||||
LogApiSearch ${StartTime1} ${EndTime1} security_event_log v1/log/list
|
||||
|
||||
*** Keywords ***
|
||||
log_search
|
||||
@@ -18,3 +32,50 @@ log_search
|
||||
${response} BasePostRequest v1/log/list ${requestbody}
|
||||
log ${response}
|
||||
[Return] ${response}
|
||||
|
||||
LogSchema
|
||||
[Arguments] ${logtype}
|
||||
${responsedata} Get-Request /v1/log/schema?logType=${logtype}
|
||||
${responsedata1} Get From Dictionary ${responsedata} data
|
||||
${responsefields} Get From Dictionary ${responsedata1} fields
|
||||
[Return] ${responsedata}
|
||||
|
||||
LogApiSearch
|
||||
[Arguments] ${start-time} ${end-time} ${logtype} ${url} ${conditions}=${None} ${filter}=null
|
||||
${schemaresponsedata} LogSchema ${logtype}
|
||||
${type1} Evaluate type(${schemaresponsedata})
|
||||
log 11111111${type1}
|
||||
${schemaresponsedata1} Get From Dictionary ${schemaresponsedata} data
|
||||
${filds} Get From Dictionary ${schemaresponsedata1} fields
|
||||
${filedsJson} json.dumps ${filds}
|
||||
${filter1} run keyword if "${filter}"=="null" Filter1 ${schemaresponsedata}
|
||||
run keyword if "${filter}"=="null" ForFilter ${start-time} ${end-time} ${logtype} ${url}
|
||||
... ${filedsJson} ${conditions} ${filter1}
|
||||
... ELSE LogSearchRequest ${start-time} ${end-time} ${logtype} ${url}
|
||||
... ${conditions} ${filter}
|
||||
# ${requestbody} Set Variable {"start_common_recv_time":"${start-time}","end_common_recv_time":"${end-time}","logType":"${type}","fields":${filedsJson},"conditions":${conditions},"filter":${filter},refuseCode":true}
|
||||
# ${response} BasePostRequest v1/log/list ${requestbody}
|
||||
# ${code} Get From Dictionary ${response} code
|
||||
|
||||
LogSearchRequest
|
||||
[Arguments] ${start-time} ${end-time} ${logtype} ${url} ${filedsJson} ${conditions} ${filter}
|
||||
# ${type2} Evaluate type(${filedsJson})
|
||||
# log 7777${type2}
|
||||
${requestbody} Set Variable {"start_common_recv_time":"${start-time}","end_common_recv_time":"${end-time}","logType":"${logtype}","fields":${filedsJson},"conditions":${conditions},"filter":${filter},refuseCode":true}
|
||||
#${requestbody1} json.loads ${requestbody}
|
||||
#${type1} Evaluate type(${requestbody})
|
||||
#log 88888888${type1}
|
||||
${response} Post-Request ${url} ${requestbody}
|
||||
${code} Get From Dictionary ${response} code
|
||||
log 22222222${response}
|
||||
|
||||
ForFilter
|
||||
[Arguments] ${start-time} ${end-time} ${logtype} ${url} ${filedsJson} ${conditions} ${filter1}
|
||||
${LongFilter} Set Variable
|
||||
: FOR ${i} IN @{filter1}
|
||||
\ ${LongFilter} catenate ${i} "and"
|
||||
\ LogSearchRequest ${start-time} ${end-time} ${logtype} ${url} ${filedsJson} ${conditions}
|
||||
\ ... ${i}
|
||||
${LongFilter1} Get Substring ${LongFilter} \ -5
|
||||
log 55555555${LongFilter1}
|
||||
LogSearchRequest ${start-time} ${end-time} ${logtype} ${url} ${conditions} ${LongFilter1}
|
||||
|
||||
125
04-CustomLibrary/Custometest/Schema.py
Normal file
125
04-CustomLibrary/Custometest/Schema.py
Normal file
@@ -0,0 +1,125 @@
|
||||
#!/user/bin/python
|
||||
#-*-coding:utf-8-*-
|
||||
import requests
|
||||
import random
|
||||
import json
|
||||
number = random.randint(0,100000)
|
||||
str = random.choice('abcdefghijklmnopqrstuvwxyz!@#$%^&*()')
|
||||
list = []
|
||||
# def schema():
|
||||
# url = "http://192.168.44.72:8080/v1/log/schema?logType=security_event_log"
|
||||
# headers = {"Content-Type":"application/x-www-form-urlencoded","Authorization":"555b5dc2-d69f-44a4-8a00-171e81edd739&889&"}
|
||||
# response = requests.get(url=url,headers=headers)
|
||||
# return response.json()
|
||||
|
||||
def Filter1(schema):
|
||||
print("1234")
|
||||
print(type(schema))
|
||||
json_str = json.dumps(schema)
|
||||
schema1 = json.loads(json_str)
|
||||
fields = schema1["data"]["fields"]
|
||||
#print(fields)
|
||||
|
||||
#print(type(fields))
|
||||
operator = schema1["data"]["doc"]["schema_query"]["references"]["operator"]
|
||||
#print(operator)
|
||||
for i in fields:
|
||||
print(i)
|
||||
name = i["name"]
|
||||
doc = i["doc"]
|
||||
if doc == None:
|
||||
type1 = i["type"]
|
||||
for j in operator:
|
||||
if type1 == j["type"]:
|
||||
if type1 == "int" or type1 == "long":
|
||||
value1 = number
|
||||
functions = j["functions"]
|
||||
functions1 = functions.split(",")
|
||||
for v in functions1:
|
||||
str1 = name + " "+v + " "+ f"{value1}"
|
||||
list.append(str1)
|
||||
elif type1 == "string":
|
||||
value1 = str
|
||||
functions = j["functions"]
|
||||
functions1 = functions.split(",")
|
||||
for v in functions1:
|
||||
str1 = name + " "+v + " "+ value1
|
||||
list.append(str1)
|
||||
else:
|
||||
if i["doc"]["constraints"]== None:
|
||||
type1 = i["type"]
|
||||
for j in operator:
|
||||
if type1==j["type"]:
|
||||
if type1=="int" or type1=="long":
|
||||
value1 = number
|
||||
functions = j["functions"]
|
||||
functions1 = functions.split(",")
|
||||
for v in functions1:
|
||||
str1 = name + " "+v + " "+ f"{value1}"
|
||||
list.append(str1)
|
||||
elif type1=="string":
|
||||
value1 = str
|
||||
functions = j["functions"]
|
||||
functions1 = functions.split(",")
|
||||
for v in functions1:
|
||||
str1=name + " "+v + " "+ value1
|
||||
list.append(str1)
|
||||
|
||||
else:
|
||||
if i["doc"]["constraints"]["operator_functions"]==None:
|
||||
type1 = i["type"]
|
||||
for j in operator:
|
||||
if type1 == j["type"]:
|
||||
if type1 == "int" or type1 == "long":
|
||||
value1 = number
|
||||
functions = j["functions"]
|
||||
functions1 = functions.split(",")
|
||||
for v in functions1:
|
||||
str1 = name + " "+ v + " "+ f"{value1}"
|
||||
list.append(str1)
|
||||
elif type1 == "string":
|
||||
value1 = str
|
||||
functions = j["functions"]
|
||||
functions1 = functions.split(",")
|
||||
for v in functions1:
|
||||
str1 = name + " "+ v + " "+ value1
|
||||
list.append(str1)
|
||||
else:
|
||||
type1 = i["type"]
|
||||
operator1 = i["doc"]["constraints"]["operator_functions"]
|
||||
operator2 = operator1.split(",")
|
||||
data = i["doc"]["data"]
|
||||
for d in data:
|
||||
code = d["code"]
|
||||
if type1 == "int" or type1 == "long":
|
||||
for o in operator2:
|
||||
str1 = name + " "+ o + " "+ code
|
||||
list.append(str1)
|
||||
else:
|
||||
for o in operator2:
|
||||
str1 = name + " "+ o + " "+ code
|
||||
list.append(str1)
|
||||
print(list)
|
||||
return list
|
||||
# def api():
|
||||
# filter2 = Filter1()
|
||||
# a = schema()
|
||||
# fields = a["data"]["fields"]
|
||||
# for i in filter2:
|
||||
# url = "http://192.168.32.59:8888/v1/log/list"
|
||||
# headers = {"Content-Type": "application/json",
|
||||
# "Authorization": "7dda2581-38ca-4c48-9103-98ab852a5be5&807&"}
|
||||
# data = {
|
||||
# "start_common_recv_time":'2021-03-20 16:36:41',
|
||||
# "end_common_recv_time":'2021-03-21 17:36:41',
|
||||
# "logType":"security_event_log",
|
||||
# "fields":fields,
|
||||
# "filter":i
|
||||
# }
|
||||
# print(data)
|
||||
# response1 = requests.post(url=url, data=json.dumps(data),headers=headers)
|
||||
# print(response1.json())
|
||||
# return response1.json()
|
||||
#
|
||||
# if __name__ == '__main__':
|
||||
# api()
|
||||
Reference in New Issue
Block a user