summaryrefslogtreecommitdiff
path: root/keyword
diff options
context:
space:
mode:
Diffstat (limited to 'keyword')
-rw-r--r--keyword/common/api_request.robot52
-rw-r--r--keyword/common/clear_data.robot68
-rw-r--r--keyword/common/command.robot103
-rw-r--r--keyword/common/common.robot255
-rw-r--r--keyword/common/common_interface.robot47
-rw-r--r--keyword/common/customlibrary/Custometest/Common.py51
-rw-r--r--keyword/common/customlibrary/Custometest/JsonDiff.py6
-rw-r--r--keyword/common/customlibrary/Custometest/LogResponseVAL.py203
-rw-r--r--keyword/common/customlibrary/Custometest/LogSchema.py513
-rw-r--r--keyword/common/customlibrary/Custometest/MD5.py40
-rw-r--r--keyword/common/customlibrary/Custometest/ReportSchema.py718
-rw-r--r--keyword/common/customlibrary/Custometest/ReportSchema_Negtive.py871
-rw-r--r--keyword/common/customlibrary/Custometest/Schema.py350
-rw-r--r--keyword/common/customlibrary/Custometest/StringManipulation.py7
-rw-r--r--keyword/common/customlibrary/Custometest/UIAssert.py22
-rw-r--r--keyword/common/customlibrary/Custometest/__init__.py16
-rw-r--r--keyword/common/customlibrary/Custometest/__pycache__/Common.cpython-36.pycbin0 -> 1315 bytes
-rw-r--r--keyword/common/customlibrary/Custometest/__pycache__/JsonDiff.cpython-36.pycbin0 -> 343 bytes
-rw-r--r--keyword/common/customlibrary/Custometest/__pycache__/LogResponseVAL.cpython-36.pycbin0 -> 3619 bytes
-rw-r--r--keyword/common/customlibrary/Custometest/__pycache__/Schema.cpython-36.pycbin0 -> 6947 bytes
-rw-r--r--keyword/common/customlibrary/Custometest/__pycache__/StringManipulation.cpython-36.pycbin0 -> 339 bytes
-rw-r--r--keyword/common/customlibrary/Custometest/__pycache__/UIAssert.cpython-36.pycbin0 -> 898 bytes
-rw-r--r--keyword/common/customlibrary/Custometest/__pycache__/log_contrast.cpython-36.pycbin0 -> 415 bytes
-rw-r--r--keyword/common/customlibrary/Custometest/certificate.yaml0
-rw-r--r--keyword/common/customlibrary/Custometest/cmd_cer.py290
-rw-r--r--keyword/common/customlibrary/Custometest/log_contrast.py8
-rw-r--r--keyword/common/customlibrary/Custometest/printlog.py11
-rw-r--r--keyword/common/customlibrary/ExtensionPackages/ExtensionLibrary/__init__.py7
-rw-r--r--keyword/common/customlibrary/ExtensionPackages/ExtensionLibrary/mytool.py26
-rw-r--r--keyword/common/customlibrary/ExtensionPackages/FileLibrary/__init__.py7
-rw-r--r--keyword/common/customlibrary/ExtensionPackages/FileLibrary/filetool.py22
-rw-r--r--keyword/common/customlibrary/ExtensionPackages/GetTimeLibrary/GetTime.py85
-rw-r--r--keyword/common/customlibrary/ExtensionPackages/GetTimeLibrary/__init__.py6
-rw-r--r--keyword/common/customlibrary/ExtensionPackages/extensionLibrary.pth2
-rw-r--r--keyword/common/customlibrary/ExtensionPackages/readme.txt4
-rw-r--r--keyword/common/customlibrary/Library/VerifyPolicy.py38
-rw-r--r--keyword/common/customlibrary/Library/__pycache__/VerifyPolicy.cpython-36.pycbin0 -> 953 bytes
-rw-r--r--keyword/common/customlibrary/Library/__pycache__/delUseless.cpython-36.pycbin0 -> 745 bytes
-rw-r--r--keyword/common/customlibrary/Library/__pycache__/fileOperations.cpython-36.pycbin0 -> 625 bytes
-rw-r--r--keyword/common/customlibrary/Library/delUseless.py45
-rw-r--r--keyword/common/customlibrary/Library/fileOperations.py26
-rw-r--r--keyword/common/customlibrary/Pop3Library/__init__.py200
-rw-r--r--keyword/common/customlibrary/Pop3Library/__pycache__/__init__.cpython-36.pycbin0 -> 4589 bytes
-rw-r--r--keyword/common/customlibrary/Pop3Library/readme.txt26
-rw-r--r--keyword/common/customlibrary/Smtp3Library/__init__.py417
-rw-r--r--keyword/common/customlibrary/Smtp3Library/version.py11
-rw-r--r--keyword/common/customlibrary/ipandstring/__init__.py4
-rw-r--r--keyword/common/customlibrary/ipandstring/stringip.py68
-rw-r--r--keyword/common/file_operation.robot36
-rw-r--r--keyword/common/functional_keywords.robot260
-rw-r--r--keyword/common/log_variable.robot146
-rw-r--r--keyword/common/login_logout.robot180
-rw-r--r--keyword/common/login_logout_switch.robot25
-rw-r--r--keyword/common/logschema.robot69
-rw-r--r--keyword/common/systemcommand.robot63
-rw-r--r--keyword/objects/application.robot55
-rw-r--r--keyword/objects/ip.yaml22
-rw-r--r--keyword/objects/ip_objects.robot176
-rw-r--r--keyword/objects/manage_object_body.robot378
-rw-r--r--keyword/objects/object.robot513
-rw-r--r--keyword/objects/process_object_body.robot562
-rw-r--r--keyword/policys/manage_policy_body.robot281
-rw-r--r--keyword/policys/policy.robot562
-rw-r--r--keyword/policys/process_policy_body.robot585
-rw-r--r--keyword/verify/verify.robot21
65 files changed, 8559 insertions, 0 deletions
diff --git a/keyword/common/api_request.robot b/keyword/common/api_request.robot
new file mode 100644
index 0000000..3325e2a
--- /dev/null
+++ b/keyword/common/api_request.robot
@@ -0,0 +1,52 @@
+*** Settings ***
+Library Collections
+Library json
+Library RequestsLibrary
+Resource ../../variable/common_variable.txt
+
+*** Keywords ***
+PostRequest1
+ [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
+ [Return] ${response}
+
+GetRequest1
+ [Arguments] ${url}
+ ${header} Create Dictionary Content-Type=application/json Authorization=${token}
+ Create Session api http://${host}:${port} headers=${header}
+ ${remoteResponse} Get Request api ${url} headers=${header}
+ ${response} to json ${remoteResponse.content}
+ Should Be Equal As Strings ${remoteResponse.status_code} 200
+ [Return] ${response}
+
+DeleteRequest1
+ [Arguments] ${url} ${data}
+ ${header} Create Dictionary Content-Type=application/json Authorization=${token}
+ Create Session api http://${host}:${port} headers=${header}
+ ${remoteResponse} Delete Request api ${url} data=${data} headers=${header}
+ ${response} to json ${remoteResponse.content}
+ Should Be Equal As Strings ${remoteResponse.status_code} 200
+ [Return] ${response}
+
+UpFilePostRequest
+ [Arguments] ${url} ${data} ${files} ${fileDesc}
+ ${header} Set To Dictionary ${fileDesc} Authorization=${token}
+ Create Session api http://${host}:${port} headers=${header}
+ ${remoteResponse} Post Request api ${url} data=${data} files=${files} headers=${header}
+ ${response} to json ${remoteResponse.content}
+ Should Be Equal As Strings ${remoteResponse.status_code} 200
+ [Return] ${response}
+
+UpFilePutRequest
+ [Arguments] ${url} ${data} ${files} ${fileDesc}
+ ${header} Set To Dictionary ${fileDesc} Authorization=${token}
+ Create Session api http://${host}:${port} headers=${header}
+ ${remoteResponse} Put Request api ${url} params=${data} files=${files} headers=${header}
+ ${response} to json ${remoteResponse.content}
+ Should Be Equal As Strings ${remoteResponse.status_code} 200
+ [Return] ${response}
diff --git a/keyword/common/clear_data.robot b/keyword/common/clear_data.robot
new file mode 100644
index 0000000..1c933fb
--- /dev/null
+++ b/keyword/common/clear_data.robot
@@ -0,0 +1,68 @@
+*** Settings ***
+Library Collections
+Library RequestsLibrary
+Resource ../../variable/common_variable.txt
+#Resource functional_keywords.robot
+Resource ../policys/policy.robot
+Resource ../objects/object.robot
+Resource ../objects/application.robot
+Resource common.robot
+*** Variables ***
+${policyUrl} /policy/compile
+*** Keywords ***
+DeletePolicyAndObjectAndOther
+ [Documentation] delete :policy object category app signature profile ...
+ [Arguments] ${policyIds}=${EMPTY} ${objectIds}=${EMPTY} ${categoryIds}=${EMPTY} ${profiledId}=${EMPTY} ${appIds}=${EMPTY} ${signatureId}=${EMPTY}
+ #Run Keyword If "${policyIds}"=="${EMPTY}" log no policyIds to del
+ #... ELSE DeletePoliciebyList ${policyIds}
+ Run Keyword If "${createPolicyIds}"=="${EMPTY}" log no policyIds to del
+ ... ELSE DeletePoliciebyList ${createPolicyIds}
+
+ #Run Keyword If "${objectIds}"=="${EMPTY}" log no objectIds to del
+ #... ELSE DeleteObjectByIds ${objectIds}
+ Run Keyword If "${createObjectIds}"=="${EMPTY}" log no objectIds to del
+ ... ELSE DeleteObjectByIds ${createObjectIds}
+
+ Run Keyword If "${categoryIds}"=="${EMPTY}" log no categoryIds to del
+ ... ELSE DeleteCategoryByIds ${categoryIds}
+ #删除文件
+ Run Keyword If "${profiledId}"=="${EMPTY}" log no profiledId to del
+ ... ELSE DeleteProfileByIds ${url} ${profiledId}
+
+ Run Keyword If "${appids}"=="${EMPTY}" log no appids to del
+ ... ELSE DeleteApplicationByIds ${appids}
+
+ Run Keyword If "${signatureId}"=="${EMPTY}" log no signatureId to del
+ ... ELSE DeleteSignatureByIds ${signatureId}
+
+DeletePolicyAndGroupObject
+ [Documentation] delete :policy object
+ ... policyList
+ [Arguments] ${policyList}=${EMPTY} ${objectIds}=${EMPTY}
+ Run Keyword If "${policyList}"=="${EMPTY}" log no policyList to del
+ ... ELSE DeletePoliciebyList ${policyList}
+
+ Run Keyword If "${objectIds}"=="${EMPTY}" log no objectIds to del
+ ... ELSE DeleteObjectByIds ${objectIds}
+DeletePolicyAndObject
+ [Arguments] ${policyids} ${objectids} ${categoriesId}=null
+ ${objectId1} Create List [${objectids}]
+ ${categoryId1} Create List [${categoriesId}]
+ DeletePolicyAndGroupObject1 ${policyIds} ${objectId1} ${categoryId1}
+
+DeletePolicyAndGroupObject1
+ [Arguments] ${policyids} ${objectids} ${categoriesId}
+ #引用此关键字,${objectids}参数必须是双层列表,eg:['[1]','[2,3]','[4,5,6,7]']
+ #删除策略和对象
+ log toDeletePolicy_DeletePolicyAndObject
+ ${listlenth}= Get Length ${policyids}
+ Run Keyword If "${listlenth}"=="0" log no Policys to del
+ ... ELSE DeletePoliciebyList ${policyids}
+ #删除对象
+ Run Keyword If "${objectids}"=="${EMPTY}" log no Objects to del
+ ... ELSE IF ${objectids}==['[]'] log no Objects to del
+ ... ELSE DeleteGroupObjects ${objectids}
+ log ${categoriesId}
+ Run Keyword If "${categoriesId}"=="${EMPTY}" or ${categoriesId}==['[null]'] or ${categoriesId}==['[]'] log no Categories to del
+ ... ELSE DeleteGroupCategories ${categoriesId}
+ \ No newline at end of file
diff --git a/keyword/common/command.robot b/keyword/common/command.robot
new file mode 100644
index 0000000..fac6643
--- /dev/null
+++ b/keyword/common/command.robot
@@ -0,0 +1,103 @@
+*** Settings ***
+Library OperatingSystem
+Library Selenium2Library
+Library RequestsLibrary
+Library Collections
+Library ../../customlib/common/common.py
+Resource ../../variable/common_variable.txt
+
+*** Keywords ***
+SystemCommands
+ [Documentation] 执行系统命令,在命令结果中匹配指定字符串列表,需匹配到所有字符串才为通过
+ [Arguments] ${commandstr} ${stringlist}
+ log toSystemCommand_SystemCommandTest
+ ${commandreturn} OperatingSystem.Run ${commandstr}
+ #Create File ${path}/test.txt ${commandreturn}
+ #Append To File ${path}/write_file.txt ${commandstr}
+ #Append To File ${path}/write_file.txt %%%%%%%%%%%%%%newbat
+ #Append To File ${path}/write_file.txt ${commandreturn}
+ ${listlenth}= Get Length ${stringlist}
+ FOR ${var} IN RANGE ${listlenth}
+ #log ${var}
+ Should Contain ${commandreturn} ${stringlist}[${var}]
+ END
+ ${rescode} Set Variable 200
+ log ${rescode}
+ [Return] ${rescode}
+
+SystemCommandsRetry
+ [Documentation] 执行系统命令,失败后重试
+ [Arguments] ${commandstr} ${stringlist} ${retryNum}=1
+ log to_SystemCommandsRetry
+ ${trueCounter} Set Variable 0
+ ${falseCounter} Set Variable 0
+ FOR ${var} IN RANGE ${retryNum}
+ ${rescode} SystemCommandContains ${commandstr} ${stringlist}
+ ${trueCounter} ${falseCounter} Counter ${trueCounter} ${falseCounter} ${rescode}
+ END
+ [Return] ${trueCounter}
+IsContain
+ [Documentation] 比较一个字符串是否包含另一个字符串,包含返回true,否则返回false
+ ... 多行内容,例如命令指向结果有问题。
+ [Arguments] ${sourceStr} ${findContent}
+ ${rescode} Evaluate "abc" in "abcd"
+ ${rescode} Evaluate ${findContent} in ${sourceStr}
+ log ${rescode}
+ #https://blog.csdn.net/sun_977759/article/details/107815615
+ #${file} Evaluate open(r'${filepath})
+ # Evaluate ${file}.close()
+ #[Robot Framework] 校验字符串中是否包含某个子字符串,校验同时满足两个条件中任意一个
+#${tWarningMessage} Run Keyword If ${tIfExist} AutoItLibrary.Win Get Text Generate Fee Data warning message ELSE Set Variable ""
+
+#${tIfDuplicateFee} Evaluate "Duplicate Fee Warning" in """${tWarningMessage}"""
+
+#${rCheckResult} Evaluate ${totalNumberNew}==${totalNumberOld} or ${totalNumberNew}>${totalNumberOld}
+
+ [Return] ${rescode}
+
+Counter
+ [Documentation] 给计数器赋值
+ [Arguments] ${trueCounter} ${falseCounter} ${value}
+ ${trueCounter} Run Keyword If "${value}" == "True" Evaluate ${trueCounter}+1
+ ... ELSE Set Variable ${trueCounter}
+ ${falseCounter} Run Keyword If "${value}" == "False" Evaluate ${falseCounter}+1
+ ... ELSE Set Variable ${falseCounter}
+ [Return] ${trueCounter} ${falseCounter}
+
+SystemCommandContains
+ [Documentation] 执行系统命令,在命令结果中匹配指定字符串列表,匹配大于指定个数即为通过
+ [Arguments] ${commandStr} ${stringList} ${passNum}=1
+ log toSystemCommand_SystemCommandTest
+ ${commandreturn} OperatingSystem.Run ${commandStr}
+ ${listlenth}= Get Length ${stringList}
+ ${trueCounter} Set Variable 0
+ ${falseCounter} Set Variable 0
+ FOR ${var} IN RANGE ${listlenth}
+ #log ${var}
+ ${rescode} aisincludeb ${stringList}[${var}] ${commandreturn}
+ ${trueCounter} ${falseCounter} Counter ${trueCounter} ${falseCounter} ${rescode}
+ END
+ #${rescode} Evaluate ${totalNumberNew}==${totalNumberOld} or ${totalNumberNew}>${totalNumberOld}
+ ${rescode} Evaluate ${trueCounter}==${passNum} or ${trueCounter}>${passNum}
+ log ${rescode}
+ [Return] ${rescode}
+
+
+SystemCommandReturnCompare
+ [Documentation] 执行命令并比对命令返回结果 需要执行的系统命令 命令返回结果要包含的字符串列表 命令返回结果不能包含的字符串列表
+ [Arguments] ${commandStr} ${stringList} ${stringListNotIn}
+ log toSystemCommand_SystemCommandTest
+ ${commandreturn} OperatingSystem.Run ${commandStr}
+ ${listlenth}= Get Length ${stringList}
+ FOR ${var} IN RANGE ${listlenth}
+ log ${var}
+ Should Contain ${commandreturn} ${stringList}[${var}]
+ END
+ ${listnotin}= Get Length ${stringlistnotin}
+ FOR ${varn} IN RANGE ${listnotin}
+ log ${varn}
+ Should Not Contain ${commandreturn} ${stringListNotIn}[${varn}]
+ END
+ ${rescode} Set Variable 200
+ log ${rescode}
+ [Return] ${rescode}
diff --git a/keyword/common/common.robot b/keyword/common/common.robot
new file mode 100644
index 0000000..4a585a6
--- /dev/null
+++ b/keyword/common/common.robot
@@ -0,0 +1,255 @@
+*** Settings ***
+Resource ../../variable/common_variable.txt
+Library REST http://${host}:${port}
+Library Collections
+Library RequestsLibrary
+Library json
+
+*** Keywords ***
+ManageApistr
+ [Documentation]
+ ... 描述:入口,apistr 为调用api地址
+ ... 本关键字的作用是判断地址前有没有加版本号,如果没有加上
+ ... policy/compile -> /v1/policy/compile
+ ... /policy/compile -> /v1/policy/compile
+ ... v1/policy/compile -> /v1/policy/compile
+ ... /v1/policy/compile -> /v1/policy/compile
+ [Arguments] ${apistr}
+ ${apiStart} Evaluate '${apistr}'[0:1]
+ ${apiStart1} Evaluate '${apistr}'[0:2]
+ ${apistr} Run Keyword If "${apiStart}"!="/" and "${apiStart}"!="v"
+ ... Set Variable /${version}/${apistr}
+ ... ELSE IF "${apiStart}"=="/" and "${apiStart1}"!="/v"
+ ... Set Variable /${version}${apistr}
+ ... ELSE IF "${apiStart}"=="v" Set Variable /${apistr}
+ ... ELSE IF "${apiStart1}"=="/v" Set Variable ${apistr}
+ ... ELSE Set Variable ${apistr}
+ log ${apistr}
+ [Return] ${apistr}
+BasePostRequest
+ [Arguments] ${apistr} ${body}
+ Set Headers {"Authorization":"${token}","Content-Type":"application/json"}
+ log ${apistr}
+ &{httpResponse} Post ${apistr} ${body}
+ #Output response body
+ Object response body
+ #Integer $.code 200
+ #Array $.data.policyList
+ ${response} Set Variable ${httpResponse.body}
+ [Return] ${response}
+
+BasePostRequestOK
+ [Arguments] ${apistr} ${body}
+ ${response} BasePostRequest ${apistr} ${body}
+ log ${response['code']}
+ Should Be Equal As Strings ${response['code']} 200
+ [Return] ${response}
+
+BasePostRequestForV2
+ [Arguments] ${requestUri} ${data} ${apiVersion}
+ ${headers} set variable {"Authorization":"${token}","Content-Type":"application/json"}
+ create session api http://${host}:${port}/${apiVersion} ${headers}
+ ${response}= Post Request api ${requestUri} data=${data}
+ log return data =${response}
+ Should Be Equal As Strings ${response.status_code} 200
+ ${response} to json ${response.content}
+ [Return] ${response}
+BaseGetRequest
+ [Arguments] ${apistr} ${body}
+ Set Headers {"Authorization":"${token}","Content-Type":"application/json"}
+ &{httpResponse} Get ${apistr}?${body}
+ #Output response body
+ Object response body
+ #Integer $.code 200
+ #Array $.data.policyList
+ ${response} Set Variable ${httpResponse.body}
+ [Return] ${response}
+BaseGetRequestOK
+ [Arguments] ${apistr} ${body}
+ ${response} BaseGetRequest ${apistr} ${body}
+ log ${response['code']}
+ Should Be Equal As Strings ${response['code']} 200
+ [Return] ${response}
+BaseGetRequestForV2
+ [Arguments] ${requestUri} ${data} ${apiVersion}
+ ${headers} set variable {"Authorization":"${token}","Content-Type":"application/json"}
+ create session api http://${host}:${port}/${apiVersion} ${headers}
+ ${response}= Get Request api ${requestUri}?${data}
+ log return data =${response}
+ Should Be Equal As Strings ${response.status_code} 200
+ ${response} to json ${response.content}
+ [Return] ${response}
+BaseDeleteRequest
+ [Arguments] ${requestUri} ${data}
+ ${headers} set variable {"Authorization":"${token}","Content-Type":"application/json"}
+ create session api http://${host}:${port} ${headers}
+ ${response}= Delete Request api ${requestUri} data=${data}
+ log return data =${response}
+ Should Be Equal As Strings ${response.status_code} 200
+ ${response} to json ${response.content}
+ [Return] ${response}
+
+BaseDeleteRequestOK
+ [Arguments] ${apistr} ${body}
+ ${response} BaseDeleteRequest ${apistr} ${body}
+ log ${response['code']}
+ Should Be Equal As Strings ${response['code']} 200
+ [Return] ${response}
+
+BaseEditRequest
+ [Arguments] ${requestUri} ${data}
+ ${headers} set variable {"Authorization":"${token}","Content-Type":"application/json"}
+ create session api http://${host}:${port} ${headers}
+ ${response}= Put Request api ${requestUri} data=${data}
+ log return data =${response}
+ Should Be Equal As Strings ${response.status_code} 200
+ ${response} to json ${response.content}
+ [Return] ${response}
+
+BaseEditRequestOK
+ [Arguments] ${apistr} ${body}
+ ${response} BaseEditRequest ${apistr} ${body}
+ log ${response['code']}
+ Should Be Equal As Strings ${response['code']} 200
+ [Return] ${response}
+BaseEditRequestForV2
+ [Arguments] ${requestUri} ${data} ${apiVersion}
+ ${apiStart} Evaluate '${requestUri}'[0:1]
+ ${requestUri} Run Keyword If "${apiStart}"=="/" set variable /${apiVersion}${requestUri}
+ ... ELSE set variable /${apiVersion}/${requestUri}
+ ${response} BaseEditRequest ${requestUri} ${data}
+ [Return] ${response}
+#拼接字典类型数据为get请求的字符串
+DictionaryToQueryParams
+ [Documentation]
+ ... 接收get参数字典,转换为请求字符串
+ [Arguments] ${params}
+ ${paramsString} = Set Variable ${EMPTY}
+ Run Keyword And Return If "${params}" == "${EMPTY}" Set Variable ${EMPTY}
+ FOR ${key} IN @{params}
+ ${value} = Get From Dictionary ${params} ${key}
+ ${paramStr} = Catenate SEPARATOR=\= ${key} ${value}
+ ${len} = Get Length ${paramsString}
+ ${paramsString} = Run Keyword If ${len} != 0 Catenate SEPARATOR=& ${paramsString} ${paramStr}
+ ... ELSE Set Variable ${paramStr}
+ END
+ Log To Console ${paramsString}
+ [Return] ${paramsString}
+BaseFormRequest
+ [Arguments] ${requestUri} ${data} ${apiVersion}
+ ${headers} set variable {"Authorization":"${token}","Content-Type":"application/x-www-form-urlencoded"}
+ create session api http://${host}:${port}/${apiVersion} ${headers}
+ ${response} Run Keyword If "${data}"=="${EMPTY}" Get Request api ${requestUri}
+ ... ELSE Get Request api ${requestUri}?${data}
+ log return data =${response}
+ Should Be Equal As Strings ${response.status_code} 200
+ ${response} to json ${response.content}
+ [Return] ${response}
+BaseFormRequest1
+ [Documentation]
+ ... 下载文件专用
+ ... 由于下载的json存在特殊字符
+ ... 隐藏需要设置response.encoding='utf-8-sig'
+ [Arguments] ${requestUri} ${data} ${apiVersion}
+ ${headers} set variable {"Authorization":"${token}","Content-Type":"application/x-www-form-urlencoded"}
+ create session api http://${host}:${port}/${apiVersion} ${headers}
+ ${response} Run Keyword If "${data}"=="${EMPTY}" Get Request api ${requestUri}
+ ... ELSE Get Request api ${requestUri}?${data}
+ log return data =${response}
+ ${response.encoding} set variable utf-8-sig
+ Should Be Equal As Strings ${response.status_code} 200
+ ${response} json.Loads ${response.content}
+ [Return] ${response}
+BaseMultipartPostRequest
+ [Arguments] ${requestUri} ${data} ${files} ${apiVersion}
+ ${headers} set variable {"Authorization":"${token}"}
+ ${dataString} DictionaryToQueryParams ${data}
+ create session api http://${host}:${port}/${apiVersion} ${headers}
+ ${response}= Post Request api ${requestUri}?${dataString} files=${files}
+ log return data =${response}
+ Should Be Equal As Strings ${response.status_code} 200
+ ${response} to json ${response.content}
+ [Return] ${response}
+BasePostRequestReturnBinary
+ [Documentation]
+ ... 下载文件专用
+ ... 返回二进制数据
+ [Arguments] ${requestUri} ${data} ${apiVersion}
+ Log Call BasePostRequestReturnBinary
+ ${headers} set variable {"Authorization":"${token}","Content-Type":"application/json"}
+ create session api http://${host}:${port}/${apiVersion} ${headers}
+ Log ${data}
+ ${response} Post Request api ${requestUri} data=${data}
+ log return data =${response}
+ Should Be Equal As Strings ${response.status_code} 200
+ [Return] ${response.content}
+BaseGetRequestReturnBinary
+ [Documentation]
+ ... 下载文件专用
+ ... 返回二进制数据
+ [Arguments] ${requestUri} ${data} ${apiVersion}
+ Log Call BasePostRequestReturnBinary
+ ${headers} set variable {"Authorization":"${token}","Content-Type":"application/json"}
+ ${dataString} DictionaryToQueryParams ${data}
+ create session api http://${host}:${port}/${apiVersion} ${headers}
+ Log ${data}
+ ${response} Get Request api ${requestUri}?${dataString}
+ log return data =${response}
+ Should Be Equal As Strings ${response.status_code} 200
+ [Return] ${response.content}
+
+BaseFormEditRequest
+ [Arguments] ${requestUri} ${data} ${apiVersion}
+ ${headers} set variable {"Authorization":"${token}","Content-Type":"application/x-www-form-urlencoded"}
+ create session api http://${host}:${port}/${apiVersion} ${headers}
+ ${response}= Put Request api ${requestUri} data=${data}
+ log return data =${response}
+ Should Be Equal As Strings ${response.status_code} 200
+ ${response} to json ${response.content}
+ [Return] ${response}
+BaseFormPostRequest
+ [Arguments] ${requestUri} ${data} ${apiVersion}
+ ${headers} set variable {"Authorization":"${token}","Content-Type":"application/x-www-form-urlencoded"}
+ create session api http://${host}:${port}/${apiVersion} ${headers}
+ ${response}= Post Request api ${requestUri} data=${data}
+ log return data =${response}
+ Should Be Equal As Strings ${response.status_code} 200
+ ${response} to json ${response.content}
+ [Return] ${response}
+
+OamRequest
+ [Arguments] ${requestUri} ${path} ${method} ${contentType} ${data}
+ ${headers} set variable {"Authorization":"${token}","Content-Type":"${contentType}","path":"${path}"}
+ create session api http://${host}:${port} ${headers}
+ ${response} Run Keyword If "${method}" == "GET" Get Request api ${requestUri}?${data}
+ ... ELSE IF "${method}" == "POST" Post Request api ${requestUri} data=${data}
+ ... ELSE IF "${method}" == "PUT" Put Request api ${requestUri} data=${data}
+ ... ELSE IF "${method}" == "DELETE" Delete Request api ${requestUri} data=${data}
+ ... ELSE Set Variable ${EMPTY}
+ Should Be Equal As Strings ${response.status_code} 200
+ ${response} to json ${response.content}
+ [Return] ${response}
+
+ResultGetRequestOK
+ [Arguments] ${apistr} ${body}
+ sleep 35
+ ${response} BaseGetRequest ${apistr} ${body}
+ log ${response['code']}
+ log ${response}[data][list][0][status]
+ Should Be Equal As Strings ${response['code']} 200
+ Should Be Equal As Strings ${response}[data][list][0][status] 2
+
+##################################################################################################
+AppendListToList
+ [Tags]
+ [Documentation] 把${addList}逐个添加到${souceList},然后返回 ${souceList}
+ ... 入参:${souceList} ${insertList}
+ ... 出:参${souceList}
+ [Arguments] ${souceList} ${insertList}
+ Comment 参数${objids}拼接后的list;参数${objectIds}对象ids
+ Comment 如果参数${objectIds}返回多个id则逐个添加
+ FOR ${objdict} IN @{insertList}
+ Append To List ${souceList} ${objdict}
+ END
+ [Return] ${souceList}
+ \ No newline at end of file
diff --git a/keyword/common/common_interface.robot b/keyword/common/common_interface.robot
new file mode 100644
index 0000000..7029c3a
--- /dev/null
+++ b/keyword/common/common_interface.robot
@@ -0,0 +1,47 @@
+*** Settings ***
+Library Collections
+Library RequestsLibrary
+Resource ../../../variable/common_variable.txt
+#Resource functional_keywords.robot
+Resource ../policys/policy.robot
+Resource ../objects/object.robot
+Resource ../objects/application.robot
+Resource common.robot
+*** Variables ***
+${policyUrl} /policy/compile
+*** Keywords ***
+GetJsonFromModeAndData
+ [Documentation] 根据接口模板和对应测试数据返回请求接口所需数据
+ [Arguments] ${modleFilePath} ${dataFilePath} ${keyword} ${datalistname}
+ #yaml在线格式化:https://www.bejson.com/validators/yaml_editor/
+ ${yamlMode}= Get File ${modleFilePath}
+ ${loadedMode}= yaml.Safe Load ${yamlMode}
+ #${retkeys} evaluate [one for one in ${ip_secuirty_allow_dns_001}]
+ #${dictType} = Evaluate type(${retkeys})
+ ${yamlData}= Get File ${dataFilePath}
+ ${loadedData}= yaml.Safe Load ${yamlData}
+ ${dataJson} Get From Dictionary ${loadedData} ${keyword}_data
+ ${dataKey} Get From Dictionary ${loadedData} keywords
+ ${dataKeyType} = Evaluate type(${dataKey})
+ FOR ${key} IN @{dataKey}
+ LOG passssssssss
+ ${data} Get From Dictionary ${dataJson}[0] ${key}
+ #Continue For Loop If Dictionary does not contain key ${key}
+ Continue For Loop If "${data}" == "Empty"
+ Remove From Dictionary ${loadedMode}[${keyword}_mode][${datalistname}][0] ${key}
+ Set To Dictionary ${loadedMode}[${keyword}_mode][${datalistname}][0] ${key} ${data}
+ END
+ ${modeJson} Get From Dictionary ${loadedMode} ${keyword}_mode
+ ${returnData} Get From Dictionary ${modeJson} returnData
+ ${returnJson} json.Dumps ${modeJson}
+
+ #Set To Dictionary ${LOADED}[patch_id_bw_data][pronghornResponseBody][responseBody][0][value][0] value=200
+ #${addItemList1} Create Dictionary isSession=endpoint ip=${testClentIP} port=0-65535 direction=0 protocol=0 isInitialize=0
+ #${addItemLists} Create list ${addItemList1}
+ #${objectDict} Create Dictionary objectType=ip objectSubType=endpoint isValid=${1} addItemList=${addItemLists}
+ #${rescode} ${objectId} AddObjects ${1} ${objectDict}
+ #${objectids} set Variable ${objectId}
+ [Return] ${returnJson}
+
+
+ \ No newline at end of file
diff --git a/keyword/common/customlibrary/Custometest/Common.py b/keyword/common/customlibrary/Custometest/Common.py
new file mode 100644
index 0000000..d009a7a
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/Common.py
@@ -0,0 +1,51 @@
+import json
+import random
+import hashlib
+import os
+
+#判断一个字符或字符串是否包含于另一个字符串:a是否再b中,是否则返回True,否则返回Falsle
+def aisincludeb(a,b):
+ result = a in b
+ print(result)
+ return result
+
+#删除字符串当前前几个,或后几个:sourcestr源串,a[2:-2] 表示去掉前面两个和后面两个,如果光去掉后面的a[:-2]
+def removeBeforOrAfter(sourcestr,a):
+ #a = "16541616584984"
+ #a = a[2:-2]
+ sourcestr = sourcestr[a]
+ return result
+
+#分离字符串
+def string2list(str,split):
+ return str.split(split)
+
+#用于生成一个指定范围内的整数
+def randomint(a,b):
+ return random.randint(a,b)
+
+#较小文件处理方法:
+def get_md5_01(file_path):
+ md5 = None
+ if os.path.isfile(file_path):
+ f = open(file_path,'rb')
+ md5_obj = hashlib.md5()
+ md5_obj.update(f.read())
+ hash_code = md5_obj.hexdigest()
+ f.close()
+ md5 = str(hash_code).lower()
+ return md5
+
+#较大文件处理方法:
+def get_md5_02(file_path):
+ f = open(file_path,'rb')
+ md5_obj = hashlib.md5()
+ while True:
+ d = f.read(8096)
+ if not d:
+ break
+ md5_obj.update(d)
+ hash_code = md5_obj.hexdigest()
+ f.close()
+ md5 = str(hash_code).lower()
+ return md5 \ No newline at end of file
diff --git a/keyword/common/customlibrary/Custometest/JsonDiff.py b/keyword/common/customlibrary/Custometest/JsonDiff.py
new file mode 100644
index 0000000..ef50112
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/JsonDiff.py
@@ -0,0 +1,6 @@
+from json_compare import Jcompare
+
+def json_diff(a,b):
+ cp=Jcompare()
+ results = cp.compare(a,b)
+ return results \ No newline at end of file
diff --git a/keyword/common/customlibrary/Custometest/LogResponseVAL.py b/keyword/common/customlibrary/Custometest/LogResponseVAL.py
new file mode 100644
index 0000000..dbf6474
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/LogResponseVAL.py
@@ -0,0 +1,203 @@
+import re
+import time
+
+import jsonpath
+# 1.说明:本方法用于对日志接口返回数据中的字段和数据进行判断
+# 2.传入数据说明:responsedict - 接口返回数据的json数据
+# targetlist - 判断参数 ,可传入多个条件,在robotfromwork中条件以Tab分隔 。参数格式为: 字段(key)_判断条件_数据(value) ,一个条件内各参数以空格分隔 例:common_log_id = 238734003578214400
+# 判断条件包括:= 、 != 、> 、< 、>= 、<= 、in 、notin 、like、 notlike 、notEmpty 、 empty 。
+# (1)其中notin、notlike、notEmpty传入时中间无空格
+# (2)notEmpty、empty 不传数据(value)
+# (3) in 、notin 多个字段以逗号分隔 例 : common_log_id notin 238734003578214400,238734003578214402,238734003578214403
+
+def FieldValidation(responsedict, targetlist):
+ responselist = responsedict["data"]["list"]
+ strlist = []
+ if responselist:
+ # 循环返回数据列表
+ sum = 1
+ for response in responselist:
+ # 循环目地列表
+ for t in targetlist:
+ # 将目的根据空格分割成列表 (“key值”,“判断条件”,“value值”)
+ target = t.split(" ")
+ #获取json串中所有的key,返回列表
+ responsekeys = getKeys(response)
+ # 判断目的条件的Key在数据中是否存在
+ if target[0] in responsekeys:
+ if len(target) != 1:
+ #targetkey 判断的字段
+ targetkey = target[0]
+ # 判断条件
+ conditions = target[1]
+ # 返回数据中对应key的Value列表
+ responsevaluelist = getjsonvalue(response,target[0])
+ for responsevalue in responsevaluelist:
+ #判断value值是否为列表,转化为字符串
+ if isinstance(responsevalue, list):
+ responsevalue=str(responsevalue)
+ if len(target) == 3:
+ targetvalue = target[2]
+ torf=is_valid_date(responsevalue)
+ if torf == True:
+ timeArray = time.strptime(responsevalue, "%Y-%m-%d %H:%M:%S")
+ timeStamp = str(int(time.mktime(timeArray)))
+ p = conditional(conditions, timeStamp, targetkey, sum, targetvalue)
+ if p != "":
+ strlist.append(p)
+ else:
+ p = conditional(conditions, responsevalue, targetkey, sum, targetvalue)
+ if p != "":
+ strlist.append(p)
+ elif len(target) == 2:
+ p = conditional(conditions, responsevalue, targetkey, sum)
+ if p != "":
+ strlist.append(p)
+ else:
+ str2 = "返回数据第" + str(sum) + "组数据中不存在该字段:" + target[0]
+ print(str2)
+ strlist.append(str2)
+ sum += 1
+ else:
+ str3 = "返回数据中无数据"
+ strlist.append(str3)
+ Assertresults(strlist)
+ return strlist
+
+def getjsonvalue(json_data, key_name):
+ '''获取到json中任意key的值,结果为list格式'''
+ keyvalue = jsonpath.jsonpath(json_data, '$..{key_name}'.format(key_name=key_name))
+ # key的值不为空字符串或者为empty(用例中空固定写为empty)返回对应值,否则返回empty
+ return keyvalue
+
+def getKeys(data):
+ # 获取json串中所有的key
+ keysAll_list = []
+ def getkeys(data): # 遍历json所有key
+ if (type(data) == type({})):
+ keys = data.keys()
+ for key in keys:
+ value = data.get(key)
+ if (type(value) != type({}) and type(value) != type([])):
+ keysAll_list.append(key)
+ elif (type(value) == type({})):
+ keysAll_list.append(key)
+ getkeys(value)
+ elif (type(value) == type([])):
+ keysAll_list.append(key)
+ for para in value:
+ if (type(para) == type({}) or type(para) == type([])):
+ getkeys(para)
+ else:
+ keysAll_list.append(para)
+ getkeys(data)
+ return keysAll_list
+
+# 对传入的数据根据条件进行判断
+def conditional(conditions, value2, targetkey, sum, value=None):
+ str1 = ""
+ if conditions == "=":
+ if value != value2:
+ str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符"
+
+ if conditions == "!=":
+ if value == value2:
+ str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
+ print(str1)
+
+ if conditions == ">":
+ if int(value2) <= int(value):
+ str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
+
+ if conditions == "<":
+ if int(value2) >= int(value):
+ str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
+
+ if conditions == ">=":
+ if int(value2) < int(value):
+ str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
+
+ if conditions == "<=":
+ if int(value2) > int(value):
+ str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
+
+ if conditions == "in":
+ value = value.split(",")
+ if value2 not in value:
+ str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
+
+ if conditions == "notin":
+ value = value.split(",")
+ if value2 in value:
+ str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
+
+ if conditions == "like":
+ left = value[0]
+ right = value[-1]
+ if left == "%" and right == "%":
+ value = value[1:len(value) - 1]
+ if value not in value2:
+ str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
+
+ elif left == "%" and right != "%":
+ v = len(value)
+ _value = value[1:]
+ _value2 = value2[-(v - 1):]
+ print(_value, _value2)
+ if _value != _value2:
+ str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
+
+ elif left != "%" and right == "%":
+ v = len(value)
+ _value = value[0:-1]
+ _value2 = value2[0:v - 1]
+ if _value != _value2:
+ str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
+
+ if conditions == "notlike":
+ left = value[0]
+ right = value[-1]
+ if left == "%" and right == "%":
+ value = value[1:len(value) - 1]
+ if value in value2:
+ str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
+
+ elif left == "%" and right != "%":
+ v = len(value)
+ _value = value[1:]
+ _value2 = value2[-(v - 1):]
+ if _value == _value2:
+ str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
+
+ elif left != "%" and right == "%":
+ v = len(value)
+ _value = value[0:-1]
+ _value2 = value2[0:v - 1]
+ if _value == _value2:
+ str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
+
+ if conditions == "notEmpty":
+ if value2 == "":
+ str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
+
+ if conditions == "Empty":
+ if value2 != "":
+ str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
+ return str1
+
+def Assertresults(resultslist):
+ print(resultslist)
+ for i in resultslist:
+ if i != "":
+ assert 1 == 2
+
+
+def is_valid_date(strdate):
+ '''判断是否是一个有效的日期字符串'''
+ a = re.findall(":", strdate)
+ b = re.findall("-", strdate)
+ if len(a) ==2 and len(b) == 2:
+ return True
+ else:
+ return False
+
diff --git a/keyword/common/customlibrary/Custometest/LogSchema.py b/keyword/common/customlibrary/Custometest/LogSchema.py
new file mode 100644
index 0000000..d190ff1
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/LogSchema.py
@@ -0,0 +1,513 @@
+# !/user/bin/python
+# -*-coding:utf-8-*-
+import requests
+import random
+import json
+import LogResponseVAL
+import time, datetime
+# import allure
+
+
+
+
+# 请求schema接口得到返回数据,用于其他接口
+def schema(schemauerl, token):
+ url = schemauerl
+ headers = {"Content-Type": "application/x-www-form-urlencoded", "Authorization": token}
+ response = requests.get(url=url, headers=headers)
+ return response.json()
+
+
+# 根据schema接口返回数据,得出所有属性所支持的比较类型的列表
+# 1、根据[doc][allow_query]值为true列支持搜索;
+# 2、如有[doc][constraints][operator_functions]值,操作优先;
+# 3、如有[doc][data]值则对应属性取值为data所列code值;
+# 4、int和long的范围不一致;
+# 5、string要包含特殊字符
+# 6、给查询条件赋值,要给出边界和正常值
+# 7、IP(V4、V6)和URL要给出专门的方法生成
+
+import ipaddress
+
+# 生成随机ipv4或ipv6
+MAX_IPV4 = ipaddress.IPv4Address._ALL_ONES # 2 ** 32 - 1
+MAX_IPV6 = ipaddress.IPv6Address._ALL_ONES # 2 ** 128 - 1
+
+
+def random_ipv4():
+ return ipaddress.IPv4Address._string_from_ip_int(
+ random.randint(0, MAX_IPV4)
+ )
+
+
+def random_ipv6():
+ return ipaddress.IPv6Address._string_from_ip_int(
+ random.randint(0, MAX_IPV6)
+ )
+
+
+from random import Random
+
+
+# 生成 12 位随机 URL 地址
+def randrom_url():
+ str = ''
+ str1 = ''
+ chars = 'abcdefghijklmnopqrstuvwxyz0123456789'
+ chars1 = 'abcdefghijklmnopqrstuvwxyz0123456789!#$%^&*()'
+ length = len(chars)
+ length1 = len(chars1)
+ random = Random()
+ for x in range(random.randint(8, 16)):
+ str += chars[random.randint(0, length - 1)]
+ for pp in range(random.randint(8, 16)):
+ str1 += chars1[random.randint(0, length1 - 1)]
+ url = str[0:-5] + "." + str[0:-6] + "." + str[0:-7] + "/" + str1
+ print(url)
+ return url
+
+
+def Filter1(schemauerl, token):
+ list = []
+ json_str = schema(schemauerl, token)
+ print("schemauerl",json_str)
+ print(type(json_str))
+ # 获取日志属性定义
+ fields = json_str["data"]["fields"]
+ print("1111111111",fields)
+ # 获取不同属性支持的部不同操作
+ operator = json_str["data"]["doc"]["schema_query"]["references"]["operator"]
+ for i in fields:
+ number = random.randint(0, 2147483647)
+ maxnumber = 2147483647
+ minnumber = -2147483648
+ str = random.choice('abcdefghijklmnopqrstuvwxyz!@#%^&*')
+ 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:
+ if v == "in" or v == "not in":
+ str1 = name + " " + v + " " + "(" + f"{value1}" + ")"
+ list.append(str1)
+ else:
+ str1 = name + " " + v + " " + f"{value1}"
+ list.append(str1)
+ elif type1 == "string":
+ value1 = str
+ functions = j["functions"]
+ functions1 = functions.split(",")
+ for v in functions1:
+ if v == "notEmpty" or v == "empty":
+ str1 = v + "(" + " '" + name + " '" + ")"
+ list.append(str1)
+ elif v == "in" or v == "not in":
+ str1 = name + " " + v + " " + "(" + " '" + value1 + " '" + ")"
+ list.append(str1)
+ else:
+ 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:
+ if v == "in" or v == "not in":
+ str1 = name + " " + v + " " + "(" + f"{value1}" + ")"
+ list.append(str1)
+ else:
+ str1 = name + " " + v + " " + f"{value1}"
+ list.append(str1)
+ elif type1 == "string":
+ value1 = str
+ functions = j["functions"]
+ functions1 = functions.split(",")
+ for v in functions1:
+ if v == "notEmpty" or v == "empty":
+ str1 = v + "(" + " '" + name + " '" + ")"
+ list.append(str1)
+ elif v == "in" or v == "not in":
+ str1 = name + " " + v + " " + "(" + " '" + value1 + " '" + ")"
+ list.append(str1)
+ else:
+ 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:
+ if v == "in" or v == "not in":
+ str1 = name + " " + v + " " + "(" + f"{value1}" + ")"
+ list.append(str1)
+ else:
+ str1 = name + " " + v + " " + f"{value1}"
+ list.append(str1)
+ elif type1 == "string":
+ value1 = str
+ functions = j["functions"]
+ functions1 = functions.split(",")
+ for v in functions1:
+ if v == "notEmpty" or v == "empty":
+ str1 = v + "(" + " '" + name + " '" + ")"
+ list.append(str1)
+ elif v == "in" or v == "not in":
+ str1 = name + " " + v + " " + "(" + " '" + value1 + " '" + ")"
+ list.append(str1)
+ else:
+ 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("22222222222",list)
+ return list
+
+
+# 根据Filter1方法中的的数据,写入log请求接口中,来验证log请求接口
+def logapiverify(schemauerl,logurl, token, starttime, endtime,logtype):
+ filter2 = Filter1(schemauerl, token)
+ a = schema(schemauerl, token)
+ fields = a["data"]["fields"]
+ print("333333333333",filter2)
+ for i in filter2:
+ print("条件:", i)
+ url = logurl # "http://192.168.44.72:8080/v1/log/list"
+ headers = {"Content-Type": "application/json",
+ "Authorization": token}
+ data = {
+ "start_common_recv_time": starttime,
+ "end_common_recv_time": endtime,
+ "logType": logtype,
+ "fields": fields,
+ "filter": i
+ }
+ print(json.dumps(data))
+ response1 = requests.post(url=url, data=json.dumps(data), headers=headers)
+ code = response1.json()["code"]
+ assert code == 200
+ print(response1.json()["code"])
+ return response1.json()
+ # print("111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")
+ # print(str2)
+ # str3 = str2[0:-4]
+ # print(str3)
+ # url = logurl # "http://192.168.44.72:8080/v1/log/list"
+ # headers = {"Content-Type": "application/json",
+ # "Authorization": token}
+ # data = {
+ # "start_common_recv_time": starttime,
+ # "end_common_recv_time": endtime,
+ # "logType": logtype,
+ # "fields": fields,
+ # "filter": str3
+ # }
+ # print(data)
+ # print(json.dumps(data))
+ # response1 = requests.post(url=url, data=json.dumps(data), headers=headers)
+ # code = response1.json()["code"]
+ # print(response1.json())
+ # assert code == 200
+ # print(response1.json()["code"])
+
+
+# 精确filter,请求日志接口
+def loglistverify(logurl, schemauerl, token, starttime, endtime, logtype, filtervalue):
+ a = schema(schemauerl, token)
+ fields = a["data"]["fields"]
+ url = logurl # "http://192.168.44.72:8080/v1/log/list"
+ headers = {"Content-Type": "application/json",
+ "Authorization": token}
+ data = {
+ "start_common_recv_time": starttime,
+ "end_common_recv_time": endtime,
+ "logType": logtype,
+ "fields": fields,
+ "filter": filtervalue
+ }
+ # print(json.dumps(data))
+ response1 = requests.post(url=url, data=json.dumps(data), headers=headers)
+ code = response1.json()["code"]
+ assert code == 200
+ print(response1.json()["code"])
+ return response1.json()
+
+#目的性验证,循坏返回列表中所有字段进行查询
+def loglistverifys(logurl, schemaurl, token, starttime, endtime, logtype, datajson):
+ nullkey = []
+ data = datajson
+ keylist = LogResponseVAL.getKeys(data)
+ a = schema(schemaurl, token)
+ fields = a["data"]["fields"]
+ for i in keylist:
+ conditions = data[i]
+ for field in fields:
+ name = field["name"]
+ if field["doc"] == None or field["doc"]["visibility"] == None:
+ if i == name:
+ if conditions != None and conditions != "":
+ if field["type"] == "string":
+ if conditions[0] == "'" and conditions[-1] == "'":
+ filtervalue = i + " = " + conditions
+ VasserValue=i + " = " + conditions[1:-1]
+
+ else:
+ filtervalue = i + " = " + "'" + conditions + "'"
+ VasserValue= i + " = " + conditions
+ else:
+ if i == "common_recv_time" or i == "common_start_time" or i == "common_end_time" or i == "common_processing_time":
+ timeArray = time.strptime(conditions, "%Y-%m-%d %H:%M:%S")
+ timeStamp = str(int(time.mktime(timeArray)))
+ filtervalue = i + " = " + timeStamp
+ VasserValue = filtervalue
+
+ else:
+ filtervalue = i + " = " + str(conditions)
+ VasserValue = filtervalue
+ print("filtervalue",filtervalue)
+ #根据提取条件进行查询日志列表
+ responsebody = loglistverify(logurl, schemaurl, token, starttime, endtime, logtype,
+ filtervalue)
+ filterlist=[VasserValue]
+ print(VasserValue)
+ LogResponseVAL.FieldValidation(responsebody,filterlist)
+
+ else:
+ nullkey.append(i) #所有为None或者“”的字段
+ return nullkey
+
+ # 多条循环 变量设置为公共参数 若循环内一个字段没有值 进行下次循坏
+def logAllFieldsListInterface(logurl, schemaurl, token, starttime, endtime, logtype, datajson,lognumber,logcycles):
+ datalist = datajson["data"]["list"]
+ keylist=[]
+ number=0
+ print(lognumber)
+ print(type(lognumber))
+ print(logcycles)
+ print(type(logcycles))
+ for i in range(0, len(datalist), int(lognumber)):# 循环取出count个列表元素
+ number+=1
+ nullkeylist=[]
+ ret=datalist[i:i + int(lognumber)]
+ for data in ret:
+ nullkey=loglistverifys(logurl, schemaurl, token, starttime, endtime, logtype, data)
+ nullkeylist.append(nullkey)
+ print(nullkeylist)
+ for j in nullkeylist:
+ #对返回的为空的key进行取交集
+ if len(keylist) == 0:
+ keylist=j
+ else:
+ #取两个列表的交集
+ keylist=list(set(keylist).intersection(set(j)))
+ if len(keylist) == 0 or number >= int(logcycles):
+ break
+ print("最终数据中没有值的字段为:",keylist)
+
+
+# 事件日志和通联日志时间分布查询 ,日志检索条件校验(filter内容验证)
+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}
+ response = requests.get(url=url, headers=headers)
+ code = response.json()["code"]
+ print(response.json())
+ assert code == 200
+ print(response.json()["code"])
+ return response.json()
+
+#日志检索条件校验 纯接口
+def LogRetrieve(schemaurl,host,port,token,logType,datajson):
+ number = random.randint(0, 2147483647)
+ str1 = random.choice('abcdefghijklmnopqrstuvwxyz')
+ data=datajson["data"]["list"][0]
+ keylist = LogResponseVAL.getKeys(data)
+ a = schema(schemaurl, token)
+ fields=a["data"]["fields"]
+ for i in keylist:
+ conditions = data[i]
+ for field in fields:
+ name = field["name"]
+ if i == name:
+ if field["type"] == "string":
+ filter = "logType=" + logType + "&" + "filter=" + i + "=" + "'" + str1 + "'"
+ else:
+ if i == "common_recv_time" or i == "common_start_time" or i == "common_end_time" or i == "common_processing_time":
+ timeArray = time.strptime(conditions, "%Y-%m-%d %H:%M:%S")
+ timeStamp = str(int(time.mktime(timeArray)))
+ filter = "logType=" + logType + "&" + "filter=" + i + "=" + timeStamp
+ else:
+ filter = "logType=" + logType + "&" + "filter=" + i + "=" + str(number)
+ Logurl = "http://" + host + ":" + port + "/v1/interface/gateway/sql/galaxy/log/filter/validation?" + filter
+ print(Logurl)
+ responsebody = distributed_query(Logurl, token)
+
+# 日志检索条件校验 复杂sql
+def LogRetrieveSql(schemaurl,host,port,token,logType,datajson):
+ data = datajson["data"]["list"][0]
+ keylist = LogResponseVAL.getKeys(data)
+ sqllist=random.sample(keylist, 4)
+ number = 45585
+ str1 = random.choice('abcdefghijklmnopqrstuvwxyz')
+ print(sqllist)
+ a = schema(schemaurl, token)
+ filterlist=[]
+ fields=a["data"]["fields"]
+ for i in sqllist:
+ conditions = data[i]
+ for field in fields:
+ name = field["name"]
+ if i == name:
+ if field["type"] == "string":
+ if conditions == "" or conditions == None:
+ conditions=str1
+ filter = i + "=" + "'" + conditions + "'"
+ else:
+ if i == "common_recv_time" or i == "common_start_time" or i == "common_end_time" or i == "common_processing_time":
+ timeArray = time.strptime(conditions, "%Y-%m-%d %H:%M:%S")
+ timeStamp = str(int(time.mktime(timeArray)))
+ filter =i + "=" + timeStamp
+ else:
+ if conditions == "" or conditions == None:
+ conditions = number
+ filter = i + "=" + str(conditions)
+ print(filter)
+ filterlist.append(filter)
+ sqlfilter = "(("+filterlist[0]+" OR "+filterlist[1]+") AND "+filterlist[2]+") OR "+filterlist[3]
+ _filter = "logType=" + logType + "&" + "filter=" + sqlfilter
+ Logurl = "http://" + host + ":" + port + "/v1/interface/gateway/sql/galaxy/log/filter/validation?" + _filter
+ print(Logurl)
+ responsebody = distributed_query(Logurl, token)
+ print(sqlfilter)
+
+ # 原始日志检索时间分布计算
+def timedistribution(logurl, token, starttime, endtime, logtype, granularity, filtervalue):
+ url = logurl # "http://192.168.44.72:8080/v1/log/timedistribution"
+ headers = {"Content-Type": "application/json",
+ "Authorization": token}
+ data = {
+ "startTime": starttime,
+ "endTime": endtime,
+ "logType": logtype,
+ "granularity": granularity,
+ "filter": filtervalue
+ }
+ print(data)
+ print(json.dumps(data))
+ response1 = requests.post(url=url, data=json.dumps(data), headers=headers)
+ code = response1.json()["code"]
+ print(response1.json())
+ print(response1.json()["code"])
+ assert code == 200
+ return response1.json()
+
+# 日志总数查询
+def countlog_query(logurl, token, starttime, endtime, logtype):
+ url = logurl
+ headers = {"Content-Type": "application/json",
+ "Authorization": token}
+ data = {
+ "pageSize": 20,
+ "logType": logtype,
+ "start_common_recv_time": starttime,
+ "end_common_recv_time": endtime,
+ "filter": ""
+ }
+ print(data)
+ print(json.dumps(data))
+ response1 = requests.post(url=url, data=json.dumps(data), headers=headers)
+ code = response1.json()["code"]
+ print(response1.json())
+ print(response1.json()["code"])
+ assert code == 200
+ return response1.json()
+
+# 日志导出接口
+def exportlog(logurl, schemauerl, token, starttime, endtime, logtype, filtervalue):
+ a = schema(schemauerl, token)
+ fields = a["data"]["fields"]
+ print(fields)
+ url = logurl
+ headers = {"Content-Type": "application/json",
+ "Authorization": token}
+ data = {
+ "start_common_recv_time": starttime,
+ "end_common_recv_time": endtime,
+ "logType": logtype,
+ "fields": fields,
+ "filter": filtervalue
+ }
+ print(data)
+ print(json.dumps(data))
+ response1 = requests.post(url=url, data=json.dumps(data), headers=headers)
+ a=type(response1)
+ if a != "class 'requests.models.Response'":
+ assert 1 == 1
+ else:
+ assert 1 == 2
+
+#判断日志内详情字段
+def LogFieldValidation(schemauerl,token,datajson):
+ Schemajson = schema(schemauerl, token)
+ fields=Schemajson["data"]["fields"]
+ keylist= LogResponseVAL.getKeys(datajson["data"]["list"][0])
+ schema_typedict=Schemajson["data"]["doc"]["schema_type"]
+ schema_typelistkey=schema_typedict.keys()
+ for schema_typekey in schema_typelistkey: #取出schema_type内的每一个key
+ for i in schema_typedict[schema_typekey]["columns"]:
+ for filter in fields:
+ if filter["name"] == i:
+ if filter["doc"] == None:
+ if i not in keylist:
+ print("该字段未存在日志详情内",i)
+ assert 1==2
+ else:
+ print("该字段通过在日志详情内",i)
+ else:
+ if filter["doc"]["visibility"] != "disabled":
+ if i not in keylist:
+ print("该字段未存在日志详情内",i)
+ assert 1==2
+ else:
+ print("该字段通过在日志详情内",i)
+
+
+
+
+
+
+
+# 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") \ No newline at end of file
diff --git a/keyword/common/customlibrary/Custometest/MD5.py b/keyword/common/customlibrary/Custometest/MD5.py
new file mode 100644
index 0000000..697ae83
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/MD5.py
@@ -0,0 +1,40 @@
+# 由于MD5模块在python3中被移除
+# 在python3中使用hashlib模块进行md5操作
+
+import hashlib
+
+class MD5:
+ def MD5(data,langer,md5_types):
+ # 创建md5对象
+ # m = hashlib.md5()
+ # Tips
+ # 此处必须encode
+ # 若写法为m.update(str) 报错为: Unicode-objects must be encoded before hashing
+ # 因为python3里默认的str是unicode
+ # 或者 b = bytes(str, encoding='utf-8'),作用相同,都是encode为bytes
+ # b = str.encode(encoding='utf-8')
+ # m.update(b)
+ # str_md5 = m.hexdigest()
+ if langer == "英文":
+ # str_md5 = hashlib.md5(b'this is a md5 test.').hexdigest()
+ str_md5 = hashlib.md5("b'"+data+"'").hexdigest()
+ print('MD5加密前为 :' + data)
+ print('MD5加密后为 :' + str_md5)
+ return str_md5
+ elif langer == "中文":
+ str_md5 = hashlib.md5('你好'.encode(encoding=md5_types)).hexdigest()
+ return str_md5
+ # utf8 和gbk 加密结构不一样
+ # hashlib.md5('你好'.encode(encoding='GBK')).hexdigest()
+ # hashlib.md5('你好'.encode(encoding='GB2312')).hexdigest()
+ # hashlib.md5('你好'.encode(encoding='GB18030')).hexdigest()
+if __name__ == '__main__':
+ data = '小猪'
+ langer = '中文'
+ md5_types = 'GBK'
+ a =MD5(data,langer,md5_types)
+ print(a)
+ b=r'C:\Users\小猪\AppData\Local\Programs\Python\Python37\Lib\site-packages\custometest\MD5.py'
+ with open(b, encoding='utf-8') as f:
+ text = f.read()
+ print(text) \ No newline at end of file
diff --git a/keyword/common/customlibrary/Custometest/ReportSchema.py b/keyword/common/customlibrary/Custometest/ReportSchema.py
new file mode 100644
index 0000000..ac2d947
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/ReportSchema.py
@@ -0,0 +1,718 @@
+import requests
+import random
+import json
+import time
+import ipaddress
+from builtins import list
+
+# Report纯接口测试正向用例方法,不验证数据统计准确性,单纯验证接口
+
+#生成随机ipv4或ipv6
+MAX_IPV4 = ipaddress.IPv4Address._ALL_ONES # 2 ** 32 - 1
+MAX_IPV6 = ipaddress.IPv6Address._ALL_ONES # 2 ** 128 - 1
+def random_ipv4():
+ return ipaddress.IPv4Address._string_from_ip_int(
+ random.randint(0, MAX_IPV4))
+def random_ipv6():
+ return ipaddress.IPv6Address._string_from_ip_int(
+ random.randint(0, MAX_IPV6))
+
+#随机生成邮箱地址
+def RandomEmail( emailType=None, rang=None):
+ __emailtype = ["@qq.com", "@163.com", "@126.com", "@189.com"]
+ # 如果没有指定邮箱类型,默认在 __emailtype中随机一个
+ if emailType == None:
+ __randomEmail = random.choice(__emailtype)
+ else:
+ __randomEmail = emailType
+ # 如果没有指定邮箱长度,默认在4-10之间随机
+ if rang == None:
+ __rang = random.randint(4, 10)
+ else:
+ __rang = int(rang)
+ __Number = "0123456789qbcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPWRSTUVWXYZ"
+ __randomNumber = "".join(random.choice(__Number) for i in range(__rang))
+ _email = __randomNumber + __randomEmail
+ return _email
+
+#获取Schema
+def schema(schemauerl,token,logtype):
+ url ="http://192.168.44.72:8080/v1/log/schema?logType="+logtype
+ headers = {"Content-Type":"application/x-www-form-urlencoded","Authorization":token}
+ response = requests.get(url=url,headers=headers)
+ return response.json()
+
+#获取json串中groupColumnList的值
+def groupby(schemajson,logtype,testpoint,field):
+ dimensions=schemajson["data"]["doc"]["schema_query"]["dimensions"]
+ dimensions.append("common_recv_time");
+ randomstr_1=[]
+ if logtype == "security_event_log" or logtype == "connection_record_log" or logtype == "voip_record_log":
+ dimensions.remove("common_start_time")
+ dimensions.remove("common_end_time")
+ if testpoint == "DataBindings":
+ randomstr_1.append("common_recv_time")
+ elif testpoint == "GroupBy":
+ randomstr_1.append(field)
+ else:
+ randomstr_1=random.sample(dimensions, 4)
+
+ #定义grp为返回值group的列表
+ grp=[]
+ for i in randomstr_1:
+ a={"name":i}
+ grp.append(a)
+
+ re=[grp,randomstr_1]
+ print("groupby",re)
+ return re
+
+#获取json串中queryColumnList的值
+def DataBindings(schemajson,randomstr_1,testpoint,field):
+ #生成queryColumnList列表
+ metrics=schemajson["data"]["doc"]["schema_query"]["metrics"]
+ metrics.append("common_log_id")
+ #在列表里随机元素
+ randomstr_2=[]
+ if testpoint == "DataBindings":
+ randomstr_2.append(field)
+ else:
+ randomstr_2=random.sample(metrics,6)
+ #在聚合列表中去掉groupby中的重复的元素
+ randomstr_3=array_diff(randomstr_2,randomstr_1)
+ #将groupby中元素添加到串中
+ qul=[]
+ for i in randomstr_1:
+ a={"name":i}
+ qul.append(a)
+
+ fields = schemajson["data"]["fields"]
+ list_1=["sum","min","max","avg","count"]
+ list_2=["count","count_distinct"]
+ if testpoint == "DataBindings":
+ for i in randomstr_3:
+ for j in fields:
+ if i == j["name"] :
+ jtype=j["type"]
+ label=i
+ sun=1
+ if jtype == "int" or jtype == "long" or jtype == "float" or jtype == "double":
+ for Aggregate in list_1:
+ randomstr_4={"name":i,"expression":Aggregate,"label":label}
+ qul.append(randomstr_4)
+ label=label+str(sun)
+ sun+=1
+ elif jtype == "randomstring" or jtype == "date" or jtype == "timestamp" or jtype == "string":
+ for Aggregate in list_2:
+ randomstr_4={"name":i,"expression":Aggregate,"label":label}
+ qul.append(randomstr_4)
+ label = label + str(sun)
+ sun += 1
+
+ else:
+ for i in randomstr_3:
+ for j in fields:
+ if i == j["name"]:
+ jtype = j["type"]
+ if jtype == "int" or jtype == "long" or jtype == "float" or jtype == "double":
+ radomlist = random.sample(list_1, 1)
+ randomstr_4 = {"name": i, "expression": radomlist[0]}
+ qul.append(randomstr_4)
+ elif jtype == "randomstring" or jtype == "date" or jtype == "timestamp" or jtype == "string":
+ randomlist = random.sample(list_2, 1)
+ randomstr_4 = {"name": i, "expression": randomlist[0]}
+ qul.append(randomstr_4)
+ print("DataBindings",qul)
+ return qul
+
+# #去除a列表中存在的b的元素
+def array_diff(a, b):
+ #定义空列表
+ c=[]
+ #range(len(a))取的为列表a的索引,根据a的
+ for i in range(len(a)):
+ #取出索引对应的值
+ t=a[i]
+ #判断值是否存在在序列b中
+ if t not in b:
+ #如果序列不在b中,则写入序列c
+ c.append(t)
+ #返回序列c,c就是列表a去除列表b之后的元素
+ return c
+
+def filterCondition(schemajson,testpoint,field):
+ number = random.randint(0,100000)
+ randomstr= random.choice('abcdefghijklmnopqrstuvwxyz')
+ schemafilters=schemajson["data"]["doc"]["schema_query"]["filters"]
+ list1=[]
+ if testpoint=="Filter":
+ list1.append(field)
+ else:
+ list1=random.sample(schemafilters, 4)
+ #获取不同属性支持的部不同操作
+ fields = schemajson["data"]["fields"]
+ operator = schemajson["data"]["doc"]["schema_query"]["references"]["operator"]
+ andConditions=[]
+ for i in list1:
+ #遍历fields列表
+ for k in fields:
+ #当filters列表值等于fields的name时
+ if i == k["name"]:
+ name = k["name"]
+ doc = k["doc"]
+ #获取无任何特殊说明列:
+ if doc == None:
+ type1 = k["type"]
+ if type1 == "int" or type1 == "long":
+ orConditions_list=[]
+ Operator=["=","!=",">","<",">=","<="]
+ if testpoint=="Filter":
+ for op in Operator:
+ value=[str(number)]
+ Field={"name":name,"expression":op,"value":value,"type":type1}
+ orConditions_list.append(Field)
+ else:
+ randomOperator= random.sample(Operator, 1)
+ value=[str(number)]
+ Field={"name":name,"expression":randomOperator[0],"value":value,"type":type1}
+ orConditions_list.append(Field)
+ orConditions={"orConditions":orConditions_list}
+ andConditions.append(orConditions)
+ elif type1 == "string":
+ orConditions_list=[]
+ Operator=["=","!=","Like","Not Like","notEmpty","empty"]
+ if testpoint=="Filter":
+ for op in Operator:
+ value=[]
+ if op == "=" or op == "!=":
+ value.append(str(number))
+ elif op == "Like" or op == "Not Like":
+ value.append(randomstr)
+ elif op=="notEmpty" or op == "empty":
+ value=[]
+ Field={"name":name,"expression":op,"value":value,"type":type1}
+ orConditions_list.append(Field)
+ else:
+ randomOperator_1 = random.sample(Operator, 1)
+ randomOperator = randomOperator_1[0]
+ value = []
+ if randomOperator == "=" or randomOperator == "!=":
+ value.append(str(number))
+ elif randomOperator == "Like" or randomOperator == "Not Like":
+ value.append(randomstr)
+ elif randomOperator == "notEmpty":
+ value = []
+ Field = {"name": name, "expression": randomOperator, "value": value, "type": type1}
+ orConditions_list.append(Field)
+ orConditions = {"orConditions": orConditions_list}
+ andConditions.append(orConditions)
+
+ else:
+ if k["doc"]["constraints"]== None:
+ type1 = k["type"]
+ if type1 == "int" or type1 == "long":
+ orConditions_list=[]
+ Operator=["=","!=",">","<",">=","<="]
+ if testpoint == "Filter":
+ for op in Operator:
+ value=[str(number)]
+ Field={"name":name,"expression":op,"value":value,"type":type1}
+ orConditions_list.append(Field)
+ else:
+ randomOperator= random.sample(Operator, 1)
+ value=[str(number)]
+ Field={"name":name,"expression":randomOperator[0],"value":value,"type":type1}
+ orConditions_list.append(Field)
+ orConditions={"orConditions":orConditions_list}
+ andConditions.append(orConditions)
+ elif type1 == "string":
+ orConditions_list=[]
+ Operator=["=","!=","Like","Not Like","notEmpty","empty"]
+ if testpoint == "Filter":
+ for op in Operator:
+ randomOperator = op
+ value = []
+ if randomOperator == "=" or randomOperator == "!=":
+ value.append(str(number))
+ elif randomOperator == "Like" or randomOperator == "Not Like":
+ value.append(randomstr)
+ elif randomOperator == "notEmpty":
+ value = []
+ Field = {"name": name, "expression": randomOperator, "value": value, "type": type1}
+ orConditions_list.append(Field)
+ else:
+ randomOperator_1= random.sample(Operator, 1)
+ randomOperator=randomOperator_1[0]
+ value=[]
+ if randomOperator == "=" or randomOperator == "!=":
+ value.append(str(number))
+ elif randomOperator == "Like" or randomOperator == "Not Like":
+ value.append(randomstr)
+ elif randomOperator=="notEmpty":
+ value=[]
+ Field={"name":name,"expression":randomOperator,"value":value,"type":type1}
+ orConditions_list.append(Field)
+ orConditions={"orConditions":orConditions_list}
+ andConditions.append(orConditions)
+
+ else:
+ if k["doc"]["constraints"]["operator_functions"]==None:
+ conrandomstraints=k["doc"]["constraints"]
+ type1 = k["type"]
+ if type1 == "int" or type1 == "long":
+ orConditions_list = []
+ Operator=["=","!=",">","<",">=","<="]
+ if testpoint == "Filter":
+ for op in Operator:
+ randomOperator = op
+ if conrandomstraints["type"] == "timestamp":
+ # 获取当前时间戳
+ t = int(time.time())
+ value = [str(t)]
+ Field = {"name": name, "expression": randomOperator, "value": value,
+ "type": type1}
+ orConditions_list.append(Field)
+ else:
+ randomOperator_1= random.sample(Operator, 1)
+ randomOperator=randomOperator_1[0]
+ if conrandomstraints["type"] == "timestamp":
+ #获取当前时间戳
+ t = int(time.time())
+ value=[str(t)]
+ Field={"name":name,"expression":randomOperator,"value":value,"type":type1}
+ orConditions_list.append(Field)
+ orConditions={"orConditions":orConditions_list}
+ andConditions.append(orConditions)
+ elif type1 == "string":
+ orConditions_list = []
+ Operator=["=","!=","Like","Not Like","notEmpty","empty"]
+ if testpoint == "Filter":
+ if conrandomstraints["type"] == "ip":
+ for op in Operator:
+ # 获取ip
+ ip = random_ipv4()
+ value = []
+ if op == "=" or op == "!=":
+ value.append(ip)
+ elif op == "Like" or op == "Not Like":
+ value.append(ip)
+ elif op == "notEmpty":
+ value = []
+ Field = {"name": name, "expression": op, "value": value,"type": type1}
+ orConditions_list.append(Field)
+ elif conrandomstraints["type"] == "email":
+ for op in Operator:
+ randomOperator = op
+ Operator = ["=", "!=", "Like", "Not Like", "notEmpty","empty"]
+ randomOperator_1 = random.sample(Operator, 1)
+ randomOperator = randomOperator_1[0]
+ # 获取ip
+ emil = RandomEmail()
+ value = []
+ if randomOperator == "=" or randomOperator == "!=":
+ value.append(emil)
+ elif randomOperator == "Like" or randomOperator == "Not Like":
+ value.append(emil)
+ elif randomOperator == "notEmpty":
+ value = []
+ Field = {"name": name, "expression": randomOperator, "value": value,
+ "type": type1}
+ orConditions_list.append(Field)
+ else:
+ randomOperator_1= random.sample(Operator, 1)
+ randomOperator=randomOperator_1[0]
+ if conrandomstraints["type"] == "ip":
+ #获取ip
+ ip =random_ipv4()
+ value=[]
+ if randomOperator == "=" or randomOperator == "!=":
+ value.append(ip)
+ elif randomOperator == "Like" or randomOperator == "Not Like":
+ value.append(ip)
+ elif randomOperator=="notEmpty":
+ value=[]
+ Field={"name":name,"expression":randomOperator,"value":value,"type":type1}
+ orConditions_list.append(Field)
+ orConditions={"orConditions":orConditions_list}
+ andConditions.append(orConditions)
+ elif conrandomstraints["type"] == "email":
+ Operator=["=","!=","Like","Not Like","notEmpty","empty"]
+ randomOperator_1= random.sample(Operator, 1)
+ randomOperator=randomOperator_1[0]
+ #获取ip
+ emil =RandomEmail()
+ value=[]
+ if randomOperator == "=" or randomOperator == "!=":
+ value.append(emil)
+ elif randomOperator == "Like" or randomOperator == "Not Like":
+ value.append(emil)
+ elif randomOperator=="notEmpty":
+ value=[]
+ Field={"name":name,"expression":randomOperator,"value":value,"type":type1}
+ orConditions_list.append(Field)
+ orConditions={"orConditions":orConditions_list}
+ andConditions.append(orConditions)
+ else:
+ type1 = k["type"]
+ orConditions_list=[]
+ operator1 = k["doc"]["constraints"]["operator_functions"]
+ operator2 = operator1.split(",")
+ if testpoint == "Filter":
+ for op in operator2:
+ operatordata = k["doc"]["data"]
+ code = []
+ for i in operatordata:
+ code_1 = i["code"]
+ code.append(code_1)
+ for co in code:
+ Field = {"name": name, "expression": op, "value": co, "type": type1}
+ orConditions_list.append(Field)
+ else:
+ operator3=random.sample(operator2,1)
+ operatordata=k["doc"]["data"]
+ code=[]
+ for i in operatordata:
+ code_1=i["code"]
+ code.append(code_1)
+ code2=random.sample(code, 1)
+ Field={"name":name,"expression":operator3[0],"value":code2,"type":type1}
+ orConditions_list.append(Field)
+ orConditions={"orConditions":orConditions_list}
+ andConditions.append(orConditions)
+ filterCondition={"andConditions":andConditions}
+ print("filterCondition",filterCondition)
+ return filterCondition
+
+#获取having条件的串
+def havingjson(schemajson,testpoint,field):
+ number = random.randint(0,100000)
+ schemametrics=schemajson["data"]["doc"]["schema_query"]["metrics"]
+ aggregation = schemajson["data"]["doc"]["schema_query"]["references"]["aggregation"]
+ schemametrics.append("common_log_id")
+ metricslist=[]
+ if testpoint == "Having":
+ metricslist.append(field)
+ else:
+ metricslist=random.sample(schemametrics, 4)
+ fields = schemajson["data"]["fields"]
+ operator=["=","!=",">","<",">=","<="]
+ Aggregate=["COUNT","AVG","SUM","MAX","MIN"]
+ andConditions_list=[]
+ #遍历的到的having条件列表
+ for i in metricslist:
+ for j in fields:
+ if i == j["name"]:
+ name = j["name"]
+ type1=j["type"]
+ for v in aggregation:
+ if type1 == v["type"]:
+ orConditions_list=[]
+ if v["type"] != "string":
+ functionslist=Aggregate
+ else:
+ functionsstr=v["functions"]
+ functionslist = functionsstr.split(",")
+ if field == "common_log_id":
+ functionslist=["COUNT"]
+ if testpoint == "Having":
+ for functions_1 in functionslist:
+ for operator_1 in operator:
+ havingdict = {"name": name, "function": str.lower(functions_1),
+ "expression": operator_1, "value": str(number)}
+ orConditions_list.append(havingdict)
+ orConditions = {"orConditions": orConditions_list}
+ andConditions_list.append(orConditions)
+ else:
+ functions_1=random.sample(functionslist, 1)
+ if functions_1=="COUNT_DISTINCT" and type1 != "string":
+ functions_1=random.sample(functionslist, 1)
+ operator_1=random.sample(operator, 1)
+
+ havingdict={"name":name,"function":str.lower(functions_1[0]),"expression":operator_1[0],"value":str(number)}
+ orConditions_list.append(havingdict)
+ orConditions={"orConditions":orConditions_list}
+ andConditions_list.append(orConditions)
+ havingCondition={"andConditions":andConditions_list}
+ print("having",havingCondition)
+ return havingCondition
+
+#拼接字符串
+def datasetjson(schemauerl,token,testname,logtype,testpoint,field):
+ schema_new=schema(schemauerl,token,logtype)
+ group_re=groupby(schema_new,logtype,testpoint,field)
+ groupColumnList=group_re[0]
+ group_randomstr=group_re[1]
+ queryColumnList=DataBindings(schema_new,group_randomstr,testpoint,field)
+ filterCondition_1=filterCondition(schema_new,testpoint,field)
+ havingjson_1=havingjson(schema_new,testpoint,field)
+ datasetdict = {
+ "list": {
+ "name":testname,
+ "logType": logtype,
+ "groupColumnList":groupColumnList,
+ "queryColumnList":queryColumnList,
+ "filterCondition":filterCondition_1,
+ "havingCondition":havingjson_1
+ }
+ }
+ print(datasetdict)
+ print("datasetjson",json.dumps(datasetdict))
+ return json.dumps(datasetdict)
+
+#拼接char的json串
+def charjson(schemaurl,token,queryColumnList,groupColumnList,datasetid,testname,logtype):
+ print("queryColumnList",queryColumnList)
+ schema_new=schema(schemaurl,token,logtype)
+ fields = schema_new["data"]["fields"]
+ # 获取条件的label
+ namelist=[]
+ for i in queryColumnList:
+ for j in fields:
+ if i["name"] == j["name"]:
+ j_label=j["label"]
+ namelist.append(j_label)
+ print("namelist",namelist)
+ #获取聚合条件的label
+ groupColumnlaberList=[]
+ for i in groupColumnList:
+ for j in fields:
+ if i["name"] == j["name"]:
+ j_label=j["label"]
+ groupColumnlaberList.append(j_label)
+ print("groupColumnlaberList",groupColumnlaberList)
+ #图表类型列表
+ chartType_1=["line","pie","bar","area","table"]
+ chartType_2=["pie","bar","table"]
+ chartType=[]
+# #随机选择图表类型
+ s=1
+ for i in namelist:
+ if i == "Receive Time" or i == "Start Time" or i == "End Time":
+ s+=1
+ if s != 1:
+ chartType=random.sample(chartType_1, 1)
+ else:
+ chartType=random.sample(chartType_2, 1)
+ chardict={}
+ print("chartType",chartType)
+ if chartType[0] == "line" or chartType[0] == "area":
+ dataBinding=[]
+ #将时间条件赋值给dataBinding
+ for j in namelist:
+ if j == "Receive Time" or j == "Start Time" or j == "End Time":
+ dataBinding.append(j)
+ timelin={
+ "dataBinding": dataBinding[0],
+ "format": "Time"
+ }
+ print("timelin",timelin)
+ namelist.remove(dataBinding[0]) #从统计查询数据列对象内去掉时间条件
+ groupColumnlaberList.remove(dataBinding[0]) #从聚合条件内去掉时间的条件
+ for i in groupColumnlaberList: #从统计查询条件内去掉聚合条件内的值
+ namelist.remove(i)
+ print("namelistrome",namelist)
+ linlist=[]
+ for i in namelist:
+ lindict={
+ "dataBinding": i,
+ "type": "Line Up",
+ "format": "Default",
+ }
+ linlist.append(lindict)
+ listdict={
+ "name": testname,
+ "datasetId": datasetid,
+ "datasetName": "",
+ "chartType": chartType[0],
+ "dataTop": 0,
+ "orderBy": "",
+ "orderDesc": 0,
+ "drilldownTop": 0,
+ "timeline": timelin,
+ "line": linlist
+ }
+ chardict={"list": listdict}
+ elif chartType[0] == "pie" or chartType[0] == "bar":
+ xAxisdataBinding=random.sample(groupColumnlaberList, 1)
+ xAxisdict={
+ "dataBinding": xAxisdataBinding[0],
+ "dataTop": 5,
+ "dataType": ""
+ }
+ for i in groupColumnlaberList:
+ namelist.remove(i)
+ yAxisBinding=random.sample(namelist, 1)
+ yAxisdict={
+ "dataBinding": yAxisBinding[0],
+ "format": "Default",
+ }
+ yAxislist=[yAxisdict]
+ listdict={
+ "name": testname,
+ "datasetId": datasetid,
+ "datasetName": "",
+ "chartType": chartType[0],
+ "dataTop": 0,
+ "orderBy": "",
+ "orderDesc": "",
+ "xAxis": xAxisdict,
+ "yAxis": yAxislist
+ }
+ chardict={"list": listdict}
+ elif chartType[0] == "table":
+ columnslist=[]
+ for i in namelist:
+ dataBindings={
+ "dataType": "",
+ "dataBinding": i,
+ "format": "Default",
+ }
+ dataBindingslist=[]
+ dataBindingslist.append(dataBindings)
+ columnsdict={
+ "title": i,
+ "width": 0,
+ "dataBindings": dataBindingslist
+ }
+ columnslist.append(columnsdict)
+
+ listdict={
+ "name": testname,
+ "datasetId": datasetid,
+ "datasetName": "",
+ "chartType": "table",
+ "dataTop": 5,
+ "orderBy": "",
+ "orderDesc": "",
+ "drilldownTop": 5,
+ "tableType": "Regular",
+ "columns": columnslist
+ }
+ chardict={"list": listdict}
+ print("charjson",json.dumps(chardict))
+ return json.dumps(chardict)
+
+def Reportsjson(chartId,testname):
+ charlist=[]
+ chardict={
+ "chartId": chartId,
+ "timeGranulartiy": 1,
+ "timeUnit": "",
+# "disabled": true
+ }
+ charlist.append(chardict)
+ reportJobList=[]
+ reportJobdct_1={
+ "rangeType": "last",
+ "rangeInterval": 1,
+ "rangeUnit": "week",
+ "jobName": testname,
+ "scheduleId": "",
+ "chartList": charlist,
+ "isNotice": 0,
+ "noticeMethod": "",
+ "startTime": "",
+ "endTime": "",
+ "filterCondition": None,
+ "isDisplayTrafficTrend": 1
+ }
+ reportJobdct_2={"reportJobList": reportJobdct_1}
+ print("reportjson",json.dumps(reportJobdct_2))
+ return json.dumps(reportJobdct_2)
+
+def ReportInterfaceTest(schemaurl,token,dataseturl,charurl,repporturl,datasetgeturl,chargeturl,testname,logtype,testpoint,field):
+ headers = {"Content-Type": "application/json","Authorization": token}
+ #dataset生成json串并发送请求
+ _datasetjson=datasetjson(schemaurl,token,testname,logtype,testpoint,field)
+ response1 = requests.post(url=dataseturl, data=_datasetjson, headers=headers)
+ print("返回数据1",response1)
+ code = response1.json()["code"]
+ print("datasetcode:",code)
+ assert code == 200
+
+
+# 获取dataset的id
+ datasetget=requests.get(url=datasetgeturl,headers=headers)
+ dasetget=datasetget.json()
+ datesetid=dasetget["data"]["list"][0]["id"]
+ Deleteinterfaces(dataseturl,token,datesetid)
+ # _datasetjson=json.loads(_datasetjson)
+ # queryColumnList=_datasetjson["list"]["queryColumnList"]
+ # groupColumnList=_datasetjson["list"]["groupColumnList"]
+ #生成charlibrariesjson串
+ # charlibrariesjson=charjson(schemaurl, token,queryColumnList,groupColumnList,datesetid,testname,logtype)
+ # response2 = requests.post(url=charurl, data=charlibrariesjson, headers=headers)
+ # code = response2.json()["code"]
+ # assert code == 200
+#
+# #获取char libraries的id
+# charget=requests.get(url=chargeturl,headers=headers)
+# charget=charget.json()
+# charid=charget["data"]["list"][0]["id"]
+#
+# #report生成json串并发送请求
+# reportjson=Reportsjson(charid,testname)
+# response3 = requests.post(url=repporturl, data=reportjson, headers=headers)
+# code = response3.json()["code"]
+# assert code == 200
+#
+
+# #循环调用ReportInterfaceTest方法
+# def ReportTest(host,token,dataseturl,charurl,repporturl,logtypelist):
+# for logtype in logtypelist:
+# testname="Report"+logtype
+# datasetgeturl=dataseturl+"?pageSize=20&pageNo=1&id=&name="+testname+"&logType=&opStartTime=&opEndTime=&opUser="
+# chargeturl=charurl+"?pageSize=20&pageNo=1&id=&name="+testname+"&opUser="
+# schemaurl="http://"+host+":8080/v1/log/schema?logType="+logtype
+# ReportInterfaceTest(schemaurl,token,dataseturl,charurl,repporturl,datasetgeturl,chargeturl,testname,logtype)
+
+
+def Deleteinterfaces(url,token,id):
+ headers = {"Content-Type": "application/json","Authorization": token}
+ datedict={"ids":[id]}
+ datajson=json.dumps(datedict)
+ response1 = requests.delete(url=url, data=datajson, headers=headers)
+
+
+def ReportPositiveTest(host,port,token,dataseturl,charurl,repporturl,logtypelist):
+ testpoint=["GroupBy","DataBindings","Filter","Having"]
+ for logtype in logtypelist:
+ schemaurl="http://"+host+":"+port+"/v1/log/schema?logType="+logtype
+ schema_new=schema(schemaurl,token,logtype)
+ metrics = schema_new["data"]["doc"]["schema_query"]["metrics"]
+ schemafilters = schema_new["data"]["doc"]["schema_query"]["filters"]
+ dimensions = schema_new["data"]["doc"]["schema_query"]["dimensions"]
+ dimensions.append("common_recv_time");
+ metrics.append("common_log_id")
+ for j in testpoint:
+ if j == "GroupBy":
+ for filter in dimensions:
+ testname="Report"+logtype+j+filter
+ dataset_geturl=dataseturl+"?pageSize=20&pageNo=1&id=&name="+testname+"&logType=&opStartTime=&opEndTime=&opUser="
+ char_geturl=charurl+"?pageSize=20&pageNo=1&id=&name="+testname+"&opUser="
+ ReportInterfaceTest(schemaurl,token,dataseturl,charurl,repporturl,dataset_geturl,char_geturl,testname,logtype,j,filter)
+ if j == "DataBindings":
+ for filter in metrics:
+ testname="Report"+logtype+j+filter
+ dataset_geturl=dataseturl+"?pageSize=20&pageNo=1&id=&name="+testname+"&logType=&opStartTime=&opEndTime=&opUser="
+ char_geturl=charurl+"?pageSize=20&pageNo=1&id=&name="+testname+"&opUser="
+ ReportInterfaceTest(schemaurl,token,dataseturl,charurl,repporturl,dataset_geturl,char_geturl,testname,logtype,j,filter)
+
+ if j == "Filter" :
+ for filter in schemafilters:
+ testname="Report"+logtype+j+filter
+ dataset_geturl=dataseturl+"?pageSize=20&pageNo=1&id=&name="+testname+"&logType=&opStartTime=&opEndTime=&opUser="
+ char_geturl=charurl+"?pageSize=20&pageNo=1&id=&name="+testname+"&opUser="
+ ReportInterfaceTest(schemaurl,token,dataseturl,charurl,repporturl,dataset_geturl,char_geturl,testname,logtype,j,filter)
+
+ if j == "Having" :
+ for filter in metrics:
+ testname="Report"+logtype+j+filter
+ dataset_geturl=dataseturl+"?pageSize=20&pageNo=1&id=&name="+testname+"&logType=&opStartTime=&opEndTime=&opUser="
+ char_geturl=charurl+"?pageSize=20&pageNo=1&id=&name="+testname+"&opUser="
+ ReportInterfaceTest(schemaurl,token,dataseturl,charurl,repporturl,dataset_geturl,char_geturl,testname,logtype,j,filter)
+
+
+
+
+
diff --git a/keyword/common/customlibrary/Custometest/ReportSchema_Negtive.py b/keyword/common/customlibrary/Custometest/ReportSchema_Negtive.py
new file mode 100644
index 0000000..dc466a9
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/ReportSchema_Negtive.py
@@ -0,0 +1,871 @@
+import requests
+import random
+import json
+import time
+import ipaddress
+
+# Report纯接口测试 反向用例方法,不验证数据统计准确性,单纯验证接口
+
+# 生成随机ipv4或ipv6
+MAX_IPV4 = ipaddress.IPv4Address._ALL_ONES # 2 ** 32 - 1
+MAX_IPV6 = ipaddress.IPv6Address._ALL_ONES # 2 ** 128 - 1
+
+
+def random_ipv4():
+ return ipaddress.IPv4Address._string_from_ip_int(
+ random.randint(0, MAX_IPV4))
+
+
+def random_ipv6():
+ return ipaddress.IPv6Address._string_from_ip_int(
+ random.randint(0, MAX_IPV6))
+
+
+# 随机生成邮箱地址
+def RandomEmail(emailType=None, rang=None):
+ __emailtype = ["@qq.com", "@163.com", "@126.com", "@189.com"]
+ # 如果没有指定邮箱类型,默认在 __emailtype中随机一个
+ if emailType == None:
+ __randomEmail = random.choice(__emailtype)
+ else:
+ __randomEmail = emailType
+ # 如果没有指定邮箱长度,默认在4-10之间随机
+ if rang == None:
+ __rang = random.randint(4, 10)
+ else:
+ __rang = int(rang)
+ __Number = "0123456789qbcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPWRSTUVWXYZ"
+ __randomNumber = "".join(random.choice(__Number) for i in range(__rang))
+ _email = __randomNumber + __randomEmail
+ return _email
+
+
+# 获取Schema
+def schema(schemauerl, token, logtype):
+ url = "http://192.168.44.72:8080/v1/log/schema?logType=" + logtype
+ headers = {"Content-Type": "application/x-www-form-urlencoded", "Authorization": token}
+ response = requests.get(url=url, headers=headers)
+ return response.json()
+
+
+# 获取json串中groupColumnList的值
+def groupby(schemajson, logtype, testpoint):
+ dimensions = schemajson["data"]["doc"]["schema_query"]["dimensions"]
+ dimensions.append("common_recv_time");
+ if logtype == "security_event_log" or logtype == "connection_record_log" or logtype == "voip_record_log":
+ dimensions.remove("common_start_time")
+ dimensions.remove("common_end_time")
+ randomstr_1 = []
+ if testpoint == "GroupBy":
+ randomstr_1.append("GroupBy_Negtive")
+ else:
+ randomstr_1 = random.sample(dimensions, 4)
+
+ # 定义grp为返回值group的列表
+ grp = []
+ for i in randomstr_1:
+ a = {"name": i}
+ grp.append(a)
+
+ re = [grp, randomstr_1]
+ print("groupby", re)
+ return re
+
+
+# 获取json串中queryColumnList的值
+def DataBindings(schemajson, randomstr_1, testpoint, field):
+ # 生成queryColumnList列表
+ print("field", field)
+ metrics = schemajson["data"]["doc"]["schema_query"]["metrics"]
+ metrics.append("common_log_id")
+ # 在列表里随机元素
+ randomstr_2 = []
+ if testpoint == "DataBindings_Field" or testpoint == "DataBindings_Aggregate":
+ randomstr_2.append(field)
+ randomstr_3 = randomstr_2
+ else:
+ randomstr_2 = random.sample(metrics, 6)
+ # 在聚合列表中去掉groupby中的重复的元素
+ randomstr_3 = array_diff(randomstr_2, randomstr_1)
+ # 将groupby中元素添加到串中
+ qul = []
+ for i in randomstr_1:
+ a = {"name": i}
+ qul.append(a)
+
+ fields = schemajson["data"]["fields"]
+ if testpoint == "DataBindings_Aggregate":
+ list_1 = ["countdistinct"]
+ list_2 = ["summ"]
+ else:
+ list_1 = ["sum", "min", "max", "avg", "count"]
+ list_2 = ["count", "count_distinct"]
+
+ if testpoint == "DataBindings_Field":
+ Aggregate = "sum"
+ randomstr_4 = {"name": randomstr_2[0], "expression": Aggregate}
+ qul.append(randomstr_4)
+
+ elif testpoint == "DataBindings_Aggregate":
+ for i in randomstr_3:
+ for j in fields:
+ if i == j["name"]:
+ jtype = j["type"]
+ label = i
+ sun = 1
+ if jtype == "int" or jtype == "long" or jtype == "float" or jtype == "double":
+ for Aggregate in list_1:
+ randomstr_4 = {"name": i, "expression": Aggregate, "label": label}
+ qul.append(randomstr_4)
+ label = label + str(sun)
+ sun += 1
+ elif jtype == "randomstring" or jtype == "date" or jtype == "timestamp" or jtype == "string":
+ for Aggregate in list_2:
+ randomstr_4 = {"name": i, "expression": Aggregate, "label": label}
+ qul.append(randomstr_4)
+ label = label + str(sun)
+ sun += 1
+
+ else:
+ for i in randomstr_3:
+ for j in fields:
+ if i == j["name"]:
+ jtype = j["type"]
+ if jtype == "int" or jtype == "long" or jtype == "float" or jtype == "double":
+ radomlist = random.sample(list_1, 1)
+ randomstr_4 = {"name": i, "expression": radomlist[0]}
+ qul.append(randomstr_4)
+ elif jtype == "randomstring" or jtype == "date" or jtype == "timestamp" or jtype == "string":
+ randomlist = random.sample(list_2, 1)
+ randomstr_4 = {"name": i, "expression": randomlist[0]}
+ qul.append(randomstr_4)
+ print("DataBindings", qul)
+ return qul
+
+
+# #去除a列表中存在的b的元素
+def array_diff(a, b):
+ # 定义空列表
+ c = []
+ # range(len(a))取的为列表a的索引,根据a的
+ for i in range(len(a)):
+ # 取出索引对应的值
+ t = a[i]
+ # 判断值是否存在在序列b中
+ if t not in b:
+ # 如果序列不在b中,则写入序列c
+ c.append(t)
+ # 返回序列c,c就是列表a去除列表b之后的元素
+ return c
+
+
+def filterCondition(schemajson, testpoint, field):
+ number = random.randint(0, 100000)
+ randomstr = random.choice('abcdefghijklmnopqrstuvwxyz')
+ schemafilters = schemajson["data"]["doc"]["schema_query"]["filters"]
+ list1 = []
+ if testpoint == "Filter_Field" or testpoint == "Filter_Operator":
+ list1.append(field)
+ else:
+ list1 = random.sample(schemafilters, 4)
+ # 获取不同属性支持的部不同操作
+ fields = schemajson["data"]["fields"]
+ operator = schemajson["data"]["doc"]["schema_query"]["references"]["operator"]
+ andConditions = []
+ if testpoint == "Filter_Field":
+ orConditions_list = []
+ Field = {"name": field, "expression": "!=", "value": [1], "type": "int"}
+ orConditions_list.append(Field)
+ orConditions = {"orConditions": orConditions_list}
+ andConditions.append(orConditions)
+ elif testpoint == "Filter_Operator":
+ for i in list1:
+ # 遍历fields列表
+ for k in fields:
+ # 当filters列表值等于fields的name时
+ if i == k["name"]:
+ name = k["name"]
+ type1 = k["type"]
+ if type1 == "int" or type1 == "long":
+ orConditions_list = []
+ Operator = ["=="]
+ randomOperator = random.sample(Operator, 1)
+ value = [str(number)]
+ Field = {"name": name, "expression": randomOperator[0], "value": value, "type": type1}
+ orConditions_list.append(Field)
+ orConditions = {"orConditions": orConditions_list}
+ andConditions.append(orConditions)
+ elif type1 == "string":
+ orConditions_list = []
+ Operator = ["=="]
+ randomOperator_1 = random.sample(Operator, 1)
+ randomOperator = randomOperator_1[0]
+ value = []
+ value.append(str(number))
+ Field = {"name": name, "expression": randomOperator, "value": value, "type": type1}
+ orConditions_list.append(Field)
+ orConditions = {"orConditions": orConditions_list}
+ andConditions.append(orConditions)
+ #
+ # else:
+ # if k["doc"]["constraints"] == None:
+ # type1 = k["type"]
+ # if type1 == "int" or type1 == "long":
+ # orConditions_list = []
+ # Operator = ["=", "!=", ">", "<", ">=", "<="]
+ # if testpoint == "Filter":
+ # for op in Operator:
+ # value = [str(number)]
+ # Field = {"name": name, "expression": op, "value": value, "type": type1}
+ # orConditions_list.append(Field)
+ # else:
+ # randomOperator = random.sample(Operator, 1)
+ # value = [str(number)]
+ # Field = {"name": name, "expression": randomOperator[0], "value": value, "type": type1}
+ # orConditions_list.append(Field)
+ # orConditions = {"orConditions": orConditions_list}
+ # andConditions.append(orConditions)
+ # elif type1 == "string":
+ # orConditions_list = []
+ # Operator = ["=", "!=", "Like", "Not Like", "notEmpty", "empty"]
+ # if testpoint == "Filter":
+ # for op in Operator:
+ # randomOperator = op
+ # value = []
+ # if randomOperator == "=" or randomOperator == "!=":
+ # value.append(str(number))
+ # elif randomOperator == "Like" or randomOperator == "Not Like":
+ # value.append(randomstr)
+ # elif randomOperator == "notEmpty":
+ # value = []
+ # Field = {"name": name, "expression": randomOperator, "value": value, "type": type1}
+ # orConditions_list.append(Field)
+ # else:
+ # randomOperator_1 = random.sample(Operator, 1)
+ # randomOperator = randomOperator_1[0]
+ # value = []
+ # if randomOperator == "=" or randomOperator == "!=":
+ # value.append(str(number))
+ # elif randomOperator == "Like" or randomOperator == "Not Like":
+ # value.append(randomstr)
+ # elif randomOperator == "notEmpty":
+ # value = []
+ # Field = {"name": name, "expression": randomOperator, "value": value, "type": type1}
+ # orConditions_list.append(Field)
+ # orConditions = {"orConditions": orConditions_list}
+ # andConditions.append(orConditions)
+ #
+ # else:
+ # if k["doc"]["constraints"]["operator_functions"] == None:
+ # conrandomstraints = k["doc"]["constraints"]
+ # type1 = k["type"]
+ # if type1 == "int" or type1 == "long":
+ # orConditions_list = []
+ # Operator = ["=", "!=", ">", "<", ">=", "<="]
+ # if testpoint == "Filter":
+ # for op in Operator:
+ # randomOperator = op
+ # if conrandomstraints["type"] == "timestamp":
+ # # 获取当前时间戳
+ # t = int(time.time())
+ # value = [str(t)]
+ # Field = {"name": name, "expression": randomOperator, "value": value,
+ # "type": type1}
+ # orConditions_list.append(Field)
+ # else:
+ # randomOperator_1 = random.sample(Operator, 1)
+ # randomOperator = randomOperator_1[0]
+ # if conrandomstraints["type"] == "timestamp":
+ # # 获取当前时间戳
+ # t = int(time.time())
+ # value = [str(t)]
+ # Field = {"name": name, "expression": randomOperator, "value": value,
+ # "type": type1}
+ # orConditions_list.append(Field)
+ # orConditions = {"orConditions": orConditions_list}
+ # andConditions.append(orConditions)
+ # elif type1 == "string":
+ # orConditions_list = []
+ # Operator = ["=", "!=", "Like", "Not Like", "notEmpty", "empty"]
+ # if testpoint == "Filter":
+ # if conrandomstraints["type"] == "ip":
+ # for op in Operator:
+ # # 获取ip
+ # ip = random_ipv4()
+ # value = []
+ # if op == "=" or op == "!=":
+ # value.append(ip)
+ # elif op == "Like" or op == "Not Like":
+ # value.append(ip)
+ # elif op == "notEmpty":
+ # value = []
+ # Field = {"name": name, "expression": op, "value": value, "type": type1}
+ # orConditions_list.append(Field)
+ # elif conrandomstraints["type"] == "email":
+ # for op in Operator:
+ # randomOperator = op
+ # Operator = ["=", "!=", "Like", "Not Like", "notEmpty", "empty"]
+ # randomOperator_1 = random.sample(Operator, 1)
+ # randomOperator = randomOperator_1[0]
+ # # 获取ip
+ # emil = RandomEmail()
+ # value = []
+ # if randomOperator == "=" or randomOperator == "!=":
+ # value.append(emil)
+ # elif randomOperator == "Like" or randomOperator == "Not Like":
+ # value.append(emil)
+ # elif randomOperator == "notEmpty":
+ # value = []
+ # Field = {"name": name, "expression": randomOperator, "value": value,
+ # "type": type1}
+ # orConditions_list.append(Field)
+ # else:
+ # randomOperator_1 = random.sample(Operator, 1)
+ # randomOperator = randomOperator_1[0]
+ # if conrandomstraints["type"] == "ip":
+ # # 获取ip
+ # ip = random_ipv4()
+ # value = []
+ # if randomOperator == "=" or randomOperator == "!=":
+ # value.append(ip)
+ # elif randomOperator == "Like" or randomOperator == "Not Like":
+ # value.append(ip)
+ # elif randomOperator == "notEmpty":
+ # value = []
+ # Field = {"name": name, "expression": randomOperator, "value": value,
+ # "type": type1}
+ # orConditions_list.append(Field)
+ # orConditions = {"orConditions": orConditions_list}
+ # andConditions.append(orConditions)
+ # elif conrandomstraints["type"] == "email":
+ # Operator = ["=", "!=", "Like", "Not Like", "notEmpty", "empty"]
+ # randomOperator_1 = random.sample(Operator, 1)
+ # randomOperator = randomOperator_1[0]
+ # # 获取ip
+ # emil = RandomEmail()
+ # value = []
+ # if randomOperator == "=" or randomOperator == "!=":
+ # value.append(emil)
+ # elif randomOperator == "Like" or randomOperator == "Not Like":
+ # value.append(emil)
+ # elif randomOperator == "notEmpty":
+ # value = []
+ # Field = {"name": name, "expression": randomOperator, "value": value,
+ # "type": type1}
+ # orConditions_list.append(Field)
+ # orConditions = {"orConditions": orConditions_list}
+ # andConditions.append(orConditions)
+ # else:
+ # type1 = k["type"]
+ # orConditions_list = []
+ # operator1 = k["doc"]["constraints"]["operator_functions"]
+ # operator2 = operator1.split(",")
+ # if testpoint == "Filter":
+ # for op in operator2:
+ # operatordata = k["doc"]["data"]
+ # code = []
+ # for i in operatordata:
+ # code_1 = i["code"]
+ # code.append(code_1)
+ # for co in code:
+ # Field = {"name": name, "expression": op, "value": co, "type": type1}
+ # orConditions_list.append(Field)
+ # else:
+ # operator3 = random.sample(operator2, 1)
+ # operatordata = k["doc"]["data"]
+ # code = []
+ # for i in operatordata:
+ # code_1 = i["code"]
+ # code.append(code_1)
+ # code2 = random.sample(code, 1)
+ # Field = {"name": name, "expression": operator3[0], "value": code2, "type": type1}
+ # orConditions_list.append(Field)
+ # orConditions = {"orConditions": orConditions_list}
+ # andConditions.append(orConditions)
+ else:
+ for i in list1:
+ # 遍历fields列表
+ for k in fields:
+ # 当filters列表值等于fields的name时
+ if i == k["name"]:
+ name = k["name"]
+ doc = k["doc"]
+ # 获取无任何特殊说明列:
+ if doc == None:
+ type1 = k["type"]
+ if type1 == "int" or type1 == "long":
+ orConditions_list = []
+ Operator = ["=", "!=", ">", "<", ">=", "<="]
+ if testpoint == "Filter":
+ for op in Operator:
+ value = [str(number)]
+ Field = {"name": name, "expression": op, "value": value, "type": type1}
+ orConditions_list.append(Field)
+ else:
+ randomOperator = random.sample(Operator, 1)
+ value = [str(number)]
+ Field = {"name": name, "expression": randomOperator[0], "value": value, "type": type1}
+ orConditions_list.append(Field)
+ orConditions = {"orConditions": orConditions_list}
+ andConditions.append(orConditions)
+ elif type1 == "string":
+ orConditions_list = []
+ Operator = ["=", "!=", "Like", "Not Like", "notEmpty", "empty"]
+ if testpoint == "Filter":
+ for op in Operator:
+ value = []
+ if op == "=" or op == "!=":
+ value.append(str(number))
+ elif op == "Like" or op == "Not Like":
+ value.append(randomstr)
+ elif op == "notEmpty" or op == "empty":
+ value = []
+ Field = {"name": name, "expression": op, "value": value, "type": type1}
+ orConditions_list.append(Field)
+ else:
+ randomOperator_1 = random.sample(Operator, 1)
+ randomOperator = randomOperator_1[0]
+ value = []
+ if randomOperator == "=" or randomOperator == "!=":
+ value.append(str(number))
+ elif randomOperator == "Like" or randomOperator == "Not Like":
+ value.append(randomstr)
+ elif randomOperator == "notEmpty":
+ value = []
+ Field = {"name": name, "expression": randomOperator, "value": value, "type": type1}
+ orConditions_list.append(Field)
+ orConditions = {"orConditions": orConditions_list}
+ andConditions.append(orConditions)
+
+ else:
+ if k["doc"]["constraints"] == None:
+ type1 = k["type"]
+ if type1 == "int" or type1 == "long":
+ orConditions_list = []
+ Operator = ["=", "!=", ">", "<", ">=", "<="]
+ if testpoint == "Filter":
+ for op in Operator:
+ value = [str(number)]
+ Field = {"name": name, "expression": op, "value": value, "type": type1}
+ orConditions_list.append(Field)
+ else:
+ randomOperator = random.sample(Operator, 1)
+ value = [str(number)]
+ Field = {"name": name, "expression": randomOperator[0], "value": value,
+ "type": type1}
+ orConditions_list.append(Field)
+ orConditions = {"orConditions": orConditions_list}
+ andConditions.append(orConditions)
+ elif type1 == "string":
+ orConditions_list = []
+ Operator = ["=", "!=", "Like", "Not Like", "notEmpty", "empty"]
+ if testpoint == "Filter":
+ for op in Operator:
+ randomOperator = op
+ value = []
+ if randomOperator == "=" or randomOperator == "!=":
+ value.append(str(number))
+ elif randomOperator == "Like" or randomOperator == "Not Like":
+ value.append(randomstr)
+ elif randomOperator == "notEmpty":
+ value = []
+ Field = {"name": name, "expression": randomOperator, "value": value,
+ "type": type1}
+ orConditions_list.append(Field)
+ else:
+ randomOperator_1 = random.sample(Operator, 1)
+ randomOperator = randomOperator_1[0]
+ value = []
+ if randomOperator == "=" or randomOperator == "!=":
+ value.append(str(number))
+ elif randomOperator == "Like" or randomOperator == "Not Like":
+ value.append(randomstr)
+ elif randomOperator == "notEmpty":
+ value = []
+ Field = {"name": name, "expression": randomOperator, "value": value, "type": type1}
+ orConditions_list.append(Field)
+ orConditions = {"orConditions": orConditions_list}
+ andConditions.append(orConditions)
+
+ else:
+ if k["doc"]["constraints"]["operator_functions"] == None:
+ conrandomstraints = k["doc"]["constraints"]
+ type1 = k["type"]
+ if type1 == "int" or type1 == "long":
+ orConditions_list = []
+ Operator = ["=", "!=", ">", "<", ">=", "<="]
+ if testpoint == "Filter":
+ for op in Operator:
+ randomOperator = op
+ if conrandomstraints["type"] == "timestamp":
+ # 获取当前时间戳
+ t = int(time.time())
+ value = [str(t)]
+ Field = {"name": name, "expression": randomOperator, "value": value,
+ "type": type1}
+ orConditions_list.append(Field)
+ else:
+ randomOperator_1 = random.sample(Operator, 1)
+ randomOperator = randomOperator_1[0]
+ if conrandomstraints["type"] == "timestamp":
+ # 获取当前时间戳
+ t = int(time.time())
+ value = [str(t)]
+ Field = {"name": name, "expression": randomOperator, "value": value,
+ "type": type1}
+ orConditions_list.append(Field)
+ orConditions = {"orConditions": orConditions_list}
+ andConditions.append(orConditions)
+ elif type1 == "string":
+ orConditions_list = []
+ Operator = ["=", "!=", "Like", "Not Like", "notEmpty", "empty"]
+ if testpoint == "Filter":
+ if conrandomstraints["type"] == "ip":
+ for op in Operator:
+ # 获取ip
+ ip = random_ipv4()
+ value = []
+ if op == "=" or op == "!=":
+ value.append(ip)
+ elif op == "Like" or op == "Not Like":
+ value.append(ip)
+ elif op == "notEmpty":
+ value = []
+ Field = {"name": name, "expression": op, "value": value, "type": type1}
+ orConditions_list.append(Field)
+ elif conrandomstraints["type"] == "email":
+ for op in Operator:
+ randomOperator = op
+ Operator = ["=", "!=", "Like", "Not Like", "notEmpty", "empty"]
+ randomOperator_1 = random.sample(Operator, 1)
+ randomOperator = randomOperator_1[0]
+ # 获取ip
+ emil = RandomEmail()
+ value = []
+ if randomOperator == "=" or randomOperator == "!=":
+ value.append(emil)
+ elif randomOperator == "Like" or randomOperator == "Not Like":
+ value.append(emil)
+ elif randomOperator == "notEmpty":
+ value = []
+ Field = {"name": name, "expression": randomOperator, "value": value,
+ "type": type1}
+ orConditions_list.append(Field)
+ else:
+ randomOperator_1 = random.sample(Operator, 1)
+ randomOperator = randomOperator_1[0]
+ if conrandomstraints["type"] == "ip":
+ # 获取ip
+ ip = random_ipv4()
+ value = []
+ if randomOperator == "=" or randomOperator == "!=":
+ value.append(ip)
+ elif randomOperator == "Like" or randomOperator == "Not Like":
+ value.append(ip)
+ elif randomOperator == "notEmpty":
+ value = []
+ Field = {"name": name, "expression": randomOperator, "value": value,
+ "type": type1}
+ orConditions_list.append(Field)
+ orConditions = {"orConditions": orConditions_list}
+ andConditions.append(orConditions)
+ elif conrandomstraints["type"] == "email":
+ Operator = ["=", "!=", "Like", "Not Like", "notEmpty", "empty"]
+ randomOperator_1 = random.sample(Operator, 1)
+ randomOperator = randomOperator_1[0]
+ # 获取ip
+ emil = RandomEmail()
+ value = []
+ if randomOperator == "=" or randomOperator == "!=":
+ value.append(emil)
+ elif randomOperator == "Like" or randomOperator == "Not Like":
+ value.append(emil)
+ elif randomOperator == "notEmpty":
+ value = []
+ Field = {"name": name, "expression": randomOperator, "value": value,
+ "type": type1}
+ orConditions_list.append(Field)
+ orConditions = {"orConditions": orConditions_list}
+ andConditions.append(orConditions)
+ else:
+ type1 = k["type"]
+ orConditions_list = []
+ operator1 = k["doc"]["constraints"]["operator_functions"]
+ operator2 = operator1.split(",")
+ if testpoint == "Filter":
+ for op in operator2:
+ operatordata = k["doc"]["data"]
+ code = []
+ for i in operatordata:
+ code_1 = i["code"]
+ code.append(code_1)
+ for co in code:
+ Field = {"name": name, "expression": op, "value": co, "type": type1}
+ orConditions_list.append(Field)
+ else:
+ operator3 = random.sample(operator2, 1)
+ operatordata = k["doc"]["data"]
+ code = []
+ for i in operatordata:
+ code_1 = i["code"]
+ code.append(code_1)
+ code2 = random.sample(code, 1)
+ Field = {"name": name, "expression": operator3[0], "value": code2, "type": type1}
+ orConditions_list.append(Field)
+ orConditions = {"orConditions": orConditions_list}
+ andConditions.append(orConditions)
+ filterCondition = {"andConditions": andConditions}
+ print("filterCondition", filterCondition)
+ return filterCondition
+
+
+# 获取having条件的串
+def havingjson(schemajson, testpoint, field):
+ number = random.randint(0, 100000)
+ schemametrics = schemajson["data"]["doc"]["schema_query"]["metrics"]
+ aggregation = schemajson["data"]["doc"]["schema_query"]["references"]["aggregation"]
+ schemametrics.append("common_log_id")
+ metricslist = []
+ if testpoint == "Having_Field" or testpoint == "Having_Aggregate" or testpoint == "Having_Operator":
+ metricslist.append(field)
+ else:
+ metricslist = random.sample(schemametrics, 4)
+ fields = schemajson["data"]["fields"]
+
+ if testpoint == "Having_Aggregate":
+ Aggregate = ["COUNTT"]
+ else:
+ Aggregate = ["COUNT", "AVG", "SUM", "MAX", "MIN"]
+
+ if testpoint == "Having_Operator":
+ operator = ["=="]
+ else:
+ operator = ["=", "!=", ">", "<", ">=", "<="]
+
+ andConditions_list = []
+ # 遍历的到的having条件列表
+ if testpoint == "Having_Field":
+ orConditions_list=[]
+ havingdict = {"name": field, "function": "count","expression": "=", "value": 11}
+ orConditions_list.append(havingdict)
+ orConditions = {"orConditions": orConditions_list}
+ andConditions_list.append(orConditions)
+ elif testpoint == "Having_Aggregate":
+ for j in fields:
+ if field == j["name"]:
+ name = j["name"]
+ type1 = j["type"]
+ for v in aggregation:
+ if type1 == v["type"]:
+ orConditions_list = []
+ if v["type"] != "string":
+ functionslist = Aggregate
+ else:
+ functionslist = ["COUNTT"]
+ if field == "common_log_id":
+ functionslist = ["COUNTT"]
+ functions_1 = random.sample(functionslist, 1)
+ operator_1 = random.sample(operator, 1)
+ havingdict = {"name": name, "function": str.lower(functions_1[0]),
+ "expression": operator_1[0], "value": str(number)}
+ orConditions_list.append(havingdict)
+ orConditions = {"orConditions": orConditions_list}
+ andConditions_list.append(orConditions)
+ elif testpoint == "Having_Operator":
+ for j in fields:
+ if field == j["name"]:
+ name = j["name"]
+ type1 = j["type"]
+ for v in aggregation:
+ if type1 == v["type"]:
+ orConditions_list = []
+ if v["type"] != "string":
+ functionslist = Aggregate
+ else:
+ functionsstr = v["functions"]
+ functionslist = functionsstr.split(",")
+ if field == "common_log_id":
+ functionslist = ["COUNT"]
+ functions_1 = random.sample(functionslist, 1)
+ if functions_1 == "COUNT_DISTINCT" and type1 != "string":
+ functions_1 = random.sample(functionslist, 1)
+ operator_1 = random.sample(operator, 1)
+
+ havingdict = {"name": name, "function": str.lower(functions_1[0]),
+ "expression": operator_1[0], "value": str(number)}
+ orConditions_list.append(havingdict)
+ orConditions = {"orConditions": orConditions_list}
+ andConditions_list.append(orConditions)
+
+ else:
+ for i in metricslist:
+ for j in fields:
+ if i == j["name"]:
+ name = j["name"]
+ type1 = j["type"]
+ for v in aggregation:
+ if type1 == v["type"]:
+ orConditions_list = []
+ if v["type"] != "string":
+ functionslist = Aggregate
+ else:
+ functionsstr = v["functions"]
+ functionslist = functionsstr.split(",")
+ if field == "common_log_id":
+ functionslist = ["COUNT"]
+ if testpoint == "Having":
+ for functions_1 in functionslist:
+ for operator_1 in operator:
+ havingdict = {"name": name, "function": str.lower(functions_1),
+ "expression": operator_1, "value": str(number)}
+ orConditions_list.append(havingdict)
+ orConditions = {"orConditions": orConditions_list}
+ andConditions_list.append(orConditions)
+ else:
+ functions_1 = random.sample(functionslist, 1)
+ if functions_1 == "COUNT_DISTINCT" and type1 != "string":
+ functions_1 = random.sample(functionslist, 1)
+ operator_1 = random.sample(operator, 1)
+
+ havingdict = {"name": name, "function": str.lower(functions_1[0]),
+ "expression": operator_1[0], "value": str(number)}
+ orConditions_list.append(havingdict)
+ orConditions = {"orConditions": orConditions_list}
+ andConditions_list.append(orConditions)
+ havingCondition = {"andConditions": andConditions_list}
+ print("having", havingCondition)
+ return havingCondition
+
+# 拼接字符串
+def datasetjson(schemauerl, token, testname, logtype, testpoint, field):
+ schema_new = schema(schemauerl, token, logtype)
+ group_re = groupby(schema_new, logtype, testpoint)
+ groupColumnList = group_re[0]
+ group_randomstr = group_re[1]
+ queryColumnList = DataBindings(schema_new, group_randomstr, testpoint, field)
+ filterCondition_1 = filterCondition(schema_new, testpoint, field)
+ havingjson_1 = havingjson(schema_new, testpoint, field)
+ if testpoint == "LogType":
+ logtype = field
+ datasetdict = {
+ "list": {
+ "name": testname,
+ "logType": logtype,
+ "groupColumnList": groupColumnList,
+ "queryColumnList": queryColumnList,
+ "filterCondition": filterCondition_1,
+ "havingCondition": havingjson_1
+ }
+ }
+ print(datasetdict)
+ print("datasetjson", json.dumps(datasetdict))
+ return json.dumps(datasetdict)
+
+def ReportInterfaceTest(schemaurl, token, dataseturl, charurl, repporturl, datasetgeturl, chargeturl, testname, logtype,
+ testpoint, field=None):
+ headers = {"Content-Type": "application/json", "Authorization": token}
+ # dataset生成json串并发送请求
+ _datasetjson = datasetjson(schemaurl, token, testname, logtype, testpoint, field)
+ response1 = requests.post(url=dataseturl, data=_datasetjson, headers=headers)
+ print("返回数据1", response1)
+ code = response1.json()["code"]
+ print("datasetcode:", code)
+ if testpoint == "LogType":
+ assert code == 40040002
+ elif testpoint == "GroupBy":
+ assert code == 40040008
+ elif testpoint == "DataBindings_Field":
+ assert code == 40040004
+ elif testpoint == "DataBindings_Aggregate":
+ assert code == 40040006
+ elif testpoint == "Filter_Field":
+ assert code == 40040007
+ elif testpoint == "Filter_Operator":
+ assert code == 40040010
+ elif testpoint == "Having_Field":
+ assert code == 40040074
+ elif testpoint == "Having_Aggregate":
+ assert code == 40040072
+ elif testpoint == "Having_Operator":
+ assert code == 40040073
+
+def ReportPositiveTest_Negtive(host, port, token, dataseturl, charurl, repporturl, logtypelist):
+ testpoint=["LogType","GroupBy","DataBindings_Field","DataBindings_Aggregate","Filter_Field","Filter_Operator","Having_Field","Having_Aggregate","Having_Operator"]
+ for logtype in logtypelist:
+ schemaurl = "http://" + host + ":" + port + "/v1/log/schema?logType=" + logtype
+ schema_new = schema(schemaurl, token, logtype)
+ metrics = schema_new["data"]["doc"]["schema_query"]["metrics"]
+ schemafilters = schema_new["data"]["doc"]["schema_query"]["filters"]
+ metrics.append("common_log_id")
+ for j in testpoint:
+ print(j)
+ if j == "LogType":
+ testname = "Report" + logtype + j
+ dataset_geturl = dataseturl + "?pageSize=20&pageNo=1&id=&name=" + testname + "&logType=&opStartTime=&opEndTime=&opUser="
+ char_geturl = charurl + "?pageSize=20&pageNo=1&id=&name=" + testname + "&opUser="
+ filter = "Negtive_log"
+ ReportInterfaceTest(schemaurl, token, dataseturl, charurl, repporturl, dataset_geturl, char_geturl,
+ testname, logtype, j, filter)
+
+ if j == "GroupBy":
+ testname = "Report" + logtype + j
+ dataset_geturl = dataseturl + "?pageSize=20&pageNo=1&id=&name=" + testname + "&logType=&opStartTime=&opEndTime=&opUser="
+ char_geturl = charurl + "?pageSize=20&pageNo=1&id=&name=" + testname + "&opUser="
+ filter = "GroupByNegtive"
+ ReportInterfaceTest(schemaurl, token, dataseturl, charurl, repporturl, dataset_geturl, char_geturl,
+ testname, logtype, j, filter)
+
+ if j == "DataBindings_Field":
+ testname = "Report" + logtype + j
+ dataset_geturl = dataseturl + "?pageSize=20&pageNo=1&id=&name=" + testname + "&logType=&opStartTime=&opEndTime=&opUser="
+ char_geturl = charurl + "?pageSize=20&pageNo=1&id=&name=" + testname + "&opUser="
+ filter = "DataBindingsFieldNegtive"
+ ReportInterfaceTest(schemaurl, token, dataseturl, charurl, repporturl, dataset_geturl, char_geturl,
+ testname, logtype, j, filter)
+
+ if j == "DataBindings_Aggregate":
+ for filter in metrics:
+ testname = "Report" + logtype + j + filter
+ dataset_geturl = dataseturl + "?pageSize=20&pageNo=1&id=&name=" + testname + "&logType=&opStartTime=&opEndTime=&opUser="
+ char_geturl = charurl + "?pageSize=20&pageNo=1&id=&name=" + testname + "&opUser="
+ ReportInterfaceTest(schemaurl, token, dataseturl, charurl, repporturl, dataset_geturl, char_geturl,
+ testname, logtype, j, filter)
+
+ if j == "Filter_Field":
+ testname = "Report" + logtype + j
+ dataset_geturl = dataseturl + "?pageSize=20&pageNo=1&id=&name=" + testname + "&logType=&opStartTime=&opEndTime=&opUser="
+ char_geturl = charurl + "?pageSize=20&pageNo=1&id=&name=" + testname + "&opUser="
+ filter = "FilterFieldNegtive"
+ ReportInterfaceTest(schemaurl, token, dataseturl, charurl, repporturl, dataset_geturl, char_geturl,
+ testname, logtype, j, filter)
+
+ if j == "Filter_Operator":
+ for filter in schemafilters:
+ testname = "Report" + logtype + j + filter
+ dataset_geturl = dataseturl + "?pageSize=20&pageNo=1&id=&name=" + testname + "&logType=&opStartTime=&opEndTime=&opUser="
+ char_geturl = charurl + "?pageSize=20&pageNo=1&id=&name=" + testname + "&opUser="
+ ReportInterfaceTest(schemaurl, token, dataseturl, charurl, repporturl, dataset_geturl, char_geturl,
+ testname, logtype, j, filter)
+ if j == "Having_Field":
+ testname = "Report" + logtype + j
+ dataset_geturl = dataseturl + "?pageSize=20&pageNo=1&id=&name=" + testname + "&logType=&opStartTime=&opEndTime=&opUser="
+ char_geturl = charurl + "?pageSize=20&pageNo=1&id=&name=" + testname + "&opUser="
+ filter="HavingFieldNegtive"
+ ReportInterfaceTest(schemaurl, token, dataseturl, charurl, repporturl, dataset_geturl, char_geturl,
+ testname, logtype, j, filter)
+
+ if j == "Having_Aggregate":
+ for filter in metrics:
+ testname = "Report" + logtype + j + filter
+ dataset_geturl = dataseturl + "?pageSize=20&pageNo=1&id=&name=" + testname + "&logType=&opStartTime=&opEndTime=&opUser="
+ char_geturl = charurl + "?pageSize=20&pageNo=1&id=&name=" + testname + "&opUser="
+ ReportInterfaceTest(schemaurl, token, dataseturl, charurl, repporturl, dataset_geturl, char_geturl,
+ testname, logtype, j, filter)
+
+ if j == "Having_Operator":
+ for filter in metrics:
+ testname = "Report" + logtype + j + filter
+ dataset_geturl = dataseturl + "?pageSize=20&pageNo=1&id=&name=" + testname + "&logType=&opStartTime=&opEndTime=&opUser="
+ char_geturl = charurl + "?pageSize=20&pageNo=1&id=&name=" + testname + "&opUser="
+ ReportInterfaceTest(schemaurl, token, dataseturl, charurl, repporturl, dataset_geturl, char_geturl,
+ testname, logtype, j, filter)
diff --git a/keyword/common/customlibrary/Custometest/Schema.py b/keyword/common/customlibrary/Custometest/Schema.py
new file mode 100644
index 0000000..835d96a
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/Schema.py
@@ -0,0 +1,350 @@
+# !/user/bin/python
+# -*-coding:utf-8-*-
+import requests
+import random
+import json
+
+# import allure
+
+list = []
+
+
+# 请求schema接口得到返回数据,用于其他接口
+def schema(schemauerl, token):
+ 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()
+
+
+# 根据schema接口返回数据,得出所有属性所支持的比较类型的列表
+# 1、根据[doc][allow_query]值为true列支持搜索;
+# 2、如有[doc][constraints][operator_functions]值,操作优先;
+# 3、如有[doc][data]值则对应属性取值为data所列code值;
+# 4、int和long的范围不一致;
+# 5、string要包含特殊字符
+# 6、给查询条件赋值,要给出边界和正常值
+# 7、IP(V4、V6)和URL要给出专门的方法生成
+
+import ipaddress
+
+# 生成随机ipv4或ipv6
+MAX_IPV4 = ipaddress.IPv4Address._ALL_ONES # 2 ** 32 - 1
+MAX_IPV6 = ipaddress.IPv6Address._ALL_ONES # 2 ** 128 - 1
+
+
+def random_ipv4():
+ return ipaddress.IPv4Address._string_from_ip_int(
+ random.randint(0, MAX_IPV4)
+ )
+
+
+def random_ipv6():
+ return ipaddress.IPv6Address._string_from_ip_int(
+ random.randint(0, MAX_IPV6)
+ )
+
+
+from random import Random
+
+
+# 生成 12 位随机 URL 地址
+def randrom_url():
+ str = ''
+ str1 = ''
+ chars = 'abcdefghijklmnopqrstuvwxyz0123456789'
+ chars1 = 'abcdefghijklmnopqrstuvwxyz0123456789!#$%^&*()'
+ length = len(chars)
+ length1 = len(chars1)
+ random = Random()
+ for x in range(random.randint(8, 16)):
+ str += chars[random.randint(0, length - 1)]
+ for pp in range(random.randint(8, 16)):
+ str1 += chars1[random.randint(0, length1 - 1)]
+ url = str[0:-5] + "." + str[0:-6] + "." + str[0:-7] + "/" + str1
+ print(url)
+ return url
+
+
+def Filter1(schemauerl, token):
+ json_str = schema(schemauerl, token)
+ print(type(json_str))
+ # 获取日志属性定义
+ fields = json_str["data"]["fields"]
+ # 获取不同属性支持的部不同操作
+ operator = json_str["data"]["doc"]["schema_query"]["references"]["operator"]
+ for i in fields:
+ number = random.randint(-2147483648, 2147483647)
+ maxnumber = 2147483647
+ minnumber = -2147483648
+ str = random.choice('abcdefghijklmnopqrstuvwxyz!@#$%^&*')
+ 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:
+ if v == "in" or v == "not in":
+ str1 = name + " " + v + " " + "(" + f"{value1}" + ")"
+ list.append(str1)
+ else:
+ str1 = name + " " + v + " " + f"{value1}"
+ list.append(str1)
+ elif type1 == "string":
+ value1 = str
+ functions = j["functions"]
+ functions1 = functions.split(",")
+ for v in functions1:
+ if v == "not empty" or v == "empty":
+ str1 = v + "(" + " '" + name + " '" + ")"
+ list.append(str1)
+ elif v == "in" or v == "not in":
+ str1 = name + " " + v + " " + "(" + " '" + value1 + " '" + ")"
+ list.append(str1)
+ else:
+ 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:
+ if v == "in" or v == "not in":
+ str1 = name + " " + v + " " + "(" + f"{value1}" + ")"
+ list.append(str1)
+ else:
+ str1 = name + " " + v + " " + f"{value1}"
+ list.append(str1)
+ elif type1 == "string":
+ value1 = str
+ functions = j["functions"]
+ functions1 = functions.split(",")
+ for v in functions1:
+ if v == "not empty" or v == "empty":
+ str1 = v + "(" + " '" + name + " '" + ")"
+ list.append(str1)
+ elif v == "in" or v == "not in":
+ str1 = name + " " + v + " " + "(" + " '" + value1 + " '" + ")"
+ list.append(str1)
+ else:
+ 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:
+ if v == "in" or v == "not in":
+ str1 = name + " " + v + " " + "(" + f"{value1}" + ")"
+ list.append(str1)
+ else:
+ str1 = name + " " + v + " " + f"{value1}"
+ list.append(str1)
+ elif type1 == "string":
+ value1 = str
+ functions = j["functions"]
+ functions1 = functions.split(",")
+ for v in functions1:
+ if v == "not empty" or v == "empty":
+ str1 = v + "(" + " '" + name + " '" + ")"
+ list.append(str1)
+ elif v == "in" or v == "not in":
+ str1 = name + " " + v + " " + "(" + " '" + value1 + " '" + ")"
+ list.append(str1)
+ else:
+ 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
+
+
+# 根据Filter1方法中的的数据,写入log请求接口中,来验证log请求接口
+def logapiverify(logurl, schemauerl, token, starttime, endtime, logtype):
+ filter2 = Filter1(schemauerl, token)
+ a = schema(schemauerl, token)
+ fields = a["data"]["fields"]
+ print(fields)
+ str2 = ""
+ for i in filter2:
+ str2 = str2 + i + " " + "and" + " "
+ url = logurl # "http://192.168.44.72:8080/v1/log/list"
+ headers = {"Content-Type": "application/json",
+ "Authorization": token}
+ data = {
+ "start_common_recv_time": starttime,
+ "end_common_recv_time": endtime,
+ "logType": logtype,
+ "fields": fields,
+ "filter": i
+ }
+ print(data)
+ print(json.dumps(data))
+ response1 = requests.post(url=url, data=json.dumps(data), headers=headers)
+ code = response1.json()["code"]
+ assert code == 200
+ print(response1.json()["code"])
+ return response1.json()
+ print(str2)
+ str3 = str2[0:-4]
+ print(str3)
+ url = logurl # "http://192.168.44.72:8080/v1/log/list"
+ headers = {"Content-Type": "application/json",
+ "Authorization": token}
+ data = {
+ "start_common_recv_time": starttime,
+ "end_common_recv_time": endtime,
+ "logType": logtype,
+ "fields": fields,
+ "filter": str3
+ }
+ print(data)
+ print(json.dumps(data))
+ response1 = requests.post(url=url, data=json.dumps(data), headers=headers)
+ code = response1.json()["code"]
+ print(response1.json())
+ assert code == 200
+ print(response1.json()["code"])
+
+
+# 精确filter,请求日志接口
+def loglistverify(logurl, schemauerl, token, starttime, endtime, logtype, filtervalue):
+ a = schema(schemauerl, token)
+ fields = a["data"]["fields"]
+ print(fields)
+ url = logurl # "http://192.168.44.72:8080/v1/log/list"
+ headers = {"Content-Type": "application/json",
+ "Authorization": token}
+ data = {
+ "start_common_recv_time": starttime,
+ "end_common_recv_time": endtime,
+ "logType": logtype,
+ "fields": fields,
+ "filter": filtervalue
+ }
+ print(data)
+ print(json.dumps(data))
+ response1 = requests.post(url=url, data=json.dumps(data), headers=headers)
+ code = response1.json()["code"]
+ print(response1.json())
+ assert code == 200
+ print(response1.json()["code"])
+ return response1.json()
+
+
+# 事件日志和通联日志时间分布查询 ,日志检索条件校验(filter内容验证)
+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}
+ response = requests.get(url=url, headers=headers)
+ code = response.json()["code"]
+ print(response.json())
+ assert code == 200
+ print(response.json()["code"])
+ return response.json()
+
+
+# 原始日志检索时间分布计算
+def timedistribution(logurl, token, starttime, endtime, logtype, granularity, filtervalue):
+ url = logurl # "http://192.168.44.72:8080/v1/log/timedistribution"
+ headers = {"Content-Type": "application/json",
+ "Authorization": token}
+ data = {
+ "startTime": starttime,
+ "endTime": endtime,
+ "logType": logtype,
+ "granularity": granularity,
+ "filter": filtervalue
+ }
+ print(data)
+ print(json.dumps(data))
+ response1 = requests.post(url=url, data=json.dumps(data), headers=headers)
+ code = response1.json()["code"]
+ print(response1.json())
+ print(response1.json()["code"])
+ assert code == 200
+ return response1.json()
+
+# 日志总数查询
+def countlog_query(logurl, token, starttime, endtime, logtype):
+ url = logurl
+ headers = {"Content-Type": "application/json",
+ "Authorization": token}
+ data = {
+ "pageSize": 20,
+ "logType": logtype,
+ "start_common_recv_time": starttime,
+ "end_common_recv_time": endtime,
+ "filter": ""
+ }
+ print(data)
+ print(json.dumps(data))
+ response1 = requests.post(url=url, data=json.dumps(data), headers=headers)
+ code = response1.json()["code"]
+ print(response1.json())
+ print(response1.json()["code"])
+ assert code == 200
+ return response1.json()
+
+# 日志导出接口
+def exportlog(logurl, schemauerl, token, starttime, endtime, logtype, filtervalue):
+ a = schema(schemauerl, token)
+ fields = a["data"]["fields"]
+ print(fields)
+ url = logurl
+ headers = {"Content-Type": "application/json",
+ "Authorization": token}
+ data = {
+ "start_common_recv_time": starttime,
+ "end_common_recv_time": endtime,
+ "logType": logtype,
+ "fields": fields,
+ "filter": filtervalue
+ }
+ print(data)
+ print(json.dumps(data))
+ response1 = requests.post(url=url, data=json.dumps(data), headers=headers)
+ a=type(response1)
+ if a != "class 'requests.models.Response'":
+ assert 1 == 1
+ else:
+ assert 1 == 2
+
+
+
+
+# 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") \ No newline at end of file
diff --git a/keyword/common/customlibrary/Custometest/StringManipulation.py b/keyword/common/customlibrary/Custometest/StringManipulation.py
new file mode 100644
index 0000000..858d6fc
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/StringManipulation.py
@@ -0,0 +1,7 @@
+from builtins import len
+
+#用于Settings和Administrator关键字对字符串的切割
+def StringSegmentation(a,k):
+ b=len(a)
+ c=a[k:b]
+ return c \ No newline at end of file
diff --git a/keyword/common/customlibrary/Custometest/UIAssert.py b/keyword/common/customlibrary/Custometest/UIAssert.py
new file mode 100644
index 0000000..267c100
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/UIAssert.py
@@ -0,0 +1,22 @@
+import ssl, socket
+
+# content of test_json_schema.py
+from jsonschema import validators
+
+
+#获取页面证书信息
+def ttt():
+ hostname = 'vip.com'
+ ctx = ssl.create_default_context()
+ with ctx.wrap_socket(socket.socket(), server_hostname=hostname) as s:
+ s.connect((hostname, 443))
+ cert = s.getpeercert()
+
+ subject = dict(x[0] for x in cert['subject'])
+ issued_to = subject['commonName']
+ issuer = dict(x[0] for x in cert['issuer'])
+ issued_by = issuer['commonName']
+ print(issued_by)
+
+
+
diff --git a/keyword/common/customlibrary/Custometest/__init__.py b/keyword/common/customlibrary/Custometest/__init__.py
new file mode 100644
index 0000000..4081636
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/__init__.py
@@ -0,0 +1,16 @@
+
+#-*- coding:utf-8 -*-
+'''
+ created by hch 2019-06-26
+'''
+
+from Custometest.printlog import printlog
+from Custometest.MD5 import MD5
+from Custometest.cmd_cer import Order
+# from custometest.printlog import printlog
+
+
+__version__ = '1.0'
+
+class Custometest(printlog,Order,MD5):
+ ROBOT_LIBRARY_SCOPE = 'GLOBAL'
diff --git a/keyword/common/customlibrary/Custometest/__pycache__/Common.cpython-36.pyc b/keyword/common/customlibrary/Custometest/__pycache__/Common.cpython-36.pyc
new file mode 100644
index 0000000..190d80c
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/__pycache__/Common.cpython-36.pyc
Binary files differ
diff --git a/keyword/common/customlibrary/Custometest/__pycache__/JsonDiff.cpython-36.pyc b/keyword/common/customlibrary/Custometest/__pycache__/JsonDiff.cpython-36.pyc
new file mode 100644
index 0000000..38716f5
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/__pycache__/JsonDiff.cpython-36.pyc
Binary files differ
diff --git a/keyword/common/customlibrary/Custometest/__pycache__/LogResponseVAL.cpython-36.pyc b/keyword/common/customlibrary/Custometest/__pycache__/LogResponseVAL.cpython-36.pyc
new file mode 100644
index 0000000..02d7ce7
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/__pycache__/LogResponseVAL.cpython-36.pyc
Binary files differ
diff --git a/keyword/common/customlibrary/Custometest/__pycache__/Schema.cpython-36.pyc b/keyword/common/customlibrary/Custometest/__pycache__/Schema.cpython-36.pyc
new file mode 100644
index 0000000..5c242a7
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/__pycache__/Schema.cpython-36.pyc
Binary files differ
diff --git a/keyword/common/customlibrary/Custometest/__pycache__/StringManipulation.cpython-36.pyc b/keyword/common/customlibrary/Custometest/__pycache__/StringManipulation.cpython-36.pyc
new file mode 100644
index 0000000..44a26a1
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/__pycache__/StringManipulation.cpython-36.pyc
Binary files differ
diff --git a/keyword/common/customlibrary/Custometest/__pycache__/UIAssert.cpython-36.pyc b/keyword/common/customlibrary/Custometest/__pycache__/UIAssert.cpython-36.pyc
new file mode 100644
index 0000000..30038ed
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/__pycache__/UIAssert.cpython-36.pyc
Binary files differ
diff --git a/keyword/common/customlibrary/Custometest/__pycache__/log_contrast.cpython-36.pyc b/keyword/common/customlibrary/Custometest/__pycache__/log_contrast.cpython-36.pyc
new file mode 100644
index 0000000..f6ad333
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/__pycache__/log_contrast.cpython-36.pyc
Binary files differ
diff --git a/keyword/common/customlibrary/Custometest/certificate.yaml b/keyword/common/customlibrary/Custometest/certificate.yaml
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/certificate.yaml
diff --git a/keyword/common/customlibrary/Custometest/cmd_cer.py b/keyword/common/customlibrary/Custometest/cmd_cer.py
new file mode 100644
index 0000000..50cdf08
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/cmd_cer.py
@@ -0,0 +1,290 @@
+import os
+import subprocess
+from time import sleep
+import platform
+
+
+
+class Order:
+ def CMD(self,data):
+ result = os.popen(data)
+ # res = result.read().encoding('GBK')
+ res = result.read()
+ result.close()
+ # res = res.decode("unicode-escape")
+ return res
+ def Linux(self):
+ pass
+ # 根据证书颁发者名字判断证书是否替换
+ def Cert_Verification(self,data):
+ c = []
+ print(1)
+ #with open(r'C:\Users\iiesoft\AppData\Local\Programs\Python\Python36\Lib\site-packages\custometest\certificate.yaml', 'r') as foo:
+ with open(r'certificate.yaml', 'r') as foo:
+ print(2)
+ for line in foo.readlines():
+ if data in line:
+ print(line)
+ c.append('证书已替换')
+ else:
+ pass
+ if '证书已替换' in c:
+ # print('证书已替换')
+ foo.close()
+ return '证书已替换'
+ else:
+ # print('证书未替换')
+ foo.close()
+ return '证书未替换'
+
+ def Content_Type(self,data):
+ d = []
+ with open('certificate.yaml', 'r') as foo:
+ for line in foo.readlines():
+ if data in line:
+ # print(line)
+ d.append('Content_Type已替换')
+ else:
+ pass
+ if 'Content_Type已替换' in d:
+ # print('证书已替换')
+ foo.close()
+ return 'Content_Type已替换'
+ else:
+ # print('证书未替换')
+ foo.close()
+ return 'Content_Type未替换'
+ # curl路由内容设置
+ def curl_name(self,data):
+ #curl_name = 'curl -kv -m 10 -1 --trace C:/Users/iiesoft/AppData/Local/Programs/Python/Python36/Lib/site-packages/custometest/certificate.yaml '+data+'| iconv -f utf-8 -t gbk'
+ curl_name = 'curl -kv -m 10 -1 --trace certificate.yaml '+data+'| iconv -f utf-8 -t gbk'
+ return curl_name
+ # 控制器
+ def manu(self,url,Certificate):
+ # print(data['url'])
+ n = 0
+ while n != len(url):
+ b = self.curl_name(url[n])
+ d = self.CMD(b)
+ # print(d)
+ sleep(1)
+ if Certificate != "":
+ c =self.Cert_Verification(Certificate)
+ # f = self.Content_Type(data["Content_Type"])
+ sleep(1)
+ assert_cer = url[n]+c
+ # assert_Content_Type = data['Content_Type']+f
+ n+=1
+ return d,assert_cer
+
+ def FTP(self, ftp_type):
+ windows_path = os.getcwd()
+ linux_path = os.getcwd().replace('\\', '/')
+ # 判断FTP执行类型:(下载/登录)
+ if ftp_type == "下载":
+ # 调用cmd执行FTP下载文件
+ data = 'curl -m 20 ftp://202.38.97.230/pub/iso/linux/knoppix/KNOPPIX_V7.7.1DVD-2016-10-22-EN/dpkg-l-dvd-771.txt -u"anonymous:[email protected]" -o zmmtext123.txt'
+ d = self.CMD(data)
+ sleep(5)
+ fsize = os.path.getsize(linux_path + "/zmmtext123.txt") # 435814
+ if fsize == 435814:
+ return "ftp_success"
+ else:
+ return "ftp_fail"
+ elif ftp_type == "登录":
+ data = 'curl -m 10 ftp://202.38.97.230/pub/iso/linux/knoppix/KNOPPIX_V7.7.1DVD-2016-10-22-EN/dpkg-l-dvd-771.txt -u"anonymous:[email protected]" | iconv -f utf-8 -t gbk'
+ d = self.CMD(data)
+ # print(d)
+ if "Graphical (Xorg) program starter for ADRIANE" in d:
+ return "ftp_success"
+ else:
+ return "ftp_fail"
+ # FTP 下载
+ def FTP_down(self, ftp_url,file_size,file_name):
+ windows_path = os.getcwd()
+ linux_path = os.getcwd().replace('\\', '/')
+ # 判断FTP执行类型:(下载/登录)
+ # 调用cmd执行FTP下载文件
+ data = 'curl -m 20 '+ftp_url+ '-o '+ file_name + " ' "
+ print(data)
+ d = self.CMD(data)
+ sleep(5)
+ fsize = os.path.getsize(linux_path + "/"+file_name) # 435814
+ print(fsize)
+ if fsize == file_size:
+ return "ftp_success"
+ else:
+ return "ftp_fail"
+
+ # FTP 登录
+ def FTP_login(self, ftp_url,file_content):
+ SYS = self.Operating_System()
+ if SYS == "Windows":
+ data = 'curl -m 10 '+ftp_url+' | iconv -f utf-8 -t gbk'
+ d = self.CMD(data)
+ else:
+ data = 'curl -m 10 '+ftp_url+' | iconv -f utf-8 -t gbk'
+ d = self.CMD(data)
+
+ if file_content in d:
+ return "ftp_success"
+ else:
+ return "ftp_fail"
+
+ # 判断当前操作系统
+ def Operating_System(self):
+ os_name = platform.system()
+ return os_name
+
+
+ #需要替换的内容进行循环替换 jsons为初始默认json datas为需要替换的内容
+ # 全局变量 null,将java中的空值(null),装换位python中空值("")
+ global null
+ null = ''
+
+ # 对需要替换的内容进行循环替换 jsons为初始默认json datas为需要替换的内容,header 启用自定义json
+ def Jsoneditmanu(self, jsons, datas=None,header=None):
+ #判断是否启用自定义json
+ if header != None:
+ header = eval(header)
+ # 返回 header
+ return header
+ # 判断是否需要更改json内容
+ elif datas != None:
+ # datas = eval(datas)
+ jsons = eval(jsons)
+ # 循环遍历替换json内容
+ for k, v in datas.items():
+ Order.UpdateAllvalues(self,jsons, k, v)
+ return jsons
+ else:
+ # 返回初始json
+ return jsons
+
+ # 循环嵌套替换
+ def UpdateAllvalues(self,mydict, key, value):
+ if isinstance(mydict, dict): # 使用isinstance检测数据类型,如果是字典
+ if key in mydict.keys(): # 替换字典第一层中所有key与传参一致的key
+ mydict[key] = value
+ for k in mydict.keys(): # 遍历字典的所有子层级,将子层级赋值为变量chdict,分别替换子层级第一层中所有key对应的value,最后在把替换后的子层级赋值给当前处理的key
+ chdict = mydict[k]
+ Order.UpdateAllvalues(self,chdict, key, value)
+ mydict[k] = chdict
+ elif isinstance(mydict, list): # 如是list
+ for element in mydict: # 遍历list元素,以下重复上面的操作
+ if isinstance(element, dict):
+ if key in element.keys():
+ element[key] = value
+ for k in element.keys():
+ chdict = element[k]
+ Order.UpdateAllvalues(self,chdict, key, value)
+ element[k] = chdict
+
+
+
+ #递归提取json中符合要求键的值
+ import json
+ def get_dict_allkeys(self,dict_a):
+ """
+ 遍历嵌套字典,获取json返回结果的所有key值
+ :param dict_a:
+ :return: key_list
+ """
+ if isinstance(dict_a, dict): # 使用isinstance检测数据类型
+ # 如果为字典类型,则提取key存放到key_list中
+ for x in range(len(dict_a)):
+ temp_key = list(dict_a.keys())[x]
+ temp_value = dict_a[temp_key]
+ if temp_key.endswith("Id"):
+ key_list.append(temp_value)
+ Order.get_dict_allkeys(self,temp_value) # 自我调用实现无限遍历
+ elif isinstance(dict_a, list):
+ # 如果为列表类型,则遍历列表里的元素,将字典类型的按照上面的方法提取key
+ for k in dict_a:
+ if isinstance(k, dict):
+ for x in range(len(k)):
+ temp_key = list(k.keys())[x]
+ temp_value = k[temp_key]
+ if temp_key.endswith("Id"):
+ key_list.append(temp_value)
+ Order.get_dict_allkeys(self,temp_value) # 自我调用实现无限遍历
+ return key_list
+
+ # 判断值是否在列表中
+ def VerifyProxy(self,data,lists):
+ global key_list
+ key_list = []
+ datas = Order.get_dict_allkeys(self,data)
+ print(type(datas))
+ lists=lists.split(",")
+ print(type(lists))
+ print("gsd")
+ datas2=list(map(str,datas))
+ print(datas2)
+ print(datas)
+ print(lists)
+
+ if set(datas2) > set(lists):
+ return "true"
+ else:
+ return "flase"
+
+
+if __name__ == '__main__':
+# datas = {"url":['https://www.baidu.com'],
+# "Certificate":"Tango Secure Gateway CA",
+# # "Content_Type":"text/html",
+# 'log':'Security Event Logs',
+# "sni":['baidu'],
+# "intercept_code":"200",
+# "log_code":"200",
+# "certifucate":"1",
+# "log_content":"true"
+# }
+# # data= {"url":['https://www.baidu.com'],
+# # "Certificate":"Tango Secure Gateway CA"
+# # }
+# # url = ['https://www.baidu.com']
+# # url = ['https://www.baidu.com']
+# # url = ['https://www.baidu.com']
+# # # Certificate1 = "Tango Secure Gateway CA"
+# # Certificate = "baidu"
+# # a='Tango Secure Gateway CA'
+# # s = Order()
+# # b = s.manu(url,Certificate)
+# # print(b[1])
+# # FTP下载 传入ftp的路径和文件大小
+# ftp_url = 'ftp://202.38.97.230/pub/iso/linux/knoppix/KNOPPIX_V7.7.1DVD-2016-10-22-EN/dpkg-l-dvd-771.txt -u"anonymous:[email protected]" '
+# ftp_size = 435814
+# ftp_issue = s.FTP_down(ftp_url,ftp_size)
+# # FTP登录 传入ftp的路径和文件内容
+# ftp_url ='ftp://202.38.97.230/pub/iso/linux/knoppix/KNOPPIX_V7.7.1DVD-2016-10-22-EN/dpkg-l-dvd-771.txt -u"anonymous:[email protected]" '
+# file_content = "Graphical (Xorg) program starter for ADRIANE"
+# ftp_issue = s.FTP_login(ftp_url,file_content)
+ # for i in b:
+ # print(i)
+ # dd = s.CMD('curl -I https://www.baidu.com')
+ # print(dd)
+ # if "private, no-cache, no-store, proxy-revalidate, no-transform"in dd:
+ # print("ok")
+ # a ='curl -kv -1 --trace certificate.yaml https://www.baidu.com | iconv -f utf-8 -t gbk'
+
+
+ # 自己写一个字典测试一下上面的方法好用不好用
+ jsons = {"opAction":"add","policyList":{"policyId":"","policyName":"2324242423","policyType":"tsg_security","action":"intercept","userTags":"","doBlacklist":0,"doLog":1,"policyDesc":"","effectiveRange":{"tag_sets":[[]]},"userRegion":{"protocol":"SSL","keyring":1,"decryption":1,"decrypt_mirror":{"enable":0,"mirror_profile":null}},"referenceObject":[{"objectId":28054,"protocolFields":["TSG_SECURITY_SOURCE_ADDR"]}],"isValid":0,"scheduleId":[],"appObjectIdArray":[3]}}
+ datas = {"protocol":"edit","opAction":"edit","policyId":123,'protocolFields':1}
+
+ print("替换前:\n %s" % jsons)
+
+
+ a = Order()
+ b = a.Jsoneditmanu(jsons,datas)
+ # print("替换前:\n %s" % jsons)
+ print("替换后:\n %s" % b)
+
+ data = {"aid":[{'bid':2},{'cid':3}]}
+ print(type(data))
+ # data="""{}"""
+ # data1 = json.loads(data)
+ get_keys = get_dict_allkeys(data)
+ print(get_keys)
diff --git a/keyword/common/customlibrary/Custometest/log_contrast.py b/keyword/common/customlibrary/Custometest/log_contrast.py
new file mode 100644
index 0000000..96e5e35
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/log_contrast.py
@@ -0,0 +1,8 @@
+#!/user/bin/python
+#-*-coding:utf-8-*-
+def log_contrast(logs,client_ip,policy_id,parmkey,parmvalue):
+ if (str(client_ip) in str(logs))and (str(policy_id) in str(logs)) and (str(parmkey) in str(logs)) and (str(parmvalue) in str(logs)):
+ print(logs)
+ return "true"
+ else:
+ return "false"
diff --git a/keyword/common/customlibrary/Custometest/printlog.py b/keyword/common/customlibrary/Custometest/printlog.py
new file mode 100644
index 0000000..02f8ced
--- /dev/null
+++ b/keyword/common/customlibrary/Custometest/printlog.py
@@ -0,0 +1,11 @@
+
+#-*- coding:utf-8 -*-
+'''
+ created by hch 2019-06-26
+'''
+
+
+class printlog():
+
+ def printA():
+ print("hello word") \ No newline at end of file
diff --git a/keyword/common/customlibrary/ExtensionPackages/ExtensionLibrary/__init__.py b/keyword/common/customlibrary/ExtensionPackages/ExtensionLibrary/__init__.py
new file mode 100644
index 0000000..e60bf56
--- /dev/null
+++ b/keyword/common/customlibrary/ExtensionPackages/ExtensionLibrary/__init__.py
@@ -0,0 +1,7 @@
+#coding=utf-8
+from mytool import mytool
+
+version = '1.0'
+
+class ExtensionLibrary(mytool):
+ ROBOT_LIBRARY_SCOPE = 'GLOBAL' \ No newline at end of file
diff --git a/keyword/common/customlibrary/ExtensionPackages/ExtensionLibrary/mytool.py b/keyword/common/customlibrary/ExtensionPackages/ExtensionLibrary/mytool.py
new file mode 100644
index 0000000..03440cb
--- /dev/null
+++ b/keyword/common/customlibrary/ExtensionPackages/ExtensionLibrary/mytool.py
@@ -0,0 +1,26 @@
+#coding=utf-8
+import socket
+
+""" 获取主机信息 """
+class mytool():
+ def __init__(self):
+ pass
+
+ def get_host_IP(self, flag="50"):
+ #try:
+ #s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ #s.connect(('8.8.8.8', 80))
+ #ip = s.getsockname()[0]
+ #finally:
+ #s.close()
+ hostname = socket.gethostname()
+ ipTriple = socket.gethostbyname_ex(hostname)
+ ips = list(ipTriple[2:])
+ ip = ""
+ for i in ips:
+ ipList = list(i)
+ for ip1 in ipList:
+ if "."+flag+"." in ip1:
+ ip = ip1
+ break
+ return ip \ No newline at end of file
diff --git a/keyword/common/customlibrary/ExtensionPackages/FileLibrary/__init__.py b/keyword/common/customlibrary/ExtensionPackages/FileLibrary/__init__.py
new file mode 100644
index 0000000..29db0ed
--- /dev/null
+++ b/keyword/common/customlibrary/ExtensionPackages/FileLibrary/__init__.py
@@ -0,0 +1,7 @@
+#coding=utf-8
+from filetool import filetool
+
+version = '1.0'
+
+class FileLibrary(filetool):
+ ROBOT_LIBRARY_SCOPE = 'GLOBAL' \ No newline at end of file
diff --git a/keyword/common/customlibrary/ExtensionPackages/FileLibrary/filetool.py b/keyword/common/customlibrary/ExtensionPackages/FileLibrary/filetool.py
new file mode 100644
index 0000000..8ad1ef7
--- /dev/null
+++ b/keyword/common/customlibrary/ExtensionPackages/FileLibrary/filetool.py
@@ -0,0 +1,22 @@
+#coding=utf-8
+
+""" 变量文件操作 """
+class filetool():
+ def __init__(self):
+ pass
+
+ def alter_dict(self, path, k, v):
+ data = ''
+ flag = True
+ key = '${%s}' % (k)
+ add = key + '\t%s' % (v) + '\n'
+ with open(path, 'r+') as f:
+ for line in f.readlines():
+ if(line.find(key + '\t') == 0):
+ line = add
+ flag = False
+ data += line
+ if(flag):
+ data += add
+ with open(path, 'w+') as f:
+ f.writelines(data) \ No newline at end of file
diff --git a/keyword/common/customlibrary/ExtensionPackages/GetTimeLibrary/GetTime.py b/keyword/common/customlibrary/ExtensionPackages/GetTimeLibrary/GetTime.py
new file mode 100644
index 0000000..7df32d2
--- /dev/null
+++ b/keyword/common/customlibrary/ExtensionPackages/GetTimeLibrary/GetTime.py
@@ -0,0 +1,85 @@
+#coding=utf-8
+import datetime
+import time
+import string
+class GetTime():
+ def __init__(self):
+ pass
+ def time1(self,t):
+ if t=="m":
+ print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
+ if time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))[-4] >= "5":
+ time2=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))[0:-4]+"5:00"
+ return time2
+ else:
+ time2=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))[0:-4] + "0:00"
+ return time2
+ elif t=="s":
+ if time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))[-2] >= "3":
+ time2=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))[0:-2]+"30"
+ return time2
+ else:
+ time2=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))[0:-2] + "00"
+ return time2
+ elif t=="h":
+ time2=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))[0:-7]+":00:00"
+ startTime = datetime.datetime.strptime(time2, "%Y-%m-%d %H:%M:%S")
+ startTime2 = (startTime + datetime.timedelta(hours=-1)).strftime("%Y-%m-%d %H:%M:%S")
+ return startTime2
+ elif t=="5m":
+ time2 = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
+ print(time2)
+ startTime = datetime.datetime.strptime(time2, "%Y-%m-%d %H:%M:%S")
+ startTime2 = (startTime + datetime.timedelta(minutes=-5)).strftime("%Y-%m-%d %H:%M:%S")
+ if startTime2[-4]>="5":
+ time3 = startTime2[0:-4] + "5:00"
+ print(time3)
+ else:
+ time3 = startTime2[0:-4] + "0:00"
+ print(time3)
+ return time3
+ elif t== "30s":
+ time2 = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
+ print(time2)
+ startTime = datetime.datetime.strptime(time2, "%Y-%m-%d %H:%M:%S")
+ startTime2 = (startTime + datetime.timedelta(seconds=-30)).strftime("%Y-%m-%d %H:%M:%S")
+ if startTime2[-2] >= "3":
+ time3 = startTime2[0:-2]+"30"
+ print(time3)
+ return time3
+ else:
+ time3 = startTime2[0:-2]+"00"
+ print(time3)
+ return time3
+ def str2sec(self,x):
+ a, b = x.strip().split(' ')
+ y, m, d = a.strip().split('-')
+
+ h, m, s = b.strip().split(':') #.split()函数将其通过':'分隔开,.strip()函数用来除去空格
+
+ return int(h)*3600 + int(m)*60 + int(s),d #int()函数转换成整数运算
+ def intersection(self,a,b):
+ c= 0
+ f = 0
+ for j in a:
+
+ for i in j:
+ if i in b[f]:
+ print(i)
+ print(b[f])
+ c= c+1
+ f = f + 1
+ d = len(b)*len(b[0])
+ if d == 0:
+ e=0
+ elif c==0:
+ e = 0
+ else:
+ e = c/d
+ if e >= 0.8 :
+ return "ture"
+ else:
+ return "false"
+
+
+
diff --git a/keyword/common/customlibrary/ExtensionPackages/GetTimeLibrary/__init__.py b/keyword/common/customlibrary/ExtensionPackages/GetTimeLibrary/__init__.py
new file mode 100644
index 0000000..c0f47eb
--- /dev/null
+++ b/keyword/common/customlibrary/ExtensionPackages/GetTimeLibrary/__init__.py
@@ -0,0 +1,6 @@
+#coding=utf-8
+from GetTimeLibrary.GetTime import GetTime
+
+__version__ = '1.0'
+class GetTimeLibrary(GetTime):
+ ROBOT_LIBRARY_SCOPE = 'GLOBAL' \ No newline at end of file
diff --git a/keyword/common/customlibrary/ExtensionPackages/extensionLibrary.pth b/keyword/common/customlibrary/ExtensionPackages/extensionLibrary.pth
new file mode 100644
index 0000000..73e1268
--- /dev/null
+++ b/keyword/common/customlibrary/ExtensionPackages/extensionLibrary.pth
@@ -0,0 +1,2 @@
+ExtensionLibrary
+FileLibrary \ No newline at end of file
diff --git a/keyword/common/customlibrary/ExtensionPackages/readme.txt b/keyword/common/customlibrary/ExtensionPackages/readme.txt
new file mode 100644
index 0000000..e3b091b
--- /dev/null
+++ b/keyword/common/customlibrary/ExtensionPackages/readme.txt
@@ -0,0 +1,4 @@
+# 导入方法:
+# 1、将‘extensionLibrary.pth’文件放到...\Python\Lib\site-packages目录下
+# 2、根据需要将包目录同‘extensionLibrary.pth’文件一同放到...\Python\Lib\site-packages目录下(目前有‘ExtensionLibrary’和‘FileLibrary’)
+# 3、在测试夹中导入此包即可使用扩展功能 \ No newline at end of file
diff --git a/keyword/common/customlibrary/Library/VerifyPolicy.py b/keyword/common/customlibrary/Library/VerifyPolicy.py
new file mode 100644
index 0000000..a0bce71
--- /dev/null
+++ b/keyword/common/customlibrary/Library/VerifyPolicy.py
@@ -0,0 +1,38 @@
+import json
+def get_dict_allkeys(dict_a):
+ if isinstance(dict_a, dict): # 使用isinstance检测数据类型
+ # 如果为字典类型,则提取key存放到key_list中
+ for x in range(len(dict_a)):
+ temp_key = list(dict_a.keys())[x]
+ temp_value = dict_a[temp_key]
+ if temp_key.endswith("Id"):
+ key_list.append(temp_value)
+ get_dict_allkeys(temp_value) # 自我调用实现无限遍历
+ elif isinstance(dict_a, list):
+ # 如果为列表类型,则遍历列表里的元素,将字典类型的按照上面的方法提取key
+ for k in dict_a:
+ if isinstance(k, dict):
+ for x in range(len(k)):
+ temp_key = list(k.keys())[x]
+ temp_value = k[temp_key]
+ if temp_key.endswith("Id"):
+ key_list.append(temp_value)
+ get_dict_allkeys(temp_value) # 自我调用实现无限遍历
+ return key_list
+def VerifyProxy(data,lists):
+ global key_list
+ key_list = []
+ datas = get_dict_allkeys(data)
+ print(type(datas))
+ lists=lists.split(",")
+ print(type(lists))
+ print("gsd")
+ datas2=list(map(str,datas))
+ print(datas2)
+ print(datas)
+ print(lists)
+
+ if set(datas2) > set(lists):
+ return "true"
+ else:
+ return "flase"
diff --git a/keyword/common/customlibrary/Library/__pycache__/VerifyPolicy.cpython-36.pyc b/keyword/common/customlibrary/Library/__pycache__/VerifyPolicy.cpython-36.pyc
new file mode 100644
index 0000000..12341de
--- /dev/null
+++ b/keyword/common/customlibrary/Library/__pycache__/VerifyPolicy.cpython-36.pyc
Binary files differ
diff --git a/keyword/common/customlibrary/Library/__pycache__/delUseless.cpython-36.pyc b/keyword/common/customlibrary/Library/__pycache__/delUseless.cpython-36.pyc
new file mode 100644
index 0000000..694ad83
--- /dev/null
+++ b/keyword/common/customlibrary/Library/__pycache__/delUseless.cpython-36.pyc
Binary files differ
diff --git a/keyword/common/customlibrary/Library/__pycache__/fileOperations.cpython-36.pyc b/keyword/common/customlibrary/Library/__pycache__/fileOperations.cpython-36.pyc
new file mode 100644
index 0000000..62d758f
--- /dev/null
+++ b/keyword/common/customlibrary/Library/__pycache__/fileOperations.cpython-36.pyc
Binary files differ
diff --git a/keyword/common/customlibrary/Library/delUseless.py b/keyword/common/customlibrary/Library/delUseless.py
new file mode 100644
index 0000000..3039794
--- /dev/null
+++ b/keyword/common/customlibrary/Library/delUseless.py
@@ -0,0 +1,45 @@
+import json
+def dict_del(key, obj):
+ if isinstance(obj, dict):
+ if key in obj:
+ obj.pop(key)
+ #print(obj.items())
+ for k, v in obj.items():
+ #print(obj.items())
+ if v is None:
+ v = '666'
+ else:
+ pass
+ dict_del(key, v)
+ elif isinstance(obj, list):
+ for x in obj:
+ dict_del(key, x)
+ else:
+ pass
+ #print(type(obj))
+ obj = json.dumps(obj)
+ return obj
+def deal(jsondata, keylist):
+ jsondata = json.loads(jsondata)
+ if "data" in jsondata.keys():
+ jsondata = jsondata["data"]
+ else:
+ pass
+ # jsondata = '{"opAction":"add","refuseCode":true,"returnData":1,"objectList":{"objectType":"fqdn","objectSubType":"fqdn","isValid":1,"isInitialize":0,"isExclusion":0,"objectName":"hbn_test_fqdn","objectDesc":"","subObjectIds":[],"addItemList":[{"keywordArray":["*abcds"],"t":"16191477536650","itemId":"","isHexbin":0,"state":2}],"updateItemList":[],"deleteItemIds":[],"iconColor":"#31739C"}}'
+ # keylist = ["objectType","objectSubType","isValid","isInitialize"]
+ # len2 = len(keylist)
+ # print("aaaaaaaaaaaaaaaaaaaaaaaaaa"+str(len2))
+ # for num in range(len2):
+ # retstr = dict_del(keylist[num], jsondata)
+ # print("#############################"+retstr)
+ # return retstr
+#for num in range(len2):
+ #print("$$$$$$$$$$$$$$$$$$"+dict_del(keylist[num],jsondata))
+ #key1 = keylist[num]
+ #print(num)
+ #print("#############################"+dict_del(key1,jsondata))
+ len1 = len(keylist)
+ for num in range(len1):
+ retstr = dict_del(keylist[num], jsondata)
+ dict_del(keylist[num], jsondata)
+ return retstr \ No newline at end of file
diff --git a/keyword/common/customlibrary/Library/fileOperations.py b/keyword/common/customlibrary/Library/fileOperations.py
new file mode 100644
index 0000000..4029e26
--- /dev/null
+++ b/keyword/common/customlibrary/Library/fileOperations.py
@@ -0,0 +1,26 @@
+def CountLines(fname):
+ count = 0
+ with open(fname, 'rb') as f:
+ for file_line in f:
+ file_line = file_line.strip()
+ # print(file_line)
+ # 空行
+ if file_line == b'':
+ pass
+
+ # 注释 # 开头
+ elif file_line.startswith(b'-->'):
+ pass
+
+ # 代码
+ else:
+ count += 1
+ print(fname + '----', count)
+ # 单个文件行数
+ # print(fname,'----count:',count)
+ return count
+def WriteBinary(response,path1):
+ with open(path1,"wb") as f2:
+ strb = response
+ f2.write(strb)
+
diff --git a/keyword/common/customlibrary/Pop3Library/__init__.py b/keyword/common/customlibrary/Pop3Library/__init__.py
new file mode 100644
index 0000000..66219ac
--- /dev/null
+++ b/keyword/common/customlibrary/Pop3Library/__init__.py
@@ -0,0 +1,200 @@
+import poplib
+import base64
+import time
+from email.parser import Parser
+# 用来解析邮件主题
+from email.header import decode_header
+# 用来解析邮件来源
+from email.utils import parseaddr
+
+from robot.api.deco import keyword
+from robot.api import logger
+
+
+class AcceptEmail(object):
+
+ def __init__(self, user_email, password, pop3_server='serverDemon'):
+ self.user_email = user_email
+ self.password = password
+ self.pop3_server = pop3_server
+
+ self.connect_email_server()
+
+ def connect_email_server(self):
+ self.server = poplib.POP3(self.pop3_server)
+ # 打印POP3服务器的欢迎文字,验证是否正确连接到了邮件服务器
+ # print('连接成功 -- ', self.server.getwelcome().decode('utf8'))
+ # +OK QQMail POP3 Server v1.0 Service Ready(QQMail v2.0)
+
+ # 开始进行身份验证
+ self.server.user(self.user_email)
+ self.server.pass_(self.password)
+
+ def __del__(self):
+ # 关闭与服务器的连接,释放资源
+ self.server.close()
+
+ def get_email_count(self):
+ # 返回邮件总数目和占用服务器的空间大小(字节数), 通过stat()方法即可
+ email_num, email_size = self.server.stat()
+ # print("消息的数量: {0}, 消息的总大小: {1}".format(email_num, email_size))
+ return email_num
+
+ def receive_email_info(self, now_count=None):
+ # 返回邮件总数目和占用服务器的空间大小(字节数), 通过stat()方法即可
+ email_num, email_size = self.server.stat()
+ # print("消息的数量: {0}, 消息的总大小: {1}".format(email_num, email_size))
+ self.email_count = email_num
+ self.email_sumsize = email_size
+
+ # 使用list()返回所有邮件的编号,默认为字节类型的串
+ rsp, msg_list, rsp_siz = self.server.list()
+ # print(msg_list, '邮件数量',len(msg_list))
+ # print("服务器的响应: {0},\n消息列表: {1},\n返回消息的大小: {2}".format(rsp, msg_list, rsp_siz))
+ # print('邮件总数: {}'.format(len(msg_list)))
+ self.response_status = rsp
+ self.response_size = rsp_siz
+
+ # 下面获取最新的一封邮件,某个邮件下标(1开始算)
+ # total_mail_numbers = len(msg_list)
+
+ # 动态取消息
+ total_mail_numbers = now_count
+
+ rsp, msglines, msgsiz = self.server.retr(total_mail_numbers)
+ # rsp, msglines, msgsiz = self.server.retr(1)
+ # print("服务器的响应: {0},\n原始邮件内容: {1},\n该封邮件所占字节大小: {2}".format(rsp, msglines, msgsiz))
+
+ # 从邮件原内容中解析
+ msg_content = b'\r\n'.join(msglines).decode('utf-8')#gbk
+ msg = Parser().parsestr(text=msg_content)
+ self.msg = msg
+ # print('解码后的邮件信息:\n{}'.format(msg))
+
+ def recv(self, now_count=None):
+ self.receive_email_info(now_count)
+ self.parser()
+
+ def get_email_title(self):
+ subject = self.msg['Subject']
+ value, charset = decode_header(subject)[0]
+ if charset:
+ value = value.decode(charset)
+ # print('邮件主题: {0}'.format(value))
+ self.email_title = value
+
+ def get_sender_info(self):
+ hdr, addr = parseaddr(self.msg['From'])
+ # name 发送人邮箱名称, addr 发送人邮箱地址
+ name, charset = decode_header(hdr)[0]
+ if charset:
+ name = name.decode(charset)
+ self.sender_qq_name = name
+ self.sender_qq_email = addr
+ # print('发送人邮箱名称: {0},发送人邮箱地址: {1}'.format(name, addr))
+
+ def get_email_content(self):
+ content = self.msg.get_payload()
+ # 文本信息
+ content_charset = content[0].get_content_charset() # 获取编码格式
+ text = content[0].as_string().split('base64')[-1]
+ text_content = base64.b64decode(text).decode(content_charset) # base64解码
+ self.email_content = text_content
+ # print('邮件内容: {0}'.format(text_content))
+
+ # 添加了HTML代码的信息
+ content_charset = content[1].get_content_charset()
+ text = content[1].as_string().split('base64')[-1]
+ # html_content = base64.b64decode(text).decode(content_charset)
+
+ # print('文本信息: {0}\n添加了HTML代码的信息: {1}'.format(text_content, html_content))
+
+ def parser(self):
+ self.get_email_title()
+ self.get_sender_info()
+ #self.get_email_content()
+
+
+def get_new_mail(user_name, pwd, pop3_server, second=5):
+ t = AcceptEmail(user_name, pwd, pop3_server)
+ now_count = t.get_email_count()
+ #print('开启的时候的邮件数量为:%s' % now_count)
+ logger.info("开启的时候的邮件数量为:"+str(now_count))
+ # 每次需要重新连接邮箱服务器,才能获取到最新的消息
+ # 默认每隔5秒看一次是否有新内容
+ num = 0
+ while True:
+ obj = AcceptEmail(user_name, pwd, pop3_server)
+ count = obj.get_email_count()
+ if count > now_count:
+ new_mail_count = count - now_count
+ #print('有新的邮件数量:%s' % new_mail_count)
+ logger.info("有新的邮件数量:"+str(new_mail_count))
+ now_count += 1
+ obj.recv(now_count)
+
+ yield {"title": obj.email_title, "sender": obj.sender_qq_name, "sender_email": obj.sender_qq_email}
+ #yield {"title": obj.email_title, "sender": obj.sender_qq_name, "sender_email": obj.sender_qq_email,
+ # "email_content": obj.email_content}
+ if new_mail_count > 0:
+ return
+ # print('-' * 30)
+ # print("邮件主题:%s\n发件人:%s\n发件人邮箱:%s\n邮件内容:%s" % (
+ # obj.email_title, obj.sender_qq_name, obj.sender_qq_email, obj.email_content))
+ # print('-' * 30)
+
+ #else:
+ #print('没有任何新消息.')
+ #logger.info("没有任何新消息.")
+ time.sleep(second)
+ num += 1
+ if num == 36:#等待时间粒度,一个粒度是5s,如果num=10意思就是等待接收邮件50s,若没有邮件就返回;36是等待3min
+ return
+
+
+@keyword('Recv Email')
+def recv_email(user_name, pwd, pop3_server, send_user, subj):
+ '''
+ 参数说明:
+ [user_name]:用户名
+ [pwd]:密码,第三方登入密码
+ [pop server]:pop服务器
+ [sender]:发送者邮箱,注意全称
+ [subj_sub]:主题的部分内容,这里是测主题是否包含该参数
+ [return]:返回值,成功返回success,失败返回n其他
+ 其他问题请阅读该库的readme.txt
+ '''
+ dic = {}
+ logger.info("正在监听邮件服务器端是否有新消息---")
+ #print('正在监听邮件服务器端是否有新消息---')
+ try:
+ iterator = get_new_mail(user_name, pwd, pop3_server)
+ except TypeError:
+ #print('监听的内容有误,有图片数据等,无法解析而报错,不是纯文本内容')
+ logger.info("监听的内容有误,有图片数据等,无法解析而报错,不是纯文本内容")
+ return "fail"
+ else:
+ for dic in iterator:
+ #print("邮件主题:%s\n发件人:%s\n发件人邮箱:%s\n邮件内容:%s" % (
+ # dic["title"], dic["sender"], dic["sender_email"], dic["email_content"]))
+ #logger.info("邮件主题: " + str(dic["title"]) + " 发件人: " + str(dic["sender"])+"发件人邮箱:"+str(dic["sender_email"]))
+ if dic["sender"] == send_user:
+ #logger.info("发送者一样")
+ if subj in dic["title"]:
+ #logger.info("主题也包含")
+ return "success"
+ else:
+ #logger.info("主题不包含")
+ return "fail"
+ else:
+ return "fail"
+
+
+#if __name__ == '__main__':
+# user = '[email protected]'
+# pwd = 'xxxx'
+# pop3_server = 'pop.qq.com'
+# send_user = '[email protected]'
+# subj = 'or2020'
+# result = recv_email(user, pwd, pop3_server, send_user, subj)
+# print(result) \ No newline at end of file
diff --git a/keyword/common/customlibrary/Pop3Library/__pycache__/__init__.cpython-36.pyc b/keyword/common/customlibrary/Pop3Library/__pycache__/__init__.cpython-36.pyc
new file mode 100644
index 0000000..ecd3bf5
--- /dev/null
+++ b/keyword/common/customlibrary/Pop3Library/__pycache__/__init__.cpython-36.pyc
Binary files differ
diff --git a/keyword/common/customlibrary/Pop3Library/readme.txt b/keyword/common/customlibrary/Pop3Library/readme.txt
new file mode 100644
index 0000000..42c7c9b
--- /dev/null
+++ b/keyword/common/customlibrary/Pop3Library/readme.txt
@@ -0,0 +1,26 @@
+导入方法:
+1.将该目录放到....\Python\Lib\site-packages 下
+2.在测试夹具里面要根据绝对路径导入此包
+
+
+注意:
+1.使用该包的关键字时不要用qq邮箱,qq邮箱测试发现时长会失灵现象,最好用163邮箱等
+2.注意关闭邮箱的加密传送方式SSL协议
+3.注意邮箱是否支持POP3的协议以及不同邮箱pop服务器的写法
+
+
+关键字:
+[return] Recv Email [user_name] [pwd] [pop server] [sender] [subj_sub]
+参数说明:
+[user_name]:用户名
+[pwd]:密码,第三方登入密码
+[pop server]:pop服务器
+[sender]:发送者邮箱,注意全称
+[subj_sub]:主题的部分内容,这里是测主题是否包含该参数
+[return]:返回值,成功返回success,失败返回n其他
+该关键字默认等待3min,3min内每5s检测邮箱是否收到邮件,
+若收到邮件与[sender]参数进行完全匹配,与[subj_sub]部分主题内容参数进行是否包含匹配,匹配成功则返回success;
+若收到邮件匹配失败或者超时则返回其他,
+
+
+若修改等待时间,可查找源码中的num变量将36改为其他值即可,注意时间粒度是5s,若num=3,则您修改的等待时间是15s
diff --git a/keyword/common/customlibrary/Smtp3Library/__init__.py b/keyword/common/customlibrary/Smtp3Library/__init__.py
new file mode 100644
index 0000000..c86362a
--- /dev/null
+++ b/keyword/common/customlibrary/Smtp3Library/__init__.py
@@ -0,0 +1,417 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# This file is part of robotframework-Smtp3Library.
+# https://github.io/lucamaro/robotframework-Smtp3Library
+
+# Licensed under the Apache License 2.0 license:
+# http://www.opensource.org/licenses/Apache-2.0
+# Copyright (c) 2016, Luca Maragnani <[email protected]>
+
+"""
+Library implementation
+"""
+import ast
+import smtplib
+import email
+import random
+import string
+import mimetypes
+import quopri
+from email.message import Message
+from email.mime.audio import MIMEAudio
+from email.mime.base import MIMEBase
+from email.mime.image import MIMEImage
+from email.mime.multipart import MIMEMultipart
+from email.mime.text import MIMEText
+from email import encoders
+import os.path
+import socket
+from robot.api.deco import keyword
+from robot.api import logger
+
+from Smtp3Library.version import __version__ # NOQA
+
+COMMASPACE = ', '
+
+class Smtp3Library(object):
+ """
+ SMTP Client class
+ """
+
+ def __init__(self):
+ """
+ Constructor
+ """
+ self.message = self._MailMessage()
+ self.host = None
+ self.port = None
+ self.user = None
+ self.password = None
+ self.smtp = None
+
+ def _prepare_connection(self, host, port, user=None, password=None):
+ """
+ Private method to collect connection informations
+ """
+ self.host = host
+ self.port = int(port)
+ self.user = user
+ self.password = password
+ self.client_hostname = socket.gethostname()
+
+
+ def prepare_ssl_connection(self, host, port=465, user=None, password=None):
+ """
+ Collect connection informations for SSL channel
+ """
+ self._prepare_connection(host, port, user, password)
+ self.smtp = smtplib.SMTP_SSL()
+
+ def prepare_connection(self, host, port=25, user=None, password=None):
+ """
+ Collect connection informations for unencrypted channel
+ """
+ self._prepare_connection(host, port, user, password)
+ self.smtp = smtplib.SMTP()
+
+ def add_to_recipient(self, recipient):
+ """
+ Add a recipient to "To:" list
+ """
+ self.message.mail_to.append(recipient)
+
+ def add_cc_recipient(self, recipient):
+ """
+ Add a recipient to "Cc:" list
+ """
+ self.message.mail_cc.append(recipient)
+
+ def add_bcc_recipient(self, recipient):
+ """
+ Add a recipient to "Bcc:" list
+ """
+ self.message.mail_bcc.append(recipient)
+
+ def set_subject(self, subj):
+ """
+ Set email subject
+ """
+ self.message.subject = subj
+
+ def set_from(self, from_recipient):
+ """
+ Set from address of message and envelope
+ """
+ self.message.mail_from = from_recipient
+
+ def set_body(self, body):
+ """
+ Set email body
+ """
+ self.message.body = body
+
+ def set_random_body(self, size):
+ """
+ Set a random body of <size> length
+ """
+ body = ''
+ for i in range(0, size):
+ body += ''.join(random.choice(string.uppercase + string.digits))
+ if i % 80 == 0:
+ body += "\n"
+ self.message.body = body
+
+ def add_attachment(self, attach):
+ """
+ Add attachment to a list of filenames
+ """
+ self.message.attachments.append(attach)
+
+ def add_header(self, name, value):
+ """
+ Add a custom header to headers list
+ """
+ self.message.headers[name] = value
+
+ def connect(self):
+ '''
+ Open connection to server
+ Returns tuple (smtp status code, message)
+ '''
+ return self.smtp.connect(self.host, self.port)
+
+ def present_client_as(self, client_hostname):
+ '''
+ Set helo/ehlo client identity
+ '''
+ self.client_hostname = client_hostname
+
+ def helo(self):
+ '''
+ Send HELO command
+ Returns tuple (smtp status code, message)
+ '''
+ result = self.smtp.helo(self.client_hostname)
+ logger.info(result)
+ return result
+
+ def ehlo(self):
+ '''
+ Send EHLO command
+ Returns tuple (smtp status code, message)
+ '''
+ result = self.smtp.ehlo(self.client_hostname)
+ logger.info(result)
+ return result
+
+ def get_esmtp_features(self):
+ '''
+ Returns hashmap with ESMTP feature received with EHLO
+ '''
+ logger.info(self.smtp.esmtp_features)
+ return self.smtp.esmtp_features
+
+ def logins(self):
+ try:
+ '''
+ Login user
+ Returns tuple (smtp status code, message)
+ '''
+ logger.info("Login with user " + self.user + " and password " + self.password)
+ '''try:
+ subuser=bytes.decode(self.user)
+ subpassword=bytes.decode(self.password)
+ result = self.smtp.login(subuser.encode('ascii'), subpassword.encode('ascii'))
+ logger.info(result)
+ return result
+ except:
+ logger.info("本身就是str类型不需要bytes to str!")
+ subuser=str(self.user).encode('ascii')
+ subpassword=str(self.password).encode('ascii')
+ result = self.smtp.login(subuser, subpassword)
+ logger.info(result)
+ return result'''
+ result = self.smtp.login(self.user, self.password)
+ logger.info(result)
+ return "mail_success"
+ except:
+ return "mail_fail"
+
+
+ def starttls(self, keyfile=None, certfile=None):
+ '''
+ sends STARTTLS
+ optional: keyfile certfile
+ Returns tuple (smtp status code, message)
+ '''
+ logger.info("STARTTLS")
+ if keyfile is None and certfile is None:
+ result = self.smtp.starttls()
+ else:
+ result = self.smtp.starttls(keyfile, certfile)
+ logger.info(result)
+ return result
+
+ def data(self):
+ '''
+ Data command send email body with "MAIL FROM:", "RCPT TO:" and "DATA" commands
+ Returns tuple (smtp status code, message)
+ '''
+ result = self.smtp.mail(self.message.mail_from)
+ result += self.smtp.rcpt(self.message.get_message_recipients())
+
+ result += self.smtp.data(self.message.get_message_as_string())
+ logger.info(result)
+ return result
+
+ def sendmail(self):
+ '''
+ Send email with "MAIL FROM:", "RCPT TO:" and "DATA" commands
+ Returns tuple (smtp status code, message)
+ '''
+ result = self.smtp.sendmail(self.message.mail_from, self.message.get_message_recipients(), self.message.get_message_as_string())
+ logger.info(result)
+ return result
+
+ def quit(self):
+ '''
+ Send QUIT command
+ Returns tuple (smtp status code, message)
+ '''
+ result = self.smtp.quit()
+ logger.info(result)
+ return result
+
+ def close_connection(self):
+ '''
+ Close connection to server
+ '''
+ return self.smtp.close()
+
+ def send_message(self):
+ """
+ Send the message, from connection establishment to quit and close connection.
+ All the connection and email parameters must be already set before invocation.
+ Returns sendmail response (code, message)
+ """
+
+ # Send the message
+ try:
+ self.connect()
+
+ if self.user is not None:
+ self.ehlo()
+ self.logins()
+
+ send_result = self.sendmail()
+
+ self.quit()
+ self.close_connection()
+ # return send_result
+ return "mail_success"
+ except:
+ return "mail_fail"
+
+ @keyword('Send Message With All Parameters')
+ def send_message_full(self, host, user, password, subj,
+ from_recipient, to_recipient, cc_recipient=None, bcc_recipient=None,
+ body=None, attach=None):
+ """
+ Send a message specifing all parameters on the same linecc
+ cc, bcc and attach parameters may be strings or array of strings
+ host, user, password, subj, fromadd, toadd - are mandatory parameters
+ to use the optional paramaters pleas specify the name fo the parameter in the call
+ user and password even if mandatory could be set to None so no authentication will be made
+ Example:
+ sendMail("smtp.mail.com", None, None, "The subject", "[email protected]", "[email protected]", body="Hello World body")
+
+ sendMail("smtp.mail.com", "scott", "tiger", "The subject", "[email protected]", "[email protected]", body="Hello World body", attach=attaches
+ where could be:
+ attaches = ["c:\\desktop\\file1.zip", "c:\\desktop\\file2.zip"] or
+ attaches = "c:\\desktop\\file1.zip"
+ Returns sendmail response (code, message)
+ """
+
+ self.host = host
+ self.user = user
+ self.password = password
+
+ self.set_subject(subj)
+ self.set_from(from_recipient)
+ self.message.mail_to = to_recipient
+ if cc_recipient != None:
+ self.message.mail_cc = cc_recipient
+ if bcc_recipient != None:
+ self.message.mail_bcc = bcc_recipient
+ #Fill the message
+ if body != None:
+ self.set_body(body)
+ # Part two is attachment
+ if attach != None:
+ attachlist = ast.literal_eval(attach)
+ self.message.attachments = attachlist
+ #logger.info("self.message.attachments:"+str(type(self.message.attachments)))
+ #logger.info("attachtype:"+str(type(attachlist)))
+ #logger.info("attachlist:"+str(attachlist))
+
+ return self.send_message()
+
+
+ class _MailMessage:
+ """
+ Simplified email message
+ This class represent email headers and payload content, not envelope data
+ """
+
+ def __init__(self):
+ """
+ init object variables
+ """
+ self.mail_from = None
+ self.mail_to = []
+ self.mail_cc = []
+ self.mail_bcc = []
+ self.subject = ''
+ self.body = ''
+ self.attachments = []
+ self.headers = {}
+
+ def get_message_recipients(self):
+ '''
+ Get all message recipients (to, cc, bcc)
+ '''
+ recipients = []
+ tolist = ast.literal_eval(self.mail_to)
+ cclist = ast.literal_eval(self.mail_cc)
+ bcclist = ast.literal_eval(self.mail_bcc)
+ recipients.extend(tolist)
+ recipients.extend(cclist)
+ recipients.extend(bcclist)
+ #logger.info("recipientslist:"+str(recipients))
+ return recipients
+
+ def get_message_as_string(self):
+ '''
+ Get message as string to be sent with smtplib.sendmail api
+ '''
+ if len(self.attachments) > 0:
+ #logger.info("attachments:"+str(self.attachments))
+ #logger.info("attachmentstype:"+str(type(self.attachments)))
+ #logger.info("attachmentsnum:"+str(len(self.attachments)))
+
+ envelope = MIMEMultipart()
+ envelope.attach(MIMEText(self.body))
+ else:
+ envelope = MIMEText(self.body)
+
+ recipients = self.get_message_recipients()
+
+
+ tolist = ast.literal_eval(self.mail_to)
+ cclist = ast.literal_eval(self.mail_cc)
+ envelope['From'] = self.mail_from
+ envelope['To'] = COMMASPACE.join(tolist)
+ envelope['Cc'] = COMMASPACE.join(cclist)
+ envelope['Subject'] = self.subject
+ #logger.info("envelope111:"+str(self.attachments))
+ for attachment in list(self.attachments):
+ ctype, encoding = mimetypes.guess_type(attachment)
+ #logger.info("attachment:"+attachment+" ctype:"+str(ctype)+" encoding:"+str(encoding))
+ if ctype is None or encoding is not None:
+ # No guess could be made, or the file is encoded (compressed), so
+ # use a generic bag-of-bits type.
+ ctype = 'application/octet-stream'
+ maintype, subtype = ctype.split('/', 1)
+ #logger.info("maintype:"+str(maintype)+" subtype:"+str(subtype))
+
+ msg = None
+ if maintype == 'text':
+ attach_file = open(attachment,'rb')
+ # TODO: we should handle calculating the charset
+ msg = MIMEText(attach_file.read(), _subtype=subtype, _charset='utf-8')
+ attach_file.close()
+ elif maintype == 'image':
+ attach_file = open(attachment, 'rb')
+ msg = MIMEImage(attach_file.read(), _subtype=subtype)
+ attach_file.close()
+ elif maintype == 'audio':
+ attach_file = open(attachment, 'rb')
+ msg = MIMEAudio(attach_file.read(), _subtype=subtype)
+ attach_file.close()
+ else:
+ attach_file = open(attachment, 'rb')
+ msg = MIMEBase(maintype, subtype)
+ msg.set_payload(attach_file.read())
+ attach_file.close()
+ # Encode the payload using Base64
+ encoders.encode_base64(msg)
+
+ # Set the filename parameter
+ msg.add_header('Content-Disposition', 'attachment',
+ filename=os.path.basename(attachment))
+ envelope.attach(msg)
+
+
+ #logger.info("envelope.as_string:"+envelope.as_string())
+ return envelope.as_string()
diff --git a/keyword/common/customlibrary/Smtp3Library/version.py b/keyword/common/customlibrary/Smtp3Library/version.py
new file mode 100644
index 0000000..8f9fcb8
--- /dev/null
+++ b/keyword/common/customlibrary/Smtp3Library/version.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# This file is part of robotframework-Smtp3Library.
+# https://github.io/lucamaro/robotframework-SmtpLibrary
+
+# Licensed under the Apache License 2.0 license:
+# http://www.opensource.org/licenses/Apache-2.0
+# Copyright (c) 2016, Luca Maragnani <[email protected]>
+
+__version__ = '0.1.3' # NOQA
diff --git a/keyword/common/customlibrary/ipandstring/__init__.py b/keyword/common/customlibrary/ipandstring/__init__.py
new file mode 100644
index 0000000..e7adf5c
--- /dev/null
+++ b/keyword/common/customlibrary/ipandstring/__init__.py
@@ -0,0 +1,4 @@
+from ipandstring.stringip import stringandip
+
+class ipandstring(stringandip):
+ ROBOT_LIBRARY_SCOPE = 'GLOBAL' \ No newline at end of file
diff --git a/keyword/common/customlibrary/ipandstring/stringip.py b/keyword/common/customlibrary/ipandstring/stringip.py
new file mode 100644
index 0000000..0ce0c44
--- /dev/null
+++ b/keyword/common/customlibrary/ipandstring/stringip.py
@@ -0,0 +1,68 @@
+import random
+import struct
+import socket
+
+class stringandip (object):
+ def __init__(self):
+ pass
+ def ipv4(self,m, n, x):
+ if m == '-1':
+ m = random.randint(0, 255)
+ if n == '-1':
+ n = random.randint(0, 255)
+ if x == '-1':
+ x = random.randint(0, 255)
+ y = random.randint(0, 255)
+ print(str(m) + '.' + str(n) + '.' + str(x) + '.' + str(y))
+ return str(m) + '.' + str(n) + '.' + str(x) + '.' + str(y)
+
+ def dec2hex(self,string_num):
+ base = [str(x) for x in range(10)] + [chr(x) for x in range(ord('A'), ord('A') + 6)]
+ num = int(string_num)
+ mid = []
+ while True:
+ if num == 0: break
+ num, rem = divmod(num, 16)
+ mid.append(base[rem])
+
+ return ''.join([str(x) for x in mid[::-1]])
+
+ def ipv6(self):
+ ipInt = random.randint(0, 400000000000000000000000000000000000)
+ ipStr = ''
+ leftValue = ipInt
+
+ for i in [7, 6, 5, 4, 3, 2, 1, 0]:
+ string_num = leftValue / 65536 ** i
+ base = [str(x) for x in range(10)] + [chr(x) for x in range(ord('A'), ord('A') + 6)]
+ num = int(string_num)
+ mid = []
+ while True:
+ if num == 0: break
+ num, rem = divmod(num, 16)
+ mid.append(base[rem])
+
+ ipTokenInt = ''.join([str(x) for x in mid[::-1]])
+ if (ipTokenInt == ''):
+ ipTokenInt = 0
+ ipStr = ipStr + str(ipTokenInt)
+ if i != 0:
+ ipStr = ipStr + ':'
+ leftValue %= 65536 ** i
+ print(ipStr)
+ return ipStr
+
+ def getstring(self,randomlength=16,base_str='ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789'):
+ """
+ 生成一个指定长度的随机字符串
+ """
+ random_str = ''
+ #base_str = 'ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789'
+ length = len(base_str) - 1
+ for i in range(randomlength):
+ random_str += base_str[random.randint(0, length)]
+ print(random_str)
+ return random_str
+# if __name__ == '__main__':
+# ipandstring = ipandstring()
+# print(ipandstring.ipv6()) \ No newline at end of file
diff --git a/keyword/common/file_operation.robot b/keyword/common/file_operation.robot
new file mode 100644
index 0000000..ee5ebed
--- /dev/null
+++ b/keyword/common/file_operation.robot
@@ -0,0 +1,36 @@
+*** Settings ***
+Library String
+Library json
+Library OperatingSystem
+Library RequestsLibrary
+Library Selenium2Library
+Library Collections
+Library FileLibrary
+Resource common.robot
+Resource ../../variable/common_variable.txt
+
+*** Keywords ***
+InsertPolicyIdToFile
+ [Arguments] ${key} ${policyId} ${objectids}
+ ${dict} Create Dictionary policyId=${policyId} objectId=${objectids}
+ ${json} json.Dumps ${dict}
+ Alter Dict ${path}/variable/AllFlowCaseVariable.txt ${key} ${json}
+
+InsertTimeToFile
+ [Arguments] ${key} ${starttime} ${endtime}
+ ${value} json.Loads ${${key}}
+ ${dict} Create Dictionary policyId=${value}[policyId] objectId=${value}[objectId] starttime=${starttime} endtime=${endtime}
+ ${json} json.Dumps ${dict}
+ Alter Dict ${path}/variable/AllFlowCaseVariable.txt ${key} ${json}
+
+InsertObjectIdToFile
+ [Arguments] ${key} ${objectids}
+ Alter Dict ${path}/all_flow_case_variable.txt ${key} ${objectids}
+
+InsertStartTimeToFile
+ [Arguments] ${key} ${starttime}
+ Alter Dict ${path}/all_flow_case_variable1.txt ${key} ${starttime}
+
+InsertReportToFile
+ [Arguments] ${key} ${objectids}
+ Alter Dict ${path}/ReportCaseVariable.txt ${key} ${objectids}
diff --git a/keyword/common/functional_keywords.robot b/keyword/common/functional_keywords.robot
new file mode 100644
index 0000000..d49c862
--- /dev/null
+++ b/keyword/common/functional_keywords.robot
@@ -0,0 +1,260 @@
+*** Settings ***
+Library String
+Library OperatingSystem
+Library RequestsLibrary
+Library Selenium2Library
+Library Collections
+Resource common.robot
+Resource api_request.robot
+Resource ../../variable/common_variable.txt
+
+*** Keywords ***
+QueryPolicyFile
+ [Arguments] ${url} ${suffix}
+ ${content_quary} GetRequest1 ${url}?isValid=1&${suffix}
+ ${msg_quary} Set Variable ${content_quary['msg']}
+ ${length} Get Length ${content_quary['data']['list']}
+ Should Be True ${length}>0
+ Log quary operation:${msg_quary}
+ Log data:${content_quary['data']['list']}
+
+QueryPolicyFile2
+ [Arguments] ${url} ${suffix}
+ ${content_quary} GetRequest1 ${url}?${suffix}
+ ${msg_quary} Set Variable ${content_quary['msg']}
+ ${length} Get Length ${content_quary['data']['list']}
+ Should Be True ${length}>0
+ Log quary operation:${msg_quary}
+ Log data:${content_quary['data']['list']}
+ ${certId} Set Variable ${content_quary['data']['list'][0]['certId']}
+ [Return] ${certId}
+
+CreatePolicyFile
+ [Documentation]
+ ... 必传参数:url、filePath(文件路径)、fileName(文件名称)
+ ... 可选参数:header(不传时使用默认值)
+ [Arguments] ${url} ${filePath} ${fileName} @{header}
+ ${suffix} Generate Random String
+ ${certName} Catenate SEPARATOR=_ test ${suffix}
+ ${header} Run Keyword If ${header}==[] Set Variable {"isValid":1,"opAction":"add","certName":"${certName}","certId":null,"returnData":1}
+ ... ELSE Get From List ${header} 0
+
+ ${binFile} Evaluate open(r"${path}/${filePath}${fileName}",'rb')
+ ${fileDict} Create Dictionary file=${binFile}
+ ${requestData} Create Dictionary name="file" filename="${fileName}" Content-Type=application/octet-stream
+ ${fileDesc} Create Dictionary File-Desc=${header}
+ ${content} UpFilePostRequest ${url} ${requestData} ${fileDict} ${fileDesc}
+ ${msg} Set Variable ${content['msg']}
+ ${list} Set Variable ${content['data']['list']}
+ ${cerId} Set Variable ${list[0]['certId']}
+ ${certName} Set Variable ${list[0]['certName']}
+ ${response} Create Dictionary msg=${msg} certId=${cerId} certName=${certName}
+ Log add operation:${msg}
+ Log cerId:${cerId}
+ [Return] ${response}
+
+CreatePolicyFile2
+ [Documentation]
+ ... 必传参数:url、filePath(文件路径)、fileName(文件名称)、flag(模块标识)
+ ... 可选参数:header(不传时使用默认值)
+ [Arguments] ${url} ${filePath} ${fileName} ${flag} @{header}
+ ${suffix} Generate Random String
+ ${randomName} Catenate SEPARATOR=_ test ${suffix}
+ ${value} Run Keyword If '${flag}'=='resPages' Set Variable {"isValid":1,"format":"html","opAction":"add","profileName":"${randomName}","profileId":null,"returnData":1}
+ ... ELSE IF '${flag}'=='hijack' Set Variable {"isValid":1,"contentType":"text/html","opAction":"add","profileName":"${randomName}","contentName":"${fileName}","profileId":null,"returnData":1}
+ ... ELSE IF '${flag}'=='insert' Set Variable {"isValid":1,"format":"js","insertOn":"after_page_load","opAction":"add","profileName":"${randomName}","profileId":null,"returnData":1}
+ ... ELSE IF '${flag}'=='insertcss' Set Variable {"isValid":1,"format":"css","insertOn":"after_page_load","opAction":"add","profileName":"${randomName}","profileId":null,"returnData":1}
+
+ ${header} Run Keyword If ${header}==[] Set Variable ${value}
+ ... ELSE Get From List ${header} 0
+
+ ${binFile} Evaluate open(r"${filePath}${fileName}",'rb')
+ ${fileDict} Create Dictionary file=${binFile}
+ ${requestData} Create Dictionary name="file" filename="${fileName}" Content-Type=application/octet-stream
+ ${suffix} Generate Random String
+ ${profileName} Catenate SEPARATOR=_ test ${suffix}
+ ${fileDesc} Create Dictionary File-Desc=${header}
+ ${content} UpFilePostRequest ${url} ${requestData} ${fileDict} ${fileDesc}
+ ${msg} Set Variable ${content['msg']}
+ ${list} Set Variable ${content['data']['list']}
+ ${profileId} Set Variable ${list[0]['profileId']}
+ ${profileName} Set Variable ${list[0]['profileName']}
+ ${response} Create Dictionary msg=${msg} profileId=${profileId} profileName=${profileName}
+ Log add operation:${msg}
+ Log profileId:${profileId}
+ [Return] ${response}
+
+CreatePolicyFile3
+ [Documentation]
+ ... 必传参数:url
+ ... 可选参数:data(不传时使用默认值)
+ [Arguments] ${url} @{data}
+ ${suffix} Generate Random String
+ ${profileName} Catenate SEPARATOR=_ test ${suffix}
+ ${data} Run Keyword If ${data}==[] Set Variable {"opAction":"add","returnData":1,"trafficMirrorList":[{"profileName":"${profileName}","addrType":"mac","isValid":1,"addrArray":["00:A1:B2:06:C3:29"]}]}
+ ... ELSE Get From List ${data} 0
+
+ ${content} PostRequest1 ${url} ${data}
+ ${msg} Set Variable ${content['msg']}
+ ${list} Set Variable ${content['data']['list']}
+ ${profileId} Set Variable ${list[0]['profileId']}
+ ${profileName} Set Variable ${list[0]['profileName']}
+ ${response} Create Dictionary msg=${msg} profileId=${profileId} profileName=${profileName}
+ Log add operation:${msg}
+ Log profileId:${profileId}
+ [Return] ${response}
+
+CreatePolicyFileNoFile
+ [Documentation]
+ ... 必传参数:url
+ ... 可选参数:data(不传时使用默认值)
+ [Arguments] ${url} ${requestbody}
+ ${content} PostRequest1 ${url} ${requestbody}
+ ${msg} Set Variable ${content['msg']}
+ ${list} Set Variable ${content['data']['list']}
+ ${profileId} Set Variable ${list[0]['profileId']}
+ ${profileName} Set Variable ${list[0]['profileName']}
+ ${response} Create Dictionary msg=${msg} profileId=${profileId} profileName=${profileName}
+ Log add operation:${msg}
+ Log profileId:${profileId}
+ [Return] ${response}
+
+CreatePolicyMutipartFile
+ [Arguments] ${url} ${filePath} ${pubFileName} ${priFileName} ${keyringType} @{header}
+ [Documentation] 必传参数:url、filePath(文件路径)、pubFileName(证书文件名)、priFileName(私钥文件名),keyringType(证书类型)
+ ... 可选参数:header(不传时使用默认值)
+ ${suffix} Generate Random String
+ ${certName} Catenate SEPARATOR=_ test ${suffix}
+ ${header} Run Keyword If ${header}==[] Set Variable {"isValid":1,"opAction":"add","returnData":1,"keyringName":"${certName}","keyringType":"${keyringType}","reissueExpiryHour":0,"crl":"null","publicKeyAlgo":"rsa1024","keyringId":null,"includeRoot":0}
+ ... ELSE Get From List ${header} 0
+ ${pubFile} Evaluate open(r"${path}/${filePath}${pubFileName}",'rb')
+ ${priFile} Evaluate open(r"${path}/${filePath}${priFileName}",'rb')
+ ${fileDict} Create Dictionary publicFile ${pubFile}
+ Set To Dictionary ${fileDict} privateFile ${priFile}
+ ${requestData} Create Dictionary name="publicFile" filename="${pubFileName}" Content-Type=application/octet-stream
+ Set To Dictionary ${requestData} name privateFile
+ Set To Dictionary ${requestData} filename ${priFileName}
+ Set To Dictionary ${requestData} Content-Type application/octet-stream
+ ${fileDesc} Create Dictionary File-Desc=${header}
+ ${content} UpFilePostRequest ${url} ${requestData} ${fileDict} ${fileDesc}
+ ${msg} Set Variable ${content['msg']}
+ ${list} Set Variable ${content['data']['list']}
+ ${keyringId} Set Variable ${list[0]['keyringId']}
+ ${keyringName} Set Variable ${list[0]['keyringName']}
+ ${response} Create Dictionary msg=${msg} keyringId=${keyringId} keyringName=${keyringName}
+ Log add operation:${msg}
+ Log keyringId:${keyringId}
+ [Return] ${response}
+
+UpdatePolicyMutipartFile
+ [Arguments] ${url} ${filePath} ${pubFileName} ${priFileName} ${reqHeader}
+ ${pubFile} Evaluate open(r"${path}/${filePath}${pubFileName}",'rb')
+ ${priFile} Evaluate open(r"${path}/${filePath}${priFileName}",'rb')
+ ${fileDict} Create Dictionary publicFile ${pubFile}
+ Set To Dictionary ${fileDict} privateFile ${priFile}
+
+ ${requestData} Create Dictionary name="publicFile" filename="${pubFileName}" Content-Type=application/octet-stream
+ Set To Dictionary ${requestData} name privateFile
+ Set To Dictionary ${requestData} filename ${priFileName}
+ Set To Dictionary ${requestData} Content-Type application/octet-stream
+
+ ${fileDesc} Create Dictionary File-Desc ${reqHeader}
+ ${content} UpFilePutRequest ${url} ${requestData} ${fileDict} ${fileDesc}
+ ${msg} Set Variable ${content['msg']}
+ Log update operation:${msg}
+ Log update condition:${reqHeader}
+
+UpdatePolicyFile
+ [Arguments] ${url} ${filePath} ${fileName} ${reqHeader}
+ ${binFile} Evaluate open(r"${path}/${filePath}${fileName}",'rb')
+ ${fileDict} Create Dictionary file=${binFile}
+ ${requestData} Create Dictionary name="file" filename="${fileName}" Content-Type=application/octet-stream
+ ${fileDesc} Create Dictionary File-Desc=${reqHeader}
+ ${content} UpFilePutRequest ${url} ${requestData} ${fileDict} ${fileDesc}
+ ${msg} Set Variable ${content['msg']}
+ Log update operation:${msg}
+ Log update condition:${reqHeader}
+
+UpdatePolicyFile2
+ [Arguments] ${url} ${data}
+ ${header} Create Dictionary Content-Type=application/json Authorization=${token}
+ Create Session api http://${host}:${port} headers=${header}
+ ${remoteResponse} Put Request api ${url} data=${data} headers=${header}
+ ${response} to json ${remoteResponse.content}
+ Should Be Equal As Strings ${remoteResponse.status_code} 200
+ ${msg} Set Variable ${response['msg']}
+ Log update operation:${msg}
+ Log update condition:${data}
+
+DeletePolicyFile
+ [Arguments] ${url} ${data}
+ ${content} DeleteRequest1 ${url} ${data}
+ ${msg} Set Variable ${content['msg']}
+ Log delete operation:${msg}
+ Log delete condition:${data}
+
+TeardownDelete
+ [Arguments] ${url} ${key} ${value}
+ ${ids} Create List ${value}
+ ${data} Create Dictionary ${key}=${ids}
+ ${content} DeleteRequest1 ${url} ${data}
+ ${msg} Set Variable ${content['msg']}
+ Log teardown operation:${msg}
+ Log teardown condition:${data}
+
+
+CreatePolicyFile4
+ [Arguments] ${url} ${filePath} ${fileName} ${objectDict}
+ [Timeout]
+ ${binFile} Evaluate open(r"${path}/${filePath}${fileName}",'rb')
+ ${fileDict} Create Dictionary file=${binFile}
+ ${requestData} Create Dictionary name="file" filename="${fileName}" Content-Type=application/octet-stream
+ ${suffix} Generate Random String
+ ${profileName} Catenate SEPARATOR=_ test ${suffix}
+ log ${objectDict}
+ ${string} Convert To String ${objectDict}
+ ${fileDesc} Create Dictionary File-Desc=${string}
+ log ${fileDesc}[File-Desc]
+ ${content} UpFilePostRequest ${url} ${requestData} ${fileDict} ${fileDesc}
+ ${msg} Set Variable ${content['msg']}
+ ${list} Set Variable ${content['data']['list']}
+ ${profileId} Set Variable ${list[0]['profileId']}
+ ${profileName} Set Variable ${list[0]['profileName']}
+ ${response} Create Dictionary msg=${msg} profileId=${profileId} profileName=${profileName}
+ Log add operation:${msg}
+ Log profileId:${profileId}
+ [Return] ${response}
+
+CreateRequest
+ [Arguments] ${url} ${data}
+ [Documentation] 必传参数:url
+ ... 可选参数:data(不传时使用默认值)
+ ${content} PostRequest1 ${url} ${data}
+ ${msg} Set Variable ${content['msg']}
+ ${list} Set Variable ${content['data']['list']}
+ ${profileId} Set Variable ${list[0]['profileId']}
+ ${profileName} Set Variable ${list[0]['profileName']}
+ ${response} Create Dictionary msg=${msg} profileId=${profileId} profileName=${profileName}
+ Log add operation:${msg}
+ Log profileId:${profileId}
+ [Return] ${response}
+DeletePolicyFile1
+ [Arguments] ${url} ${profileId}
+ #删除文件
+ log todeleteobj
+ ${response} BaseDeleteRequest ${url} {"profileIds":[${profileId}]}
+ ${response_code} Get From Dictionary ${response} code
+ Should Be Equal As Strings ${response_code} 200
+ ${response} Convert to String ${response}
+ log ${response}
+DeleteProfileByIds
+ [Arguments] ${typeUrl} ${profileIds}
+ #删除对象
+ log DeleteProfile
+ ${response} BaseDeleteRequest /${version}/policy/profile/${typeUrl} {"profileIds":[${profileIds}]}
+ ${response_code} Get From Dictionary ${response} code
+ #log aaaaaaaaaa:${response_code}
+ Should Be Equal As Strings ${response_code} 200
+ #Integer ${response_code} 200
+ ${response} Convert to String ${response}
+ log ${response} \ No newline at end of file
diff --git a/keyword/common/log_variable.robot b/keyword/common/log_variable.robot
new file mode 100644
index 0000000..dc12fb2
--- /dev/null
+++ b/keyword/common/log_variable.robot
@@ -0,0 +1,146 @@
+*** Settings ***
+Resource ../../variable/common_variable.txt
+Resource logschema.robot
+Library REST http://${host}:${port}
+Library RequestsLibrary
+Library OperatingSystem
+Library Collections
+Library string
+Library customlibrary/Custometest/log_contrast.py
+
+
+*** Keywords ***
+GetLogSchemaByType
+ [Documentation] 根据日志类型获取对应schema
+ ... ${logType}日志类型:
+ ... security_event_log:安全策略
+ ... proxy_event_log:代理策略
+ ... connection_record_log: 协议采集日志
+ ... radius_record_log radius:采集日志
+ ... active_defence_event_log:主动防御日志
+ ... voip_record_log:voip协议日志
+ ... transaction_record_log:事务日志
+ ... live_session_record_log:活跃会话日志
+ ... gtpc_record_log:gtp协议日志
+ ...
+ [Arguments] ${logType}
+ Set Headers {"Content-Type":"application/x-www-form-urlencoded","Authorization":"${token}"}
+ &{LogSchemaResponse}= GET /${version}/log/schema?logType=${logType}
+ log ${logType}
+ #Output Schema response body
+ Object response body
+ #Integer $.code 200
+ log ${LogSchemaResponse.body['data']}
+ #${field} Evaluate json.dumps(eval(str(${LogSchemaResponse.body['data']['fields']}))) json
+ [Return] ${LogSchemaResponse.body['data']}
+
+GetLogContentByKeyword
+ [Documentation] 根据关键字重schema获取对应内容
+ ... ${logSchema}schema内容
+ ... security_event_log:安全策略
+ ... proxy_event_log:代理策略
+ ... connection_record_log: 协议采集日志
+ ... radius_record_log radius:采集日志
+ ... active_defence_event_log:主动防御日志
+ ... voip_record_log:voip协议日志
+ ... transaction_record_log:事务日志
+ ... live_session_record_log:活跃会话日志
+ ... gtpc_record_log:gtp协议日志
+ ...
+ [Arguments] ${logSchema} ${keyword}
+ ${keyword} Run Keyword If "${keyword}"=="field" Set Veriable ${LogSchemaResponse.body['data']['fields']}
+ ... ELSE IF "${keyword}"=="field" Set Veriable ${LogSchemaResponse.body['data']['fields']}
+ ... ELSE Set Veriable ${LogSchemaResponse.body['data']['fields']}
+ ${content} Evaluate json.dumps(eval(str(${keyword}))) json
+ #${field} Evaluate json.dumps(eval(str(${LogSchemaResponse.body['data']['fields']}))) json
+ [Return] ${content}
+
+OrganizeLogCondition
+ [Documentation] 根据条件list组织条件
+ [Arguments] ${logname} ${startTime} ${endTime} ${field} ${filter}=
+ #${logname} ${startTime} ${endTime} ${client_ip} ${policy_id}
+ ${pageSize} Set Variable 30
+ ${pageNo} Set Variable 1
+ ${logCondition} Set Variable {"pageNo":${pageNo},"pageSize":${pageSize},"logType":"${logname}","fields":${field},"start_common_recv_time":"${startTime}","end_common_recv_time":"${endTime}", "filter":"${filter}"}
+ log this time query condition:${logCondition}
+ [Return] ${filds}
+
+LogVeriable
+ [Arguments] ${logType} ${startTime} ${endTime} ${filter}
+ ${logSchema} GetLogSchemaByType ${logType}
+ ${filds} GetLogContentByKeyword ${logSchema} field
+ ${logCondition} OrganizeLogCondition ${logname} ${startTime} ${endTime} ${filds} ${filter}
+ #common_client_ips":"${client_ip}" and "common_policy_ids":"${policy_id}
+ ${logs} GetLogList ${logType} ${logCondition}
+ ${returnvalue} log_contrast ${logs} ${client_ip} ${policy_id} ${parmkey} ${parmvalue}
+ ${trueorfalse} Run Keyword If "${returnvalue}"=="true" set variable true
+ ... ELSE set variable false
+ Run Keyword If "${returnvalue}"=="true" Exit for loop
+ [Return] ${trueorfalse}
+
+GetLogList
+ [Arguments] ${logType} ${logCondition}
+ log ${logCondition}
+ ${LogListResponse} PostRemoteData /${version}/log/list ${logCondition}
+ Should Be Equal As Strings ${LogListResponse.status_code} 200
+ ${returnData} To Json ${LogListResponse.content}
+ ${responseCode} Get From Dictionary ${returnData} code
+ Log ${responseCode}
+ Should Be Equal ${responseCode} ${200} security_event_log \ \ test query list failed
+ log this time request security_event_log \ table logRecord \ : ${LogListResponse.content}
+ ${a} Set Variable this time request security_event_log \ table logRecord \ : ${LogListResponse.content}
+ log ${a}
+ ${log} Set Variable ${LogListResponse.json()}[data][list]
+ FOR ${logs} IN ${log}
+ log ${logs}
+ END
+ [Return] ${logs}
+
+GetLogList1
+ [Arguments] ${logType} ${startTime} ${endTime} ${client_ip} ${policy_id} ${parmkey} ${parmvalue}
+ ${logCondition} GetLogCondition ${logType} ${startTime} ${endTime} ${client_ip} ${policy_id}
+ log ${logCondition}
+ ${LogListResponse} PostRemoteData /${version}/log/list ${logCondition}
+ Should Be Equal As Strings ${LogListResponse.status_code} 200
+ ${returnData} To Json ${LogListResponse.content}
+ ${responseCode} Get From Dictionary ${returnData} code
+ Log ${responseCode}
+ Should Be Equal ${responseCode} ${200} security_event_log \ \ test query list failed
+ log this time request security_event_log \ table logRecord \ : ${LogListResponse.content}
+ ${a} Set Variable this time request security_event_log \ table logRecord \ : ${LogListResponse.content}
+ log ${a}
+ ${log} Set Variable ${LogListResponse.json()}[data][list]
+ FOR ${logs} IN ${log}
+ log ${logs}
+ END
+ log %%%%%%%%%%%%%%%%%%%%%%%%${logs}
+ Should Contain ${logs}"" ${client_ip}
+ Should Contain ${logs}"" ${policy_id}
+ Should Contain ${logs}"" ${parmkey}
+ Should Contain ${logs}"${parmkey}" ${parmvalue}
+
+GetLogListSize
+ [Documentation]
+ ... 描述:ProxyPinning
+ ...
+ [Arguments] ${logType} ${startTime} ${endTime} ${client_ip} ${policy_id} ${parmkey} ${parmvalue}
+ ${logCondition} GetALLLogCondition ${logType} ${startTime} ${endTime} ${client_ip} ${policy_id} 10000 1
+ log ${logCondition}
+ ${LogListResponse} PostRemoteData /${version}/log/list ${logCondition}
+ Should Be Equal As Strings ${LogListResponse.status_code} 200
+ ${returnData} To Json ${LogListResponse.content}
+ ${data} Get From Dictionary ${returnData} data
+ ${len} Get Length ${data}[list]
+ [Return] ${len}
+
+
+GetLogCount
+ [Arguments] ${logType} ${startTime} ${endTime} ${client_ip} ${policy_id} ${parmkey} ${parmvalue}
+ ${logCondition} GetALLLogCondition ${logType} ${startTime} ${endTime} ${client_ip} ${policy_id} 10000 1
+ ${LogListResponse} PostRemoteData /${version}/log/count ${logCondition}
+ Should Be Equal As Strings ${LogListResponse.status_code} 200
+ ${returnData} To Json ${LogListResponse.content}
+ ${len} Set Variable ${LogListResponse.json()}[data][total]
+ #${len} Get From Dictionary ${returnData} total
+ [Return] ${len}
+ \ No newline at end of file
diff --git a/keyword/common/login_logout.robot b/keyword/common/login_logout.robot
new file mode 100644
index 0000000..218ac31
--- /dev/null
+++ b/keyword/common/login_logout.robot
@@ -0,0 +1,180 @@
+*** Settings ***
+Resource ../../variable/common_variable.txt
+Library REST http://${host}:${port}
+Library Collections
+#Library SSHLibrary
+Library yaml
+#Library json
+Library OperatingSystem
+Resource ../policys/policy.robot
+Resource ../objects/object.robot
+Resource clear_data.robot
+
+*** Keywords ***
+InitPotocol
+ ${appDict} Create Dictionary
+ ${appVDict} Create Dictionary
+ Connect To Database Using Custom Params pymysql ${mysqlHost}
+ ${app_id} query SELECT group_id,low_boundary,region_name FROM tsg_obj_app_id WHERE is_valid=1 AND region_name='http' OR region_name='ssl' OR region_name='dns' OR region_name='ftp' OR region_name='mail' OR region_name='doh' OR region_name='rtp' OR region_name='sip'
+ # ... SELECT group_id,low_boundary,region_name FROM tsg_obj_app_id WHERE is_valid=1 and region_name in('http','ftp','https','ssl','dns','doh','quic','mail')
+ ${app_length} Get Length ${app_id}
+ FOR ${n} IN RANGE ${app_length}
+ log ${n}
+ Set To Dictionary ${appDict} ${app_id}[${n}][2]=${app_id}[${n}][0]
+ Set To Dictionary ${appVDict} ${app_id}[${n}][2]=${app_id}[${n}][1]
+ log ${appDict}
+ log ${appVDict}
+ END
+ Disconnect From Database
+ #供策略创建使用的appid
+ SET GLOBAL VARIABLE ${objprotol} ${appDict}
+ #供策略验证使用的appid
+ SET GLOBAL VARIABLE ${appportol} ${appVDict}
+ GetProtocol
+
+GetProtocol
+ ${HTTP_ID1} Get From Dictionary ${objprotol} http
+ ${RTP_ID1} Get From Dictionary ${objprotol} rtp
+ ${DNS_ID1} Get From Dictionary ${objprotol} dns
+ ${MAIL_ID1} Get From Dictionary ${objprotol} MAIL
+ ${FTP_ID1} Get From Dictionary ${objprotol} ftp
+ ${SIP_ID1} Get From Dictionary ${objprotol} sip
+ ${SSL_ID1} Get From Dictionary ${objprotol} ssl
+ ${DOH_ID1} Get From Dictionary ${objprotol} DoH
+ SET GLOBAL VARIABLE ${HTTP_ID} ${HTTP_ID1}
+ SET GLOBAL VARIABLE ${RTP_ID} ${RTP_ID1}
+ SET GLOBAL VARIABLE ${DNS_ID} ${DNS_ID1}
+ SET GLOBAL VARIABLE ${MAIL_ID} ${MAIL_ID1}
+ SET GLOBAL VARIABLE ${FTP_ID} ${FTP_ID1}
+ SET GLOBAL VARIABLE ${SIP_ID} ${SIP_ID1}
+ SET GLOBAL VARIABLE ${SSL_ID} ${SSL_ID1}
+ SET GLOBAL VARIABLE ${DOH_ID} ${DOH_ID1}
+
+ ${HTTP_VID1} Get From Dictionary ${appportol} http
+ ${RTP_VID1} Get From Dictionary ${appportol} rtp
+ ${DNS_VID1} Get From Dictionary ${appportol} dns
+ ${MAIL_VID1} Get From Dictionary ${appportol} MAIL
+ ${FTP_VID1} Get From Dictionary ${appportol} ftp
+ ${SIP_VID1} Get From Dictionary ${appportol} sip
+ ${SSL_VID1} Get From Dictionary ${appportol} ssl
+ ${DOH_VID1} Get From Dictionary ${appportol} DoH
+ SET GLOBAL VARIABLE ${HTTP_VID} ${HTTP_VID1}
+ SET GLOBAL VARIABLE ${RTP_VID} ${RTP_VID1}
+ SET GLOBAL VARIABLE ${DNS_VID} ${DNS_VID1}
+ SET GLOBAL VARIABLE ${MAIL_VID} ${MAIL_VID1}
+ SET GLOBAL VARIABLE ${FTP_VID} ${FTP_VID1}
+ SET GLOBAL VARIABLE ${SIP_VID} ${SIP_VID1}
+ SET GLOBAL VARIABLE ${SSL_VID} ${SSL_VID1}
+ SET GLOBAL VARIABLE ${DOH_VID} ${DOH_VID1}
+
+
+InitTemplate
+ #加载对象mode
+ ${YAML}= Get File ${path}/data/template/template.yaml
+ ${LOADED}= yaml.Safe Load ${YAML}
+ ${objMode} Get From Dictionary ${LOADED} ip_batch_mode
+ ${objList} Get From Dictionary ${objMode} objectList
+ #转json替换
+ ${toJson} json.Dumps ${objMode}
+ ${objList} json.Dumps ${objList}
+ SET GLOBAL VARIABLE ${objModeJson} ${toJson}
+ SET GLOBAL VARIABLE ${objListMode} ${objList}
+
+ #${YAML}= Get File ${path}/data/policy_template.yaml
+ #${LOADED}= yaml.Safe Load ${YAML}
+ ${policyMode} Get From Dictionary ${LOADED} policy_template
+ ${policyList} Get From Dictionary ${policyMode} policyList
+ ${toJson} json.Dumps ${policyMode}
+ ${policyList} json.Dumps ${policyList}
+ SET GLOBAL VARIABLE ${policyModeJson} ${toJson}
+ SET GLOBAL VARIABLE ${policyListMode} ${policyList}
+
+ApiLogin
+ [Tags]
+ # 毕方接口密码加密
+ GET /${version}/user/encryptpwd?password=${password}
+ Object response body
+ Integer $.code 200
+ #log ${rescode}
+ ${pwd} String $.data.encryptpwd
+ #log ${pwd}
+ ${pwdstr} Get From List ${pwd} 0
+ log ${pwdstr}
+ SET GLOBAL VARIABLE ${encodePassword} ${pwdstr}
+ log ${encodePassword}
+ #log ${username}
+ #log ${pwdstr}
+ POST /${version}/user/login?username=${username}&password=${encodePassword}&authMode=${authmode}
+ Object response body
+ #OUTPUT response body
+ Integer $.code 200
+ ${rescode} Integer $.code
+ log ${rescode}
+ ${tokenGlobal} String $.data.token
+ ${tokenStr} Get From List ${tokenGlobal} 0
+ log ${tokenStr}
+ SET GLOBAL VARIABLE ${token} ${tokenStr}
+ log ${token}
+ SET GLOBAL VARIABLE ${headers} {"Contest-Type":"application/json","Authorization":"${token}"}
+ #初始化接口中策略中引用协议和策略校验协议
+ Run Keyword If ${addPolicy}==1 InitPotocol
+ #加载对象mode
+ InitTemplate
+ #初始化删除参数
+ SET GLOBAL VARIABLE ${createObjectIds} ${EMPTY}
+ SET GLOBAL VARIABLE ${createPolicyIds} ${EMPTY}
+ #Return ${rescode}
+ApiLogout
+ [Tags] tsg_adc tsg_bf_api
+ POST /${version}/user/logout headers=${headers}
+ Object response body
+ Integer $.code 200
+ ${rescode} Integer $.code
+ #[Return] ${rescode}
+
+BifangLoginAndAddLocalIP
+ [Tags] tsg_adc tsg_bf_api
+ log ApiLoginAndAddLocalIP
+ ApiLogin
+ #log **********
+
+ Run Keyword If ${addTestClentIPFlag}==1 AddLocalIPObject
+ log ApiLoginAndAddLocalIP
+ #添加tsgUIAPI
+ Run Keyword If ${addTsgUIAPIFlag}==1 SecurityPolicyAllowTSGUIAPIAdd
+
+BifangLogoutAndDelLocalIP
+ [Tags] tsg_adc tsg_bf_api
+ log ApiLogoutAndDelLocalIP
+ log to_LogoutAndDelLocalIP_LogoutAndDelLocalIP
+ #删除tsgUIAPI 先删除白名单,是因为此策略也引用了本机IP
+ Run Keyword If ${addTsgUIAPIFlag}==1 SecurityPolicyAllowTSGUIAPIDEL
+ Run Keyword If ${addTestClentIPFlag}==1 DelLocalIPObject
+ #ApiDeleteAutoTagsCase
+ ApiLogout
+ #[Return] ${rescode}
+
+SecurityPolicyAllowTSGUIAPIAdd
+ [Tags] uiallow
+ log toAddTSGUIAPI
+ ${addItemList1} Create Dictionary isSession=endpoint ip=${host}/32 port=0-0 direction=0 protocol=0 isInitialize=0
+ #可以添加多个
+ ${addItemLists} Create list ${addItemList1}
+ #objectList对象
+ ${objectDict} Create Dictionary objectType=ip objectSubType=endpoint isValid=${1} addItemList=${addItemLists}
+ ${rescode} ${objectId} AddObjects ${1} ${objectDict}
+ SET GLOBAL VARIABLE ${testBifangIP} ${objectId}
+ ${HTTP_ID} Get From Dictionary ${objprotol} http
+ ${SSL_ID} Get From Dictionary ${objprotol} ssl
+ Comment 创建安全策略
+ ${policyDict} Create Dictionary policyName=SecurityPolicy-Allow-TSGUIAPI policyType=tsg_security policyDesc=autotest action=allow source=${testClentID}|TSG_SECURITY_SOURCE_ADDR destination=${objectId}|TSG_SECURITY_DESTINATION_ADDR userRegion={} isValid=${1} appIdObjects=${HTTP_ID},${SSL_ID}
+ log ${policyDict}
+ ${rescode} ${policyId} AddPolicies 1 ${policyDict} v2
+ SET GLOBAL VARIABLE ${testBifangPolicy} ${policyId}
+ log addTSGUIAPISucess
+SecurityPolicyAllowTSGUIAPIDEL
+ [Tags] uiallow
+ log toDelTSGUIAPI
+ ${objectIds} Create List ${testBifangIP}
+ DeletePolicyAndGroupObject ${testBifangPolicy} ${objectIds}
+ log delTSGUIAPISucess \ No newline at end of file
diff --git a/keyword/common/login_logout_switch.robot b/keyword/common/login_logout_switch.robot
new file mode 100644
index 0000000..38e9d7b
--- /dev/null
+++ b/keyword/common/login_logout_switch.robot
@@ -0,0 +1,25 @@
+*** Settings ***
+Resource ../../variable/common_variable.txt
+Library Collections
+Resource login_logout.robot
+#Resource logout.robot
+#Resource login.robot
+
+
+*** Keywords ***
+LoginAndAddLocalIP
+ [Tags] tsg_adc tsg_bf_api tsg_device tsg_adc_wp adc_api adc_verify adc_log
+ #[Tags] 分步骤之外的全流程 毕方接口 设备相关 分步骤全部 分步骤策略 分步骤功能端验证 分步骤日志验证
+ # 获取主机IP
+ #${ip} Get Host IP
+ #Run Keyword If '${ip}' != '${EMPTY}' Set Global Variable ${testClentIP} ${ip}
+
+ Run Keyword If '${loginType}' == 'api' BifangLoginAndAddLocalIP
+ #... ELSE IF '${loginType}' == 'cli' CliLogin
+ ... ELSE IF '${loginType}' != '${None}' UiLoginAndAddLocalIP
+
+LogoutAndDelLocalIP
+ [Tags] tsg_adc tsg_bf_api tsg_device tsg_adc_wp adc_api adc_verify adc_log
+ Run Keyword If '${loginType}' == 'api' BifangLogoutAndDelLocalIP
+ #... ELSE IF '${loginType}' == 'cli' CliLogout
+ ... ELSE IF '${loginType}' != '${None}' UiLogoutAndDelLocalIP
diff --git a/keyword/common/logschema.robot b/keyword/common/logschema.robot
new file mode 100644
index 0000000..f10094c
--- /dev/null
+++ b/keyword/common/logschema.robot
@@ -0,0 +1,69 @@
+*** Settings ***
+Resource ../../other/all_flow_case_variable.txt
+Library RequestsLibrary
+Library OperatingSystem
+Library Collections
+Library string
+Library REST http://${host}:${port}
+
+*** Keywords ***
+GetLogCondition
+ [Arguments] ${logname} ${startTime} ${endTime} ${client_ip} ${policy_id}
+ Set Headers {"Content-Type":"application/x-www-form-urlencoded","Authorization":"${token}"}
+ &{LogSchemaResponse}= GET /${version}/log/schema?logType=${logname}
+ log ${logname}
+ #Output Schema response body
+ Object response body
+ #Integer $.code 200
+ log ${LogSchemaResponse.body['data']}
+ ${field} Evaluate json.dumps(eval(str(${LogSchemaResponse.body['data']['fields']}))) json
+ log ${field}
+ ${pageSize} Set Variable 30
+ ${pageNo} Set Variable 1
+ ${condition} Set Variable [{"value":["${startTime}","${endTime}"],"symbol":"between","field":"common_recv_time","type":"timestamp"}]
+ ${logCondition} Set Variable {"pageNo":${pageNo},"pageSize":${pageSize},"logType":"${logname}","fields":${field},"start_common_recv_time":"${startTime}","end_common_recv_time":"${endTime}","conditions":${condition} ,"common_client_ips":"${client_ip}","common_policy_ids":"${policy_id}"}
+ log this time query condition:${logCondition}
+ [Return] ${logCondition}
+
+PostRemoteData
+ [Arguments] ${url} ${data}
+ ${header} Create Dictionary Content-Type=application/json Authorization=${token}
+ Create Session api http://${host}:${port} headers=${header}
+ ${remoteResponse} Post Request api ${url} data=${data} headers=${header}
+ [Return] ${remoteResponse}
+
+GetALLLogCondition
+ [Arguments] ${logname} ${startTime} ${endTime} ${client_ip} ${policy_id} ${pageSize} ${pageNo}
+ Set Headers {"Content-Type":"application/x-www-form-urlencoded","Authorization":"${token}"}
+ &{LogSchemaResponse}= GET /${version}/log/schema?logType=${logname}
+ log ${logname}
+ #Output Schema response body
+ Object response body
+ #Integer $.code 200
+ log ${LogSchemaResponse.body['data']}
+ ${field} Evaluate json.dumps(eval(str(${LogSchemaResponse.body['data']['fields']}))) json
+ log ${field}
+ #${pageSize} Set Variable 30
+ #${pageNo} Set Variable 1
+ ${condition} Set Variable [{"value":["${startTime}","${endTime}"],"symbol":"between","field":"common_recv_time","type":"timestamp"}]
+ ${logCondition} Set Variable {"pageNo":${pageNo},"pageSize":${pageSize},"logType":"${logname}","fields":${field},"start_common_recv_time":"${startTime}","end_common_recv_time":"${endTime}","conditions":${condition} ,"common_client_ips":"${client_ip}","common_policy_ids":"${policy_id}"}
+ log this time query condition:${logCondition}
+ [Return] ${logCondition}
+
+GetLogCountConditon
+ [Arguments] ${logname} ${startTime} ${endTime} ${client_ip} ${policy_id} ${pageSize} ${pageNo}
+ Set Headers {"Content-Type":"application/x-www-form-urlencoded","Authorization":"${token}"}
+ &{LogSchemaResponse}= GET /${version}/log/schema?logType=${logname}
+ log ${logname}
+ #Output Schema response body
+ Object response body
+ #Integer $.code 200
+ log ${LogSchemaResponse.body['data']}
+ ${field} Evaluate json.dumps(eval(str(${LogSchemaResponse.body['data']['fields']}))) json
+ log ${field}
+ #${pageSize} Set Variable 30
+ #${pageNo} Set Variable 1
+ ${condition} Set Variable [{"value":["${startTime}","${endTime}"],"symbol":"between","field":"common_recv_time","type":"timestamp"}]
+ ${logCondition} Set Variable {"pageNo":${pageNo},"pageSize":${pageSize},"logType":"${logname}","fields":${field},"start_common_recv_time":"${startTime}","end_common_recv_time":"${endTime}","conditions":${condition} ,"common_client_ips":"${client_ip}","common_policy_ids":"${policy_id}"}
+ log this time query condition:${logCondition}
+ [Return] ${logCondition} \ No newline at end of file
diff --git a/keyword/common/systemcommand.robot b/keyword/common/systemcommand.robot
new file mode 100644
index 0000000..cc96c8c
--- /dev/null
+++ b/keyword/common/systemcommand.robot
@@ -0,0 +1,63 @@
+*** Settings ***
+Library OperatingSystem
+Library Selenium2Library
+Library RequestsLibrary
+Library Collections
+Resource ../../variable/common_variable.txt
+
+*** Keywords ***
+SystemCommands
+ [Arguments] ${commandstr} ${stringlist}
+ log toSystemCommand_SystemCommandTest
+ ${commandreturn} OperatingSystem.Run ${commandstr}
+ Append To File ${path}/write_file.txt ${commandstr}
+ Append To File ${path}/write_file.txt %%%%%%%%%%%%%%newbat
+ Append To File ${path}/write_file.txt ${commandreturn}
+ ${listlenth}= Get Length ${stringlist}
+ FOR ${var} IN RANGE ${listlenth}
+ #log ${var}
+ Should Contain ${commandreturn} ${stringlist}[${var}]
+ END
+ ${rescode} Set Variable 200
+ log ${rescode}
+ [Return] ${rescode}
+
+SystemCommand
+ [Arguments] ${commandstr} @{stringlist}
+ log dxytest${commandstr}
+ ${commandreturn} OperatingSystem.Run ${commandstr}
+ #nslookup -d www.jd.com
+ log ${commandreturn}
+ FOR ${var} IN @{stringlist}
+ log dxytest
+ log ${var}
+ Should Contain ${commandreturn} ${var}
+ END
+ #Should Contain ${commandreturn} ${qatype}
+ ${rescode} Set Variable 200
+ log ${rescode}
+ [Return] ${rescode}
+
+
+SystemCommandReturnCompare
+ #执行命令并比对命令返回结果 需要执行的系统命令 命令返回结果要包含的字符串列表 命令返回结果不能包含的字符串列表
+ [Arguments] ${commandstr} ${stringlist} ${stringlistnotin}
+ log toSystemCommand_SystemCommandTest
+ ${commandreturn} OperatingSystem.Run ${commandstr}
+ Append To File ${path}/write_file.txt ${commandstr}
+ Append To File ${path}/write_file.txt %%%%%%%%%%%%%%newbat
+ Append To File ${path}/write_file.txt ${commandreturn}
+ #${commandreturn} Set Variable abcdeConnection was reset
+ ${listlenth}= Get Length ${stringlist}
+ FOR ${var} IN RANGE ${listlenth}
+ log ${var}
+ Should Contain ${commandreturn} ${stringlist}[${var}]
+ END
+ ${listnotin}= Get Length ${stringlistnotin}
+ FOR ${varn} IN RANGE ${listnotin}
+ log ${varn}
+ Should Not Contain ${commandreturn} ${stringlistnotin}[${varn}]
+ END
+ ${rescode} Set Variable 200
+ log ${rescode}
+ [Return] ${rescode}
diff --git a/keyword/objects/application.robot b/keyword/objects/application.robot
new file mode 100644
index 0000000..43e2c6d
--- /dev/null
+++ b/keyword/objects/application.robot
@@ -0,0 +1,55 @@
+*** Settings ***
+Library Collections
+Library RequestsLibrary
+Resource ../../variable/common_variable.txt
+#Resource functional_keywords.robot
+Library Collections
+Resource ../common/common.robot
+#Library ../../../04-CustomLibrary/Library/fileOperations.py
+
+*** Variables ***
+${applicationUrl} /application
+${signatureUrl} /application/signatures
+*** Keywords ***
+AddSignature
+ [Arguments] ${signaturereqbody}
+ [Documentation] 新增Signature,返回Signature ID
+ ${response} BasePostRequestForV2 ${signatureUrl} ${signaturereqbody} ${version}
+ ${rescode} Set Variable ${response['code']}
+ ${signatureId} Set Variable ${response['data']['signatures'][0]['signatureId']}
+ Should Be Equal As Strings ${rescode} 200
+ [Return] ${signatureId}
+AddApplication
+ [Arguments] ${appreqbody}
+ [Documentation] 新增Application,返回APPIDObject
+ ${response} BasePostRequestForV2 ${applicationUrl} ${appreqbody} ${version}
+ ${rescode} Set Variable ${response['code']}
+ ${appids} Set Variable ${response['data']['appObj']['appId']}
+ Should Be Equal As Strings ${rescode} 200
+ [Return] ${appids}
+GetAppIdObjects
+ [Arguments] ${appids}
+ [Documentation] 通过APPID查询Application,返回APPIDObject
+ ${response} BaseFormRequest ${applicationUrl} appIds=${appids} ${version}
+ ${rescode} Set Variable ${response['code']}
+ ${appidobject} Set Variable ${response['data']['list'][0]['objectId']}
+ Should Be Equal As Strings ${rescode} 200
+ [Return] ${appidobject}
+
+DeleteApplicationByIds
+ [Arguments] ${appids}
+ #删除Application
+ ${response} BaseDeleteRequest /${version}/application {"appIds":[${appids}]}
+ ${response_code} Get From Dictionary ${response} code
+ Should Be Equal As Strings ${response_code} 200
+ ${response} Convert to String ${response}
+ log ${response}
+
+DeleteSignatureByIds
+ [Arguments] ${signatureId}
+ #删除Signature
+ ${response} BaseDeleteRequest /${version}/application/signatures {"signatureIds":[${signatureId}]}
+ ${response_code} Get From Dictionary ${response} code
+ Should Be Equal As Strings ${response_code} 200
+ ${response} Convert to String ${response}
+ log ${response}
diff --git a/keyword/objects/ip.yaml b/keyword/objects/ip.yaml
new file mode 100644
index 0000000..0cfc271
--- /dev/null
+++ b/keyword/objects/ip.yaml
@@ -0,0 +1,22 @@
+#yaml在线格式化:https://www.bejson.com/validators/yaml_editor/
+"ip_secuirty_allow_dns_001":
+ "opAction": "add"
+ "returnData": 1
+ "objectList":
+ "objectType": "ip"
+ "objectSubType": "endpoint"
+ "isValid": 1
+ "isInitialize": 0
+ "isExclusion": 0
+ "objectName": "dxytest"
+ "objectDesc": "test"
+ "subObjectIds":
+ "addItemList":
+ "ip": "192.168.50.19"
+ "port": "1-65535"
+ "itemId":
+ "isSession": "endpoint"
+ "updateItemList":
+ "deleteItemIds":
+ "iconColor": "#31739C"
+
diff --git a/keyword/objects/ip_objects.robot b/keyword/objects/ip_objects.robot
new file mode 100644
index 0000000..19a4b55
--- /dev/null
+++ b/keyword/objects/ip_objects.robot
@@ -0,0 +1,176 @@
+*** Settings ***
+Library yaml
+Resource ../../../variable/common_variable.txt
+Resource object.robot
+Resource ../../common/common.robot
+Library Collections
+Library json
+Library String
+#Resource ip.yaml
+*** Variables ***
+${objectUrl} /policy/object
+${objectids} ${EMPTY}
+
+*** Keywords ***
+AllowDns001ObjectV4
+ [Tags]
+ [Arguments] ${filepath} ${filename} ${keywords}
+ Comment 参数 ${filepath}读取文件路径 ${filename}读取文件名 ${keywords}获取数据关键字
+ Comment 创建IP
+ #yaml在线格式化:https://www.bejson.com/validators/yaml_editor/
+ ${YAML}= Get File ${filepath}${/}${filename}
+ ${LOADED}= yaml.Safe Load ${YAML}
+ ${ip_secuirty_allow_dns_001} Get From Dictionary ${LOADED} ${keywords}
+ ${retkeys} evaluate [one for one in ${ip_secuirty_allow_dns_001}]
+ ${dictType} = Evaluate type(${retkeys})
+ ${returnData} Get From Dictionary ${ip_secuirty_allow_dns_001} returnData
+ ${bodyJson} json.Dumps ${ip_secuirty_allow_dns_001}
+
+ #Set To Dictionary ${LOADED}[patch_id_bw_data][pronghornResponseBody][responseBody][0][value][0] value=200
+ #${addItemList1} Create Dictionary isSession=endpoint ip=${testClentIP} port=0-65535 direction=0 protocol=0 isInitialize=0
+ #${addItemLists} Create list ${addItemList1}
+ #${objectDict} Create Dictionary objectType=ip objectSubType=endpoint isValid=${1} addItemList=${addItemLists}
+ #${rescode} ${objectId} AddObjects ${1} ${objectDict}
+ #${objectids} set Variable ${objectId}
+
+ ${response} BasePostRequestForV2 ${objectUrl} ${bodyJson} ${version}
+ ${objectIds} Run Keyword If "${returnData}" == "1" GetObjectIds ${response}
+ ... ELSE Create List
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ [Return] ${rescode} ${objectIds}
+
+IpObject
+ [Tags]
+ [Arguments] ${filepath} ${filename} ${keywords}
+ Comment 参数 ${filepath}读取文件路径 ${filename}读取文件名 ${keywords}获取数据关键字
+ Comment 创建IP
+ #yaml在线格式化:https://www.bejson.com/validators/yaml_editor/
+ ${YAML}= Get File ${filepath}${/}${filename}
+ ${LOADED}= yaml.Safe Load ${YAML}
+ ${ipList} Get From Dictionary ${LOADED} ${keywords}
+ ${rescode} ${objectIds} IpRequest ${ipList}
+ [Return] ${rescode} ${objectIds}
+
+BatchCreateIps
+ [Tags]
+ [Arguments] ${filepath} ${filename} ${keywords}
+ Comment 参数 ${filepath}读取文件路径 ${filename}读取文件名 ${keywords}获取数据关键字
+ Comment 创建IP
+ #yaml在线格式化:https://www.bejson.com/validators/yaml_editor/
+ ${YAML}= Get File ${filepath}${/}${filename}
+ ${LOADED}= yaml.Safe Load ${YAML}
+ ${ipList} Get From Dictionary ${LOADED} ${keywords}
+ ${ipListType} = Evaluate type(${ipList})
+ #${retkeys} evaluate [one for one in ${ipList}]
+ #${dictType} = Evaluate type(${retkeys})
+ ${objectIds} Run Keyword If "${ipListType}" == "<class 'list'>" IpObjectBatch ${ipList}
+ ... ELSE Set Variable ${EMPTY}
+ ${ipListType} = Evaluate type(${objectIds})
+ ${json} json.Dumps ${objectIds} ensure_ascii=False
+ ${json} = Replace String ${json} ["", [
+ ${objectIds} json.loads ${json}
+ [Return] ${objectIds}
+
+IpObjectBatch
+ [Tags]
+ [Arguments] ${objDictList}
+ Comment 参数${objDictList}多个象字典列表
+ Comment 创建IP
+ ${objids} Create List ${EMPTY}
+ ${ipListType} = Evaluate type(${objDictList})
+ FOR ${objDict} IN @{objDictList}
+ ${rescode} ${objectIds} CreateObject ${objDict}
+ AppendListToList ${objids} ${objectIds}
+ END
+ [Return] ${objids}
+
+
+#####################################################################################################################
+
+OrangeFilter
+ [Documentation] filer对象处理,把一个filter的list处理为一个filter
+ #[Arguments] ${filterList} ${objectList}
+ [Arguments] ${objectList}
+ ${list} Create List ${objectList}
+ ${filter} Create Dictionary filter=${list}
+ #${filterList} Append To List ${filter}
+ [Return] ${filter}
+
+CreateObjectList
+ [Documentation] 处理对象
+ [Arguments] ${objectData}
+ Comment 针对位置进行处理
+ ${protocolField} Get From Dictionary ${objectData} protocolField
+ #${objList} Get From Dictionary ${objectData} objList
+
+ ${objectIds} ${objectList} CreateObjects ${objectData}
+ ${objectList} Run Keyword If "${protocolField}" == "TSG_SECURITY_SOURCE_ADDR" or "${protocolField}" == "None" or "${protocolField}" == "TSG_SECURITY_SOURCE_LOCATION" or "${protocolField}" == "TSG_SECURITY_SOURCE_ASN" or "${protocolField}" == "TSG_FILED_GTP_IMSI" or "${protocolField}" == "TSG_FILED_GTP_PHONE_NUMBER" or "${protocolField}" == "TSG_FILED_GTP_APN" Set Variable ${objectList}
+ ##############destination
+ ... ELSE IF "${protocolField}" == "TSG_SECURITY_DESTINATION_ADDR" or "${protocolField}" == "TSG_SECURITY_DESTINATION_LOCATION" or "${protocolField}" == "TSG_SECURITY_DESTINATION_ASN" Set Variable ${objectList}
+ #filter
+ ... ELSE OrangeFilter ${objectList}
+ [Return] ${objectIds} ${objectList}
+CreateObjects
+ [Documentation] 处理对象
+ [Arguments] ${objectData}
+ Comment 针对位置进行处理
+ #${YAML}= Get File ${path}/data/mode.yaml
+ #${LOADED}= yaml.Safe Load ${YAML}
+ #${ipMode} Get From Dictionary ${LOADED} ip_batch_mode
+ ${protocolField} Get From Dictionary ${objectData} protocolField
+ ${objList} Get From Dictionary ${objectData} objList
+
+ Comment ${objJson}对象模板取自全局变量
+ ${objJson} Set Variable ${objModeJson}
+ ${objectJson} Set Variable ${objListMode}
+ #JSON处理
+ ${return} ${objectType} Run Keyword And Ignore Error Get From Dictionary ${objectData} objectType
+ ${objectJson} = Run Keyword If "${return}"!="FAIL" and "${objectType}" != "None" Replace String ${objectJson} "objectType": "ip" "objectType":"${objectType}"
+ ... ELSE Set Variable ${objectJson}
+ ${return} ${objectSubType} Run Keyword And Ignore Error Get From Dictionary ${objectData} objectSubType
+ #${objectSubType} Run Keyword If "${return}"!="FAIL" Set Variable ${objectSubType} ELSE Set Variable ${EMPTY}
+ ${objectJson} = Run Keyword If "${return}"!="FAIL" and "${objectSubType}" != "None" Replace String ${objectJson} "objectSubType": "endpoint" "objectSubType":"${objectSubType}"
+ ... ELSE Set Variable ${objectJson}
+ ${return} ${objectId} Run Keyword And Ignore Error Get From Dictionary ${objectData} objectId
+ ${objectJson} = Run Keyword If "${return}"!="FAIL" and "${objectId}" != "None" Replace String ${objectJson} "objectId": null "objectId":${objectId}
+ ... ELSE Set Variable ${objectJson}
+ ${objectJson} = Run Keyword If "${return}"!="FAIL" and "${objectId}" != "None" Replace String ${objectJson} "opAction": "add" "option": "update"
+ ... ELSE Set Variable ${objectJson}
+ #${objectId} Run Keyword If "${return}"!="FAIL" Set Variable ${objectId} ELSE Set Variable ${EMPTY}
+ #JSON处理
+ ${objectJsonList} Create List
+ ${objListType} = Evaluate type(${objList})
+ FOR ${obj} IN @{objList}
+ ${return} ${addItemList} Run Keyword And Ignore Error Get From Dictionary ${obj} addItemList
+ #${objectJson} Convert To String ${objectJson}
+ #${addItemList} Convert To String ${addItemList}
+ #${objectJson} josn.loads ${objectJson}
+ ${addItemList} json.Dumps ${addItemList}
+ #${objectJson} = Replace String ${objectJson} "addItemList": "addItemList":${itemList}
+ ${addItemList} = Run Keyword If "${return}"!="FAIL" and "${objectSubType}" == "ip_learning" Replace String ${addItemList} [{" "
+ ... ELSE Set Variable ${addItemList}
+ ${addItemList} = Run Keyword If "${return}"!="FAIL" and "${objectSubType}" == "ip_learning" Replace String ${addItemList} "}] "
+ ... ELSE Set Variable ${addItemList}
+ ${objectJson} = Run Keyword If "${return}"!="FAIL" and "${objectSubType}" == "ip_learning" Replace String ${objectJson} "addItemList": [null] "addItemList": [], ${addItemList}
+ ... ELSE IF "${return}"!="FAIL" Replace String ${objectJson} "addItemList": [null] "addItemList": ${addItemList}
+ ... ELSE Set Variable ${objectJson}
+ ${objectJson} = Replace String ${objectJson} [null] []
+ #提交接口返回id拼接
+
+ #Create File ${path}/test.txt ${objectJson}
+ #Append To File ${path}/test.txt ${objectJson}
+ ${objDictionary} json.loads ${objectJson}
+ AppendListToList ${objectJsonList} ${objDictionary}
+ END
+ ${objectData} Create Dictionary opAction=add returnData=1 objectList=${objectJsonList}
+ ${rescode} ${objectIds} createObject ${objectData}
+ Should Be Equal As Strings ${rescode} 200
+
+ ${protocolField} Run Keyword If "${protocolField}" != "None" Set Variable ${protocolField}
+ ${objectsList} Create List
+ FOR ${obj} IN @{objectIds}
+ ${objectList} Create Dictionary objectId=${objectIds}[0] protocolField=${protocolField}
+ Append To List ${objectsList} ${objectList}
+ END
+ [Return] ${objectIds} ${objectList}
diff --git a/keyword/objects/manage_object_body.robot b/keyword/objects/manage_object_body.robot
new file mode 100644
index 0000000..dc57ae4
--- /dev/null
+++ b/keyword/objects/manage_object_body.robot
@@ -0,0 +1,378 @@
+*** Settings ***
+Library json
+Library Collections
+Resource ../../variable/common_variable.txt
+Resource ../../variable/policy_object_default.txt
+Resource Object.robot
+
+*** Keywords ***
+ObjectParamsOpertion
+ [Documentation]
+ ... 描述:入口,opAction参数固定为'add'
+ ... 其它参数默认值见/03-Variable/PolicyObjectDefault.txt
+
+ [Arguments] ${returnData} ${objectList} ${opAction}
+ ${emptyList} Create List
+ ${returnDict} Create Dictionary
+ # 断言必传参数
+ # Should Not Be Empty ${objectList}[objectType]
+ # Set To Dictionary ${returnDict} objectType=${objectList}[objectType]
+ Should Not Be Empty ${objectList}[addItemList]
+ # 取可选参数,为传入设置默认值
+ ${return} ${objectType} Run Keyword And Ignore Error Set Variable ${objectList}[objectType]
+ ${objectTypeV} Run Keyword If "${return}"!="FAIL" and "${objectType}"!="${EMPTY}" Evaluate '${objectType}'.lower()
+ ... ELSE Evaluate '${Default_ObjectType}'.lower()
+ Set To Dictionary ${objectList} objectType=${objectTypeV}
+ Set To Dictionary ${returnDict} objectType=${objectTypeV}
+ ${return} ${objectSubType} Run Keyword And Ignore Error Set Variable ${objectList}[objectSubType]
+ Run Keyword If "${return}"!="FAIL" and "${objectSubType}"!="${EMPTY}" Set To Dictionary ${returnDict} objectSubType=${objectSubType}
+ ... ELSE Set To Dictionary ${returnDict} objectSubType=${Default_ObjectSubType}
+ ${return} ${isValid} Run Keyword And Ignore Error Set Variable ${objectList}[isValid]
+ Run Keyword If "${return}"=="FAIL" or "${isValid}"=="${EMPTY}" Set To Dictionary ${returnDict} isValid=${Default_IsValid}
+ ... ELSE Set To Dictionary ${returnDict} isValid=${isValid}
+ ${return} ${isInitialize} Run Keyword And Ignore Error Set Variable ${objectList}[isInitialize]
+ Run Keyword If "${return}"=="FAIL" or "${isInitialize}"=="${EMPTY}" Set To Dictionary ${returnDict} isInitialize=${Default_IsInitialize}
+ ... ELSE Set To Dictionary ${returnDict} isInitialize=${isInitialize}
+ ${return} ${isExclusion} Run Keyword And Ignore Error Set Variable ${objectList}[isExclusion]
+ Run Keyword If "${return}"=="FAIL" or "${isExclusion}"=="${EMPTY}" Set To Dictionary ${returnDict} isExclusion=${Default_IsExclusion}
+ ... ELSE Set To Dictionary ${returnDict} isExclusion=${isExclusion}
+ ${return} ${objectName} Run Keyword And Ignore Error Set Variable ${objectList}[objectName]
+ Run Keyword If "${return}"=="FAIL" or "${objectName}"=="${EMPTY}" Set To Dictionary ${returnDict} objectName=${Default_ObjectName}
+ ... ELSE Set To Dictionary ${returnDict} objectName=${objectName}
+ ${return} ${objectDesc} Run Keyword And Ignore Error Set Variable ${objectList}[objectDesc]
+ Run Keyword If "${return}"!="FAIL" and "${objectDesc}"!="${EMPTY}" Set To Dictionary ${returnDict} objectDesc=${objectDesc}
+ ... ELSE Set To Dictionary ${returnDict} objectDesc=${Default_ObjectDesc}
+ ${return} ${subObjectIds} Run Keyword And Ignore Error Set Variable ${objectList}[subObjectIds]
+ ${subObjectIdsV} Run Keyword If "${return}"!="FAIL" and "${subObjectIds}"!="${EMPTY}" and "${subObjectIds}"!="${None}" Evaluate list(map(int, re.split('[,]', '${subObjectIds}'))) re
+ ... ELSE Set Variable ${emptyList}
+ ${return} ${objectId} Run Keyword And Ignore Error Set Variable ${objectList}[objectId]
+ Run Keyword If "${return}"=="FAIL" or "${objectId}"=="${EMPTY}" Set To Dictionary ${returnDict} objectId=${EMPTY}
+ ... ELSE Set To Dictionary ${returnDict} objectId=${objectId}
+ Set To Dictionary ${returnDict} subObjectIds=${subObjectIdsV}
+
+ # 处理AddItemList
+ ManageAddItemList ${objectList} ${returnDict}
+
+ # 转为json结构并返回
+ ${dict} Create Dictionary opAction=${opAction} returnData=${returnData} objectList=${returnDict}
+ ${json} json.Dumps ${dict} ensure_ascii=False
+ Log Object_Request_Body-${json}
+ [Return] ${json}
+
+ManageAddItemList
+ # 处理addItemList数组
+ [Arguments] ${objectList} ${returnDict}
+ ${itemList} Run Keyword If '${objectList}[objectType]'=='ip' ManageIpItemList ${objectList}[addItemList]
+ ... ELSE IF '${objectList}[objectType]'=='http_signature' ManageStrItemList ${objectList}[addItemList] ${True}
+ ... ELSE ManageStrItemList ${objectList}[addItemList] ${False}
+ Set To Dictionary ${returnDict} addItemList=${itemList}
+
+ManageIpItemList
+ # 处理IP对象
+ [Arguments] ${str}
+ ${returnList} Create List
+ # ${list} Evaluate re.split('[,]', '${str}') re
+ log ${str}
+ FOR ${var} IN @{str}
+ # Continue For Loop If '${var}' == '${EMPTY}'
+ # 区分入参的类型,分别处理
+ Append To List ${returnList} ${var}
+ END
+ [Return] ${returnList}
+
+ManageStrItemList
+ # 处理除IP外其它字符串对象
+ [Arguments] ${str} ${flag}
+ ${returnList} Create List
+ ${list} Evaluate re.split('[,]', '${str}') re
+ FOR ${var} IN @{list}
+ Continue For Loop If '${var}' == '${EMPTY}'
+ ${obj} AnalysisStrItem ${var} ${flag}
+ Append To List ${returnList} ${obj}
+ END
+ [Return] ${returnList}
+IpItemType11
+ [Arguments] ${str}
+ ${obj} Create Dictionary
+ ${values} Evaluate re.split('[|]', '${str}') re
+ ${isSession} Convert To Integer ${values}[0]
+ ${ip} Convert To Integer ${values}[1]
+ ${port} Convert To Integer ${values}[2]
+ ${direction} Convert To Integer ${values}[3]
+ ${protocol} Convert To Integer ${values}[4]
+ ${return} ${isInitialize} Run Keyword And Ignore Error Convert To Integer ${list}[${index+1}]
+ Run Keyword If "${return}"!="FAIL" and "${isInitialize}"!="${EMPTY}" Set To Dictionary ${obj} isInitialize=${isInitialize}
+IpItemType1
+ # IP类型1:4|0|0|endpoint#range|192.168.40.1|192.168.40.50|80/88&range|192.168.40.1|192.168.40.50|80/88|1|itemName|itemDesc,...
+ [Arguments] ${str}
+ ${obj} Create Dictionary
+ ${left} Evaluate '${str}'[0:'${str}'.find('#')]
+ ${right} Evaluate '${str}'['${str}'.find('#')+1:]
+ ${values} Evaluate re.split('[|]', '${left}') re
+ ${addrType} Convert To Integer ${values}[0]
+ ${protocol} Convert To Integer ${values}[1]
+ ${direction} Convert To Integer ${values}[2]
+ Set To Dictionary ${obj} addrType=${addrType} protocol=${protocol} direction=${direction} isSession=${values}[3]
+
+ ${cfgs} Evaluate re.split('[&]', '${right}') re
+ ${client} Set Variable ${cfgs}[0]
+ ${server} Set Variable ${cfgs}[1]
+
+ ${cValues} Evaluate re.split('[|]', '${client}') re
+ ${sValues} Evaluate re.split('[|]', '${server}') re
+ ${clientPort1} Evaluate int(re.split('[/]', '${cValues}[3]')[0]) re
+ ${clientPort2} Evaluate int(re.split('[/]', '${cValues}[3]')[1]) re
+ ${serverPort1} Evaluate int(re.split('[/]', '${sValues}[3]')[0]) re
+ ${serverPort2} Evaluate int(re.split('[/]', '${sValues}[3]')[1]) re
+ Set To Dictionary ${obj} clientIpFormat=${cValues}[0] clientIp1=${cValues}[1] clientIp2=${cValues}[2] clientPortFormat=range clientPort1=${clientPort1} clientPort2=${clientPort2}
+ Set To Dictionary ${obj} serverIpFormat=${sValues}[0] serverIp1=${sValues}[1] serverIp2=${sValues}[2] serverPortFormat=range serverPort1=${serverPort1} serverPort2=${serverPort2}
+
+ OtherParams ${sValues} ${obj}
+ [Return] ${obj}
+
+IpItemType2
+ # IP类型2:4|0|0|endpoint#range|192.168.40.1|192.168.40.50|80/88|1|itemName|itemDesc,...
+ [Arguments] ${str}
+ ${obj} Create Dictionary
+ ${left} Evaluate '${str}'[0:'${str}'.find('#')]
+ ${client} Evaluate '${str}'['${str}'.find('#')+1:]
+ ${values} Evaluate re.split('[|]', '${left}') re
+ ${addrType} Convert To Integer ${values}[0]
+ ${protocol} Convert To Integer ${values}[1]
+ ${direction} Convert To Integer ${values}[2]
+ Set To Dictionary ${obj} addrType=${addrType} protocol=${protocol} direction=${direction} isSession=${values}[3]
+
+ ${cValues} Evaluate re.split('[|]', '${client}') re
+ ${clientPort1} Evaluate int(re.split('[/]', '${cValues}[3]')[0]) re
+ ${clientPort2} Evaluate int(re.split('[/]', '${cValues}[3]')[1]) re
+ Set To Dictionary ${obj} clientIpFormat=${cValues}[0] clientIp1=${cValues}[1] clientIp2=${cValues}[2] clientPortFormat=range clientPort1=${clientPort1} clientPort2=${clientPort2}
+ # 设置默认值
+ Set To Dictionary ${obj} serverIpFormat=range serverIp1= serverIp2= serverPortFormat=range serverPort1=${0} serverPort2=${0}
+ OtherParams ${cValues} ${obj}
+ [Return] ${obj}
+
+IpItemType3
+ # IP类型3:range|192.168.40.1|192.168.40.50|80/88&range|192.168.40.1|192.168.40.50|80/88|1|itemName|itemDesc,...
+ [Arguments] ${str}
+ ${obj} Create Dictionary
+ # 设置默认值
+ Run Keyword If ':' in '${str}' Set To Dictionary ${obj} addrType=${6}
+ ... ELSE Set To Dictionary ${obj} addrType=${Default_AddItem_AddrType}
+ Set To Dictionary ${obj} protocol=${Default_AddItem_Protocol} direction=${Default_AddItem_Direction} isSession=${Default_AddItem_IsSession}
+
+ ${cfgs} Evaluate re.split('[&]', '${str}') re
+ ${client} Set Variable ${cfgs}[0]
+ ${server} Set Variable ${cfgs}[1]
+
+ ${cValues} Evaluate re.split('[|]', '${client}') re
+ ${sValues} Evaluate re.split('[|]', '${server}') re
+ ${clientPort1} Evaluate int(re.split('[/]', '${cValues}[3]')[0]) re
+ ${clientPort2} Evaluate int(re.split('[/]', '${cValues}[3]')[1]) re
+ ${serverPort1} Evaluate int(re.split('[/]', '${sValues}[3]')[0]) re
+ ${serverPort2} Evaluate int(re.split('[/]', '${sValues}[3]')[1]) re
+ Set To Dictionary ${obj} clientIpFormat=${cValues}[0] clientIp1=${cValues}[1] clientIp2=${cValues}[2] clientPortFormat=range clientPort1=${clientPort1} clientPort2=${clientPort2}
+ Set To Dictionary ${obj} serverIpFormat=${sValues}[0] serverIp1=${sValues}[1] serverIp2=${sValues}[2] serverPortFormat=range serverPort1=${serverPort1} serverPort2=${serverPort2}
+
+ OtherParams ${sValues} ${obj}
+ [Return] ${obj}
+
+IpItemType4
+ # IP类型4:range|192.168.40.1|192.168.40.50|80/88|1|itemName|itemDesc,...
+ [Arguments] ${str}
+ ${obj} Create Dictionary
+ # 设置默认值
+ Run Keyword If ':' in '${str}' Set To Dictionary ${obj} addrType=${6}
+ ... ELSE Set To Dictionary ${obj} addrType=${4}
+ Set To Dictionary ${obj} protocol=${0} direction=${0} isSession=endpoint
+
+ ${cValues} Evaluate re.split('[|]', '${str}') re
+ ${clientPort1} Evaluate int(re.split('[/]', '${cValues}[3]')[0]) re
+ ${clientPort2} Evaluate int(re.split('[/]', '${cValues}[3]')[1]) re
+ Set To Dictionary ${obj} clientIpFormat=${cValues}[0] clientIp1=${cValues}[1] clientIp2=${cValues}[2] clientPortFormat=range clientPort1=${clientPort1} clientPort2=${clientPort2}
+ # 设置默认值
+ Set To Dictionary ${obj} serverIpFormat=range serverIp1= serverIp2= serverPortFormat=range serverPort1=${0} serverPort2=${0}
+
+ OtherParams ${cValues} ${obj}
+ [Return] ${obj}
+
+AnalysisStrItem
+ [Arguments] ${str} ${flag}
+ ${obj} Create Dictionary
+ ${list} Evaluate re.split('[|]', '${str}') re
+ # keywordArray
+ ${keywords} KeywordsForEach ${list}[0]
+ Set To Dictionary ${obj} keywordArray=${keywords}
+ # district
+ Run Keyword If '${flag}'=='${True}' Set To Dictionary ${obj} district=${list}[1]
+ ${index} Run Keyword If '${flag}'=='${True}' Set Variable ${2}
+ ... ELSE Set Variable ${1}
+ # isHexbin
+ ${return} ${isHexBin} Run Keyword And Ignore Error Convert To Integer ${list}[${index}]
+ Run Keyword If "${return}"!="FAIL" and "${isHexBin}"!="${EMPTY}" Set To Dictionary ${obj} isHexbin=${isHexBin}
+ ... ELSE Set To Dictionary ${obj} isHexbin=${0}
+
+ # isInitialize、itemName、itemDesc
+ ${return} ${isInitialize} Run Keyword And Ignore Error Convert To Integer ${list}[${index+1}]
+ Run Keyword If "${return}"!="FAIL" and "${isInitialize}"!="${EMPTY}" Set To Dictionary ${obj} isInitialize=${isInitialize}
+ ${return} ${itemName} Run Keyword And Ignore Error Set Variable ${list}[${index+2}]
+ Run Keyword If "${return}"!="FAIL" and "${itemName}"!="${EMPTY}" Set To Dictionary ${obj} itemName=${itemName}
+ ${return} ${itemDesc} Run Keyword And Ignore Error Set Variable ${list}[${index+3}]
+ Run Keyword If "${return}"!="FAIL" and "${itemDesc}"!="${EMPTY}" Set To Dictionary ${obj} itemDesc=${itemDesc}
+ [Return] ${obj}
+
+KeywordsForEach
+ # 处理多关键字keyword1&keyword2&...
+ [Arguments] ${str}
+ ${returnList} Create List
+ ${list} Evaluate re.split('[&]', '${str}') re
+ FOR ${var} IN @{list}
+ Append To List ${returnList} ${var}
+ END
+ [Return] ${returnList}
+
+OtherParams
+ [Documentation]
+ ... 处理isInitialize、itemName、itemDesc参数
+ [Arguments] ${values} ${obj}
+ ${return} ${isInitialize} Run Keyword And Ignore Error Convert To Integer ${values}[4]
+ Run Keyword If "${return}"!="FAIL" and "${isInitialize}"!="${EMPTY}" Set To Dictionary ${obj} isInitialize=${isInitialize}
+ ${return} ${itemName} Run Keyword And Ignore Error Set Variable ${values}[5]
+ Run Keyword If "${return}"!="FAIL" and "${itemName}"!="${EMPTY}" Set To Dictionary ${obj} itemName=${itemName}
+ ${return} ${itemDesc} Run Keyword And Ignore Error Set Variable ${values}[6]
+ Run Keyword If "${return}"!="FAIL" and "${itemDesc}"!="${EMPTY}" Set To Dictionary ${obj} itemDesc=${itemDesc}
+
+WanVpn
+ [Arguments] ${wanvpnlist}
+ ${data} Set Variable "opAction":"add","returnData":1
+ ${dict}= Evaluate eval ('{${data}}')
+ ${data2} set to dictionary ${dict} list=${wanvpnlist}
+ ${json} json.Dumps ${data2} ensure_ascii=False
+ [Return] ${json}
+
+IpList
+ [Arguments] ${Iplist}
+ ${list} Create List
+ FOR ${k} ${v} IN ENUMERATE @{Iplist}
+ Append To List ${list} ${v}
+ END
+ ${list2} Set Variable ${list}[2]
+ ${list3} Set Variable ${list}[3]
+ ${link_id} evaluate int(${Iplist}[${list2}])
+ ${src_mac} evaluate int(${Iplist}[${list3}])
+ ${list_info} Create Dictionary ${list}[2]=${link_id} ${list}[3]=${src_mac}
+ ${Ip_list} Create Dictionary ip=${Iplist}[ip] relative_location=${Iplist}[relative_location] link_info=${list_info}
+ log 123213213213213123
+ log ${Ip_list}
+ # log ${link_info}
+ [Return] ${Ip_list}
+WanNatIpPood
+ [Arguments] ${must_parameter} ${wan_nat_ip_iplist}
+ # 编写iplist json格式
+ ${wan_nat_ip_iplist} Create Dictionary profileId=${must_parameter}[profileId] profileName=${must_parameter}[profileName] ipList=${wan_nat_ip_iplist} isValid=1
+ #编写二层list内地格式
+ ${wan_nat_ip_list} Create List ${wan_nat_ip_iplist}
+ # 判断sjon是用于修改还是新增
+ ${opAction} run keyword if '${must_parameter}[profileId]'=="" Set Variable add
+ ... ELSE Set Variable update
+ #编写最外面的格式
+ ${returnData} evaluate int(1)
+ ${wan_nat_ip_pood_data} Create Dictionary opAction=${opAction} returnData=${returnData} list=${wan_nat_ip_list}
+ # 返回请求json
+ log ${wan_nat_ip_pood_data}
+ ${json} json.Dumps ${wan_nat_ip_pood_data} ensure_ascii=False
+ log ${json}
+ [Return] ${json}
+
+
+Index
+ [Arguments] ${list} ${value}
+ ${index} evaluate int(0)
+ ${1} evaluate int(1)
+ FOR ${a} IN @{list}
+ #${a} Set Variable ${a}
+ log ${a}
+ ${index} run Keyword if '${a}'=='${value}' log ${index}
+ ... ELSE Evaluate ${index}+${1}
+ log ${a}
+ END
+
+abcd
+ [Arguments] ${effectiveRange_list} ${DataCenter}
+ ${ab} create list
+ FOR ${a} IN @{DataCenter}
+ ${i} index ${effectiveRange_list} ${a}
+ Append To List ${ab} ${i}
+ END
+ [Return] ${ab}
+
+IspJson
+ [Arguments] ${isp_json}
+ ${1} Create List ${isp_json}
+ [Return] ${1}
+
+LocationJson
+ [Arguments] ${location_json}
+ ${2} Create List ${location_json}
+ [Return] ${2}
+
+LoccationAndIspJson
+ [Arguments] ${location_json} ${isp_json}
+ ${3} Create List ${location_json} ${isp_json}
+ [Return] ${3}
+
+
+
+PacketCapture
+ [Arguments] ${PacketCapturedata} ${DataCenter}
+ # 构建effectiveRange_tsg_sets
+ ${effectiveRange_list_manu} Create List Almaty
+ ${DataCenter_length} = Get Length ${DataCenter}
+ # ${isp_length} = Get Length ${isp}
+
+ ${DataCenter_ids} run keyword if ${DataCenter_length}==0 abcd ${effectiveRange_list_manu} ${DataCenter}
+ ... ELSE abcd ${effectiveRange_list_manu} ${DataCenter}
+ log ${DataCenter_ids}
+ ${DataCenter_json} Create Dictionary tag=data_center value=${DataCenter} ids=${DataCenter_ids}
+
+ # ${isp_ids} run keyword if ${isp_length}==0 abcd ${effectiveRange_list_manu} ${isp}
+ # ... ELSE abcd ${effectiveRange_list_manu} ${isp}
+ # log ${isp}
+ # ${isp_json} Create Dictionary tag=isp value=${isp} ids=${isp_ids}
+
+ ${tag_sets_2} Create List ${DataCenter_json}
+ ${tag_sets} Create List ${tag_sets_2}
+ ${effectiveRange} Create Dictionary tag_sets=${tag_sets}
+ # 编写iplist json格式
+ log ${PacketCapturedata}
+ # 构建PolicyList
+ ${addrType} evaluate int(${PacketCapturedata}[addrType])
+ ${protocol} evaluate int(${PacketCapturedata}[protocol])
+ ${second} Set Variable ${3600}
+ ${captureDuration1} evaluate int(${PacketCapturedata}[captureDuration])
+ ${captureDuration} evaluate ${captureDuration1}*${second}
+ log ${captureDuration}
+ ${policyListDict} Create Dictionary
+ ... policyId=${PacketCapturedata}[policyId]
+ ... policyName=${PacketCapturedata}[policyName]
+ ... addrType=${addrType}
+ ... protocol=${protocol}
+ ... clientIp=${PacketCapturedata}[clientIp]
+ ... clientPort=${PacketCapturedata}[clientPort]
+ ... serverIp=${PacketCapturedata}[serverIp]
+ ... serverPort=${PacketCapturedata}[serverPort]
+ ... maxPacket=${PacketCapturedata}[maxPacket]
+ ... captureDuration=${captureDuration}
+ ... effectiveRange=${effectiveRange}
+ log ${policyListDict}
+ ${policyList} Create List ${policyListDict}
+ # 判断json是用于修改还是新增
+ ${opAction} run keyword if '${PacketCapturedata}[policyId]'=="" Set Variable add
+ ... ELSE Set Variable update
+ #编写最外面的格式
+ ${returnData} evaluate int(1)
+ ${PacketCapture} Create Dictionary opAction=${opAction} returnData=${returnData} policyList=${policyList}
+ # 返回请求json
+ log ${PacketCapture}
+ ${json} json.Dumps ${PacketCapture} ensure_ascii=False
+ log 111111111111${json}
+ [Return] ${json} \ No newline at end of file
diff --git a/keyword/objects/object.robot b/keyword/objects/object.robot
new file mode 100644
index 0000000..2ae994a
--- /dev/null
+++ b/keyword/objects/object.robot
@@ -0,0 +1,513 @@
+*** Settings ***
+Library Collections
+Library RequestsLibrary
+Resource ../../variable/common_variable.txt
+Resource ../common/functional_keywords.robot
+Resource process_object_body.robot
+Library Collections
+Resource ../common/common.robot
+#Library ../../../04-CustomLibrary/Library/fileOperations.py
+Library DatabaseLibrary
+
+*** Variables ***
+${objectUrl} /policy/object
+${categoryUrl} /category/dict
+${applicationDictUrl} /application/update/dict
+${fileUploaduRL} /system/feature/update/
+
+*** Keywords ***
+AddLocalIPObject
+ #创建对象IP
+ log to_AddLocalIPObject
+ Comment 创建IP
+ #object为IP→endpoint时的addItemList单个对象
+ ${addItemList1} Create Dictionary isSession=endpoint ip=${testClentIP} port=0-65535 direction=0 protocol=0 isInitialize=0
+ #可以添加多个
+ ${addItemLists} Create list ${addItemList1}
+ #objectList对象
+ ${objectDict} Create Dictionary objectType=ip objectSubType=endpoint isValid=${1} addItemList=${addItemLists}
+ ${rescode} ${objectId1} AddObjects ${1} ${objectDict}
+ SET GLOBAL VARIABLE ${testClentID} ${objectId1}
+ Comment 创建SubId
+ log to_AddLocalSubidObject
+ #可以添加多个
+ ${addItemList1} Create Dictionary keywordArray=${testSubscriberID} isHexbin=${0}
+ ${addItemLists} Create list ${addItemList1}
+ ${objectDict} Create Dictionary objectType=subscriberid objectSubType=subscriberid objectName=autotest_localSubId_${testSubscriberID} isValid=${1} addItemList=${addItemLists}
+ ${rescode} ${subiid} AddObjects ${1} ${objectDict}
+ #log ${subiid}
+ log LocalSubIP:${subiid}
+ SET GLOBAL VARIABLE ${testClentSubID} ${subiid}
+ Comment 创建mobile_identity-imsi
+ ${addItemList1} Create Dictionary keywordArray=${imsi} isHexbin=${0}
+ ${addItemLists} Create list ${addItemList1}
+ ${objectDict} Create Dictionary objectType=mobile_identity objectSubType=imsi isValid=${1} addItemList=${addItemLists}
+ ${rescode} ${imsi_id} AddObjects ${1} ${objectDict}
+ InsertObjectIdToFile global_imsi_id ${imsi_id}
+ SET GLOBAL VARIABLE ${object_imsi_id} ${imsi_id}
+ Comment 创建mobile_identity-phone_number
+ ${addItemList1} Create Dictionary keywordArray=${phone_number1} isHexbin=${0}
+ ${addItemList2} Create Dictionary keywordArray=${phone_number2} isHexbin=${0}
+ ${addItemList3} Create Dictionary keywordArray=${phone_number3} isHexbin=${0}
+ ${addItemList4} Create Dictionary keywordArray=${phone_number4} isHexbin=${0}
+ ${addItemLists} Create list ${addItemList1} ${addItemList2} ${addItemList3} ${addItemList4}
+ ${objectDict} Create Dictionary objectType=mobile_identity objectSubType=phone_number isValid=${1} addItemList=${addItemLists}
+ ${rescode} ${phoneNum_id} AddObjects ${1} ${objectDict}
+ InsertObjectIdToFile global_phoneNum_id ${imsi_id}
+ SET GLOBAL VARIABLE ${obj_phoneNum_Id} ${phoneNum_id}
+ Comment 创建apn
+ ${addItemList1} Create Dictionary keywordArray=${apn1} isHexbin=${0}
+ ${addItemList2} Create Dictionary keywordArray=${apn2} isHexbin=${0}
+ ${addItemLists} Create list ${addItemList1} ${addItemList2}
+ ${objectDict} Create Dictionary objectType=apn objectSubType=apn isValid=${1} addItemList=${addItemLists}
+ ${rescode} ${apn_id} AddObjects ${1} ${objectDict}
+ InsertObjectIdToFile global_apn_id ${imsi_id}
+ SET GLOBAL VARIABLE ${obj_apn_Id} ${apn_id}
+
+AddObjects
+ [Arguments] ${returnData} ${objectList}
+ [Documentation] 新增策略对象
+ ... objectList,策略对象,可为list类型与dict类型
+ ... addItemList自动过滤itemId
+ ... updateItemList自动过滤isInitialize(update时该字段引发异常)
+ ... ipItem格式为dict,自动过滤空的字段
+ ... stringItem格式为dict,需要注意keywordArray字段应传入逗号分隔的字符串eg: keyword1,keyword2
+ ... http_signature为代表的拓展关键字keywordArray字段也是以逗号分隔的
+ ... returnData,是否返回数据,固定为1
+ ${returnData}= Run Keyword If '${returnData}' == '${EMPTY}' Set Variable 1
+ ... ELSE Set Variable ${returnData}
+ #必选参数判定
+ Should Not Be Empty ${objectList}
+ ${dictType} = Evaluate type(${objectList})
+ ${body} Run Keyword If "${dictType}" == "<class 'list'>" ObjectListOperation ${returnData} ${objectList} add
+ ... ELSE IF "${dictType}" == "<class 'dict'>" ObjectOperation ${returnData} ${objectList} add
+ ... ELSE Set Variable ${EMPTY}
+ ${response} BasePostRequestForV2 ${objectUrl} ${body} ${version}
+ ${objectIds} Run Keyword If "${returnData}" == "1" GetObjectIds ${response}
+ ... ELSE Create List
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ [Return] ${rescode} ${objectIds}
+
+UpdateObjects
+ [Arguments] ${returnData} ${objectList} ${opAction}
+ [Documentation] 更新策略对象
+ ... objectList,策略对象,可为list类型与dict类型
+ ... addItemList自动过滤itemId
+ ... updateItemList自动过滤isInitialize(update时该字段引发异常)
+ ... ipItem格式为dict,自动过滤空的字段
+ ... stringItem格式为dict,需要注意keywordArray字段应传入逗号分隔的字符串eg: keyword1,keyword2
+ ... http_signature为代表的拓展关键字keywordArray字段也是以逗号分隔的
+ ... returnData,是否返回数据,固定为1
+ ... opAction,可为update,enable,disable
+ ${returnData}= Run Keyword If '${returnData}' == '${EMPTY}' Set Variable 1
+ ... ELSE Set Variable ${returnData}
+ #必选参数判定
+ Should Not Be Empty ${objectList}
+ ${dictType} = Evaluate type(${objectList})
+ ${body} Run Keyword If "${dictType}" == "<class 'list'>" ObjectListOperation ${returnData} ${objectList} ${opAction}
+ ... ELSE IF "${dictType}" == "<class 'dict'>" ObjectOperation ${returnData} ${objectList} ${opAction}
+ ... ELSE Set Variable ${EMPTY}
+ ${response} BaseEditRequestForV2 ${objectUrl} ${body} ${version}
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ [Return] ${rescode}
+
+UpdateInstall
+ [Arguments] ${updateDict}
+ [Documentation] 更新策略对象
+ ... objectList,策略对象,可为list类型与dict类型
+ ... addItemList自动过滤itemId
+ ... updateItemList自动过滤isInitialize(update时该字段引发异常)
+ ... ipItem格式为dict,自动过滤空的字段
+ ... stringItem格式为dict,需要注意keywordArray字段应传入逗号分隔的字符串eg: keyword1,keyword2
+ ... http_signature为代表的拓展关键字keywordArray字段也是以逗号分隔的
+ ... returnData,是否返回数据,固定为1
+ ... opAction,可为update,enable,disable
+ #必选参数判定
+ Should Not Be Empty ${updateDict}
+ ${bodyJson} json.Dumps ${updateDict} ensure_ascii=False
+ ${response} BaseEditRequestForV2 ${fileUploaduRL} ${body} ${version}
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ [Return] ${rescode}
+
+GetObjectItems
+ [Arguments] ${params}
+ [Documentation] 获取策略对象中的item,策略对象单元
+ ... 当updateItemList中有需要传入数据时
+ ... 调用此关键字
+ #必选参数判定
+ Should Not Be Empty ${params}
+ ${paramsStr} DictionaryToQueryParams ${params}
+ ${response} BaseFormRequest /policy/items ${paramsStr} ${version}
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ ${data} Set Variable ${response['data']}
+ ${itemIds} Create List
+ FOR ${item} IN @{data['list']}
+ Append To List ${itemIds} ${item['itemId']}
+ END
+ [Return] ${rescode} ${itemIds} ${data['list']}
+
+GetObjectItems1
+ [Arguments] ${params}
+ [Documentation] 获取策略对象中的item,策略对象单元
+ ... 当updateItemList中有需要传入数据时
+ ... 调用此关键字
+ #必选参数判定
+ Should Not Be Empty ${params}
+ ${paramsStr} DictionaryToQueryParams ${params}
+ ${response} BaseFormRequest /policy/items ${paramsStr} ${version}
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ ${data} Set Variable ${response['data']}
+ [Return] ${rescode} ${data}
+
+DeleteObjectByIds
+ [Arguments] ${objectIds}
+ [Documentation] 删除策略对象
+ ... params,传入的删除字典
+ ... 结构为[1,2,3]
+ ${type} Evaluate isinstance(${objectIds},list)
+ Should Be True ${type}
+ ${dict} Create Dictionary objectIds=${objectIds}
+ ${json} json.Dumps ${dict} ensure_ascii=False
+ ${response} BaseDeleteRequest /${version}${objectUrl} ${json}
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ [Return] ${rescode}
+
+ImportObject
+ [Arguments] ${filePath} ${fileName} ${objectType} ${objectSubType} ${objectName}
+ [Documentation] 策略对象导入
+ ... filePath文件路径
+ ... fileName文件名称
+ ... objectType对象类型
+ ... objectSubType对象子类型
+ ... objectName对象名称
+ ... jira CHON-12导入限制需求支持
+ Directory Should Exist ${path}
+ File Should Exist ${path}/${filePath}/${fileName}
+ File Should Not Be Empty ${path}/${filePath}/${fileName}
+ ${size} Get File Size ${path}/${filePath}/${fileName}
+ Should Not Be Empty ${objectType}
+ #获取Item 的总数
+ ${total} GetItemNum ${objectType} ${objectSubType}
+ #获取导入文件中的总行数
+ #${lines} CountLines ${path}/${filePath}/${fileName}
+ ${lines} CountLines ${path}/${filePath}/${fileName}
+ #总数超过一定数据量测试不通过
+ ${total1} Evaluate ${total}+${lines}
+ #链接数据库查询上限
+ Connect To Database Using Custom Params pymysql ${mysqlHost}
+ ${objectLimit} query SELECT cfg_value FROM t_sys_cfg WHERE cfg_name='${objectType}_upper_limit'
+ ${objectLimit} Set Variable ${objectLimit[0][0]}
+ ${remaining} Evaluate ${objectLimit}-${total}
+ log ${objectType}剩余可导入量为:${remaining}
+ ${testType} Evaluate type($objectLimit)
+ Disconnect From Database
+ #jira CHON-12导入限制需求支持
+ Run Keyword If "${objectType}"=="url" and ${total1}>${objectLimit} log 当前已经存在item个数${total},待导入个数${lines},总数超过${objectLimit}条!
+ ... ELSE IF ${total1}>${objectLimit} log 当前已经存在item个数${total},待导入个数${lines},总数超过${objectLimit}条!
+ ${objectSubType} Run Keyword If "${objectType}"=="ip" and "${objectSubType}"=="${EMPTY}" Set Variable endpoint
+ ... ELSE Set Variable ${objectSubType}
+ ${subfix} Fetch From Right ${fileName} .
+ ${binFile} Run Keyword If "${subfix}"=="txt" Evaluate (r'${fileName}',open(r"${path}/${filePath}/${fileName}",'rb'),'text/plain')
+ ... ELSE IF "${subfix}"=="csv" Evaluate (r'${fileName}',open(r"${path}/${filePath}/${fileName}",'rb'),'application/vnd.ms-excel')
+ ... ELSE ${EMPTY}
+ ${data} Create Dictionary objectType=${objectType}
+ Run Keyword If "${objectSubType}"!="${EMPTY}" Set To Dictionary ${data} objectSubType=${objectSubType}
+ Run Keyword If "${objectName}"!="${EMPTY}" Set To Dictionary ${data} objectName=${objectName}
+ ${file} Create Dictionary file=${binFile}
+ ${response} BaseMultipartPostRequest ${objectUrl}/batch ${data} ${file} ${version}
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ [Return] ${rescode} ${objectType} ${response}
+
+ImportApplication
+ [Arguments] ${filePath} ${fileName} ${feature} ${code}
+ [Documentation] 策略对象导入
+ ... filePath文件路径
+ ... fileName文件名称
+ ... feature是特征
+ Directory Should Exist ${path}
+ File Should Exist ${path}/${filePath}/${fileName}
+ File Should Not Be Empty ${path}/${filePath}/${fileName}
+ ${size} Get File Size ${path}/${filePath}/${fileName}
+ ${binFile} Run Keyword If "${feature}"=="${EMPTY}" Evaluate (r'${fileName}',open(r"${path}/${filePath}/${fileName}",'rb'),'application/xml')
+ ... ELSE IF "${feature}"=="app_library" or "${feature}"=="app_signature" Evaluate (r'${fileName}',open(r"${path}/${filePath}/${fileName}",'rb'),'application/octet-stream')
+ ... ELSE ${EMPTY}
+ ${file} Create Dictionary file=${binFile}
+ # ${response} BaseMultipartPostRequest ${objectUrl}/batch ${EMPTY} ${file} ${version}
+ ${response} Run Keyword If "${feature}"=="${EMPTY}" BaseMultipartPostRequest ${applicationDictUrl} ${EMPTY} ${file} ${version}
+ ... ELSE IF "${feature}"=="app_library" or "${feature}"=="app_signature" BaseMultipartPostRequest ${fileUploaduRL} ${EMPTY} ${file} ${version}
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} ${code}
+
+
+ExportObject
+ [Arguments] ${objectType} ${objectSubType} ${objectIds} ${objectName}
+ [Documentation] 策略对象导出
+ ... objectType ip,url等
+ ... objectSubType 子类型
+ ... objectIds 1,2,3
+ ... objectName 字符串
+ Should Not Be Empty ${objectType}
+ ${params} Create Dictionary objectType=${objectType}
+ Run Keyword If "${objectSubType}"!="${EMPTY}" Set To Dictionary ${params} objectSubType=${objectSubType}
+ Run Keyword If "${objectIds}"!="${EMPTY}" Set To Dictionary ${params} objectIds=${objectIds}
+ Run Keyword If "${objectName}"!="${EMPTY}" Set To Dictionary ${params} objectName=${objectName}
+ ${response} BaseGetRequestReturnBinary ${objectUrl}/batch ${params} ${version}
+ [Return] ${response}
+
+GetItemNum
+ [Arguments] ${objectType} ${objectSubType}
+ [Documentation] 获取策略对象单元总数
+ ${getTotal} Create Dictionary pageNo=${1} pageSize=${1}
+ Run Keyword If "${objectType}"=="ip" and "${objectSubType}"=="endpoint" Set To Dictionary ${getTotal} itemType=IP
+ ... ELSE IF "${objectType}"=="ip" and "${objectSubType}"=="geo_location" Set To Dictionary ${getTotal} itemType=geo_location
+ ... ELSE IF "${objectType}"=="ip" and "${objectSubType}"=="as_number" Set To Dictionary ${getTotal} itemType=as_number
+ ... ELSE IF "${objectType}"=="url" Set To Dictionary ${getTotal} itemType=URL
+ ... ELSE Set To Dictionary ${getTotal} itemType=${objectType}
+ ${rescode} ${data} GetObjectItems1 ${getTotal}
+ ${total} Set Variable ${data['total']}
+ Run Keyword If "${objectType}"=="fqdn_category" Set To Dictionary ${getTotal} isInitialize=1
+ ${rescode} ${data} Run Keyword If "${objectType}"=="fqdn_category" GetObjectItems1 ${getTotal}
+ ... ELSE Set Variable ${rescode} ${data}
+ ${total} Run Keyword If "${objectType}"=="fqdn_category" Evaluate ${total} - ${data['total']}
+ ... ELSE Set Variable ${total}
+ [Return] ${total}
+
+CountLines1
+ [Arguments] ${file}
+ [Documentation] 获取文件总行数
+ ${count} Set Variable ${0}
+ ${openFile} Evaluate enumerate(open(r"${file}",'r'))
+ FOR ${line} IN @{openFile}
+ ${val} Run Keyword If "${line[0]}"=="0" Set Variable ${line[1]}
+ ... ELSE Set Variable ${EMPTY}
+ ${val2} Run Keyword If "${line[1]}"=="\n" Set Variable ${line[0]}
+ ... ELSE Set Variable ${EMPTY}
+ log ${line}
+ log "${line[1]}"
+ ${match} Get Regexp Matches ${val} ^-->
+ #${match2} Get Regexp Matches ${val} ^(\t)*$\n
+ ${len} Get Length ${match}
+ #${len2} Get Length ${match2}
+ ${count} Run Keyword If "${line[0]}"=="0" and ${len}>0 Set Variable ${count}
+ ... ELSE Evaluate ${count}+1
+ END
+ [Return] ${count}
+
+PolicProtocolFields
+ [Arguments] ${policyType} ${protocol} ${objectType}
+ [Documentation] 策略对象生效协议字段查询
+ ... policyType策略类型
+ ... protocol协议
+ ... objectType对象类型
+ ${dict} Create Dictionary
+ Run Keyword If "${policyType}"!="${EMPTY}" Set To Dictionary ${dict} policyType=${policyType}
+ Run Keyword If "${protocol}"!="${EMPTY}" Set To Dictionary ${dict} protocol=${protocol}
+ Run Keyword If "${objectType}"!="${EMPTY}" Set To Dictionary ${dict} objectType=${objectType}
+ ${parmStr} DictionaryToQueryParams ${dict}
+ ${response} BaseFormRequest ${objectUrl}/protocolFields ${parmStr} ${version}
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ [Return] ${response['data']}
+
+ObjectReference
+ [Arguments] ${objectId}
+ [Documentation] 策略对象相关性查询
+ ${response} BaseFormRequest ${objectUrl}/reference objectId=${objectId} ${version}
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ [Return] ${response['data']}
+
+AppIdTreeSearch
+ [Arguments] ${referenceObjectId}
+ [Documentation] App ID对象树查询
+ ${response} BaseFormRequest ${objectUrl}/appId/tree referenceObjectId=${referenceObjectId} ${version}
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ [Return] ${response['data']}
+
+AddCategories
+ [Arguments] ${returnData} ${categoryList} ${opAction} ${testCode}=null
+ [Documentation] 新增Category
+ ... returnData,是否返回数据,固定为1
+ Comment 此处思路给category单独的另一套关键字,原因:地址与json串名称与Object部分不同了
+ ${returnData}= Run Keyword If '${returnData}' == '${EMPTY}' Set Variable 1
+ ... ELSE Set Variable ${returnData}
+ #必选参数判定
+ Should Not Be Empty ${categoryList}
+ ${dictType} = Evaluate type(${categoryList})
+ ${body} Run Keyword If "${dictType}" == "<class 'list'>" CategoryListOperation ${returnData} ${categoryList} ${opAction}
+ ... ELSE IF "${dictType}" == "<class 'dict'>" CategoryOperation ${returnData} ${categoryList} ${opAction}
+ ... ELSE Set Variable ${EMPTY}
+
+ log ${body}
+ # ${response} BasePostRequestForV2 ${categoryUrl} ${body} ${version}
+ ${response} Run Keyword If "${opAction}"=="add" BasePostRequestForV2 ${categoryUrl} ${body} ${version}
+ ... ELSE IF "${opAction}"=="update" BaseEditRequestForV2 ${categoryUrl} ${body} ${version}
+ ${CategoryObjIds} Run Keyword If "${returnData}" == "1" and ${testCode} == 200 and "${opAction}"=="add" GetCategoryObjIds ${response}
+ ... ELSE Set Variable ${EMPTY}
+ ${CategoryIds} Run Keyword If "${returnData}" == "1" and ${testCode} == 200 and "${opAction}"=="add" GetCategoryIds ${response}
+ ... ELSE Set Variable ${EMPTY}
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} ${testCode}
+ [Return] ${rescode} ${CategoryObjIds} ${CategoryIds}
+
+QueryUpadateRecord
+ [Arguments] ${body} ${code}
+ ${response} BaseGetRequestOK /${version}/system/feature/update body=${body}
+ log ${response}
+ ${rescode} Set Variable ${response['code']}
+ Shoule Be Equal As Strings ${rescode} ${code}
+ [Return] ${rescode}
+
+DeleteCategoryByIds
+ [Arguments] ${categoryids}
+ #删除对象
+ log todeleteobjAndCategory
+ ${response} BaseDeleteRequest /${version}/category/dict {"categoryIds":[${categoryids}]}
+ ${response_code} Get From Dictionary ${response} code
+ Should Be Equal As Strings ${response_code} 200
+ ${response} Convert to String ${response}
+ log ${response}
+DelLocalIPObject
+ log to_DelLocalIPObject
+
+ ${emptyList} Create List
+ ${objectId1} Set Variable [${testClentID},${testClentSubID}]
+ ${objectId1} json.loads ${objectId1}
+ # ${objectId1} Create List [${testClentID},${testClentSubID},${object_imsi_id},${obj_phoneNum_Id},${obj_apn_Id}]
+ DeleteObjectByIds ${objectId1}
+ SET GLOBAL VARIABLE ${testClentID} ${EMPTY}
+ SET GLOBAL VARIABLE ${testClentSubID} ${EMPTY}
+###############################################################################
+#数据分离,测试数据来自对应的yaml文件
+ObjectsByTemplate
+ [Documentation] 根据测试数据文件,使用对应公共模板,创建对象
+ ... 入参:${dataFilePath}数据文件,全路径文件名 ${keyword}测试用例名称
+ ... data数据文件格式参照:other/data/object/demo_data.yaml
+ ... 返回数据:对象idlist${objectIds},格式:[107582, 107583]
+ ... 返回数据:策略id+类型list${policyIds},格式:[{'objectId': 107582, 'protocolField': 'TSG_SECURITY_SOURCE_ADDR'},{'objectId': 107583, 'protocolField': 'TSG_SECURITY_SOURCE_ADDR'}]
+ [Arguments] ${dataFilePath} ${keyword}
+ ${yamlData}= Get File ${dataFilePath}
+ ${loadedData}= yaml.Safe Load ${yamlData}
+ ${list} Get From Dictionary ${loadedData} ${keyword}_data
+ ${objectIds} Create List
+ Comment 循环创建策略
+ FOR ${key} IN @{list}
+ LOG passssssssss
+ ${objectId} ${objectList} Run Keyword And Continue On Failure CreateObjectList ${key} ${keyword}
+ #返回的对象和策略信息添加到对象和策略列表
+ Run Keyword If "${objectId}" !="None" AppendListToList ${objectIds} ${objectId}
+ END
+ [Return] ${objectIds}
+OrangeFilter
+ [Documentation] filer对象处理,把一个filter的list处理为一个filter
+ #[Arguments] ${filterList} ${objectList}
+ [Arguments] ${objectList}
+ ${list} Create List ${objectList}
+ ${filter} Create Dictionary filter=${list}
+ #${filterList} Append To List ${filter}
+ [Return] ${filter}
+
+CreateObjectList
+ [Documentation] 处理对象
+ [Arguments] ${objectData} ${keyword}=${EMPTY}
+ Comment 针对位置进行处理
+ ${return} ${protocolField} Run Keyword And Ignore Error Get From Dictionary ${objectData} protocolField
+ #${objList} Get From Dictionary ${objectData} objList
+
+ ${objectIds} ${objectList} CreateObjects ${objectData}
+ ${objectList} Run Keyword If "${return}"=="FAIL" Set Variable ${objectList}
+ ... ELSE IF "${protocolField}" == "TSG_SECURITY_SOURCE_ADDR" or "${protocolField}" == "None" or "${protocolField}" == "TSG_SECURITY_SOURCE_LOCATION" or "${protocolField}" == "TSG_SECURITY_SOURCE_ASN" or "${protocolField}" == "TSG_FILED_GTP_IMSI" or "${protocolField}" == "TSG_FILED_GTP_PHONE_NUMBER" or "${protocolField}" == "TSG_FILED_GTP_APN" Set Variable ${objectList}
+ ##############destination
+ ... ELSE IF "${protocolField}" == "TSG_SECURITY_DESTINATION_ADDR" or "${protocolField}" == "TSG_SECURITY_DESTINATION_LOCATION" or "${protocolField}" == "TSG_SECURITY_DESTINATION_ASN" Set Variable ${objectList}
+ #filter
+ ... ELSE OrangeFilter ${objectList}
+ [Return] ${objectIds} ${objectList}
+CreateObjects
+ [Documentation] 处理对象
+ [Arguments] ${objectData}
+ Comment 针对位置进行处理
+ #${YAML}= Get File ${path}/data/mode.yaml
+ #${LOADED}= yaml.Safe Load ${YAML}
+ #${ipMode} Get From Dictionary ${LOADED} ip_batch_mode
+ ${return} ${protocolField} Run Keyword And Ignore Error Get From Dictionary ${objectData} protocolField
+ ${objList} Get From Dictionary ${objectData} objectList
+
+ Comment ${objJson}对象模板取自全局变量
+ ${objJson} Set Variable ${objModeJson}
+ ${objectJson} Set Variable ${objListMode}
+ #JSON处理
+ ${return} ${objectType} Run Keyword And Ignore Error Get From Dictionary ${objectData} objectType
+ ${objectJson} = Run Keyword If "${return}"!="FAIL" and "${objectType}" != "None" Replace String ${objectJson} "objectType": "ip" "objectType":"${objectType}"
+ ... ELSE Set Variable ${objectJson}
+ ${return} ${objectSubType} Run Keyword And Ignore Error Get From Dictionary ${objectData} objectSubType
+ #${objectSubType} Run Keyword If "${return}"!="FAIL" Set Variable ${objectSubType} ELSE Set Variable ${EMPTY}
+ ${objectJson} = Run Keyword If "${return}"!="FAIL" and "${objectSubType}" != "None" Replace String ${objectJson} "objectSubType": "endpoint" "objectSubType":"${objectSubType}"
+ ... ELSE Set Variable ${objectJson}
+ ${return} ${objectId} Run Keyword And Ignore Error Get From Dictionary ${objectData} objectId
+ ${objectJson} = Run Keyword If "${return}"!="FAIL" and "${objectId}" != "None" Replace String ${objectJson} "objectId": null "objectId":${objectId}
+ ... ELSE Set Variable ${objectJson}
+ ${objectJson} = Run Keyword If "${return}"!="FAIL" and "${objectId}" != "None" Replace String ${objectJson} "opAction": "add" "option": "update"
+ ... ELSE Set Variable ${objectJson}
+ #${objectId} Run Keyword If "${return}"!="FAIL" Set Variable ${objectId} ELSE Set Variable ${EMPTY}
+ #JSON处理
+ ${objectJsonList} Create List
+ ${objListType} = Evaluate type(${objList})
+ FOR ${obj} IN @{objList}
+ ${return} ${addItemList} Run Keyword And Ignore Error Get From Dictionary ${obj} addItemList
+ #${objectJson} Convert To String ${objectJson}
+ #${addItemList} Convert To String ${addItemList}
+ #${objectJson} josn.loads ${objectJson}
+ ${addItemList} json.Dumps ${addItemList}
+ #${objectJson} = Replace String ${objectJson} "addItemList": "addItemList":${itemList}
+ ${addItemList} = Run Keyword If "${return}"!="FAIL" and "${objectSubType}" == "ip_learning" Replace String ${addItemList} [{" "
+ ... ELSE Set Variable ${addItemList}
+ ${addItemList} = Run Keyword If "${return}"!="FAIL" and "${objectSubType}" == "ip_learning" Replace String ${addItemList} "}] "
+ ... ELSE Set Variable ${addItemList}
+ ${objectJson} = Run Keyword If "${return}"!="FAIL" and "${objectSubType}" == "ip_learning" Replace String ${objectJson} "addItemList": [null] "addItemList": [], ${addItemList}
+ ... ELSE IF "${return}"!="FAIL" Replace String ${objectJson} "addItemList": [null] "addItemList": ${addItemList}
+ ... ELSE Set Variable ${objectJson}
+ ${objectJson} = Replace String ${objectJson} [null] []
+ #提交接口返回id拼接
+
+ #Create File ${path}/test.txt ${objectJson}
+ #Append To File ${path}/test.txt ${objectJson}
+ ${objDictionary} json.loads ${objectJson}
+ AppendListToList ${objectJsonList} ${objDictionary}
+ END
+ ${objectData} Create Dictionary opAction=add returnData=1 objectList=${objectJsonList}
+ ${rescode} ${objectIds} CreateObject ${objectData}
+ Should Be Equal As Strings ${rescode} 200
+
+ ${protocolField} Run Keyword If "${protocolField}" != "None" Set Variable ${protocolField}
+ ${objectsList} Create List
+ FOR ${obj} IN @{objectIds}
+ ${objectList} Create Dictionary objectId=${objectIds}[0] protocolField=${protocolField}
+ Append To List ${objectsList} ${objectList}
+ END
+ [Return] ${objectIds} ${objectList}
+CreateObject
+ [Tags]
+ [Arguments] ${ipList}
+ Comment 参数${ipList}对象dict
+ Comment 创建IP
+ ${returnData} Get From Dictionary ${ipList} returnData
+ ${bodyJson} json.Dumps ${ipList}
+ #${bodyJson} = Replace String ${bodyJson} [null] []
+ ${response} BasePostRequestForV2 ${objectUrl} ${bodyJson} ${version}
+ ${objectIds} Run Keyword If "${returnData}" == "1" getObjectListIds ${response}
+ ... ELSE Create List
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+
+ ${objectIds} Run Keyword IF "${createObjectIds}" != "${EMPTY}" AppendListToList ${objectIds} ${createObjectIds}
+ ... ELSE Set Variable ${objectIds}
+ SET GLOBAL VARIABLE ${createObjectIds} ${objectIds}
+ [Return] ${rescode} ${objectIds} \ No newline at end of file
diff --git a/keyword/objects/process_object_body.robot b/keyword/objects/process_object_body.robot
new file mode 100644
index 0000000..0c7c59d
--- /dev/null
+++ b/keyword/objects/process_object_body.robot
@@ -0,0 +1,562 @@
+*** Settings ***
+Library json
+Library Collections
+Resource ../../variable/common_variable.txt
+Resource ../../variable/policy_object_default.txt
+Resource manage_object_body.robot
+*** Variables ***
+*** Keywords ***
+ObjectListOperation
+ [Documentation]
+ ... 描述:入口,opAction参数可为'add','update','disable','enable'
+ ... 参数:returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。
+ ... objectList: 必传,字典类型。字典内可选参数信息:
+ ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt
+ ... 多个对象处理
+
+ [Arguments] ${returnData} ${objectList} ${opAction}
+ Log Call ObjectListOperation
+ ${objectListJson} Set Variable [
+ FOR ${object} IN @{objectList}
+ ${json} ObjectOrganize ${object} ${opAction}
+ ${objectListJson} Set Variable ${objectListJson}${json},
+ END
+ ${objectListJson}= Replace String Using Regexp ${objectListJson} ,$ ]
+ # 转为json结构并返回
+ ${dict} Create Dictionary opAction=${opAction} returnData=${returnData} objectList=replace:objectList
+ ${bodyJson} json.Dumps ${dict} ensure_ascii=False
+ ${json} Replace String ${bodyJson} "replace:objectList" ${objectListJson}
+ Log Object_Request_Body-${json}
+ [Return] ${json}
+
+CategoryListOperation
+ [Documentation]
+ ... 描述:入口,opAction参数可为'add','update','disable','enable'
+ ... 参数:returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。
+ ... objectList: 必传,字典类型。字典内可选参数信息:
+ ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt
+ ... 多个对象处理
+
+ [Arguments] ${returnData} ${objectList} ${opAction}
+ Log Call ObjectListOperation
+ ${objectListJson} Set Variable [
+ FOR ${object} IN @{objectList}
+ ${json} CategoryOrganize ${object} ${opAction}
+ ${objectListJson} Set Variable ${objectListJson}${json},
+ END
+ ${objectListJson}= Replace String Using Regexp ${objectListJson} ,$ ]
+
+ # 转为json结构并返回
+ ${dict} Create Dictionary opAction=${opAction} returnData=${returnData} categoryList=replace:objectList
+ ${bodyJson} json.Dumps ${dict} ensure_ascii=False
+ ${json} Replace String ${bodyJson} "replace:objectList" ${json}
+
+ Log Category_Request_Body-${json}
+
+ # 转为json结构并返回
+ # ${dict} Create Dictionary opAction=${opAction} returnData=${returnData} objectList=replace:objectList
+ # ${bodyJson} json.Dumps ${dict} ensure_ascii=False
+ # ${json} Replace String ${bodyJson} "replace:objectList" ${objectListJson}
+ # Log Object_Request_Body-${json}
+ [Return] ${json}
+
+ObjectOperation
+ [Documentation]
+ ... 描述:入口,opAction参数可为'add','update','disable','enable'
+ ... 参数:returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。
+ ... object: 必传,字典类型。字典内可选参数信息:
+ ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt
+ ... 单个策略处理
+
+ [Arguments] ${returnData} ${object} ${opAction}
+ Log Call ObjectOperation
+ ${json} ObjectOrganize ${object} ${opAction}
+ # 转为json结构并返回
+ ${dict} Create Dictionary opAction=${opAction} returnData=${returnData} objectList=replace:objectList
+ ${bodyJson} json.Dumps ${dict} ensure_ascii=False
+ ${json} Replace String ${bodyJson} "replace:objectList" ${json}
+
+ Log Object_Request_Body-${json}
+ [Return] ${json}
+
+InstallOperation
+ [Documentation]
+ ... 描述:入口,opAction参数可为'add','update','disable','enable'
+ ... 参数:returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。
+ ... object: 必传,字典类型。字典内可选参数信息:
+ ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt
+ ... 单个策略处理
+
+ [Arguments] ${object}
+ Log Call ObjectOperation
+ ${json} ObjectOrganize ${object}
+ # 转为json结构并返回
+ ${dict} Create Dictionary opAction=${opAction} returnData=${returnData} objectList=replace:objectList
+ ${bodyJson} json.Dumps ${dict} ensure_ascii=False
+ ${json} Replace String ${bodyJson} "replace:objectList" ${json}
+
+ Log Object_Request_Body-${json}
+ [Return] ${json}
+
+FeatureOperation
+ [Documentation]
+ ... 描述:入口,opAction参数可为'add','update','disable','enable'
+ ... 参数:returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。
+ ... object: 必传,字典类型。字典内可选参数信息:
+ ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt
+ ... 单个策略处理
+
+ [Arguments] ${returnData} ${object} ${opAction}
+ Log Call ObjectOperation
+ ${json} ObjectOrganize ${object} ${opAction}
+ # 转为json结构并返回
+ ${dict} Create Dictionary opAction=${opAction} returnData=${returnData} objectList=replace:objectList
+ ${bodyJson} json.Dumps ${dict} ensure_ascii=False
+ ${json} Replace String ${bodyJson} "replace:objectList" ${json}
+
+ Log Object_Request_Body-${json}
+ [Return] ${json}
+
+CategoryOperation
+ [Documentation]
+ ... 描述:入口,opAction参数可为'add','update','disable','enable'
+ ... 参数:returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。
+ ... object: 必传,字典类型。字典内可选参数信息:
+ ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt
+ ... 单个策略处理
+
+ [Arguments] ${returnData} ${category} ${opAction}
+ Log Call ObjectOperation
+ ${json} CategoryOrganize ${category} ${opAction}
+
+ # 转为json结构并返回
+ ${dict} Create Dictionary opAction=${opAction} returnData=${returnData} list=replace:objectList
+ ${bodyJson} json.Dumps ${dict} ensure_ascii=False
+ ${json} Replace String ${bodyJson} "replace:objectList" ${json}
+
+ Log Category_Request_Body-${json}
+ [Return] ${json}
+
+listorone
+ [Arguments] ${object}
+ ${addItemList} Evaluate str('addItemList'in${object}.keys())
+ log ${addItemList}
+ ${subObjectIds} Evaluate str('subObjectIds'in${object}.keys())
+ log ${subObjectIds}
+ ${objectparm} set variable ${addItemList} ${subObjectIds}
+ should contain x times ${objectparm} True 1
+ # Should Not Be Empty ${object}[addItemList] or Should Not Be Empty ${object}[subObjectIds]
+ObjectOrganize
+ [Documentation]
+ ... 描述:入口,opAction参数可为'add','update','disable','enable'
+ ... object: 必传,字典类型。字典内可选参数信息:
+ ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt
+ ... 单个策略转换为json
+ [Arguments] ${object} ${opAction}
+ Log Call ObjectOrganize
+ ${emptyList} Create List
+ ${returnDict} Create Dictionary
+ # 断言必传参数
+ # Should Not Be Empty ${object}[objectType]
+ # Set To Dictionary ${returnDict} objectType=${object}[objectType]
+ #新增时addItemList不能为空
+ Run Keyword If "${opAction}"=="add" listorone ${object}
+ Run Keyword If "${opAction}"=="update" Should Not Be Empty ${object}[objectId]
+ Run Keyword If "${opAction}"=="enable" Should Not Be Empty ${object}[objectId]
+ Run Keyword If "${opAction}"=="disable" Should Not Be Empty ${object}[objectId]
+
+ ${return} ${objectId} Run Keyword And Ignore Error Get From Dictionary ${object} objectId
+ Run Keyword If "${return}"=="FAIL" or "${objectId}"=="${EMPTY}" Set To Dictionary ${returnDict} objectId=${EMPTY}
+ ... ELSE Set To Dictionary ${returnDict} objectId=${objectId}
+
+ ${return} ${objectType} Run Keyword And Ignore Error Get From Dictionary ${object} objectType
+ ${objectTypeV} Run Keyword If "${return}"!="FAIL" and "${objectType}"!="${EMPTY}" Evaluate '${objectType}'.lower()
+ ... ELSE Evaluate '${Default_ObjectType}'.lower()
+ Set To Dictionary ${returnDict} objectType=${objectTypeV}
+ #enable disable直接返回json
+ Run Keyword And Return If "${opAction}"=="enable" or "${opAction}"=="disable" ManageEnableAndDisable ${object} ${returnDict} ${opAction}
+ # 取可选参数,为传入设置默认值
+ Set To Dictionary ${returnDict} objectType=${objectTypeV}
+ ${return} ${objectSubType} Run Keyword And Ignore Error Get From Dictionary ${object} objectSubType
+ Run Keyword If "${return}"!="FAIL" and "${objectSubType}"!="${EMPTY}" Set To Dictionary ${returnDict} objectSubType=${objectSubType}
+ ... ELSE Set To Dictionary ${returnDict} objectSubType=${Default_ObjectSubType}
+ ${return} ${isValid} Run Keyword And Ignore Error Get From Dictionary ${object} isValid
+ Run Keyword If "${return}"=="FAIL" or "${isValid}"=="${EMPTY}" Set To Dictionary ${returnDict} isValid=${Default_IsValid}
+ ... ELSE Set To Dictionary ${returnDict} isValid=${isValid}
+
+ ${return} ${isInitialize} Run Keyword And Ignore Error Get From Dictionary ${object} isInitialize
+ Run Keyword If "${return}"=="FAIL" or "${isInitialize}"=="${EMPTY}" Set To Dictionary ${returnDict} isInitialize=${Default_IsInitialize}
+ ... ELSE Set To Dictionary ${returnDict} isInitialize=${isInitialize}
+ ${return} ${isExclusion} Run Keyword And Ignore Error Get From Dictionary ${object} isExclusion
+ Run Keyword If "${return}"=="FAIL" or "${isExclusion}"=="${EMPTY}" Set To Dictionary ${returnDict} isExclusion=${Default_IsExclusion}
+ ... ELSE Set To Dictionary ${returnDict} isExclusion=${isExclusion}
+ ${return} ${objectName} Run Keyword And Ignore Error Get From Dictionary ${object} objectName
+ Run Keyword If "${return}"=="FAIL" or "${objectName}"=="${EMPTY}" Set To Dictionary ${returnDict} objectName=${Default_ObjectName}
+ ... ELSE Set To Dictionary ${returnDict} objectName=${objectName}
+ ${return} ${objectDesc} Run Keyword And Ignore Error Get From Dictionary ${object} objectDesc
+ Run Keyword If "${return}"!="FAIL" and "${objectDesc}"!="${EMPTY}" Set To Dictionary ${returnDict} objectDesc=${objectDesc}
+ ... ELSE Set To Dictionary ${returnDict} objectDesc=${Default_ObjectDesc}
+ ${return} ${subObjectIds} Run Keyword And Ignore Error Get From Dictionary ${object} subObjectIds
+ Run Keyword If "${return}"!="FAIL" and "${subObjectIds}"!="${EMPTY}" and "${subObjectIds}"!="${None}" Set To Dictionary ${returnDict} subObjectIds=${subObjectIds}
+ ... ELSE Set Variable ${emptyList}
+
+ ${return} ${iconColor} Run Keyword And Ignore Error Set Variable ${object['iconColor']}
+ Run Keyword If "${return}"!="FAIL" Set To Dictionary ${returnDict} iconColor=${iconColor}
+ #补充ip learning对象
+ ${return} ${fromFqdns} Run Keyword And Ignore Error Get From Dictionary ${object} fromFqdns
+ Run Keyword If "${return}"!="FAIL" Set To Dictionary ${returnDict} fromFqdns=${fromFqdns}
+ #... ELSE Set To Dictionary ${returnDict} fromFqdns=${emptyList}
+ log ${fromFqdns}
+ ${return} ${fromProtocol} Run Keyword And Ignore Error Get From Dictionary ${object} fromProtocol
+ Run Keyword If "${return}"!="FAIL" and "${fromProtocol}"!="${EMPTY}" Set To Dictionary ${returnDict} fromProtocol=${fromProtocol}
+ #... ELSE Set To Dictionary ${returnDict} fromProtocol=${Default_fromProtocol}
+ ${return} ${learningDepth} Run Keyword And Ignore Error Get From Dictionary ${object} learningDepth
+ Run Keyword If "${return}"!="FAIL" and "${learningDepth}"!="${EMPTY}" Set To Dictionary ${returnDict} learningDepth=${learningDepth}
+ #... ELSE Set To Dictionary ${returnDict} learningDepth=${Default_learningDepth}
+ ${return} ${agingTime} Run Keyword And Ignore Error Get From Dictionary ${object} agingTime
+ Run Keyword If "${return}"!="FAIL" and "${fromProtocol}"!="${EMPTY}" Set To Dictionary ${returnDict} agingTime=${agingTime}
+ #... ELSE Set To Dictionary ${returnDict} agingTime=${Default_agingTime}
+ ${return} ${voteClientNum} Run Keyword And Ignore Error Get From Dictionary ${object} voteClientNum
+ Run Keyword If "${return}"!="FAIL" and "${fromProtocol}"!="${EMPTY}" Set To Dictionary ${returnDict} voteClientNum=${voteClientNum}
+ #... ELSE Set To Dictionary ${returnDict} voteClientNum=${Default_voteClientNum}
+ ${return} ${learnedIpLimit} Run Keyword And Ignore Error Get From Dictionary ${object} learnedIpLimit
+ Run Keyword If "${return}"!="FAIL" and "${fromProtocol}"!="${EMPTY}" Set To Dictionary ${returnDict} learnedIpLimit=${learnedIpLimit}
+ #... ELSE Set To Dictionary ${returnDict} learnedIpLimit=${Default_learnedIpLimit}
+
+ # 处理AddItemList
+ ${return} ${addItemList} Run Keyword And Ignore Error Get From Dictionary ${object} addItemList
+ Run Keyword If "${return}"!="FAIL" and "${addItemList}"!="${EMPTY}" ManageAddItemListNew ${addItemList} ${returnDict} ${objectTypeV} ${objectSubType}
+
+ # 处理UpdateItemList
+ ${return} ${updateItemList} Run Keyword And Ignore Error Get From Dictionary ${object} updateItemList
+ Run Keyword If "${opAction}"=="update" and "${return}"!="FAIL" and "${updateItemList}"!="${EMPTY}" ManageUpdateItemList ${updateItemList} ${returnDict} ${objectTypeV} ${objectSubType}
+ # 处理deleteItemIds
+ ${return} ${deleteItemIds} Run Keyword And Ignore Error Get From Dictionary ${object} deleteItemIds
+ Run Keyword If "${opAction}"=="update" and "${return}"!="FAIL" and "${deleteItemIds}"!="${EMPTY}" ManageDeleteItemIds ${deleteItemIds} ${returnDict}
+ # 转为json结构并返回
+ ${json} json.Dumps ${returnDict} ensure_ascii=False
+ Log Object-${json}
+ [Return] ${json}
+Categorylistorone
+ [Arguments] ${category}
+ ${addItemList} Evaluate str('fqdnList'in${category}.keys())
+ log ${addItemList}
+ ${objectparm} set variable ${addItemList}
+ should contain x times ${objectparm} True 1
+ # Should Not Be Empty ${object}[addItemList] or Should Not Be Empty ${object}[subObjectIds]
+
+CategoryOrganize
+ [Documentation]
+ ... 描述:入口,opAction参数可为'add','update','disable','enable'
+ ... object: 必传,字典类型。字典内可选参数信息:
+ ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt
+ ... 单个策略转换为json
+ [Arguments] ${category} ${opAction}
+ Log Call CategoryOrganize
+ ${emptyList} Create List
+ ${returnDict} Create Dictionary
+ # 断言必传参数
+ # Should Not Be Empty ${object}[objectType]
+ # Set To Dictionary ${returnDict} objectType=${object}[objectType]
+ #新增时addItemList不能为空
+ Run Keyword If "${opAction}"=="add" Categorylistorone ${category}
+ Run Keyword If "${opAction}"=="update" Should Not Be Empty ${category}[categoryId]
+ Run Keyword If "${opAction}"=="update" Should Not Be Empty ${category}[objectId]
+ ${return} ${objectId} Run Keyword And Ignore Error Get From Dictionary ${category} objectId
+ Run Keyword If "${return}"=="FAIL" or "${objectId}"=="${EMPTY}" Set To Dictionary ${returnDict} objectId=${EMPTY}
+ ... ELSE Set To Dictionary ${returnDict} objectId=${objectId}
+ ${return} ${categoryId} Run Keyword And Ignore Error Get From Dictionary ${category} categoryId
+ Run Keyword If "${return}"=="FAIL" or "${categoryId}"=="${EMPTY}" Set To Dictionary ${returnDict} categoryId=${EMPTY}
+ ... ELSE Set To Dictionary ${returnDict} categoryId=${categoryId}
+
+ ${return} ${categoryType} Run Keyword And Ignore Error Get From Dictionary ${category} categoryType
+ ${categoryTypeV} Run Keyword If "${return}"!="FAIL" and "${categoryType}"!="${EMPTY}" Evaluate '${categoryType}'.lower()
+ ... ELSE Evaluate '${Default_CategoryType}'.lower()
+ Set To Dictionary ${returnDict} categoryType=${categoryTypeV}
+ # 取可选参数,为传入设置默认值
+ Set To Dictionary ${returnDict} categoryType=${categoryTypeV}
+ # ${return} ${isDelete} Run Keyword And Ignore Error Get From Dictionary ${category} isDelete
+ # Run Keyword If "${return}"=="FAIL" or "${isDelete}"=="${EMPTY}" Set To Dictionary ${returnDict} isDelete=${Default_IsDelete}
+ # ... ELSE Set To Dictionary ${returnDict} isDelete=${isDelete}
+ ${return} ${categoryDimension} Run Keyword And Ignore Error Get From Dictionary ${category} categoryDimension
+ Run Keyword If "${return}"=="FAIL" or "${categoryDimension}"=="${EMPTY}" Set To Dictionary ${returnDict} categoryDimension=${Default_Dimension}
+ ... ELSE Set To Dictionary ${returnDict} categoryDimension=${categoryDimension}
+ ${return} ${categoryOrigin} Run Keyword And Ignore Error Get From Dictionary ${category} categoryOrigin
+ Run Keyword If "${return}"=="FAIL" or "${categoryOrigin}"=="${EMPTY}" Set To Dictionary ${returnDict} categoryOrigin=${Default_Origin}
+ ... ELSE Set To Dictionary ${returnDict} categoryOrigin=${categoryOrigin}
+ ${return} ${isInitialize} Run Keyword And Ignore Error Get From Dictionary ${category} isInitialize
+ Run Keyword If "${return}"=="FAIL" or "${isInitialize}"=="${EMPTY}" Set To Dictionary ${returnDict} isInitialize=${Default_IsInitialize}
+ ... ELSE Set To Dictionary ${returnDict} isInitialize=${isInitialize}
+ ${return} ${categoryName} Run Keyword And Ignore Error Get From Dictionary ${category} categoryName
+ Run Keyword If "${return}"=="FAIL" or "${categoryName}"=="${EMPTY}" Set To Dictionary ${returnDict} categoryName=${Default_ObjectName}
+ ... ELSE Set To Dictionary ${returnDict} categoryName=${categoryName}
+ ${return} ${categoryDesc} Run Keyword And Ignore Error Get From Dictionary ${category} categoryDesc
+ Run Keyword If "${return}"!="FAIL" and "${categoryDesc}"!="${EMPTY}" Set To Dictionary ${returnDict} categoryDesc=${categoryDesc}
+ ... ELSE Set To Dictionary ${returnDict} categoryDesc=${Default_ObjectDesc}
+ ${return} ${objectSubType} Run Keyword And Ignore Error Get From Dictionary ${category} objectSubType
+ Run Keyword If "${return}"!="FAIL" and "${objectSubType}"!="${EMPTY}" Set To Dictionary ${returnDict} objectSubType=${objectSubType}
+ ... ELSE Set To Dictionary ${returnDict} objectSubType=${Default_ObjectSubType}
+ # 处理AddItemList
+ ${return} ${addItemList} Run Keyword And Ignore Error Get From Dictionary ${category} fqdnList
+ Run Keyword If "${opAction}"=="add" Should Not Be Empty ${addItemList}
+ # Run Keyword If "${return}"!="FAIL" and "${addItemList}"!="${EMPTY}" ManageAddItemListNew ${addItemList} ${returnDict} ${categoryTypeV} ${objectSubType}
+ ManageAddItemListNew ${addItemList} ${returnDict} ${categoryTypeV} ${objectSubType}
+
+ # 删除无用判断key值objectSubType
+ Remove From Dictionary ${returnDict} objectSubType
+ # 转为json结构并返回
+ ${json} json.Dumps ${returnDict} ensure_ascii=False
+ Log Object-${json}
+ [Return] ${json}
+
+ManageEnableAndDisable
+ [Documentation]
+ ... 启用与禁用时调用
+ [Arguments] ${object} ${returnDict} ${opAction}
+ Run Keyword If "${opAction}"=="enable" Set To Dictionary ${returnDict} isValid=1
+ Run Keyword If "${opAction}"=="disable" Set To Dictionary ${returnDict} isValid=0
+ ${json} json.Dumps ${returnDict} ensure_ascii=False
+ Log Object-${json}
+ [Return] ${json}
+ManageAddItemListNew
+ # 处理addItemList数组
+ [Arguments] ${addItemList} ${returnDict} ${type} ${subType}
+ Log Call ManageAddItemListNew
+ ${itemList} Create List
+ FOR ${item} IN @{addItemList}
+ ${itemNew} Run Keyword If '${type}'=='ip' and '${subType}'=="geo_location" ManageGeoItem ${item} ${subType} add
+ ... ELSE IF '${type}'=='ip' ManageIpItem ${item} ${subType} add
+ ... ELSE IF '${type}'=='url' or ('${type}'=='fqdn' and '${subType}'!='category') or '${type}'=='keywords' or '${type}'=='subscriberid' or '${type}'=='fqdn_category' or '${type}'=='account' or '${type}'=='app_id' or '${type}'=='mobile_identity' or '${type}'=='apn'
+ ... ManageStrItem ${item} ${type} add
+ ... ELSE IF '${type}'=='file_type' ManageFileItem ${item} ${type} add
+ ... ELSE IF '${type}'=='fqdn' and '${subType}'=='category' ManageCategory ${item} ${type} add
+ ... ELSE IF '${type}'=='http_signature' ManageExtensionStrItem ${item} ${type} add
+ ... ELSE IF '${type}'=='file_size' or '${type}'=='file_integrity_rate' ManageNumberItem ${item} ${type} add
+ ... ELSE Fail
+ Append To List ${itemList} ${itemNew}
+ END
+ Run Keyword If '${subType}'=='category' Set To Dictionary ${returnDict} fqdnList=${itemList}
+ ... ELSE Set To Dictionary ${returnDict} addItemList=${itemList}
+
+
+ManageUpdateItemList
+ [Documentation]
+ ... 处理updateItemList
+ [Arguments] ${updateItemList} ${returnDict} ${type} ${subType}
+ ${itemList} Create List
+ FOR ${item} IN @{updateItemList}
+ ${itemId} Get From Dictionary ${item} itemId
+
+
+ ${itemNew} Run Keyword If '${type}'=='ip' and '${subType}'=="geo_location" ManageGeoItem ${item} ${subType} update
+ ... ELSE IF '${type}'=='ip' ManageIpItem ${item} ${subType} update
+ ... ELSE IF '${type}'=='url' or '${type}'=='fqdn' or '${type}'=='keywords' or '${type}'=='subscriberid' or '${type}'=='fqdn_category' or '${type}'=='account' or '${type}'=='app_id'
+ ... ManageStrItem ${item} ${type} update
+ ... ELSE IF '${type}'=='file_type' ManageFileItem ${item} ${type} update
+ ... ELSE IF '${type}'=='http_signature' ManageExtensionStrItem ${item} ${type} update
+ ... ELSE IF '${type}'=='file_size' or '${type}'=='file_integrity_rate' ManageNumberItem ${item} ${type} update
+ ... ELSE Fail
+ Set To Dictionary ${itemNew} itemId=${itemId}
+ #由于接口更新时是否内置字段会导致40014001,策略对象单元不可改是否为内置(isInitialize)参数状态,这里去掉是否内置字段
+ Remove From Dictionary ${itemNew} isInitialize
+ Append To List ${itemList} ${itemNew}
+ END
+ Set To Dictionary ${returnDict} updateItemList=${itemList}
+ManageIpItem
+ [Documentation]
+ ... ip item处理
+ [Arguments] ${item} ${subType} ${action}
+ Log Call ManageIpItem
+ ${return} ${isSession} Run Keyword And Ignore Error Get From Dictionary ${item} isSession
+ ${isSession} Run Keyword If "${return}"!="FAIL" Set Variable ${isSession} ELSE Set Variable ${EMPTY}
+ Run Keyword If "${action}"=="add" Should Not Be Empty ${isSession}
+ ${return} ${ip} Run Keyword And Ignore Error Get From Dictionary ${item} ip
+ ${ip} Run Keyword If "${return}"!="FAIL" Set Variable ${ip} ELSE Set Variable ${EMPTY}
+ Run Keyword If "${action}"=="add" Should Not Be Empty ${ip}
+ ${return} ${port} Run Keyword And Ignore Error Get From Dictionary ${item} port
+ Run Keyword If "${action}"=="add" Should Not Be Empty ${port}
+ #Run Keyword If "${action}"=="add" Dictionary Should Contain Key ${item} direction
+ #${return} ${direction} Run Keyword And Ignore Error Get From Dictionary ${item} direction
+ #${direction} Run Keyword If "${return}"!="FAIL" Set Variable ${direction} ELSE Set Variable ${EMPTY}
+ #Run Keyword If "${action}"=="add" Dictionary Should Contain Key ${item} protocol
+ ${return} ${protocol} Run Keyword And Ignore Error Get From Dictionary ${item} protocol
+ ${protocol} Run Keyword If "${return}"!="FAIL" Set Variable ${protocol} ELSE Set Variable ${EMPTY}
+ ${return} ${isInitialize} Run Keyword And Ignore Error Set Variable ${item['isInitialize']}
+ ${isInitialize} Run Keyword If "${return}"!="FAIL" Set Variable ${isInitialize}
+ ... ELSE Set Variable ${EMPTY}
+ ${return} ${itemName} Run Keyword And Ignore Error Set Variable ${item['itemName']}
+ ${itemName} Run Keyword If "${return}"!="FAIL" Set Variable ${itemName}
+ ... ELSE Set Variable ${EMPTY}
+ ${return} ${itemDesc} Run Keyword And Ignore Error Set Variable ${item['itemDesc']}
+ ${itemDesc} Run Keyword If "${return}"!="FAIL" Set Variable ${itemDesc}
+ ... ELSE Set Variable ${EMPTY}
+ ${itemNew} Create Dictionary
+ Run Keyword If "${isSession}"!="${EMPTY}" Set To Dictionary ${itemNew} isSession=${isSession}
+ Run Keyword If "${ip}"!="${EMPTY}" Set To Dictionary ${itemNew} ip=${ip}
+ Run Keyword If "${port}"!="${EMPTY}" Set To Dictionary ${itemNew} port=${port}
+ #Run Keyword If "${direction}"!="${EMPTY}" Set To Dictionary ${itemNew} direction=${direction}
+ Run Keyword If "${protocol}"!="${EMPTY}" Set To Dictionary ${itemNew} protocol=${protocol}
+ Run Keyword If "${isInitialize}"!="${EMPTY}" Set To Dictionary ${itemNew} isInitialize=${isInitialize}
+ Run Keyword If "${itemName}"!="${EMPTY}" Set To Dictionary ${itemNew} itemName=${itemName}
+ Run Keyword If "${itemDesc}"!="${EMPTY}" Set To Dictionary ${itemNew} itemDesc=${itemDesc}
+ [Return] ${itemNew}
+
+ManageGeoItem
+ [Documentation]
+ ... ip item处理
+ [Arguments] ${item} ${subType} ${action}
+ Log ManageGeoItem
+ ${return} ${keywordArray} Run Keyword And Ignore Error Get From Dictionary ${item} keywordArray
+ ${keywordArray} Run Keyword If "${return}"!="FAIL" Set Variable ${keywordArray} ELSE Set Variable ${EMPTY}
+ ${itemNew} Create Dictionary
+ ${kArray} Create List
+ Run Keyword If "${keywordArray}"!="${EMPTY}" Append To List ${kArray} ${keywordArray}
+ Run Keyword If "${keywordArray}"!="${EMPTY}" Set To Dictionary ${itemNew} keywordArray=${kArray}
+ [Return] ${itemNew}
+
+ManageStrItem
+ [Documentation]
+ ... 字符串item处理
+ [Arguments] ${item} ${type} ${action}
+ Log Call ManageStrItem
+ ${return} ${keywordArray} Run Keyword And Ignore Error Set Variable ${item['keywordArray']}
+ ${keywordArray} Run Keyword If "${return}"!="FAIL" Set Variable ${keywordArray} ELSE Set Variable ${EMPTY}
+ Run Keyword If "${action}"=="add" Should Not Be Empty ${keywordArray}
+ ${array} Evaluate re.split('[,]', '${keywordArray}') re
+
+ Run Keyword If "${action}"=="add" Dictionary Should Contain Key ${item} isHexbin
+ ${return} ${isHexbin} Run Keyword And Ignore Error Get From Dictionary ${item} isHexbin
+ ${isHexbin} Run Keyword If "${return}"!="FAIL" Set Variable ${isHexbin}
+ ... ELSE Set Variable ${EMPTY}
+
+ ${return} ${isInitialize} Run Keyword And Ignore Error Set Variable ${item['isInitialize']}
+ ${isInitialize} Run Keyword If "${return}"!="FAIL" Set Variable ${isInitialize}
+ ... ELSE Set Variable ${EMPTY}
+ ${return} ${itemName} Run Keyword And Ignore Error Set Variable ${item['itemName']}
+ ${itemName} Run Keyword If "${return}"!="FAIL" Set Variable ${itemName}
+ ... ELSE Set Variable ${EMPTY}
+ ${return} ${itemDesc} Run Keyword And Ignore Error Set Variable ${item['itemDesc']}
+ ${itemDesc} Run Keyword If "${return}"!="FAIL" Set Variable ${itemDesc}
+ ... ELSE Set Variable ${EMPTY}
+
+ ${itemNew} Create Dictionary
+ Run Keyword If "${keywordArray}"!="${EMPTY}" Set To Dictionary ${itemNew} keywordArray=${array}
+ Run Keyword If "${isHexbin}"!="${EMPTY}" Set To Dictionary ${itemNew} isHexbin=${isHexbin}
+ Run Keyword If "${isInitialize}"!="${EMPTY}" Set To Dictionary ${itemNew} isInitialize=${isInitialize}
+ Run Keyword If "${itemName}"!="${EMPTY}" Set To Dictionary ${itemNew} itemName=${itemName}
+ Run Keyword If "${itemDesc}"!="${EMPTY}" Set To Dictionary ${itemNew} itemDesc=${itemDesc}
+ [Return] ${itemNew}
+
+ManageCategory
+ [Documentation]
+ ... 字符串item处理
+ [Arguments] ${item} ${type} ${action}
+ Log Call ManageStrItem
+ ${return} ${fqdn} Run Keyword And Ignore Error Set Variable ${item['fqdn']}
+ ${fqdn} Run Keyword If "${return}"!="FAIL" Set Variable ${fqdn} ELSE Set Variable ${EMPTY}
+ Run Keyword If "${action}"=="add" Should Not Be Empty ${fqdn}
+ ${itemNew} Create Dictionary
+ Run Keyword If "${fqdn}"!="${EMPTY}" Set To Dictionary ${itemNew} fqdn=${fqdn}
+ [Return] ${itemNew}
+
+ManageFileItem
+ [Documentation]
+ ... 接口未说明,待接口说明字段类型之后再完善
+ [Arguments] ${item} ${type} ${action}
+ Log Call ManageFileItem
+ [Return] ${item}
+ManageExtensionStrItem
+ [Documentation]
+ ... http_signature参数说明
+ [Arguments] ${item} ${type} ${action}
+ Log Call ManageExtensionStrItem
+ ${return} ${district} Run Keyword And Ignore Error Get From Dictionary ${item} district
+ ${district} Run Keyword If "${return}"!="FAIL" Set Variable ${district} ELSE Set Variable ${EMPTY}
+ Run Keyword If "${action}"=="add" Should Not Be Empty ${district}
+ ${itemNew} ManageStrItem ${item} ${type} ${action}
+ Run Keyword If "${district}"!="${EMPTY}" Set To Dictionary ${itemNew} district=${district}
+ [Return] ${itemNew}
+ManageNumberItem
+ [Documentation]
+ ... 接口未说明,待接口说明字段类型之后再完善
+ [Arguments] ${item} ${type} ${action}
+ Log Call ManageNumberItem
+ [Return] ${item}
+ManageDeleteItemIds
+ [Documentation]
+ ... 处理deleteItemIds
+ ... ${1},${2},${3} -> [1,2,3]
+ [Arguments] ${deleteItemIds} ${returnDict}
+ ${list} Evaluate re.split('[,]', '${deleteItemIds}') re
+ ${list1} Create List
+ FOR ${var} IN @{list}
+ ${var} Run Keyword If '${var}'.isdigit() Evaluate int('${var}')
+ ... ELSE Set Variable ${var}
+ Append To List ${list1} ${var}
+ END
+ Set To Dictionary ${returnDict} deleteItemIds=${list1}
+GetObjectIds
+ [Documentation]
+ ... 获取结果中的对象ID
+ [Arguments] ${value}
+ Log Call Get-ObjectIds
+ ${objectIds} Create List
+ ${objectIdsTemp} Set Variable ${EMPTY}
+ ${return} ${data} Run Keyword And Ignore Error Get From Dictionary ${value} data
+ Return From Keyword If "${return}"=="FAIL" ${objectIdsTemp}
+
+ FOR ${object} IN @{value['data']['objectList']}
+ Append To List ${objectIds} ${object['objectId']}
+ END
+ ${json} json.Dumps ${objectIds} ensure_ascii=False
+ ${json} Remove String ${json} [
+ ${json} Remove String ${json} ]
+ [Return] ${json}
+getObjectListIds
+ [Documentation]
+ ... 获取结果中的对象ID
+ [Arguments] ${value}
+ Log Call Get-ObjectIds
+ ${objectIds} Create List
+ ${objectIdsTemp} Set Variable ${EMPTY}
+ ${return} ${data} Run Keyword And Ignore Error Get From Dictionary ${value} data
+ Return From Keyword If "${return}"=="FAIL" ${objectIdsTemp}
+
+ FOR ${object} IN @{value['data']['objectList']}
+ Append To List ${objectIds} ${object['objectId']}
+ END
+ [Return] ${objectIds}
+GetCategoryIds
+ [Documentation]
+ ... 获取结果中的对象ID
+ [Arguments] ${value}
+ Log Call Get-ObjectIds
+ ${CategoryIds} Create List
+ ${CategoryTemp} Set Variable ${EMPTY}
+ ${return} ${data} Run Keyword And Ignore Error Get From Dictionary ${value} data
+ Return From Keyword If "${return}"=="FAIL" ${CategoryTemp}
+
+ FOR ${category} IN @{value['data']['list']}
+ Append To List ${CategoryIds} ${category['categoryId']}
+ END
+ ${json} json.Dumps ${CategoryIds} ensure_ascii=False
+ ${json} Remove String ${json} [
+ ${json} Remove String ${json} ]
+ [Return] ${json}
+GetCategoryObjIds
+ [Documentation]
+ ... 获取Category结果中的对象ID
+ [Arguments] ${value}
+ Log Call Get-CategoryObjectIds
+ ${CategoryObjIds} Create List
+ ${CategoryTemp} Set Variable ${EMPTY}
+ ${return} ${data} Run Keyword And Ignore Error Get From Dictionary ${value} data
+ Return From Keyword If "${return}"=="FAIL" ${CategoryTemp}
+
+ FOR ${category} IN @{value['data']['list']}
+ Append To List ${CategoryObjIds} ${category['objectId']}
+ END
+ ${json} json.Dumps ${CategoryObjIds} ensure_ascii=False
+ ${json} Remove String ${json} [
+ ${json} Remove String ${json} ]
+ [Return] ${json} \ No newline at end of file
diff --git a/keyword/policys/manage_policy_body.robot b/keyword/policys/manage_policy_body.robot
new file mode 100644
index 0000000..3ef02cb
--- /dev/null
+++ b/keyword/policys/manage_policy_body.robot
@@ -0,0 +1,281 @@
+*** Settings ***
+Library json
+Library Collections
+Resource ../../variable/common_variable.txt
+Resource ../../variable/policy_object_default.txt
+Resource policy.robot
+*** Variables ***
+#arraySplitor:数组元素之间的分隔符
+${arraySplitor} ,
+#protocolFiledSplitor:protocolFiled之间的分隔符
+${protocolFiledSplitor} &
+#objectIdSplitor:objectId之间的分隔符
+${objectIdSplitor} :
+#idFiledSplitor: objectId和protocolFiled之间的分隔符
+${idFiledSplitor} |
+*** Keywords ***
+# ... 特殊参数说明:
+# ... effectiveRange=Nursurtan|Transtelecom&Astel,Almaty&Nursurtan,|Astel&Transtelecom
+# ... 为字符串类型,每条生效区域信息以','分隔
+# ... ①以'|'字符开头表示仅为isp信息,如:effectiveRange=|Astel&Transtelecom
+# ... ②非'|'字符开头表示仅为location信息或location和isp信息,如:
+# ... effectiveRange=Nursurtan(仅为location信息)
+# ... effectiveRange=Nursurtan|Transtelecom&Astel(location和isp信息)
+# ... userRegion=protocol:HTTP,keyring:${1}
+# ... 为字符串类型,每条动作参数以','分隔
+# ... [key]:[value],...
+# ... referenceObject=${265}|TSG_FIELD_HTTP_HOST,${266}|TSG_FIELD_SSL_SNI&TSG_FIELD_SSL_SAN
+# ... 为字符串类型,每条引用的策略对象信息以','分隔
+# ... [objectId]|[protocolFileds],... ,多个protocolFileds用'&'连接
+# ... scheduleId=${3},${1}
+# ... 为字符串类型,以','分隔
+# ... appObjectIdArray==${2},${3}
+# ... 为字符串类型,以','分隔
+# ...
+# ... 注:数字类型变量为${0}、${1}、${...}
+
+PolicyParamsOpertion
+ [Documentation]
+ ... 描述:入口,opAction参数固定为'add'
+ ... 参数:returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。
+ ... policyList: 必传,字典类型。字典内可选参数信息:
+ ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt
+
+ [Arguments] ${returnData} ${policyList} ${opAction}
+ ${emptyList} Create List
+ # 断言必传参数
+ # Should Not Be Empty ${policyList}[policyType]
+ # Should Not Be Empty ${policyList}[action]
+ # 取可选参数,为传入设置默认值
+ ${return} ${policyName} Run Keyword And Ignore Error Set Variable ${policyList}[policyName]
+ Run Keyword If "${return}"=="FAIL" or "${policyName}"=="${EMPTY}" Set To Dictionary ${policyList} policyName=${Default_PolicyName}
+ ${return} ${policyType} Run Keyword And Ignore Error Set Variable ${policyList}[policyType]
+ Run Keyword If "${return}"=="FAIL" or "${policyType}"=="${EMPTY}" Set To Dictionary ${policyList} policyType=${Default_PolicyType}
+ ${return} ${policyDesc} Run Keyword And Ignore Error Set Variable ${policyList}[policyDesc]
+ Run Keyword If "${return}"=="FAIL" or "${policyDesc}"=="${EMPTY}" Set To Dictionary ${policyList} policyDesc=${Default_PolicyDesc}
+ ${return} ${action} Run Keyword And Ignore Error Set Variable ${policyList}[action]
+ Run Keyword If "${return}"=="FAIL" or "${action}"=="${EMPTY}" Set To Dictionary ${policyList} action=${Default_Action}
+ ${return} ${userTags} Run Keyword And Ignore Error Set Variable ${policyList}[userTags]
+ Run Keyword If "${return}"=="FAIL" or "${userTags}"=="${EMPTY}" Set To Dictionary ${policyList} userTags=${Default_UserTags}
+ ${return} ${doLog} Run Keyword And Ignore Error Set Variable ${policyList}[doLog]
+ Run Keyword If "${return}"=="FAIL" or "${doLog}"=="${EMPTY}" Set To Dictionary ${policyList} doLog=${Default_DoLog}
+ ${return} ${isValid} Run Keyword And Ignore Error Set Variable ${policyList}[isValid]
+ Run Keyword If "${return}"=="FAIL" or "${isValid}"=="${EMPTY}" Set To Dictionary ${policyList} isValid=${Default_IsValid}
+ ${return} ${scheduleId} Run Keyword And Ignore Error Set Variable ${policyList}[scheduleId]
+ #${scheduleIdV} Run Keyword If "${return}"=="FAIL" or "${scheduleId}"=="${EMPTY}" Evaluate list(map(int, re.split('[,]', '${Default_ScheduleId}'))) re
+ # ... ELSE Evaluate list(map(int, re.split('[,]', '${scheduleId}'))) re
+ ${scheduleIdV} Run Keyword If "${return}"!="FAIL" and "${scheduleId}"!="${EMPTY}" and "${scheduleId}"!="${None}" Evaluate list(map(int, re.split('[,]', '${scheduleId}'))) re
+ ... ELSE Set Variable ${emptyList}
+ Set To Dictionary ${policyList} scheduleId=${scheduleIdV}
+ ${return} ${appObjectIdArray} Run Keyword And Ignore Error Set Variable ${policyList}[appObjectIdArray]
+ ${appObjectIdArrayV} Run Keyword If "${return}"=="FAIL" or "${appObjectIdArray}"=="${EMPTY}" Evaluate list(map(int, re.split('[,]', '${Default_AppObjectIdArray}'))) re
+ ... ELSE Evaluate list(map(int, re.split('[,]', '${appObjectIdArray}'))) re
+ Set To Dictionary ${policyList} appObjectIdArray=${appObjectIdArrayV}
+ ${policyId} Run Keyword If "${opAction}"=="add" Set Variable ${EMPTY}
+ ... ELSE Set Variable ${policyList}[policyId]
+ # 固定值
+ Set To Dictionary ${policyList} policyId=${policyId} doBlacklist=${0}
+ # 分别处理EffectiveRange、UserRegion和ReferenceObject参数
+ ManageEffectiveRange ${policyList}
+ #ManageUserRegion ${policyList}
+ ManageReferenceObject ${policyList}
+ #先取出useragion 再放回json
+ ${return} ${userRegion} Run Keyword And Ignore Error Set Variable ${policyList}[userRegion]
+ Set To Dictionary ${policyList} userRegion=${Default_UserRegion}
+ ${userRegion} Run Keyword If "${return}"=="FAIL" or '${userRegion}'=="${EMPTY}" Set Variable ""
+ ... ELSE Set Variable ${userRegion}
+
+ #针对主动防御特殊处理,主动防御不应用对象
+ ${active_defence_emptyList} Create List
+ ${return} ${policyType} Run Keyword And Ignore Error Set Variable ${policyList}[policyType]
+ Run Keyword If "${policyType}"=="active_defence" Set To Dictionary ${policyList} referenceObject=${active_defence_emptyList}
+ Run Keyword If "${policyType}"=="active_defence" Set To Dictionary ${policyList} appObjectIdArray=${active_defence_emptyList}
+ # 转为json结构并返回
+ ${dict} Create Dictionary opAction=${opAction} returnData=${returnData} policyList=${policyList}
+ ${json} json.Dumps ${dict} ensure_ascii=False
+ ${json} Replace String ${json} "method:rst" ${userRegion}
+
+ Log Policy_Request_Body-${json}
+ [Return] ${json}
+
+ManageEffectiveRange
+ # 处理EffectiveRange
+ [Arguments] ${policyList}
+ ${emptyList} Create List
+ ${emptyListDouble} Create List ${emptyList}
+
+ ${return} ${effectiveRange} Run Keyword And Ignore Error Set Variable ${policyList}[effectiveRange]
+ ${effectiveRange} Run Keyword If "${return}"=="FAIL" or "${effectiveRange}"=="${EMPTY}" Set Variable ${Default_EffectiveRange}
+ ... ELSE Set Variable ${effectiveRange}
+
+ ${value} Run Keyword If "${effectiveRange}"=="${EMPTY}" Create Dictionary tag_sets=${emptyListDouble}
+ ... ELSE AnalysisEffectiveRange ${effectiveRange}
+ Set To Dictionary ${policyList} effectiveRange=${value}
+
+AnalysisEffectiveRange
+ # 解析EffectiveRange,区分值类型
+ [Arguments] ${effectiveRange}
+ ${value} Create List
+ ${list} Evaluate re.split('[,]', '${effectiveRange}') re
+ FOR ${var} IN @{list}
+ ${param} Run Keyword If '${var}'.startswith('|') EffectiveRangeValueType1 ${var}
+ ... ELSE IF '|' in '${var}' EffectiveRangeValueType2 ${var}
+ ... ELSE EffectiveRangeValueType3 ${var}
+ Append To List ${value} ${param}
+ END
+ ${obj} Create Dictionary tag_sets=${value}
+ [Return] ${obj}
+
+EffectiveRangeValueType1
+ # EffectiveRange值类型1,仅为isp信息
+ [Arguments] ${str}
+ # #Astel
+ ${value} Evaluate '${str}'[1:]
+
+ ${valueList} Create List
+ ${list} Evaluate re.split('[&]', '${value}') re
+ FOR ${var} IN @{list}
+ Append To List ${valueList} ${var}
+ END
+ ${obj} Create Dictionary tag=isp value=${valueList}
+ ${return} Create List ${obj}
+ [Return] ${return}
+
+EffectiveRangeValueType2
+ # EffectiveRange值类型2,location|isp都包含
+ [Arguments] ${str}
+ # Nursurtan#Transtelecom
+ ${list} Evaluate re.split('[|]', '${str}') re
+ # Location
+ ${valueList1} Create List
+ ${list1} Evaluate re.split('[&]', '${list}[0]') re
+ FOR ${var} IN @{list1}
+ Append To List ${valueList1} ${var}
+ END
+ ${obj1} Create Dictionary tag=data_center value=${valueList1}
+ # ISP
+ ${valueList2} Create List
+ ${list2} Evaluate re.split('[&]', '${list}[1]') re
+ FOR ${var} IN @{list2}
+ Append To List ${valueList2} ${var}
+ END
+ ${obj2} Create Dictionary tag=isp value=${valueList2}
+
+ ${return} Create List ${obj1} ${obj2}
+ [Return] ${return}
+
+EffectiveRangeValueType3
+ # EffectiveRange值类型3,仅为location信息
+ [Arguments] ${str}
+ # Almaty
+ ${valueList} Create List
+ ${list} Evaluate re.split('[&]', '${str}') re
+ FOR ${var} IN @{list}
+ Append To List ${valueList} ${var}
+ END
+ ${obj} Create Dictionary tag=data_center value=${valueList}
+ #适应adc设定标签
+ #${obj} Create Dictionary tag=device_id value=${valueList}
+ ${return} Create List ${obj}
+ [Return] ${return}
+
+ManageUserRegion
+ [Arguments] ${policyList}
+ ${emptyObj} Create Dictionary
+
+ ${return} ${userRegion} Run Keyword And Ignore Error Set Variable ${policyList}[userRegion]
+ #${userRegion} Replace String ${userRegion} ' ${EMPTY}
+ ${userRegion} Run Keyword If "${return}"=="FAIL" or "${userRegion}"=="${EMPTY}" Set Variable ${Default_UserRegion}
+ ... ELSE Set Variable ${userRegion}
+
+ ${value} Run Keyword If "${userRegion}"=="${EMPTY}" Create Dictionary
+ ... ELSE AnalysisUserRegion ${userRegion}
+ Set To Dictionary ${policyList} userRegion=${value}
+
+ Log ${policyList}[userRegion]
+
+AnalysisUserRegion
+ [Arguments] ${userRegion}
+ # protocol:HTTP,keyring:1
+ ${obj} Create Dictionary
+ ${list} Evaluate re.split('[,]', '${userRegion}') re
+ FOR ${var} IN @{list}
+ ${k} Evaluate '${var}'[0:'${var}'.find(':')]
+ ${v} Evaluate '${var}'['${var}'.find(':')+1:]
+ ${v} Run Keyword If '${v}'.isdigit() Evaluate int('${v}')
+ ... ELSE Set Variable ${v}
+ Set To Dictionary ${obj} ${k}=${v}
+ END
+ [Return] ${obj}
+
+ManageReferenceObject
+ # 处理引用对象字符串
+ [Arguments] ${policyList}
+ ${emptyList} Create List
+ #默认客户端条件类型:clientip or clientsubid
+ ${return} ${defaultClient} Run Keyword And Ignore Error Set Variable ${policyList}[defalutClient]
+ ${defaultClient} Run Keyword If "${return}"=="FAIL" or "${defaultClient}"=="${EMPTY}" Set Variable ${Default_Client_Type}
+ ... ELSE Set Variable ${defaultClient}
+ Run Keyword If '${addTestClentIPFlag}'=='1' and '${defaultClient}'=='clientip' ManageClientIPObject ${emptyList}
+ Run Keyword If '${addTestClentIPFlag}'=='1' and '${defaultClient}'=='clientsubid' ManageClientSubIDObject ${emptyList}
+ #Run Keyword If '${addTestClentIPFlag}'=='1' ManageClientObject ${emptyList}
+ # Run Keyword If "${clientHostObj}"!="${None}" Append To List ${emptyList} ${clientHostObj}
+
+ ${defaultObj} Create Dictionary
+ ${return} ${referenceObject} Run Keyword And Ignore Error Set Variable ${policyList}[referenceObject]
+ ${referenceObject} Run Keyword If "${return}"=="FAIL" or "${referenceObject}"=="${EMPTY}" Set Variable ${Default_ReferenceObject}
+ ... ELSE Set Variable ${referenceObject}
+ ${value} Run Keyword If "${referenceObject}"=="${EMPTY}" Create List ${defaultObj}
+ ... ELSE AnalysisReferenceObject ${referenceObject}
+ # 若参数为空,设置默认结构
+ FOR ${var} IN @{value}
+ Run Keyword If ${var}!={} Append To List ${emptyList} ${var}
+ END
+ Set To Dictionary ${policyList} referenceObject=${emptyList}
+
+ManageClientIPObject
+ [Arguments] ${emptyList}
+ # 增加引用测试终端IP策略对象
+ ${list1} Create List TSG_SECURITY_SOURCE_ADDR
+ ${intid} Evaluate int(${testClentID})
+ ${obj1} Create Dictionary objectId=${intid} protocolFields=${list1}
+ Append To List ${emptyList} ${obj1}
+ # ${list2} Create List null
+ # ${obj2} Create Dictionary objectId=${testClentSubID} protocolFields=${list2}
+ # Append To List ${emptyList} ${obj2}
+ManageClientSubIDObject
+ [Arguments] ${emptyList}
+ # 增加引用测试终端IP策略对象
+ ${list1} Create List
+ ${obj1} Create Dictionary objectId=${testClentSubID} protocolFields=${list1}
+ Append To List ${emptyList} ${obj1}
+
+AnalysisReferenceObject
+ # 解析引用对象
+ [Arguments] ${referenceObject}
+ ${objList} Create List
+ ${list} Evaluate re.split('[${arraySplitor}]', '${referenceObject}') re
+ FOR ${var} IN @{list}
+ ${emptyList} Create List
+ ${emptyObj} Create Dictionary
+ ${key} Evaluate '${var}'[0:'${var}'.find('${idFiledSplitor}')]
+ ${values} Evaluate '${var}'['${var}'.find('${idFiledSplitor}')+1:]
+ ${valueList} InnerForEach ${values}
+ ${key} Run Keyword If '${key}'.isdigit() Evaluate int('${key}')
+ ... ELSE Set Variable ${key}
+ Set To Dictionary ${emptyObj} objectId=${key}
+ Set To Dictionary ${emptyObj} protocolFields=${valueList}
+ Append To List ${objList} ${emptyObj}
+ END
+ [Return] ${objList}
+
+InnerForEach
+ # 循环嵌套
+ [Arguments] ${values}
+ ${emptyList} Create List
+ ${list} Evaluate re.split('[${protocolFiledSplitor}]', '${values}') re
+ FOR ${var} IN @{list}
+ Append To List ${emptyList} ${var}
+ END
+ [Return] ${list}
+
diff --git a/keyword/policys/policy.robot b/keyword/policys/policy.robot
new file mode 100644
index 0000000..180ef50
--- /dev/null
+++ b/keyword/policys/policy.robot
@@ -0,0 +1,562 @@
+*** Settings ***
+Library yaml
+Library Collections
+Library String
+Library json
+Library RequestsLibrary
+Resource ../../variable/common_variable.txt
+#Resource functional_keywords.robot
+Resource process_policy_body.robot
+Resource ../common/common.robot
+Resource ../objects/object.robot
+*** Variables ***
+${policyUrl} /policy/compile
+*** Keywords ***
+#get查询策略,传入字典对象,该方法将字典对象自动拼接成get请求查询条件
+QueryPolicies
+ [Documentation]
+ ... 查询策略,params为参数字典,version为接口版本号
+ [Arguments] ${params} ${version}
+ Log To Console Call QueryPolicies
+ Dictionary Should Contain Key ${params} policyType
+ ${paramsStr} DictionaryToQueryParams ${params}
+ ${response} BaseGetRequestForV2 ${policyUrl} ${paramsStr} ${version}
+ ${rescode} Set Variable ${response['code']}
+ [Return] ${rescode} ${response}
+
+AddPolicies
+ [Documentation]
+ ... 新增策略
+ ... returnData:是否返回数据,这里需要设置为1
+ ... policyList:策略列表,支持dict与list两种形式
+ ... version:接口版本号
+ ... 支持v1版本接口与v2版本接口
+ ... v1版本特殊参数说明:
+ ... referenceObject=${265}|TSG_FIELD_HTTP_HOST,${266}|TSG_FIELD_SSL_SNI&TSG_FIELD_SSL_SAN
+ ... 为字符串类型,每条引用的策略对象信息以','分隔
+ ... [objectId]|[protocolFileds],... ,多个protocolFileds用'&'连接
+ ... appObjectIdArray==${2},${3}
+ ... 为字符串类型,以','分隔
+ ... v2版本特殊参数说明:
+ ... v2版本中无referenceObject,取而代之的是source,destination,filterList
+ ... source= ${265}|TSG_FIELD_HTTP_HOST,${266}|TSG_FIELD_SSL_SNI
+ ... destination= ${265}|TSG_FIELD_HTTP_HOST,${266}|TSG_FIELD_SSL_SNI
+ ... filterList= ${265}:${257}|TSG_FIELD_HTTP_HOST,${266}:${299}|TSG_FIELD_SSL_SNI
+ ... filterList由多个数字用‘:’分隔,加上|对上对应的protocolFiled,
+ ... 一个filter中的protocolFiled是确定的,一个protocolFiled对应多个objectId
+ ... v2版本不支持protocolFiled之间的&符号连接,因为接口中protocolFiled不是数组结构
+ ... appIdObjects==${2},${3}
+ ... 20200701修订:分隔符号在Variables中定义,可替换
+ [Arguments] ${returnData} ${policyList} ${version}
+ Log To Console Call AddPolicies
+ ${returnData}= Run Keyword If '${returnData}' == '${EMPTY}' Set Variable 1
+ ... ELSE Set Variable ${returnData}
+ #控制台打印参数
+ #Log To Console ${policyList}
+ #必选参数判定
+ Should Not Be Empty ${policyList}
+ ${dictType} = Evaluate type(${policyList})
+ ${body} Run Keyword If "${dictType}" == "<class 'list'>" PolicyListDataOperation ${returnData} ${policyList} add ${version}
+ ... ELSE IF "${dictType}" == "<class 'dict'>" PolicyDataOperation ${returnData} ${policyList} add ${version}
+ ... ELSE Set Variable ${EMPTY}
+ #${body} Set Variable {"opAction":"add","policyList":{"policyName":"wx-test","policyType":"tsg_security","action":"deny","userTags":"","doBlacklist":0,"doLog":1,"policyDesc":"","effectiveRange":{"tag_sets":[[]]},"userRegion":{"protocol":"SSL","method":"drop"},"source":[{"objectId":3101,"protocolField":"TSG_SECURITY_SOURCE_ADDR"}],"destination":[],"filterList":[{"filter":[{"objectId":3404,"protocolField":"TSG_FIELD_SSL_CN"}]}],"appIdObjects":[3],"isValid":0,"scheduleId":[]}}
+ ${response} BasePostRequestForV2 ${policyUrl} ${body} ${version}
+ ${policyIds} Run Keyword If "${returnData}" == "1" GetPolicyIds ${response}
+ ... ELSE Create List
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ [Return] ${rescode} ${policyIds}
+UpdatePolicies
+ [Documentation]
+ ... 与新增类似,update多一个参数opAction
+ ... opAction可为update,enable,disable
+ [Arguments] ${returnData} ${policyList} ${version} ${opAction}
+ Log To Console Call UpdatePolicies
+ ${returnData}= Run Keyword If '${returnData}' == '${EMPTY}' Set Variable 1
+ ... ELSE Set Variable ${returnData}
+ #必选参数判定
+ Should Not Be Empty ${policyList}
+ ${dictType} = Evaluate type(${policyList})
+ ${body} Run Keyword If "${dictType}" == "<class 'list'>" PolicyListDataOperation ${returnData} ${policyList} ${opAction} ${version}
+ ... ELSE IF "${dictType}" == "<class 'dict'>" PolicyDataOperation ${returnData} ${policyList} ${opAction} ${version}
+ ... ELSE Set Variable ${EMPTY}
+ ${response} BaseEditRequestForV2 ${policyUrl} ${body} ${version}
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ [Return] ${rescode}
+DeletePoliciebyList
+ [Documentation]
+ ... 删除策略
+ ... params结构可为List或者dict
+ ... dict结构
+ ... dict data:{'policyType':'tsg_security','policyIds':[1,2,3]}
+ ... list 结构
+ ... list data:[{'policyType':'tsg_security','policyIds':[1,2,3]},{'policyType':'pxy_manipulation','policyIds':[4,5,6]}]
+ [Arguments] ${params}
+ ${paramsType} Evaluate type(${params})
+ Run Keyword And Return If "${paramsType}" == "<class 'dict'>" DeletePolicyWithParamDict ${params}
+ FOR ${param} IN @{params}
+ ${rescode} DeletePolicyWithParamDict ${param}
+ END
+ [Return] ${rescode}
+
+DeletePolicyByIds
+ [Documentation]
+ ... policyIds 策略id list [1,2,3]
+ ... policyType 策略类型 tsg_security等
+ [Arguments] ${policyIds} ${policyType}
+ ${params} Create Dictionary policyIds=${policyIds} policyType=${policyType}
+ ${response} BaseDeleteRequest /${version}${policyUrl} ${params}
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ [Return] ${rescode}
+
+DeleteAllTypePolicyByIds
+ [Documentation]
+ ... policyIds 策略id list [[1,2,3],[4,5,6],[7,8,9]]分别为安全策略id,代理策略id
+ ... policyType 策略类型 tsg_security等
+ [Arguments] ${policyIds}
+ ${policyType} Create List ['tsg_security','pxy_manipulation','pxy_manipulation','active_defence','inline_device','wannat','pxy_tcp_option']
+ ${var} Set Variable 0
+ FOR ${param} IN @{policyIds}
+ ${varvalue} Get From List ${policyType}
+ ${rescode} DeletePolicyByIds ${param} ${varvalue}
+ END
+ ${params} Create Dictionary policyIds=${policyIds} policyType=${policyType}
+ ${response} BaseDeleteRequest /${version}${policyUrl} ${params}
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ [Return] ${rescode}
+
+ImportPolicy
+ [Documentation]
+ ... 策略导入
+ ... jira CHON-12导入限制需求支持
+ [Arguments] ${filePath} ${fileName} ${policyType}
+ Directory Should Exist ${path}
+ File Should Exist ${path}/${filePath}/${fileName}
+ File Should Not Be Empty ${path}/${filePath}/${fileName}
+ #获取导入策略总数
+ ${file} Get File ${path}/${filePath}/${fileName}
+ ${fileJson} json.Loads ${file}
+ #待导入的策略总数
+ ${totalNum} Get From Dictionary ${fileJson} totalNum
+ #查询已经导入的非内置策略的数量
+ ${totalExists} GetPolicyTotal 10
+ ${calTotal} Evaluate ${totalNum} + ${totalExists}
+ Connect To Database Using Custom Params pymysql ${mysqlHost}
+ ${policyLimit} query SELECT cfg_value FROM t_sys_cfg WHERE cfg_name='policy_upper_limit'
+ ${policyLimit} Set Variable ${policyLimit[0][0]}
+ ${remaining} Evaluate ${policyLimit}-${totalExists}
+ log 策略剩余可导入量为:${remaining}
+ ${testType} Evaluate type($policyLimit)
+ Disconnect From Database
+ #jira CHON-12导入限制需求支持
+ Run Keyword If ${calTotal}>${policyLimit} log 当前已经存在策略条数${totalExists},待导入条数${totalNum},总数超过${policyLimit}条!
+ ${binFile} Evaluate (r'import_policy.json',open(r"${path}/${filePath}/${fileName}",'rb'),'application/json')
+ Log ${binFile}
+ ${data} Create Dictionary policyType=${policyType}
+ ${file} Create Dictionary file=${binFile}
+ ${response} BaseMultipartPostRequest ${policyUrl}/batch ${data} ${file} ${version2}
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ [Return] ${rescode} ${totalNum}
+ExportPolicy
+ [Documentation]
+ ... 策略导出
+ ... policyType tsg_security等
+ ... policyIds 1,2,3
+ ... policyName 字符串
+ [Arguments] ${policyType} ${policyIds} ${policyName}
+ Should Not Be Empty ${policyType}
+ ${params} Create Dictionary policyType=${policyType}
+ Run Keyword If "${policyIds}"!="${EMPTY}" Set To Dictionary ${params} policyIds=${policyIds}
+ Run Keyword If "${policyName}"!="${EMPTY}" Set To Dictionary ${params} policyName=${policyName}
+ ${paramsStr} DictionaryToQueryParams ${params}
+ ${response} BaseFormRequest1 ${policyUrl}/batch ${paramsStr} ${version}
+ [Return] ${response}
+WriteFile
+ [Arguments] ${filePath} ${fileName} ${content}
+ Create File ${path}/${filePath}/${fileName}
+ ${type} Evaluate type(${content})
+ ${content} Run Keyword If "${type}" == "<class 'dict'>" json.Dumps ${content}
+ ... ELSE Set Variable ${content}
+ Append To File ${path}/${filePath}/${fileName} ${content}
+VerifyPolicies
+ [Documentation]
+ ... 策略验证
+ ... 支持多个策略验证与单个策略验证
+ ... 单个策略验证时verifyList 是一个dict
+ ... 多个策略验证时是一个list
+ ... atrributeValue字段可为三种格式
+ ... 1:dict
+ ... 2:json
+ ... 3.字符串,ip的value对应格式为ip|port|addrType|protocol,注意addrType,protocol为数字
+ ... signature 的value对应格式为district|string
+ ... string的格式就是string
+ ... 以上三种方式可以混合搭配使用
+ [Arguments] ${verifyList}
+ Log To Console Call VerifyPolicies
+ #必选参数判定
+ Should Not Be Empty ${verifyList}
+ ${dictType} = Evaluate type(${verifyList})
+ ${body} Run Keyword If "${dictType}" == "<class 'list'>" VerifyPolicyList ${verifyList}
+ ... ELSE IF "${dictType}" == "<class 'dict'>" VerifyPolicyObj ${verifyList}
+ ... ELSE Set Variable ${EMPTY}
+ ${body} Set Variable {"verifyList":${body}}
+ ${response} BasePostRequestForV2 /policy/verify ${body} ${version}
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ [Return] ${rescode} ${response['data']}
+GetPolicyTotal
+ [Documentation]
+ ... 获取已经存在的策略总量
+ ... 排除内置策略
+ ... initializeNum内置策略数量
+ [Arguments] ${initializeNum}
+ ${response} BaseFormRequest ${policyUrl}/statistics ${EMPTY} ${version}
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ ${total} Set Variable ${response['data']['policyNum']}
+ ${total} Evaluate ${total} - ${initializeNum}
+ [Return] ${total}
+SortPolicies
+ [Documentation]
+ ... 将策略排序
+ ... policyList
+ ... 支持list dict两种结构
+ ... dict结构:policyType=tsg_security policyId=${1517} afterPolicyId=${1518}
+ [Arguments] ${policyList}
+ Should Not Be Empty ${policyList}
+ ${isList} Evaluate isinstance(${policyList},list)
+ ${policyJson} Run Keyword If "${isList}"=="True" SortPolicyList ${policyList}
+ ... ELSE SortPolicyObject ${policyList}
+
+ ${response} BasePostRequestForV2 ${policyUrl}/moveto {"policyList":${policyJson}} ${version}
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ [Return] ${response}
+StatisticsPolicies
+ [Documentation]
+ ... 获取策略总量
+ ... 不需要传参
+ [Arguments]
+ ${response} BaseFormRequest ${policyUrl}/statistics ${EMPTY} ${version}
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ ${data} Set Variable ${response['data']}
+ [Return] ${data}
+
+
+###############################################################################
+#数据分离,测试数据来自对应的yaml文件
+PolilcysByTemplate
+ [Documentation] 根据测试数据文件,使用对应公共模板,创建策略及策略相关数据:策略信息,对象信息,引用文件信息,返回本策略创建的策略及策略相关数据,用于teamdow删除
+ ... 入参:${dataFilePath}数据文件,全路径文件名 ${keyword}测试用例名称
+ ... data数据文件格式参照:other/data/security/http/demo_data.yaml
+ ... 待扩展:策略验证
+ ... 待扩展:功能端效果验证数据,如果存在对用数据则进行功能端效果验证和日志验证,如果不存在则不进行功能端效果验证和日志验证;
+ ... 返回数据:对象idlist${objectIds},格式:[107582, 107583]
+ ... 返回数据:策略id+类型list${policyIds},格式:[{'objectId': 107582, 'protocolField': 'TSG_SECURITY_SOURCE_ADDR'},{'objectId': 107583, 'protocolField': 'TSG_SECURITY_SOURCE_ADDR'}]
+ [Arguments] ${dataFilePath} ${keyword}
+ ${yamlData}= Get File ${dataFilePath}
+ ${loadedData}= yaml.Safe Load ${yamlData}
+ ${policyList} Get From Dictionary ${loadedData} ${keyword}_data
+ ${objectIds} Create List
+ ${policyIds} Create List
+ Comment 循环创建策略
+ FOR ${key} IN @{policyList}
+ LOG passssssssss
+ ${objectId} ${policyId} Run Keyword And Continue On Failure CreatePolicysAndObjects ${key} ${keyword}
+ #返回的对象和策略信息添加到对象和策略列表
+ Run Keyword If "${objectId}" !="None" AppendListToList ${objectIds} ${objectId}
+ Run Keyword If "${policyId}" !="None" AppendListToList ${policyIds} ${policyId}
+ END
+ [Return] ${objectIds} ${policyIds}
+
+
+CreatePolicysAndObjects
+ [Documentation] 组织单个策略数据,${policyModeJson}来自初始化加载的全局变量策略模板;${policyData}策略模板文件路径 从数据文件中获取的单个策略数据,还包含对象数据,引用文件等内容
+ ... 入参:${policyData},从数据文件获取的单个策略数据: ${testName}测试用例名称
+ ... 返回参数${objectId}格式:[107582, 107583]
+ ... 返回参数:${policyId} [{'objectId': 107582, 'protocolField': 'TSG_SECURITY_SOURCE_ADDR'},{'objectId': 107583, 'protocolField': 'TSG_SECURITY_SOURCE_ADDR'}]
+ [Arguments] ${policyData} ${testName}
+ Comment 获取模板
+ Comment ${policyModeJson}策略模板取自全局变量
+ ${policyJson} Set Variable ${policyModeJson}
+ Comment 用data数据替换模板内容生成策略新增数据
+ ${condation} Get From Dictionary ${policyData} condation
+ ${objectIds} ${sourceList} ${destinationList} ${filterList} CreateCondation ${condation}
+ ${sourceList} json.Dumps ${sourceList}
+ ${destinationList} json.Dumps ${destinationList}
+ ${filterList} json.Dumps ${filterList}
+ #${policyJson} = Run Keyword If "${sourceList}" != "${EMPTY}" Replace String ${policyJson} "source": null "sourceList":${sourceList}
+ #... ELSE Set Variable ${policyJson}
+ #${policyJson} = Run Keyword If "${destinationList}" != "${EMPTY}" Replace String ${policyJson} "destination": null "destinationList":${sourceList}
+ #... ELSE Set Variable ${policyJson}
+ #${policyJson} = Run Keyword If "${filterList}" != "${EMPTY}" Replace String ${policyJson} "filterList": null "filterList":${filterList}
+ #... ELSE Set Variable ${policyJson}
+ ${policyJson} Replace String ${policyJson} "source": null "source":${sourceList}
+ ${policyJson} Replace String ${policyJson} "destination": null "destination":${destinationList}
+ ${policyJson} Replace String ${policyJson} "filterList": null "filterList":${filterList}
+
+ #${policyInfo} Get From Dictionary ${policyData} condation
+ Comment 处理策略数据: "opAction": "add" "returnData": 1 "policyName": "autotest" "policyType": "tsg_security" "action": "allow" "userTags": "" "doBlacklist": 0 "doLog": 1 "policyDesc": "autotest" "effectiveRange": "userRegion": "appIdObjects": "appSelectorObjects": "isValid": 1 "scheduleId":
+ #转json替换
+ #${policyJson} json.Dumps ${ipMode}
+ #JSON处理
+ ${return} ${opAction} Run Keyword And Ignore Error Get From Dictionary ${policyData} opAction
+ #${opAction} Run Keyword If "${return}"!="FAIL" Set Variable ${opAction} ELSE Set Variable ${EMPTY}
+ ${policyJson} = Run Keyword If "${return}"!="FAIL" and "${opAction}" != "${EMPTY}" Replace String ${policyJson} "opAction": "add" "opAction": "${opAction}"
+ ... ELSE Set Variable ${policyJson}
+
+ ${return} ${returnData} Run Keyword And Ignore Error Get From Dictionary ${policyData} returnData
+ #${returnData} Run Keyword If "${return}"!="FAIL" Set Variable ${returnData} ELSE Set Variable ${EMPTY}
+ ${policyJson} = Run Keyword If "${return}"!="FAIL" and "${returnData}" != "${EMPTY}" Replace String ${policyJson} "returnData": 1 "returnData": "${returnData}"
+ ... ELSE Set Variable ${policyJson}
+
+ ${return} ${policyName} Run Keyword And Ignore Error Get From Dictionary ${policyData} policyName
+ #${policyName} Run Keyword If "${return}"!="FAIL" Set Variable ${policyName} ELSE Set Variable ${EMPTY}
+ ${policyJson} = Run Keyword If "${return}"!="FAIL" and "${policyName}" != "None" Replace String ${policyJson} "policyName": "autotest" "policyName": "${policyName}"
+ ... ELSE Replace String ${policyJson} "policyName": "autotest" "policyName": "${testName}"
+
+ ${return} ${policyType} Run Keyword And Ignore Error Get From Dictionary ${policyData} policyType
+ #${policyType} Run Keyword If "${return}"!="FAIL" Set Variable ${policyType} ELSE Set Variable ${EMPTY}
+ ${policyJson} = Run Keyword If "${return}"!="FAIL" and "${policyType}" != "None" Replace String ${policyJson} "policyType": "tsg_security" "policyType": "${policyType}"
+ ... ELSE Set Variable ${policyJson}
+
+ ${return} ${action} Run Keyword And Ignore Error Get From Dictionary ${policyData} action
+ #${action} Run Keyword If "${return}"!="FAIL" Set Variable ${action} ELSE Set Variable ${EMPTY}
+ ${policyJson} = Run Keyword If "${return}"!="FAIL" and "${action}" != "None" Replace String ${policyJson} "action": "allow" "action": "${action}"
+ ... ELSE Set Variable ${policyJson}}
+
+ ${return} ${method} Run Keyword And Ignore Error Get From Dictionary ${policyData} method
+ #${method} Run Keyword If "${return}"!="FAIL" Set Variable ${method} ELSE Set Variable ${EMPTY}
+
+ ${return} ${userTags} Run Keyword And Ignore Error Get From Dictionary ${policyData} userTags
+ #${userTags} Run Keyword If "${return}"!="FAIL" Set Variable ${userTags} ELSE Set Variable ${EMPTY}
+ ${policyJson} = Run Keyword If "${return}"!="FAIL" and "${userTags}" != "None" Replace String ${policyJson} "userTags": null "userTags": ${userTags}
+ ... ELSE Set Variable ${policyJson}
+
+ ${return} ${doBlacklist} Run Keyword And Ignore Error Get From Dictionary ${policyData} doBlacklist
+ #${doBlacklist} Run Keyword If "${return}"!="FAIL" Set Variable ${doBlacklist} ELSE Set Variable ${EMPTY}
+ ${policyJson} = Run Keyword If "${return}"!="FAIL" and "${doBlacklist}" != "None" Replace String ${policyJson} "doBlacklist": 0 "doBlacklist": ${doBlacklist}
+ ... ELSE Set Variable ${policyJson}
+
+ ${return} ${doLog} Run Keyword And Ignore Error Get From Dictionary ${policyData} doLog
+ #${doLog} Run Keyword If "${return}"!="FAIL" Set Variable ${doLog} ELSE Set Variable ${EMPTY}
+ ${policyJson} = Run Keyword If "${return}"!="FAIL" and "${doLog}" != "None" Replace String ${policyJson} "doLog": 1 "doLog": ${doLog}
+ ... ELSE Set Variable ${policyJson}
+
+ ${return} ${policyDesc} Run Keyword And Ignore Error Get From Dictionary ${policyData} policyDesc
+ #${policyDesc} Run Keyword If "${return}"!="FAIL" Set Variable ${policyDesc} ELSE Set Variable ${EMPTY}
+ ${policyJson} = Run Keyword If "${return}"!="FAIL" and "${policyDesc}" != "None" Replace String ${policyJson} "policyDesc": "autotest" "policyDesc": "${policyDesc}"
+ ... ELSE Set Variable ${policyJson}
+
+ ${return} ${effectiveRange} Run Keyword And Ignore Error Get From Dictionary ${policyData} effectiveRange
+ #${effectiveRange} Run Keyword If "${return}"!="FAIL" Set Variable ${effectiveRange} ELSE Set Variable ${EMPTY}
+ ${policyJson} = Run Keyword If "${return}"!="FAIL" and "${effectiveRange}" != "None" Replace String ${policyJson} "effectiveRange": null "effectiveRange": ${effectiveRange}
+ ... ELSE Replace String ${policyJson} "effectiveRange": null "effectiveRange": {}
+
+ ${return} ${userRegion} Run Keyword And Ignore Error Get From Dictionary ${policyData} userRegion
+ #${userRegion} Run Keyword If "${return}"!="FAIL" Set Variable ${userRegion} ELSE Set Variable ${EMPTY}
+ #${policyJson} = Run Keyword If "${return}"!="FAIL" and "${userRegion}" != "None" Replace String ${policyJson} "userRegion": null "userRegion": ${userRegion}
+ #... ELSE Replace String ${policyJson} "userRegion": null "userRegion": {}
+ ${return} ${code} Run Keyword And Ignore Error Get From Dictionary ${policyData} code
+ ${return} ${message} Run Keyword And Ignore Error Get From Dictionary ${policyData} message
+ ${return} ${html_profile} Run Keyword And Ignore Error Get From Dictionary ${policyData} html_profile
+ ${message} = Run Keyword If "${return}"!="FAIL" and "${html_profile}" != "None" Set Variable ${html_profile}
+ ... ELSE Set Variable ${message}
+ ${messageKey} = Run Keyword If "${return}"!="FAIL" and "${html_profile}" != "None" Set Variable html_profile
+ ... ELSE Set Variable message
+ ${return} ${keyring} Run Keyword And Ignore Error Get From Dictionary ${policyData} keyring
+ ${keyring} = Run Keyword If "${return}"!="FAIL" and "${keyring}" != "None" Set Variable ${keyring}
+ ... ELSE Set Variable ""
+ ${return} ${decryption} Run Keyword And Ignore Error Get From Dictionary ${policyData} decryption
+ ${decryption} = Run Keyword If "${return}"!="FAIL" and "${decryption}" != "None" Set Variable ${decryption}
+ ... ELSE Set Variable ""
+ ${return} ${decrypt_mirror} Run Keyword And Ignore Error Get From Dictionary ${policyData} decrypt_mirror
+ ${decrypt_mirror} = Run Keyword If "${return}"!="FAIL" and "${decrypt_mirror}" != "None" Set Variable ${decrypt_mirror}
+ ... ELSE Set Variable ""
+ ${decrypt_mirror} json.Dumps ${decrypt_mirror}
+ ${return} ${appIdObjects} Run Keyword And Ignore Error Get From Dictionary ${policyData} appIdObjects
+ #${appIdObjects} Run Keyword If "${return}"!="FAIL" Set Variable ${appIdObjects} ELSE Set Variable ${EMPTY}
+ ${appIdObjectIds} Create List
+ Comment userRegionStr由:动作,协议,动作参数等决定,待完成;userregion在allow,monitor动作时多个协议为空;deny,多个协议时为子动作;Intercept,多个协议为空;http为,ssl为,判断appid对象的个数。
+ ${userRegionStr} Set Variable
+ FOR ${key} IN @{appIdObjects}
+ ${appObjId} Get From Dictionary ${objprotol} ${key}
+ Append To List ${appIdObjectIds} ${appObjId}
+
+ ${userRegionStr} Run Keyword If "${method}" == "block" or "${method}" == "alert" Set Variable {"protocol":"${key}","method": "${method}","code":${code},"${messageKey}":${message}}
+ ... ELSE IF "${action}" == "deny" Set Variable {"protocol":"${key}","method": "${method}"}
+ ... ELSE IF "${action}" == "intercept" and "${key}" == "ssl" Set Variable {"protocol":"SSL","keyring": ${keyring},"decryption":${decryption},"decrypt_mirror":${decrypt_mirror}}
+ ... ELSE Set Variable {"protocol":"HTTP"}
+ END
+ # Run Keyword If "${return}"!="FAIL" and "${appIdObjects}" != "${EMPTY}" Remove From List ${appIdObjectIds} 0
+ ${policyJson} = Run Keyword If "${return}"!="FAIL" and "${appIdObjects}" != "None" Replace String ${policyJson} "appIdObjects": [null] "appIdObjects": ${appIdObjectIds}
+ ... ELSE Set Variable ${policyJson}
+
+ ${policyJson} = Replace String ${policyJson} "userRegion": null "userRegion": ${userRegionStr}
+ ${policyJson} = Replace String ${policyJson} "userRegion": null "userRegion": {}
+
+ ${return} ${appSelectorObjects} Run Keyword And Ignore Error Get From Dictionary ${policyData} appSelectorObjects
+ ${appSelectorObjects} Run Keyword If "${return}"!="FAIL" Set Variable ${appSelectorObjects} ELSE Set Variable ${EMPTY}
+ ${policyJson} = Run Keyword If "${return}"!="FAIL" and "${appSelectorObjects}" != "None" Replace String ${policyJson} "appSelectorObjects": "add" "appSelectorObjects": ${appSelectorObjects}
+ ... ELSE Set Variable ${policyJson}
+
+ ${return} ${isValid} Run Keyword And Ignore Error Get From Dictionary ${policyData} isValid
+ ${appSelectorObjects} Run Keyword If "${return}"!="FAIL" Set Variable ${isValid} ELSE Set Variable ${EMPTY}
+ ${policyJson} = Run Keyword If "${return}"!="FAIL" and "${isValid}" != "None" Replace String ${policyJson} "isValid": 1 "isValid": ${isValid}
+ ... ELSE Set Variable ${policyJson}
+
+ ${return} ${scheduleId} Run Keyword And Ignore Error Get From Dictionary ${policyData} scheduleId
+ ${scheduleId} Run Keyword If "${return}"!="FAIL" Set Variable ${scheduleId} ELSE Set Variable ${EMPTY}
+ ${policyJson} = Run Keyword If "${return}"!="FAIL" and "${scheduleId}" != "None" Replace String ${policyJson} "scheduleId": [null] "scheduleId": ${scheduleId}
+ ... ELSE Set Variable ${policyJson}
+
+ ${policyJson} = Replace String ${policyJson} [null] []
+ ${policyJson} json.loads ${policyJson}
+ ${policyIds} CreatePolilcy ${policyJson}
+ [Return] ${objectIds} ${policyIds}
+CreatePolilcy
+ [Documentation]
+ ... 场景策略:secuiryt、proxy策略
+ ... 数据分离,测试数据来自对应的yaml文件
+ ... 入参 ${policyList},创建参数的dictionary
+ ... 返回参数;${policyIds} 策略id:格式:[{'policyType': 'tsg_security', 'policyIds': [52291]}]
+ [Arguments] ${policyList}
+ Comment 参数 ${filepath}读取文件路径 ${filename}读取文件名 ${keywords}获取数据关键字
+ Comment 创建策略
+
+ ${returnData} Get From Dictionary ${policyList} returnData
+ ${bodyJson} json.Dumps ${policyList}
+ #${bodyJson} = Replace String ${bodyJson} [null] []
+ ${response} BasePostRequestForV2 ${policyUrl} ${bodyJson} ${version2}
+ ${policyIds} Run Keyword If "${returnData}" == "1" GetPolicyIds ${response}
+ ... ELSE Create List
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ #${policyIds} json.loads ${json}
+ ${policyIds} Run Keyword IF "${createPolicyIds}" != "${EMPTY}" AppendListToList ${policyIds} ${createPolicyIds}
+ ... ELSE Set Variable ${policyIds}
+ SET GLOBAL VARIABLE ${createPolicyIds} ${policyIds}
+ [Return] ${policyIds}
+CreateCondation
+ [Documentation] 解析策略条件,根据key:protocolField值判断其在source、destation、filter中
+ ... 入参${objectListData}所有的condation:"condation": 格式参照如下
+ ... "condation":
+ ... -
+ ... "protocolField": "TSG_SECURITY_SOURCE_ADDR"
+ ... "objectType": "ip"
+ ... "objectSubType": "endpoint"
+ ... "objList":
+ ... - "addItemList":
+ ... -
+ ... "ip": "255.255.255.255"
+ ... "port": "0-65535"
+ ... -
+ ... "ip": "255.255.255.255"
+ ... "port": "1-65535"
+ ... - "addItemList":
+ ... -
+ ... "ip": "255.255.255.1-255.255.255.255"
+ ... "port": "0-65535"
+ ... -
+ ... "ip": "255.255.255.2/24"
+ ... "port": "1-65535"
+ ... 返回参数:${objectIdsList} 格式:[107582, 107583]
+ ... ${sourceList} ${destinationList} ${filterList} 策略中的对象id,源、目的、filterlist条件 ,格式参照:[{'objectId': 107582, 'protocolField': 'TSG_SECURITY_SOURCE_ADDR'},{'objectId': 107582, 'protocolField': 'TSG_SECURITY_SOURCE_ADDR'}]
+ [Arguments] ${objectListData}
+ Comment 循环读取对象list
+ ${sourceList} create List
+ ${destinationList} create List
+ ${filterList} create List
+ ${objectIdsList} create List
+ #S${objectListDataType} = Evaluate type(${objectListData})
+ FOR ${key} IN @{objectListData}
+ ${protocolField} Get From Dictionary ${key} protocolField
+ ${objectIds} ${objectList} CreateObjectList ${key}
+ ${len}= Get Length ${objectIdsList}
+ ${objectIdsList} Run Keyword If ${len} != 0 AppendListToList ${objectIdsList} ${objectIds} ELSE Set Variable ${objectIds}
+ Run Keyword If "${protocolField}" == "TSG_SECURITY_SOURCE_ADDR" or "${protocolField}" == "None" or "${protocolField}" == "TSG_SECURITY_SOURCE_LOCATION" or "${protocolField}" == "TSG_SECURITY_SOURCE_ASN" or "${protocolField}" == "TSG_FILED_GTP_IMSI" or "${protocolField}" == "TSG_FILED_GTP_PHONE_NUMBER" or "${protocolField}" == "TSG_FILED_GTP_APN" Append To List ${sourceList} ${objectList}
+ ##############destination
+ ... ELSE IF "${protocolField}" == "TSG_SECURITY_DESTINATION_ADDR" or "${protocolField}" == "TSG_SECURITY_DESTINATION_LOCATION" or "${protocolField}" == "TSG_SECURITY_DESTINATION_ASN" Append To List ${destinationList} ${objectList}
+ #filter
+ ... ELSE Append To List ${filterList} ${objectList}
+ #... ELSE orangeFilter ${filterList} ${objectList}
+ #Run Keyword If "${protocolField}" == "TSG_SECURITY_SOURCE_ADDR" or "${protocolField}" == "subid" or "${protocolField}" == "TSG_SECURITY_SOURCE_IPLearnning" or "${protocolField}" == "TSG_SECURITY_SOURCE_LOCATION" or "${protocolField}" == "TSG_SECURITY_SOURCE_ASN" or "${protocolField}" == "TSG_FILED_GTP_IMSI" or "${protocolField}" == "TSG_FILED_GTP_PHONE_NUMBER" or "${protocolField}" == "TSG_FILED_GTP_APN" AppendListToList ${sourceList} ${objectList}
+ ##############destination
+ #... ELSE IF "${protocolField}" == "TSG_SECURITY_DESTINATION_ADDR" or "${protocolField}" == "TSG_SECURITY_DESTINATION_IPLearnning" or "${protocolField}" == "TSG_SECURITY_DESTINATION_LOCATION" or "${protocolField}" == "TSG_SECURITY_DESTINATION_ASN" AppendListToList ${destinationList} ${objectList}
+ #filter
+ #... ELSE AppendListToList ${filterList} ${objectList}
+ END
+ [Return] ${objectIdsList} ${sourceList} ${destinationList} ${filterList}
+
+
+
+CreatePolilcys
+ [Documentation]
+ ... 场景策略:secuiryt、proxy策略
+ ... 数据分离,测试数据来自对应的yaml文件
+ ... 参数 ${filepath}读取文件路径 ${filename}读取文件名 ${keywords}获取数据关键字
+ [Arguments] ${filepath} ${filename} ${keywords}
+ Comment 参数 ${filepath}读取文件路径 ${filename}读取文件名 ${keywords}获取数据关键字
+ Comment 创建策略
+ ${YAML}= Get File ${filepath}${/}${filename}
+ ${LOADED}= yaml.Safe Load ${YAML}
+ ${policyList} Get From Dictionary ${LOADED} ${keywords}
+ ${policyListType} = Evaluate type(${policyList})
+ #${retkeys} evaluate [one for one in ${ipList}]
+ #${dictType} = Evaluate type(${retkeys})
+ ${policyIds} Run Keyword If "${policyListType}" == "<class 'list'>" PolicyBatch ${policyList}
+ ... ELSE Set Variable ${EMPTY}
+ ${policyListType} = Evaluate type(${policyIds})
+ ${json} json.Dumps ${policyIds} ensure_ascii=False
+ ${json} = Replace String ${json} ["", [
+ ${policyIds} json.loads ${json}
+ [Return] ${policyIds}
+
+PolicyBatch
+ [Tags]
+ [Arguments] ${policyDictList}
+ Comment 参数${policyDictList}多个策略列表
+ Comment 循环批量创建策略
+ ${pIds} Create List ${EMPTY}
+ FOR ${policyDict} IN @{policyDictList}
+ ${rescode} ${ids} PolicyRequest ${policyDict}
+ AppendListToList ${pIds} ${ids}
+ END
+ [Return] ${pIds}
+
+PolicyRequest
+ [Tags]
+ [Arguments] ${policyList}
+ Comment 参数${policyList}策略dict
+ Comment 创建策略
+ ${returnData} Get From Dictionary ${policyList} returnData
+ ${bodyJson} json.Dumps ${policyList}
+ ${response} BasePostRequestForV2 ${policyUrl} ${bodyJson} ${version2}
+ ${policyIds} Run Keyword If "${returnData}" == "1" GetPolicyIds ${response}
+ ... ELSE Create List
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ #S${dictType} = Evaluate type(${objectIds})
+ #log %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%${dictType}
+ [Return] ${rescode} ${policyIds}
+
+GetVerifyState
+ [Documentation]
+ ... 传入VerifyPolicies返回的resData值
+ ... 以及已知的被命中的策略id
+ [Arguments] ${resData} ${policyId}
+ ${len} Get Length ${resData['hitPolicyList']}
+ ${policyState} Create Dictionary
+ FOR ${n} IN RANGE ${len}
+ Set To Dictionary ${policyState} '${resData['hitPolicyList'][${n}]['policyId']}'=${resData['hitPolicyList'][${n}]['isExecutePolicy']}
+ END
+ log ${policyState}
+ ${State} Get From Dictionary ${policyState} '${policyId}'
+ Should Be Equal As Strings ${State} True
+
+ \ No newline at end of file
diff --git a/keyword/policys/process_policy_body.robot b/keyword/policys/process_policy_body.robot
new file mode 100644
index 0000000..55d446e
--- /dev/null
+++ b/keyword/policys/process_policy_body.robot
@@ -0,0 +1,585 @@
+*** Settings ***
+Library json
+Library Collections
+Resource ../../variable/common_variable.txt
+Resource ../../variable/policy_object_default.txt
+Resource manage_policy_body.robot
+Resource ../common/file_operation.robot
+
+*** Variables ***
+#arraySplitor:数组元素之间的分隔符
+${arraySplitor} ,
+#protocolFiledSplitor:protocolFiled之间的分隔符
+${protocolFiledSplitor} &
+#objectIdSplitor:objectId之间的分隔符
+${objectIdSplitor} :
+#idFiledSplitor: objectId和protocolFiled之间的分隔符
+${idFiledSplitor} |
+
+*** Keywords ***
+PolicyListDataOperation
+ [Arguments] ${returnData} ${policyList} ${opAction} ${policyObjectVersion}
+ [Documentation] 描述:入口,opAction参数可为'add','update','disable','enable'
+ ... 参数:returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。
+ ... policyList: 必传,字典类型。字典内可选参数信息:
+ ... policyObjectVersion: 必传,v1,v2,涉及策略版本
+ ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt
+ ... 多个策略处理
+ # ... 特殊参数说明:
+ # ... effectiveRange=Nursurtan|Transtelecom&Astel,Almaty&Nursurtan,|Astel&Transtelecom
+ # ... 为字符串类型,每条生效区域信息以','分隔
+ # ... ①以'|'字符开头表示仅为isp信息,如:effectiveRange=|Astel&Transtelecom
+ # ... ②非'|'字符开头表示仅为location信息或location和isp信息,如:
+ # ... effectiveRange=Nursurtan(仅为location信息)
+ # ... effectiveRange=Nursurtan|Transtelecom&Astel(location和isp信息)
+ # ... userRegion=protocol:HTTP,keyring:${1}
+ # ... 为字符串类型,每条动作参数以','分隔
+ # ... [key]:[value],...
+ # ... 在v1版本中referenceObject=${265}|TSG_FIELD_HTTP_HOST,${266}|TSG_FIELD_SSL_SNI&TSG_FIELD_SSL_SAN
+ # ... 为字符串类型,每条引用的策略对象信息以','分隔
+ # ... [objectId]|[protocolFileds],... ,多个protocolFileds用'&'连接
+ # ... scheduleId=${3},${1}
+ # ... 为字符串类型,以','分隔
+ # ... 在v1版本接口中appObjectIdArray==${2},${3}
+ # ... 在v2版本接口中appIdObjects==${2},${3}
+ # ... 为字符串类型,以','分隔
+ # ...
+ # ... 注:数字类型变量为${0}、${1}、${...}
+ # ... 在v2版本中 无referenceObject,取而代之的是source,destination,filterList
+ # ... source= ${265}|TSG_FIELD_HTTP_HOST,${266}|TSG_FIELD_SSL_SNI
+ # ... destination= ${265}|TSG_FIELD_HTTP_HOST,${266}|TSG_FIELD_SSL_SNI
+ # ... filterList= ${265}:${257}|TSG_FIELD_HTTP_HOST,${266}:${299}|TSG_FIELD_SSL_SNI
+ # ... filterList由多个数字用‘:’分隔,加上|对上对应的protocolFiled,
+ # ... 一个filter中的protocolFiled是确定的,一个protocolFiled对应多个objectId
+ Log To Console Call PolicyListDataOperation
+ ${policyListJson} Set Variable [
+ FOR ${policy} IN @{policyList}
+ ${json} PolicyOrganize ${policy} ${opAction} ${policyObjectVersion}
+ ${policyListJson} Set Variable ${policyListJson}${json},
+ END
+ ${policyListJson}= Replace String Using Regexp ${policyListJson} ,$ ]
+ # 转为json结构并返回
+ ${dict} Create Dictionary opAction=${opAction} returnData=${returnData} policyList=replace:policyList
+ ${bodyJson} json.Dumps ${dict} ensure_ascii=False
+ ${json} Replace String ${bodyJson} "replace:policyList" ${policyListJson}
+ Log Policy_Request_Body-${json}
+ [Return] ${json}
+
+PolicyDataOperation
+ [Arguments] ${returnData} ${policy} ${opAction} ${policyObjectVersion}
+ [Documentation] 描述:入口,opAction参数可为'add','update','disable','enable'
+ ... 参数:returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。
+ ... policy: 必传,字典类型。字典内可选参数信息:
+ ... policyObjectVersion: 必传,v1,v2,涉及策略版本
+ ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt
+ ... 单个策略处理
+ Log To Console Call PolicyDataOperation
+ ${json} PolicyOrganize ${policy} ${opAction} ${policyObjectVersion}
+ # 转为json结构并返回
+ ${dict} Create Dictionary opAction=${opAction} returnData=${returnData} policyList=replace:policyList
+ ${bodyJson} json.Dumps ${dict} ensure_ascii=False
+ ${json} Replace String ${bodyJson} "replace:policyList" ${json}
+ Log Policy_Request_Body-${json}
+ [Return] ${json}
+
+PolicyOrganize
+ [Arguments] ${policy} ${opAction} ${policyObjectVersion}
+ [Documentation] 描述:入口,opAction参数可为'add','update','disable','enable'
+ ... policy: 必传,字典类型。字典内可选参数信息:
+ ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt
+ ... policyObjectVersion: 必传,v1,v2,涉及策略版本
+ ... 单个策略转换为json
+ Log To Console Call PolicyOrganize
+ ${returnDict} Create Dictionary
+ ${emptyList} Create List
+ #v1版本接口与v2版本接口不同的字段
+ Run Keyword If "${policyObjectVersion}"=="v1" Dictionary Should Not Contain Key ${policy} source
+ Run Keyword If "${policyObjectVersion}"=="v1" Dictionary Should Not Contain Key ${policy} destination
+ Run Keyword If "${policyObjectVersion}"=="v1" Dictionary Should Not Contain Key ${policy} filterList
+ Run Keyword If "${policyObjectVersion}"=="v1" Dictionary Should Not Contain Key ${policy} appIdObjects
+ Run Keyword If "${policyObjectVersion}"=="v2" Dictionary Should Not Contain Key ${policy} referenceObject
+ #Run Keyword If "${policyObjectVersion}"=="v2" Dictionary Should Not Contain Key ${policy} appObjectIdArray
+ #更新时 policyId不允许为空
+ ${return} ${policyId} Run Keyword And Ignore Error Get From Dictionary ${policy} policyId
+ Run Keyword If "${opAction}"=="update" and "${return}"=="FAIL" Fail policyId is required when opAction is update
+ Run Keyword If "${opAction}"=="update" and "${policyId}"=="${EMPTY}" Fail policyId is required when opAction is update
+ Run Keyword If "${opAction}"=="disable" and "${return}"=="FAIL" Fail policyId is required when opAction is disable
+ Run Keyword If "${opAction}"=="disable" and "${policyId}"=="${EMPTY}" Fail policyId is required when opAction is disable
+ Run Keyword If "${opAction}"=="enable" and "${return}"=="FAIL" Fail policyId is required when opAction is enable
+ Run Keyword If "${opAction}"=="enable" and "${policyId}"=="${EMPTY}" Fail policyId is required when opAction is enable
+ ${policyId} Run Keyword If "${opAction}"=="add" Set Variable ${EMPTY}
+ ... ELSE Get From Dictionary ${policy} policyId
+ Set To Dictionary ${returnDict} policyId=${policyId}
+ ${return} ${policyType} Run Keyword And Ignore Error Get From Dictionary ${policy} policyType
+ Run Keyword If "${return}"=="FAIL" or "${policyType}"=="${EMPTY}" Set To Dictionary ${returnDict} policyType=${Default_PolicyType}
+ ... ELSE Set To Dictionary ${returnDict} policyType=${policyType}
+ #enable disable直接返回json
+ Run Keyword And Return If "${opAction}"=="enable" or "${opAction}"=="disable" ManagePolicyEnableAndDisable ${returnDict} ${opAction}
+ # 取可选参数,为传入设置默认值
+ ${return} ${policyName} Run Keyword And Ignore Error Get From Dictionary ${policy} policyName
+ Run Keyword If "${return}"=="FAIL" or "${policyName}"=="${EMPTY}" Set To Dictionary ${returnDict} policyName=${Default_PolicyName}
+ ... ELSE Set To Dictionary ${returnDict} policyName=${policyName}
+ #policyDesc 不是必填的选项
+ ${return} ${policyDesc} Run Keyword And Ignore Error Get From Dictionary ${policy} policyDesc
+ Run Keyword If "${return}"=="FAIL" or "${policyDesc}"=="${EMPTY}" Set To Dictionary ${returnDict} policyDesc=${Default_PolicyDesc}
+ ... ELSE Set To Dictionary ${returnDict} policyDesc=${policyDesc}
+ ${return} ${action} Run Keyword And Ignore Error Get From Dictionary ${policy} action
+ Run Keyword If "${return}"=="FAIL" or "${action}"=="${EMPTY}" Set To Dictionary ${returnDict} action=${Default_Action}
+ ... ELSE Set To Dictionary ${returnDict} action=${action}
+ #userTags 不是必填的选项
+ ${return} ${userTags} Run Keyword And Ignore Error Get From Dictionary ${policy} userTags
+ Run Keyword If "${return}"=="FAIL" or "${userTags}"=="${EMPTY}" Set To Dictionary ${returnDict} userTags=${Default_UserTags}
+ ... ELSE Set To Dictionary ${returnDict} userTags=${userTags}
+ ${return} ${doLog} Run Keyword And Ignore Error Get From Dictionary ${policy} doLog
+ Run Keyword If "${return}"=="FAIL" or "${doLog}"=="${EMPTY}" Set To Dictionary ${returnDict} doLog=${Default_DoLog}
+ ... ELSE Set To Dictionary ${returnDict} doLog=${doLog}
+ ${return} ${isValid} Run Keyword And Ignore Error Get From Dictionary ${policy} isValid
+ Run Keyword If "${return}"=="FAIL" or "${isValid}"=="${EMPTY}" Set To Dictionary ${returnDict} isValid=${Default_IsValid}
+ ... ELSE Set To Dictionary ${returnDict} isValid=${isValid}
+ ${return} ${scheduleId} Run Keyword And Ignore Error Get From Dictionary ${policy} scheduleId
+ ${scheduleIdV} Run Keyword If "${return}"!="FAIL" and "${scheduleId}"!="${EMPTY}" and "${scheduleId}"!="${None}" Evaluate list(map(int, re.split('[,]', '${scheduleId}'))) re
+ ... ELSE Set Variable ${emptyList}
+ Set To Dictionary ${returnDict} scheduleId=${scheduleIdV}
+ ${return} ${appObjectIdArray} Run Keyword If "${policyObjectVersion}"=="v1" Run Keyword And Ignore Error Get From Dictionary ${policy} appObjectIdArray
+ ... ELSE Run Keyword And Ignore Error Get From Dictionary ${policy} appIdObjects
+ #${appObjectIdArrayV} Run Keyword If "${return}"=="FAIL" or "${appObjectIdArray}"=="${EMPTY}" Evaluate list(map(int, re.split('[,]', '${Default_AppObjectIdArray}'))) re
+ ${appObjectIdArrayV} Run Keyword If "${return}"=="FAIL" or "${appObjectIdArray}"=="${EMPTY}" Evaluate ${Default_AppObjectIdArray} re
+ ... ELSE Evaluate list(map(int, re.split('[,]', '${appObjectIdArray}'))) re
+ Run Keyword If "${policyObjectVersion}"=="v1" Set To Dictionary ${returnDict} appObjectIdArray=${appObjectIdArrayV}
+ ... ELSE IF "${policyObjectVersion}"=="v2" Set To Dictionary ${returnDict} appIdObjects=${appObjectIdArrayV}
+ # 固定值
+ Set To Dictionary ${returnDict} doBlacklist=${0}
+ # 分别处理EffectiveRange、UserRegion和ReferenceObject参数
+ ProcessEffectiveRange ${policy} ${returnDict}
+ #WxManageUserRegion ${policy}
+ Run Keyword If "${policyObjectVersion}"=="v1" ProcessReferenceObject ${policy} ${returnDict}
+ ... ELSE IF "${policyObjectVersion}"=="v2" ManageObjectV2 ${policy} ${returnDict}
+ #先取出useragion 再放回json
+ ${return} ${userRegion} Run Keyword And Ignore Error Get From Dictionary ${policy} userRegion
+ Set To Dictionary ${returnDict} userRegion=${Default_UserRegion}
+ ${userRegion} Run Keyword If "${return}"=="FAIL" or '${userRegion}'=="${EMPTY}" Set Variable ""
+ ... ELSE Set Variable ${userRegion}
+ #针对主动防御特殊处理,主动防御不应用对象
+ ${active_defence_emptyList} Create List
+ ${return} ${policyType} Run Keyword And Ignore Error Get From Dictionary ${policy} policyType
+ Run Keyword If "${policyObjectVersion}"=="v1" and "${policyType}"=="active_defence" Set To Dictionary ${returnDict} referenceObject=${active_defence_emptyList}
+ Run Keyword If "${policyObjectVersion}"=="v1" and "${policyType}"=="active_defence" Set To Dictionary ${returnDict} appObjectIdArray=${active_defence_emptyList}
+ #v版本主动防御
+ Run Keyword If "${policyObjectVersion}"=="v2" and "${policyType}"=="active_defence" Set To Dictionary ${returnDict} source=${active_defence_emptyList}
+ Run Keyword If "${policyObjectVersion}"=="v2" and "${policyType}"=="active_defence" Set To Dictionary ${returnDict} destination=${active_defence_emptyList}
+ Run Keyword If "${policyObjectVersion}"=="v2" and "${policyType}"=="active_defence" Set To Dictionary ${returnDict} filterList=${active_defence_emptyList}
+ Run Keyword If "${policyObjectVersion}"=="v2" and "${policyType}"=="active_defence" Set To Dictionary ${returnDict} appIdObjects=${active_defence_emptyList}
+ #针对WAN NAT特殊处理
+ ${wannat_emptyList} Create List
+ ${return} ${policyType} Run Keyword And Ignore Error Get From Dictionary ${policy} policyType
+ Run Keyword If "${policyObjectVersion}"=="v2" and "${policyType}"=="wannat" Set To Dictionary ${returnDict} appIdObjects=${wannat_emptyList}
+ Run Keyword If "${policyObjectVersion}"=="v2" and "${policyType}"=="wannat" Set To Dictionary ${returnDict} filterList=${wannat_emptyList}
+ # 转为json结构并返回
+ ${json} json.Dumps ${returnDict} ensure_ascii=False
+ ${json} Replace String ${json} "method:rst" ${userRegion}
+ #${json} Replace String ${json} "effectiveRange:Empty" {}
+ Log Policy-${json}
+ [Return] ${json}
+
+ManagePolicyEnableAndDisable
+ [Arguments] ${returnDict} ${opAction}
+ [Documentation] 启用与禁用时调用
+ Run Keyword If "${opAction}"=="enable" Set To Dictionary ${returnDict} isValid=1
+ Run Keyword If "${opAction}"=="disable" Set To Dictionary ${returnDict} isValid=0
+ ${json} json.Dumps ${returnDict} ensure_ascii=False
+ Log Policy-${json}
+ [Return] ${json}
+
+ProcessEffectiveRange
+ [Arguments] ${policyList} ${returnDict}
+ [Documentation] 处理EffectiveRange
+ ... 加入effectiveRange={}的处理支持
+ Log To Console Call ProcessEffectiveRange
+ ${emptyList} Create List
+ ${emptyListDouble} Create List ${emptyList}
+ ${return} ${effectiveRange} Run Keyword And Ignore Error Get From Dictionary ${policyList} effectiveRange
+ ${effectiveRange} Run Keyword If "${return}"=="FAIL" or "${effectiveRange}"=="${EMPTY}" Set Variable ${Default_EffectiveRange}
+ ... ELSE Set Variable ${effectiveRange}
+ ${value} Run Keyword If "${effectiveRange}"=="${EMPTY}" Create Dictionary tag_sets=${emptyListDouble}
+ ... ELSE IF "${effectiveRange}"=="{}" Create Dictionary
+ ... ELSE AnalysisEffectiveRange ${effectiveRange}
+ Set To Dictionary ${returnDict} effectiveRange=${value}
+
+ProcessReferenceObject
+ [Arguments] ${policy} ${returnDict}
+ [Documentation] 处理引用对象字符串
+ ... v1版本接口使用
+ Log To Console Call ProcessReferenceObject
+ ${emptyList} Create List
+ #默认客户端条件类型:clientip or clientsubid
+ ${return} ${defaultClient} Run Keyword And Ignore Error Get From Dictionary ${policy} defaultClient
+ ${defaultClient} Run Keyword If "${return}"=="FAIL" or "${defaultClient}"=="${EMPTY}" Set Variable ${Default_Client_Type}
+ ... ELSE Set Variable ${defaultClient}
+ Run Keyword If '${addTestClentIPFlag}'=='1' and '${defaultClient}'=='clientip' ManageClientIPObject ${emptyList}
+ Run Keyword If '${addTestClentIPFlag}'=='1' and '${defaultClient}'=='clientsubid' ManageClientSubIDObject ${emptyList}
+ #Run Keyword If '${addTestClentIPFlag}'=='1' ManageClientObject ${emptyList}
+ # Run Keyword If "${clientHostObj}"!="${None}" Append To List ${emptyList} ${clientHostObj}
+ ${defaultObj} Create Dictionary
+ ${return} ${referenceObject} Run Keyword And Ignore Error Get From Dictionary ${policy} referenceObject
+ ${referenceObject} Run Keyword If "${return}"=="FAIL" or "${referenceObject}"=="${EMPTY}" Set Variable ${Default_ReferenceObject}
+ ... ELSE Set Variable ${referenceObject}
+ ${value} Run Keyword If "${referenceObject}"=="${EMPTY}" Create List ${defaultObj}
+ ... ELSE AnalysisReferenceObject ${referenceObject}
+ # 若参数为空,设置默认结构
+ # FOR ${var} IN @{value}
+ # Run Keyword If ${var}!={} Append To List ${referenceObject} ${var}
+ # END
+ ObjectLoop ${value} ${emptyList}
+ Set To Dictionary ${returnDict} referenceObject=${emptyList}
+
+ObjectLoop
+ [Arguments] ${value} ${valueList}
+ # 若参数为空,设置默认结构
+ FOR ${var} IN @{value}
+ Run Keyword If ${var}!={} Append To List ${valueList} ${var}
+ END
+ [Return] ${valueList}
+
+ManageObjectV2
+ [Arguments] ${policy} ${returnDict}
+ [Documentation] 处理引用对象字符串
+ ... v2版本接口使用
+ ... source,destination,filterList
+ # 处理引用对象字符串
+ Log To Console Call ManageObjectV2
+ #默认客户端条件类型:clientip or clientsubid
+ ${return} ${defaultClient} Run Keyword And Ignore Error Get From Dictionary ${policy} defaultClient
+
+ ${return1} ${defaultClient1} Run Keyword And Ignore Error Get From Dictionary ${policy} defaultClient1
+ ${return2} ${defaultClient2} Run Keyword And Ignore Error Get From Dictionary ${policy} defaultClient2
+ ${return3} ${defaultClient3} Run Keyword And Ignore Error Get From Dictionary ${policy} defaultClient3
+ ${return4} ${defaultClient4} Run Keyword And Ignore Error Get From Dictionary ${policy} defaultClient4
+
+ ${defaultClient} Run Keyword If "${return}"=="FAIL" or "${defaultClient}"=="${EMPTY}" Set Variable ${Default_Client_Type}
+ ${defaultClient1} Run Keyword If "${return1}"=="FAIL" or "${defaultClient1}"=="${EMPTY}" Set Variable ${Default_Client_subidType}
+ ${defaultClient2} Run Keyword If "${return2}"=="FAIL" or "${defaultClient2}"=="${EMPTY}" Set Variable ${Default_Client_imsiType}
+ ${defaultClient3} Run Keyword If "${return3}"=="FAIL" or "${defaultClient3}"=="${EMPTY}" Set Variable ${Default_Client_phonenumberType}
+ ${defaultClient4} Run Keyword If "${return4}"=="FAIL" or "${defaultClient4}"=="${EMPTY}" Set Variable ${Default_Client_apnType}
+ # ... ELSE Set Variable ${defaultClient}
+ ${sourceList} Create List
+ ${destinationList} Create List
+ ${filterList} Create List
+ Run Keyword If '${addTestClentIPFlag}'=='1' and '${defaultClient}'!='${EMPTY}' and '${defaultClient}'=='clientip' ManageClientIPObjectV2 ${sourceList}
+
+ Run Keyword If '${addTestClentIPFlag}'=='1' and '${defaultClient1}'!='${EMPTY}' and '${defaultClient1}'=='clientsubid' ManageClientSubIDObjectV2 ${sourceList}
+ Run Keyword If '${addTestClentIPFlag}'=='1' and '${defaultClient2}'!='${EMPTY}' and '${defaultClient2}'=='clientImsi' ManageClientImsiObjectV2 ${sourceList}
+ Run Keyword If '${addTestClentIPFlag}'=='1' and '${defaultClient3}'!='${EMPTY}' and '${defaultClient3}'=='clientPhoneNumber' ManageClientPhoneNumberObjectV2 ${sourceList}
+ Run Keyword If '${addTestClentIPFlag}'=='1' and '${defaultClient4}'!='${EMPTY}' and '${defaultClient4}'=='clientApn' ManageClientApnObjectV2 ${sourceList}
+
+ AnalysisObjectV2 ${policy} source ${sourceList}
+ AnalysisObjectV2 ${policy} destination ${destinationList}
+ AnalysisObjectV2 ${policy} filterList ${filterList}
+ Set To Dictionary ${returnDict} source=${sourceList} destination=${destinationList} filterList=${filterList}
+ Log ${policy}
+
+ManageClientIPObjectV2
+ [Arguments] ${emptyList}
+ # 增加引用测试终端IP策略对象
+ ${intid} Evaluate int(${testClentID})
+ log ${intid}
+ InsertObjectIdToFile testClentIpId ${intid}
+ ${obj1} Create Dictionary objectId=${intid} protocolField=TSG_SECURITY_SOURCE_ADDR
+ Append To List ${emptyList} ${obj1}
+
+ManageClientSubIDObjectV2
+ [Arguments] ${emptyList}
+ # 增加引用测试终端IP策略对象
+ ${protocolField} Set Variable
+ log ${testClentSubID}
+ InsertObjectIdToFile addpolicySubId ${testClentSubID}
+ ${obj1} Create Dictionary objectId=${testClentSubID} protocolField=${protocolField}
+ Append To List ${emptyList} ${obj1}
+
+ManageClientImsiObjectV2
+ [Arguments] ${emptyList}
+ # 增加引用测试终端Imsi策略对象
+ ${protocolField} Set Variable
+ InsertObjectIdToFile testImsiId ${object_imsi_id}
+ ${obj1} Create Dictionary objectId=${object_imsi_id} protocolField=TSG_FILED_GTP_IMSI
+ Append To List ${emptyList} ${obj1}
+
+ManageClientPhoneNumberObjectV2
+ [Arguments] ${emptyList}
+ # 增加引用测试终端phonenumber策略对象
+ ${protocolField} Set Variable
+ InsertObjectIdToFile testPhoneNumberId ${obj_phoneNum_Id}
+ ${obj1} Create Dictionary objectId=${obj_phoneNum_Id} protocolField=TSG_FILED_GTP_PHONE_NUMBER
+ Append To List ${emptyList} ${obj1}
+
+ManageClientApnObjectV2
+ [Arguments] ${emptyList}
+ # 增加引用测试终端apn策略对象
+ ${protocolField} Set Variable
+ InsertObjectIdToFile testApnId ${obj_apn_Id}
+ ${obj1} Create Dictionary objectId=${obj_apn_Id} protocolField=TSG_FILED_GTP_APN
+ Append To List ${emptyList} ${obj1}
+
+AnalysisObjectV2
+ [Arguments] ${policy} ${objectType} ${objList}
+ Log To Console Call AnalysisObjectV2
+ ${policyObjectDefault} Run Keyword If "${objectType}"=="source" Set Variable ${EMPTY}
+ ... ELSE IF "${objectType}"=="destination" Set Variable ${EMPTY}
+ ... ELSE IF "${objectType}"=="filterList" Set Variable ${EMPTY}
+ ${return} ${objectList} Run Keyword And Ignore Error Get From Dictionary ${policy} ${objectType}
+ # source,destination,filterList
+ ${objectList} Run Keyword If "${return}"=="FAIL" or "${objectList}"=="${EMPTY}" Set Variable ${policyObjectDefault}
+ ... ELSE Set Variable ${objectList}
+ ${list} Evaluate re.split('[${arraySplitor}]', '${objectList}') re
+ FOR ${var} IN @{list}
+ ${tempObj} Run Keyword If "${objectType}"=="filterList" and "${var}" != "" ManageFilter ${var}
+ ... ELSE IF "${var}" != "" ManageObject ${var}
+ ... ELSE Set Variable ${EMPTY}
+ Run Keyword If "${tempObj}" != "${EMPTY}" Append To List ${objList} ${tempObj}
+ END
+ Log ${objList}
+
+ManageObject
+ [Arguments] ${object}
+ [Documentation] source,destination处理
+ Log To Console Call ManageObject
+ ${objectList} Create List
+ #截取objectId
+ ${objectId} Evaluate '${object}'[0:'${object}'.find('${idFiledSplitor}')]
+ #截取protocolField
+ ${protocolField} Evaluate '${object}'['${object}'.find('${idFiledSplitor}')+1:]
+ ${tempObj} Create Dictionary
+ ${objectId} Run Keyword If '${objectId}'.isdigit() Evaluate int('${objectId}')
+ ... ELSE Set Variable ${objectId}
+ Set To Dictionary ${tempObj} objectId=${objectId}
+ Set To Dictionary ${tempObj} protocolField=${protocolField}
+ [Return] ${tempObj}
+
+ManageFilter
+ [Arguments] ${filter}
+ [Documentation] filterList处理
+ Log Call ManageFilter
+ ${filterObjectList} Create List
+ #截取objectId
+ ${objectIds} Evaluate '${filter}'[0:'${filter}'.find('${idFiledSplitor}')]
+ #截取protocolField
+ ${protocolField} Evaluate '${filter}'['${filter}'.find('${idFiledSplitor}')+1:]
+ #遍历 objectId
+ ${list} Evaluate re.split('[${objectIdSplitor}]', '${objectIds}') re
+ Log list ${list}
+ FOR ${var} IN @{list}
+ ${tempObj} Create Dictionary
+ ${var} Run Keyword If '${var}'.isdigit() Evaluate int('${var}')
+ ... ELSE Set Variable ${var}
+ Set To Dictionary ${tempObj} objectId=${var}
+ Set To Dictionary ${tempObj} protocolField=${protocolField}
+ Append To List ${filterObjectList} ${tempObj}
+ END
+ ${filterObject} Create Dictionary filter=${filterObjectList}
+ [Return] ${filterObject}
+
+GetPolicyIds
+ [Arguments] ${value}
+ [Documentation] 获取结果中的策略类型及ID
+ ... 策略接口返回json串
+ ... 返回结果格式:[{'policyType': 'tsg_security', 'policyIds': [108480]}, {'policyType': 'tsg_security', 'policyIds': [108481]}, {'policyType': 'tsg_security', 'policyIds': [108482]}, {'policyType': 'tsg_security', 'policyIds': [108483]}, {'policyType': 'tsg_security', 'policyIds': [108484]}]
+ ${policyIds} Create List
+ FOR ${policy} IN @{value['data']['policyList']}
+ ${policyIdList} Create List ${policy['policyId']}
+ ${policyObj} Create Dictionary policyType=${policy['policyType']} policyIds=${policyIdList}
+ Append To List ${policyIds} ${policyObj}
+ #Append To List ${policyIds} ${policy['policyId']}
+ END
+ log ${policyIds}
+ #${len} Get Length ${policyIds}
+ #${policyIds} Run Keyword If ${len}==1 Set Variable ${policyIds[0]}
+ #... ELSE Set Variable ${policyIds}
+ [Return] ${policyIds}
+GetPids
+ [Arguments] ${policyIds}
+ [Documentation] 获取结果中的策略ID
+ ... 入参格式:[{'policyType': 'tsg_security', 'policyIds': [108480]}, {'policyType': 'tsg_security', 'policyIds': [108481]}, {'policyType': 'tsg_security', 'policyIds': [108482]}, {'policyType': 'tsg_security', 'policyIds': [108483]}, {'policyType': 'tsg_security', 'policyIds': [108484]}]
+ ... 返回结果格式 [108480, 108481, 108482, 108483, 108484]
+ ${ids} Create List
+ ${len} Get Length ${policyIds}
+ FOR ${var} IN RANGE ${len}
+ ${policy} Evaluate ${policyIds} [${var}]
+ ${return} ${policyId} Run Keyword And Ignore Error Get From Dictionary ${policy} policyIds
+ Append To List ${ids} ${policyId}[0]
+ #Append To List ${policyIds} ${policy['policyId']} Evaluate
+ END
+ log ${ids}
+ #${len} Get Length ${policyIds}
+ #${policyIds} Run Keyword If ${len}==1 Set Variable ${policyIds[0]}
+ #... ELSE Set Variable ${policyIds}
+ [Return] ${ids}
+DeletePolicyWithParamDict
+ [Arguments] ${params}
+ [Documentation] 删除策略
+ ... params,传入的删除字典
+ ... 结构为policyIds=${policyIds} (List) policyType=${policyType} (variable)
+ ${response} BaseDeleteRequest /${version}${policyUrl} ${params}
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ [Return] ${rescode}
+
+VerifyPolicyList
+ [Arguments] ${verifyList}
+ [Documentation] 策略验证
+ ... 多个策略验证
+ Log To Console Call VerifyPolicyList
+ ${verifyListJson} Set Variable [
+ FOR ${verifyObj} IN @{verifyList}
+ ${json} VerifyPolicyObj ${verifyObj}
+ ${verifyListJson} Set Variable ${verifyListJson}${json},
+ END
+ ${verifyListJson}= Replace String Using Regexp ${verifyListJson} ,$ ]
+ Log Policy_Request_Body-${verifyListJson}
+ [Return] ${verifyListJson}
+
+VerifyPolicyObj
+ [Arguments] ${verifyObj}
+ [Documentation] 策略验证
+ ... 单个策略验证
+ Log To Console Call VerifyPolicyObj
+ ${emptyList} Create List
+ ${return} ${policyType} Run Keyword And Ignore Error Set Variable ${verifyObj['policyType']}
+ #Should Not Be Empty ${policyType}
+ ${verifySession} Get From Dictionary ${verifyObj} verifySession
+ Should Not Be Empty ${verifySession}
+ ${attributes} Get From Dictionary ${verifySession} attributes
+ Should Not Be Empty ${attributes}
+ FOR ${attribute} IN @{attributes}
+ ${attributeType} Get From Dictionary ${attribute} attributeType
+ ${return} ${tableName} Run Keyword And Ignore Error Set Variable ${attribute['tableName']}
+ ${return} ${protocol} Run Keyword And Ignore Error Set Variable ${attribute['protocol']}
+ ${attributeName} Get From Dictionary ${attribute} attributeName
+ ${attributeValue} Get From Dictionary ${attribute} attributeValue
+ #将json转换为dict
+ ${attributeValue} Convert To String ${attributeValue}
+ ${start} Get Regexp Matches ${attributeValue} ^{\"
+ ${start1} Get Regexp Matches ${attributeValue} ^{\'
+ ${len} Get Length ${start}
+ ${len1} Get Length ${start1}
+ ${attributeValue} Run Keyword If ${len}>0 Evaluate eval('${attributeValue}')
+ ... ELSE IF ${len1}>0 Evaluate eval("${attributeValue}")
+ ... ELSE Set Variable ${attributeValue}
+ ${type} Run Keyword If ${len}>0 or ${len1}>0 Set Variable dict
+ ... ELSE Set Variable str
+ ${attributeValue} Run Keyword If "${attributeType}"=="ip" ManageIpAttributeValue ${attributeValue} ${attributeName} ${type}
+ ... ELSE IF "${attributeType}"=="signature" ManageSignatureAttributeValue ${attributeValue} ${type}
+ ... ELSE ManageStringAttributeValue ${attributeValue} ${type}
+ Set To Dictionary ${attribute} attributeValue=${attributeValue}
+ END
+ Set To Dictionary ${verifyObj} verifySession=${verifySession}
+ # 转为json结构并返回
+ ${json} json.Dumps ${verifyObj} ensure_ascii=False
+ Log VerifyPolicy-${json}
+ [Return] ${json}
+
+ManageIpAttributeValue
+ [Arguments] ${attributeValue} ${attributeName} ${type}
+ Run Keyword And Return If "${type}"=="str" ExtractIpAttributeValue ${attributeValue}
+ ${dict} Create Dictionary
+ ${return} ${ip} Run Keyword And Ignore Error Set Variable ${attributeValue['ip']}
+ Run Keyword If "${ip}"=="${EMPTY}" and "${attributeName}"=="source" Should Not Be Empty ${ip}
+ Run Keyword If "${ip}"=="${EMPTY}" and "${attributeName}"=="destination" Should Not Be Empty ${ip}
+ Set To Dictionary ${dict} ip=${ip}
+ ${return} ${port} Run Keyword And Ignore Error Set Variable ${attributeValue['port']}
+ Run Keyword If "${port}"=="${EMPTY}" and "${attributeName}"=="source" Should Not Be Empty ${port}
+ Run Keyword If "${port}"=="${EMPTY}" and "${attributeName}"=="destination" Should Not Be Empty ${port}
+ Set To Dictionary ${dict} port=${port}
+ ${return} ${addrType} Run Keyword And Ignore Error Set Variable ${attributeValue['addrType']}
+ Run Keyword If "${addrType}"=="${EMPTY}" and "${attributeName}"=="source" Should Not Be Empty ${addrType}
+ Run Keyword If "${addrType}"=="${EMPTY}" and "${attributeName}"=="destination" Should Not Be Empty ${addrType}
+ Set To Dictionary ${dict} addrType=${addrType}
+ ${return} ${protocol} Run Keyword And Ignore Error Set Variable ${attributeValue['protocol']}
+ Run Keyword If "${protocol}"=="${EMPTY}" and "${attributeName}"=="source" Should Not Be Empty ${protocol}
+ Run Keyword If "${protocol}"=="${EMPTY}" and "${attributeName}"=="destination" Should Not Be Empty ${protocol}
+ Set To Dictionary ${dict} protocol=${protocol}
+ ${return} ${tableName} Run Keyword And Ignore Error Set Variable ${attributeValue['tableName']}
+ Run Keyword If "${tableName}"=="${EMPTY}" and "${attributeName}"=="source" Should Not Be Empty ${tableName}
+ Run Keyword If "${tableName}"=="${EMPTY}" and "${attributeName}"=="destination" Should Not Be Empty ${tableName}
+ Set To Dictionary ${dict} tableName=${tableName}
+ [Return] ${dict}
+
+ExtractIpAttributeValue
+ [Arguments] ${attributeValue}
+ ${list} Split String ${attributeValue} |
+ ${len} Get Length ${list}
+ Should Be Equal As Integers ${len} 5
+ ${addrType} Evaluate int(${list}[2])
+ ${protocol} Set Variable ${list}[3]
+ ${tableName} Set Variable ${list}[4]
+ ${dict} Create Dictionary ip=${list}[0] port=${list}[1] tableName=${tableName} addrType=${addrType} protocol=${protocol}
+ [Return] ${dict}
+
+ExtractIpAttributeValue_bak
+ [Arguments] ${attributeValue}
+ ${list} Split String ${attributeValue} |
+ ${len} Get Length ${list}
+ Should Be Equal As Integers ${len} 4
+ ${addrType} Evaluate int(${list}[2])
+ ${protocol} Evaluate int(${list}[3])
+ ${dict} Create Dictionary ip=${list}[0] port=${list}[1] addrType=${addrType} protocol=${protocol}
+ [Return] ${dict}
+
+ManageSignatureAttributeValue
+ [Arguments] ${attributeValue} ${type}
+ Run Keyword And Return If "${type}"=="str" ExtractSignatureAttributeValue ${attributeValue}
+ ${dict} Create Dictionary
+ ${district} Get From Dictionary ${attributeValue} district
+ Should Not Be Empty ${district}
+ Set To Dictionary ${dict} district=${district}
+ ${string} Get From Dictionary ${attributeValue} string
+ Should Not Be Empty ${string}
+ Set To Dictionary ${dict} string=${string}
+ [Return] ${dict}
+
+ExtractSignatureAttributeValue
+ [Arguments] ${attributeValue}
+ ${list} Split String ${attributeValue} |
+ ${len} Get Length ${list}
+ Should Be Equal As Integers ${len} 2
+ ${dict} Create Dictionary district=${list}[0] string=${list}[1]
+ [Return] ${dict}
+
+ManageStringAttributeValue
+ [Arguments] ${attributeValue} ${type}
+ ${dict} Create Dictionary
+ Run Keyword And Return If "${type}"=="str" Create Dictionary string=${attributeValue}
+ ${string} Get From Dictionary ${attributeValue} string
+ Should Not Be Empty ${string}
+ Set To Dictionary ${dict} string=${string}
+ [Return] ${dict}
+
+SortPolicyList
+ [Arguments] ${policyList}
+ [Documentation] 多策略排序
+ ... policyList为数组结构
+ Log Call SortPolicyList
+ ${policyListJson} Set Variable [
+ FOR ${policyObj} IN @{policyList}
+ ${json} SortPolicyObject ${policyObj}
+ ${policyListJson} Set Variable ${policyListJson}${json},
+ END
+ ${policyListJson}= Replace String Using Regexp ${policyListJson} ,$ ]
+ Log SortPolicyList-${policyListJson}
+ [Return] ${policyListJson}
+
+SortPolicyObject
+ [Arguments] ${policyObject}
+ [Documentation] 策略排序
+ ... policyObject为字典结构
+ ... policyObject policyId=${policyId} policyType=${policyType} beforePolicyId=${beforePolicyId} afterPolicyId=${afterPolicyId}
+ Dictionary Should Contain Key ${policyObject} policyId
+ Dictionary Should Contain Key ${policyObject} policyType
+ ${policyId} Get From Dictionary ${policyObject} policyId
+ Run Keyword If "${policyId}"=="${EMPTY}" Should Not Be Empty ${policyId}
+ ${policyType} Get From Dictionary ${policyObject} policyType
+ Should Not Be Empty ${policyType}
+ ${return} ${beforePolicyId} Run Keyword And Ignore Error Get From Dictionary ${policyObject} beforePolicyId
+ ${return1} ${afterPolicyId} Run Keyword And Ignore Error Get From Dictionary ${policyObject} afterPolicyId
+ Run Keyword If "${return}"=="FAIL" and "${return1}"=="FAIL" Fail beforePolicyId和 afterPolicyId必须设置一个!
+ Run Keyword If "${return}"=="PASS" and "${return1}"=="PASS" and "${beforePolicyId}"=="${EMPTY}" and "${afterPolicyId}"=="${EMPTY}" Fail beforePolicyId和 afterPolicyId不能同时为空!
+ ${json} json.Dumps ${policyObject} ensure_ascii=False
+ [Return] ${json}
diff --git a/keyword/verify/verify.robot b/keyword/verify/verify.robot
new file mode 100644
index 0000000..cab11b7
--- /dev/null
+++ b/keyword/verify/verify.robot
@@ -0,0 +1,21 @@
+*** Settings ***
+Resource ../comman/command.robot
+Resource ../../variable/common_variable.txt
+*** Variables ***
+${policyIds} ${EMPTY}
+${objectids} ${EMPTY}
+
+
+*** Keywords ***
+verify
+ [Documentation] delete :policy object category app signature profile ...
+ [Arguments] ${windowsCommand} ${linuxCommand} ${windowsStrList} ${linuxStrList}
+ [Tags] admission basic api adc
+ Comment 功能端验证HTTP验证
+ ${commandstr} run keyword if '${systemType}'=='Windows' set variable ${windowsCommand}
+ ... ELSE set variable ${linuxCommand}
+ ${stringlist} run keyword if '${systemType}'=='Windows' Create List ${windowsStrList}
+ ... ELSE Create List ${linuxStrList}
+ ${rescode} SystemCommands ${commandstr} ${stringlist}
+ [Return] ${rescode}
+ \ No newline at end of file