From 2230c98d24d8a7cdf7ca1a1f1912032002b01c74 Mon Sep 17 00:00:00 2001 From: wangxin Date: Tue, 23 Jun 2020 18:15:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:(=E7=AD=96=E7=95=A5=E9=AA=8C=E8=AF=81)1.?= =?UTF-8?q?=E7=AD=96=E7=95=A5=E9=AA=8C=E8=AF=81=E6=8F=90=E4=BA=A4;2?= =?UTF-8?q?=EF=BC=9AWx=E5=BC=80=E5=A4=B4=E7=9A=84=E5=85=B3=E9=94=AE?= =?UTF-8?q?=E5=AD=97=E4=BF=AE=E6=94=B9;=203:=E4=BF=AE=E5=A4=8D=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E7=AD=96=E7=95=A5=E4=B8=80=E8=A1=8C=E5=85=B3=E9=94=AE?= =?UTF-8?q?=E5=AD=97=E5=90=8D=E5=86=99=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../policy_object/PolicyObjectTests.robot | 80 +++++++++-- .../tsg_bfapi/policy_object/Object.robot | 10 +- .../tsg_bfapi/policy_object/Policy.robot | 73 ++++++---- .../policy_object/ProcessObjectBody.robot | 20 +-- .../policy_object/ProcessPolicyBody.robot | 135 +++++++++++++++++- 5 files changed, 263 insertions(+), 55 deletions(-) diff --git a/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot b/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot index b63fdac..9a6cf7f 100644 --- a/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot +++ b/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot @@ -336,14 +336,12 @@ Policy-Post-v1-00013 ${rescode} ${itemIds} ${itemList} GetObjectItems ${params} Log To Console ${itemIds} Comment 更新IP - ${len} Get Length ${itemList} - FOR ${index} IN ${len} - ${index1} Evaluate int(${index})-1 - Set To Dictionary ${itemList}[${index1}] clientIp1 192.168.41.67 - Set To Dictionary ${itemList}[${index1}] clientIp2 192.168.41.67 - Remove From Dictionary ${itemList}[${index1}] isInitialize - Set To Dictionary ${itemList}[${index1}] serverIp1 192.168.41.68 - Set To Dictionary ${itemList}[${index1}] serverIp2 192.168.41.68 + FOR ${item} IN @{itemList} + Set To Dictionary ${item} clientIp1 192.168.41.67 + Set To Dictionary ${item} clientIp2 192.168.41.67 + Remove From Dictionary ${item} isInitialize + Set To Dictionary ${item} serverIp1 192.168.41.68 + Set To Dictionary ${item} serverIp2 192.168.41.68 END ${objectDict} Create Dictionary objectId=${objectId1} objectType=ip ... updateItemList=${itemList} @@ -395,7 +393,7 @@ Policy-Delete-v1-00016 ${rescode} ${policyIds} AddPolicies 1 ${policy} v2 Log ${rescode} Comment 删除安全策略 - ${rescode} WxDeletePolicy1 ${policyIds[0]['policyIds']} tsg_security + ${rescode} DeletePolicy1 ${policyIds[0]['policyIds']} tsg_security ${policyIds} Create List Log ${rescode} Policy-Delete-v1-00017 @@ -434,4 +432,66 @@ Policy-Export-v1-00019 Comment 导 出json ${objectIds} Set Variable ${EMPTY} ${response} ExportPolicy tsg_security ${EMPTY} ${EMPTY} - WriteFile downloads download.json ${response} \ No newline at end of file + WriteFile downloads download.json ${response} +Policy-Verify-v1-00020 + ${objectIds} Set Variable ${EMPTY} + Comment 创建对象 + ${ipValue} Create Dictionary clientIp=192.168.41.67 clientPort=${1} serverIp=192.168.41.67 serverPort=${1} + ... addrType=${4} protocol=${6} + ${ipObj} Create Dictionary attributeType=ip tableName=TSG_OBJ_IP_ADDR protocol=HTTP attributeName=ip + ... attributeValue=${ipValue} + ${stringValue} Create Dictionary string=*baidu.com + ${stringObj} Create Dictionary attributeType=string tableName=TSG_OBJ_URL protocol=HTTP attributeName=url + ... attributeValue=${stringValue} + ${appIdValue} Create Dictionary string=http. + ${appIdObj} Create Dictionary attributeType=string protocol=HTTP attributeName=app_id + ... attributeValue=${appIdValue} + ${attributes} Create List ${ipObj} ${stringObj} ${appIdObj} + ${verifySession} Create Dictionary attributes=${attributes} + ${verifyList} Create Dictionary policyType=tsg_security verifySession=${verifySession} + ${rescode} ${resData} VerifyPolicies ${verifyList} +Policy-Verify-v1-00021 + ${objectIds} Set Variable ${EMPTY} + Comment 创建对象 + ${ipObj} Create Dictionary attributeType=ip tableName=TSG_OBJ_IP_ADDR protocol=HTTP attributeName=ip + ... attributeValue={"clientIp":"192.168.41.67","clientPort":1,"serverIp":"192.168.41.67","serverPort":1,"addrType":4,"protocol":6} + ${stringValue} Create Dictionary string=*baidu.com + ${stringObj} Create Dictionary attributeType=string tableName=TSG_OBJ_URL protocol=HTTP attributeName=url + ... attributeValue=${stringValue} + ${appIdValue} Create Dictionary string=http. + ${appIdObj} Create Dictionary attributeType=string protocol=HTTP attributeName=app_id + ... attributeValue=${appIdValue} + ${attributes} Create List ${ipObj} ${stringObj} ${appIdObj} + ${verifySession} Create Dictionary attributes=${attributes} + ${verifyList} Create Dictionary policyType=tsg_security verifySession=${verifySession} + ${rescode} ${resData} VerifyPolicies ${verifyList} +Policy-Verify-v1-00022 + ${objectIds} Set Variable ${EMPTY} + Comment 创建对象 + ${ipObj} Create Dictionary attributeType=ip tableName=TSG_OBJ_IP_ADDR protocol=HTTP attributeName=ip + ... attributeValue={"clientIp":"192.168.41.67","clientPort":1,"serverIp":"192.168.41.67","serverPort":1,"addrType":4,"protocol":6} + ${stringObj} Create Dictionary attributeType=string tableName=TSG_OBJ_URL protocol=HTTP attributeName=url + ... attributeValue={'string':'*baidu.com'} + ${appIdValue} Create Dictionary string=http. + ${appIdObj} Create Dictionary attributeType=string protocol=HTTP attributeName=app_id + ... attributeValue=${appIdValue} + ${attributes} Create List ${ipObj} ${stringObj} ${appIdObj} + ${verifySession} Create Dictionary attributes=${attributes} + ${verifyList} Create Dictionary policyType=tsg_security verifySession=${verifySession} + ${rescode} ${resData} VerifyPolicies ${verifyList} + +Policy-Verify-v1-00023 + ${objectIds} Set Variable ${EMPTY} + Comment 创建对象 + ${ipObj} Create Dictionary attributeType=ip tableName=TSG_OBJ_IP_ADDR protocol=HTTP attributeName=ip + ... attributeValue=192.168.41.67|1|192.168.41.67|1|4|6 + ${stringObj} Create Dictionary attributeType=string tableName=TSG_OBJ_URL protocol=HTTP attributeName=url + ... attributeValue=*baidu.com + ${appIdObj} Create Dictionary attributeType=string protocol=HTTP attributeName=app_id + ... attributeValue=http. + ${signatureObj} Create Dictionary attributeType=signature protocol=HTTP attributeName=req_body + ... attributeValue=Content-Type|application/json + ${attributes} Create List ${ipObj} ${stringObj} ${appIdObj} ${signatureObj} + ${verifySession} Create Dictionary attributes=${attributes} + ${verifyList} Create Dictionary policyType=tsg_security verifySession=${verifySession} + ${rescode} ${resData} VerifyPolicies ${verifyList} \ No newline at end of file diff --git a/02-Keyword/tsg_bfapi/policy_object/Object.robot b/02-Keyword/tsg_bfapi/policy_object/Object.robot index e7bdb85..2139430 100644 --- a/02-Keyword/tsg_bfapi/policy_object/Object.robot +++ b/02-Keyword/tsg_bfapi/policy_object/Object.robot @@ -21,12 +21,12 @@ AddObjects #必选参数判定 Should Not Be Empty ${objectList} ${dictType} = Evaluate type(${objectList}) - ${body} Run Keyword If "${dictType}" == "" WxObjectListOperation ${returnData} ${objectList} add - ... ELSE IF "${dictType}" == "" WxObjectOperation ${returnData} ${objectList} add + ${body} Run Keyword If "${dictType}" == "" ObjectListOperation ${returnData} ${objectList} add + ... ELSE IF "${dictType}" == "" ObjectOperation ${returnData} ${objectList} add ... ELSE Set Variable ${EMPTY} ${response} BasePostRequestForV2 ${objectUrl} ${body} ${version} - ${objectIds} Run Keyword If "${returnData}" == "1" WxGet-ObjectIds ${response} + ${objectIds} Run Keyword If "${returnData}" == "1" Get-ObjectIds ${response} ... ELSE Create List ${rescode} Set Variable ${response['code']} Should Be Equal As Strings ${rescode} 200 @@ -44,8 +44,8 @@ UpdateObjects #必选参数判定 Should Not Be Empty ${objectList} ${dictType} = Evaluate type(${objectList}) - ${body} Run Keyword If "${dictType}" == "" WxObjectListOperation ${returnData} ${objectList} ${opAction} - ... ELSE IF "${dictType}" == "" WxObjectOperation ${returnData} ${objectList} ${opAction} + ${body} Run Keyword If "${dictType}" == "" ObjectListOperation ${returnData} ${objectList} ${opAction} + ... ELSE IF "${dictType}" == "" ObjectOperation ${returnData} ${objectList} ${opAction} ... ELSE Set Variable ${EMPTY} ${response} BaseEditRequestForV2 ${objectUrl} ${body} ${version} diff --git a/02-Keyword/tsg_bfapi/policy_object/Policy.robot b/02-Keyword/tsg_bfapi/policy_object/Policy.robot index e40c59b..ef9c028 100644 --- a/02-Keyword/tsg_bfapi/policy_object/Policy.robot +++ b/02-Keyword/tsg_bfapi/policy_object/Policy.robot @@ -51,12 +51,12 @@ AddPolicies #必选参数判定 Should Not Be Empty ${policyList} ${dictType} = Evaluate type(${policyList}) - ${body} Run Keyword If "${dictType}" == "" WxPolicyListOperation ${returnData} ${policyList} add ${version} - ... ELSE IF "${dictType}" == "" WxPolicyOperation ${returnData} ${policyList} add ${version} + ${body} Run Keyword If "${dictType}" == "" PolicyListDataOperation ${returnData} ${policyList} add ${version} + ... ELSE IF "${dictType}" == "" 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" WxGet-PolicyIds ${response} + ${policyIds} Run Keyword If "${returnData}" == "1" Get-PolicyIds ${response} ... ELSE Create List ${rescode} Set Variable ${response['code']} Should Be Equal As Strings ${rescode} 200 @@ -72,36 +72,32 @@ UpdatePolicies #必选参数判定 Should Not Be Empty ${policyList} ${dictType} = Evaluate type(${policyList}) - ${body} Run Keyword If "${dictType}" == "" WxPolicyListOperation ${returnData} ${policyList} ${opAction} ${version} - ... ELSE IF "${dictType}" == "" WxPolicyOperation ${returnData} ${policyList} ${opAction} ${version} + ${body} Run Keyword If "${dictType}" == "" PolicyListDataOperation ${returnData} ${policyList} ${opAction} ${version} + ... ELSE IF "${dictType}" == "" 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} DeletePolicies - [Arguments] ${params} - ${paramsType} Evaluate type(${params}) - Run Keyword And Return If "${paramsType}" == "" DeletePoliciy ${params} - FOR ${param} IN @{params} - ${rescode} WxDeletePolicy ${param} - END - [Return] ${rescode} -WxDeletePolicy [Documentation] ... 删除策略 - ... params,传入的删除字典 - ... 结构为policyIds=${policyIds} (List) policyType=${policyType} (variable) - [Arguments] ${params} - ${response} BaseDeleteRequest /${version}${policyUrl} ${params} - ${rescode} Set Variable ${response['code']} - Should Be Equal As Strings ${rescode} 200 + ... 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}" == "" DeletePolicyWithParamDict ${params} + FOR ${param} IN @{params} + ${rescode} DeletePolicyWithParamDict ${param} + END [Return] ${rescode} -WxDeletePolicy1 +DeletePolicy1 [Documentation] - ... 与DeletePoliciy类似,但是参数分开 - ... policyIds 策略id list - ... policyType 策略类型 + ... policyIds 策略id list [1,2,3] + ... policyType 策略类型 tsg_security等 [Arguments] ${policyIds} ${policyType} ${params} Create Dictionary policyIds=${policyIds} policyType=${policyType} ${response} BaseDeleteRequest /${version}${policyUrl} ${params} @@ -127,6 +123,9 @@ ImportPolicy ExportPolicy [Documentation] ... 策略导出 + ... policyType tsg_security等 + ... policyIds 1,2,3 + ... policyName 字符串 [Arguments] ${policyType} ${policyIds} ${policyName} Should Not Be Empty ${policyType} ${params} Create Dictionary policyType=${policyType} @@ -141,4 +140,30 @@ WriteFile ${type} Evaluate type(${content}) ${content} Run Keyword If "${type}" == "" json.Dumps ${content} ... ELSE Set Variable ${content} - Append To File ${path}/${filePath}/${fileName} ${content} \ No newline at end of file + Append To File ${path}/${filePath}/${fileName} ${content} +VerifyPolicies + [Documentation] + ... 策略验证 + ... 支持多个策略验证与单个策略验证 + ... 单个策略验证时verifyList 是一个dict + ... 多个策略验证时是一个list + ... atrributeValue字段可为三种格式 + ... 1:dict + ... 2:json + ... 3.字符串,ip的value对应格式为clientIp|clientPort|serverIp|serverPort|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}" == "" VerifyPolicyList ${verifyList} + ... ELSE IF "${dictType}" == "" 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']} \ No newline at end of file diff --git a/02-Keyword/tsg_bfapi/policy_object/ProcessObjectBody.robot b/02-Keyword/tsg_bfapi/policy_object/ProcessObjectBody.robot index e7aab82..f34565d 100644 --- a/02-Keyword/tsg_bfapi/policy_object/ProcessObjectBody.robot +++ b/02-Keyword/tsg_bfapi/policy_object/ProcessObjectBody.robot @@ -5,7 +5,7 @@ Resource ../../../03-Variable/BifangApiVariable.txt Resource ../../../03-Variable/PolicyObjectDefault.txt Resource ../../tsg_common/ManageObjectBody.robot *** Keywords *** -WxObjectListOperation +ObjectListOperation [Documentation] ... 描述:入口,opAction参数可为'add','update','disable','enable' ... 参数:returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。 @@ -14,10 +14,10 @@ WxObjectListOperation ... 多个对象处理 [Arguments] ${returnData} ${objectList} ${opAction} - Log To Console Call WxObjectListOperation + Log To Console Call ObjectListOperation ${objectListJson} Set Variable [ FOR ${object} IN @{objectList} - ${json} WxObjectOrganize ${object} ${opAction} + ${json} ObjectOrganize ${object} ${opAction} ${objectListJson} Set Variable ${objectListJson}${json}, END ${objectListJson}= Replace String Using Regexp ${objectListJson} ,$ ] @@ -28,7 +28,7 @@ WxObjectListOperation Log Object_Request_Body-${json} [Return] ${json} -WxObjectOperation +ObjectOperation [Documentation] ... 描述:入口,opAction参数可为'add','update','disable','enable' ... 参数:returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。 @@ -37,8 +37,8 @@ WxObjectOperation ... 单个策略处理 [Arguments] ${returnData} ${object} ${opAction} - Log To Console Call WxPolicyOperation - ${json} WxObjectOrganize ${object} ${opAction} + Log To Console Call ObjectOperation + ${json} ObjectOrganize ${object} ${opAction} # 转为json结构并返回 ${dict} Create Dictionary opAction=${opAction} returnData=${returnData} objectList=replace:objectList ${bodyJson} json.Dumps ${dict} ensure_ascii=False @@ -47,14 +47,14 @@ WxObjectOperation Log Object_Request_Body-${json} [Return] ${json} -WxObjectOrganize +ObjectOrganize [Documentation] ... 描述:入口,opAction参数可为'add','update','disable','enable' ... object: 必传,字典类型。字典内可选参数信息: ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt ... 单个策略转换为json [Arguments] ${object} ${opAction} - Log To Console Call WxObjectOrganize + Log To Console Call ObjectOrganize ${emptyList} Create List ${returnDict} Create Dictionary # 断言必传参数 @@ -144,11 +144,11 @@ ManageDeleteItemIds Append To List ${list1} ${var} END Set To Dictionary ${returnDict} deleteItemIds=${list1} -WxGet-ObjectIds +Get-ObjectIds [Documentation] ... 获取结果中的对象ID [Arguments] ${value} - Log Call WxGet-ObjectIds + Log Call Get-ObjectIds ${objectIds} Create List ${objectIdsTemp} Set Variable ${EMPTY} ${return} ${data} Run Keyword And Ignore Error Get From Dictionary ${value} data diff --git a/02-Keyword/tsg_bfapi/policy_object/ProcessPolicyBody.robot b/02-Keyword/tsg_bfapi/policy_object/ProcessPolicyBody.robot index a0069d2..cd2130a 100644 --- a/02-Keyword/tsg_bfapi/policy_object/ProcessPolicyBody.robot +++ b/02-Keyword/tsg_bfapi/policy_object/ProcessPolicyBody.robot @@ -31,7 +31,7 @@ Resource ../../tsg_common/ManagePolicyBody.robot # ... filterList= ${265}|${257}:TSG_FIELD_HTTP_HOST,${266}|${299}:TSG_FIELD_SSL_SNI&TSG_FIELD_SSL_SAN # ... filterList由多个数字用‘|’分隔,加上:对上对应的protocolFiled, # ... 一个filter中的protocolFiled是确定的,一个protocolFiled对应多个objectId -WxPolicyListOperation +PolicyListDataOperation [Documentation] ... 描述:入口,opAction参数可为'add','update','disable','enable' ... 参数:returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。 @@ -41,7 +41,7 @@ WxPolicyListOperation ... 多个策略处理 [Arguments] ${returnData} ${policyList} ${opAction} ${policyObjectVersion} - Log To Console Call WxPolicyListOperation + Log To Console Call PolicyListDataOperation ${policyListJson} Set Variable [ FOR ${policy} IN @{policyList} ${json} WxPolicyOrganize ${policy} ${opAction} ${policyObjectVersion} @@ -55,7 +55,7 @@ WxPolicyListOperation Log Policy_Request_Body-${json} [Return] ${json} -WxPolicyOperation +PolicyDataOperation [Documentation] ... 描述:入口,opAction参数可为'add','update','disable','enable' ... 参数:returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。 @@ -65,7 +65,7 @@ WxPolicyOperation ... 单个策略处理 [Arguments] ${returnData} ${policy} ${opAction} ${policyObjectVersion} - Log To Console Call WxPolicyOperation + Log To Console Call PolicyDataOperation ${json} WxPolicyOrganize ${policy} ${opAction} ${policyObjectVersion} # 转为json结构并返回 ${dict} Create Dictionary opAction=${opAction} returnData=${returnData} policyList=replace:policyList @@ -333,7 +333,7 @@ ManageFilter ${filterObject} Create Dictionary filter=${filterObjectList} [Return] ${filterObject} -WxGet-PolicyIds +Get-PolicyIds [Documentation] ... 获取结果中的策略ID [Arguments] ${value} @@ -348,4 +348,127 @@ WxGet-PolicyIds #Log To Console ${objectType} END - [Return] ${policyIds} \ No newline at end of file + [Return] ${policyIds} +DeletePolicyWithParamDict + [Documentation] + ... 删除策略 + ... params,传入的删除字典 + ... 结构为policyIds=${policyIds} (List) policyType=${policyType} (variable) + [Arguments] ${params} + ${response} BaseDeleteRequest /${version}${policyUrl} ${params} + ${rescode} Set Variable ${response['code']} + Should Be Equal As Strings ${rescode} 200 + [Return] ${rescode} +VerifyPolicyList + [Documentation] + ... 策略验证 + ... 多个策略验证 + [Arguments] ${verifyList} + 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 + [Documentation] + ... 策略验证 + ... 单个策略验证 + [Arguments] ${verifyObj} + Log To Console Call VerifyPolicyObj + ${emptyList} Create List + ${return} ${policyType} Run Keyword And Ignore Error Get From Dictionary ${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 Get From Dictionary ${attribute} tableName + ${return} ${protocol} Run Keyword And Ignore Error Get From Dictionary ${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} ${clientIp} Run Keyword And Ignore Error Get From Dictionary ${attributeValue} clientIp + Run Keyword If "${clientIp}"=="${EMPTY}" and "${attributeName}"=="src_ip" Should Not Be Empty ${clientIp} + Set To Dictionary ${dict} clientIp=${clientIp} + ${return} ${clientPort} Run Keyword And Ignore Error Get From Dictionary ${attributeValue} clientPort + Run Keyword If "${clientPort}"=="${EMPTY}" and "${attributeName}"=="src_ip" Should Not Be Empty ${clientPort} + Set To Dictionary ${dict} clientPort=${clientPort} + ${return} ${serverIp} Run Keyword And Ignore Error Get From Dictionary ${attributeValue} serverIp + Run Keyword If "${serverIp}"=="${EMPTY}" and "${attributeName}"=="dest_ip" Should Not Be Empty ${serverIp} + Set To Dictionary ${dict} serverIp=${serverIp} + ${return} ${serverPort} Run Keyword And Ignore Error Get From Dictionary ${attributeValue} serverPort + Run Keyword If "${serverPort}"=="${EMPTY}" and "${attributeName}"=="dest_ip" Should Not Be Empty ${serverPort} + Set To Dictionary ${dict} serverPort=${serverPort} + ${return} ${addrType} Run Keyword And Ignore Error Get From Dictionary ${attributeValue} addrType + Should Be Equal As Strings ${return} PASS + Set To Dictionary ${dict} addrType=${addrType} + ${return} ${protocol} Run Keyword And Ignore Error Get From Dictionary ${attributeValue} protocol + Should Be Equal As Strings ${return} PASS + Set To Dictionary ${dict} protocol=${protocol} + [Return] ${dict} +ExtractIpAttributeValue + [Arguments] ${attributeValue} + ${list} Split String ${attributeValue} | + ${len} Get Length ${list} + Should Be Equal As Integers ${len} 6 + ${addrType} Evaluate int(${list}[4]) + ${protocol} Evaluate int(${list}[5]) + ${dict} Create Dictionary clientIp=${list}[0] clientPort=${list}[1] serverIp=${list}[2] + ... serverPort=${list}[3] 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} \ No newline at end of file