diff --git a/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot b/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot new file mode 100644 index 0000000..f5824c4 --- /dev/null +++ b/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot @@ -0,0 +1,125 @@ +*** Settings *** +Test Teardown DeletePolicyAndObject ${policyIds} ${objectIds} +Resource ../../../02-Keyword/tsg_bfapi/PolicyObject.robot +Resource ../../../02-Keyword/tsg_bfapi/policy_object/Policy.robot +*** Test Cases *** +Policy-Get-v1-00001 + ${policy} Create Dictionary policyType=tsg_security action=deny + ... pageNo=1 pageSize=10 + ${rescode} ${response} QueryPolicies ${policy} v1 + ${policyIds} Create List + ${objectIds} Set Variable ${EMPTY} + Log ${rescode} ${response} +Policy-Get-v2-00001 + ${policy} Create Dictionary policyType=tsg_security action=deny + ... pageNo=1 pageSize=10 + ${rescode} ${response} QueryPolicies ${policy} v2 + ${policyIds} Create List + ${objectIds} Set Variable ${EMPTY} + Log ${rescode} ${response} +Policy-Post-v1-00001 + ${policy} Create Dictionary policyId=1 policyType=tsg_security + ... policyName=wx-policyName1 action=allow doBlacklist=0 + ... doLog=0 isValid=1 effectiveRange={} + ... userRegion={"protocol":"HTTP","traffic_forward":{"enable":1}} + ${objectIds} Set Variable ${EMPTY} + ${rescode} ${policyIds} AddPolicies 1 ${policy} v1 + Log ${rescode} ${policyIds} ${objectIds} +Policy-Post-v2-00001 + ${policy} Create Dictionary policyId=1 policyType=tsg_security + ... policyName=wx-policyName1 action=allow doBlacklist=0 + ... doLog=0 isValid=1 effectiveRange={} + ... userRegion={"protocol":"HTTP","traffic_forward":{"enable":1}} + ${objectIds} Set Variable ${EMPTY} + ${rescode} ${policyIds} AddPolicies 1 ${policy} v2 + Log ${rescode} ${policyIds} ${objectIds} +Policy-Post-v1-00002 + ${policy} Create Dictionary policyId=1 policyType=tsg_security + ... policyName=wx-policyName1 action=allow doBlacklist=0 + ... doLog=0 isValid=1 effectiveRange={} + ... userRegion={"protocol":"HTTP","traffic_forward":{"enable":1}} + + ${policy1} Create Dictionary policyId=2 policyType=tsg_security + ... policyName=wx-policyName2 action=allow doBlacklist=0 + ... doLog=0 isValid=1 + ... userRegion={"protocol":"HTTP","traffic_forward":{"enable":1}} + + ${policy2} Create Dictionary policyId=3 policyType=tsg_security + ... policyName=wx-policyName3 action=allow doBlacklist=0 + ... doLog=0 isValid=0 + ... userRegion={"protocol":"HTTP","traffic_forward":{"enable":1}} + ${objectIds} Set Variable ${EMPTY} + @{policyList} Create List ${policy} ${policy1} ${policy2} + ${rescode} ${policyIds} AddPolicies 1 ${policyList} v1 + Log ${rescode} ${policyIds} ${objectIds} +Policy-Post-v2-00002 + ${policy} Create Dictionary policyId=1 policyType=tsg_security + ... policyName=wx-policyName1 action=allow doBlacklist=0 + ... doLog=0 isValid=1 effectiveRange={} + ... userRegion={"protocol":"HTTP","traffic_forward":{"enable":1}} + + ${policy1} Create Dictionary policyId=2 policyType=tsg_security + ... policyName=wx-policyName2 action=allow doBlacklist=0 + ... doLog=0 isValid=1 + ... userRegion={"protocol":"HTTP","traffic_forward":{"enable":1}} + + ${policy2} Create Dictionary policyId=3 policyType=tsg_security + ... policyName=wx-policyName3 action=allow doBlacklist=0 + ... doLog=0 isValid=0 + ... userRegion={"protocol":"HTTP","traffic_forward":{"enable":1}} + ${objectIds} Set Variable ${EMPTY} + @{policyList} Create List ${policy} ${policy1} ${policy2} + ${rescode} ${policyIds} AddPolicies 1 ${policyList} v2 + Log ${rescode} ${policyIds} ${objectIds} +Policy-Post-v1-00003 + Comment 创建fqdn + ${objectDict} Create Dictionary objectType=fqdn isValid=${1} addItemList=*baidu.com + ${rescode} ${objectId} AddObject2 ${1} ${objectDict} + ${objectIds} Set Variable ${objectId} + Comment 创建安全策略 + ${policy} Create Dictionary policyName=WX_SecurityPolicy-v1-00003 policyType=tsg_security + ... policyDesc=autotest userTags= + ... action=deny effectiveRange={} + ... userRegion={"protocol":"SSL","method":"drop"} + ... referenceObject=${objectId}|TSG_FIELD_SSL_CN&TSG_FIELD_SSL_SAN + ... isValid=${1} appObjectIdArray=3 + ${rescode} ${policyIds} AddPolicies 1 ${policy} v1 + Log ${rescode} ${policyIds} ${objectIds} +Policy-Post-v2-00004 + #${testClentID} ${testClentSubID} + Comment 创建fqdn + ${objectDict} Create Dictionary objectType=fqdn isValid=${1} addItemList=*baidu.com + ${rescode} ${objectId} AddObject2 ${1} ${objectDict} + ${objectIds} Set Variable ${objectId} + Comment 创建安全策略 + ${policy} Create Dictionary policyName=WX_SecurityPolicy-v2-00004 policyType=tsg_security + ... policyDesc=autotest + ... action=deny #effectiveRange={} + ... userRegion={"protocol":"SSL","method":"drop"} + ... filterList=${objectId}:TSG_FIELD_SSL_CN + ... isValid=${1} appIdObjects=3 + ${rescode} ${policyIds} AddPolicies 1 ${policy} v2 + Log ${rescode} ${policyIds} ${objectIds} +Policy-Post-v2-00005 + Comment 创建IP + ${objectDict} Create Dictionary objectType=ip isValid=${1} + ... isInitialize=0 + ... addItemList=range|192.168.41.68|192.168.41.68|0/0 + ${rescode} ${objectId1} AddObject2 ${1} ${objectDict} + ${objectIds} Set Variable ${objectId1} + Log To Console Create IP Object + Comment 创建url + ${objectDict} Create Dictionary objectType=url isValid=${1} addItemList=*baidu.com + ${rescode} ${objectId2} AddObject2 ${1} ${objectDict} + ${objectIds} Set Variable ${objectId2},${objectIds} + Log To Console Create url Object + Comment 创建安全策略 + ${policy} Create Dictionary policyName=WX_SecurityPolicy-v2-00005 policyType=tsg_security + ... policyDesc=wx-autotest + ... action=deny effectiveRange={} + ... userRegion={"protocol":"HTTP","method":"drop"} + ... source=${objectId1}|TSG_SECURITY_SOURCE_ADDR + ... destination=${objectId2}|TSG_FIELD_HTTP_URL + ... isValid=${1} appIdObjects=2 + ${rescode} ${policyIds} AddPolicies 1 ${policy} v2 + Log ${rescode} ${policyIds} ${objectIds} \ No newline at end of file diff --git a/02-Keyword/tsg_bfapi/Common.robot b/02-Keyword/tsg_bfapi/Common.robot index a969fe3..b9a1b28 100644 --- a/02-Keyword/tsg_bfapi/Common.robot +++ b/02-Keyword/tsg_bfapi/Common.robot @@ -5,8 +5,28 @@ Library Collections Library RequestsLibrary *** 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} + [Arguments] ${apistr} ${body} Set Headers {"Authorization":"${token}","Content-Type":"application/json"} log 111111111111111111111111${apistr} &{httpResponse} Post ${apistr} ${body} @@ -16,7 +36,15 @@ BasePostRequest #Array $.data.policyList ${response} Set Variable ${httpResponse.body} [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"} @@ -27,7 +55,15 @@ BaseGetRequest #Array $.data.policyList ${response} Set Variable ${httpResponse.body} [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"} diff --git a/02-Keyword/tsg_bfapi/policy_object/Policy.robot b/02-Keyword/tsg_bfapi/policy_object/Policy.robot new file mode 100644 index 0000000..7eac1ab --- /dev/null +++ b/02-Keyword/tsg_bfapi/policy_object/Policy.robot @@ -0,0 +1,62 @@ +*** Settings *** +Library Collections +Library RequestsLibrary +Resource ../../../03-Variable/BifangApiVariable.txt +Resource ../../../02-Keyword/tsg_bfapi/policy_file_interface/FunctionalKeywords.robot +Resource ProcessPolicyBody.robot +Library Collections +Resource ../Common.robot +*** Variables *** +${url} /policy/compile +*** Keywords *** +#拼接字典类型数据为get请求的字符串 +Dictionary-To-QueryParams + [Documentation] + ... 接收get参数字典,转换为请求字符串 + [Arguments] ${params} + ${paramsString} = 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} +#get查询策略,传入字典对象,该方法将字典对象自动拼接成get请求查询条件 +QueryPolicies + [Documentation] + ... 查询策略,params为参数字典,version为接口版本号 + [Arguments] ${params} ${version} + Log To Console Call QueryPolicies + Dictionary Should Contain Key ${params} policyType + ${paramsStr} Dictionary-To-QueryParams ${params} + ${response} BaseGetRequestForV2 ${url} ${paramsStr} ${version} + ${rescode} Set Variable ${response['code']} + [Return] ${rescode} ${response} + +AddPolicies + [Documentation] + ... 新增策略 + ... returnData:是否返回数据,这里需要设置为1 + ... policyList:策略列表,支持dict与list两种形式 + ... version:接口版本号 + [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}" == "" WxPolicyListOperation ${returnData} ${policyList} add ${version} + ... ELSE IF "${dictType}" == "" WxPolicyOperation ${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 ${url} ${body} ${version} + ${policyIds} Run Keyword If "${returnData}" == "1" WxGet-PolicyIds ${response} + ... ELSE Create List + ${rescode} Set Variable ${response['code']} + [Return] ${rescode} ${policyIds} \ No newline at end of file diff --git a/02-Keyword/tsg_bfapi/policy_object/ProcessPolicyBody.robot b/02-Keyword/tsg_bfapi/policy_object/ProcessPolicyBody.robot new file mode 100644 index 0000000..0d1f422 --- /dev/null +++ b/02-Keyword/tsg_bfapi/policy_object/ProcessPolicyBody.robot @@ -0,0 +1,307 @@ +*** Settings *** +Library json +Library Collections +Resource ../../../03-Variable/BifangApiVariable.txt +Resource ../../../03-Variable/PolicyObjectDefault.txt +Resource ../../tsg_common/ManagePolicyBody.robot +*** 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],... +# ... 在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&TSG_FIELD_SSL_SAN +# ... destination= ${265}|TSG_FIELD_HTTP_HOST,${266}|TSG_FIELD_SSL_SNI&TSG_FIELD_SSL_SAN +# ... filterList= ${265}|${257}:TSG_FIELD_HTTP_HOST,${266}|${299}:TSG_FIELD_SSL_SNI&TSG_FIELD_SSL_SAN +# ... filterList由多个数字用‘|’分隔,加上:对上对应的protocolFiled, +# ... 一个filter中的protocolFiled是确定的,一个protocolFiled对应多个objectId +WxPolicyListOperation + [Documentation] + ... 描述:入口,opAction参数固定为'add' + ... 参数:returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。 + ... policyList: 必传,字典类型。字典内可选参数信息: + ... policyObjectVersion: 必传,v1,v2,涉及策略版本 + ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt + ... 多个策略处理 + + [Arguments] ${returnData} ${policyList} ${opAction} ${policyObjectVersion} + Log To Console Call WxPolicyListOperation + ${policyListJson} Set Variable [ + FOR ${policy} IN @{policyList} + ${json} WxPolicyOrganize ${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} + +WxPolicyOperation + [Documentation] + ... 描述:入口,opAction参数固定为'add' + ... 参数:returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。 + ... policyList: 必传,字典类型。字典内可选参数信息: + ... policyObjectVersion: 必传,v1,v2,涉及策略版本 + ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt + ... 单个策略处理 + + [Arguments] ${returnData} ${policy} ${opAction} ${policyObjectVersion} + Log To Console Call WxPolicyOperation + ${json} WxPolicyOrganize ${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} + +WxPolicyOrganize + [Documentation] + ... 描述:入口,opAction参数固定为'add' + ... policyList: 必传,字典类型。字典内可选参数信息: + ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt + ... policyObjectVersion: 必传,v1,v2,涉及策略版本 + ... 单个策略转换为json + [Arguments] ${policy} ${opAction} ${policyObjectVersion} + Log To Console Call WxPolicyOrganize + ${emptyList} Create List + # 取可选参数,为传入设置默认值 + ${return} ${policyName} Run Keyword And Ignore Error Get From Dictionary ${policy} policyName + Run Keyword If "${return}"=="FAIL" or "${policyName}"=="${EMPTY}" Set To Dictionary ${policy} policyName=${Default_PolicyName} + + ${return} ${policyType} Run Keyword And Ignore Error Get From Dictionary ${policy} policyType + Run Keyword If "${return}"=="FAIL" or "${policyType}"=="${EMPTY}" Set To Dictionary ${policy} policyType=${Default_PolicyType} + #policyDesc 不是必填的选项 + ${return} ${policyDesc} Run Keyword And Ignore Error Get From Dictionary ${policy} policyDesc + Run Keyword If "${return}"=="FAIL" or "${policyDesc}"=="${EMPTY}" Set To Dictionary ${policy} policyDesc=${Default_PolicyDesc} + + ${return} ${action} Run Keyword And Ignore Error Get From Dictionary ${policy} action + Run Keyword If "${return}"=="FAIL" or "${action}"=="${EMPTY}" Set To Dictionary ${policy} action=${Default_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 ${policy} userTags=${Default_UserTags} + + ${return} ${doLog} Run Keyword And Ignore Error Get From Dictionary ${policy} doLog + Run Keyword If "${return}"=="FAIL" or "${doLog}"=="${EMPTY}" Set To Dictionary ${policy} doLog=${Default_DoLog} + ${return} ${isValid} Run Keyword And Ignore Error Get From Dictionary ${policy} isValid + Run Keyword If "${return}"=="FAIL" or "${isValid}"=="${EMPTY}" Set To Dictionary ${policy} isValid=${Default_IsValid} + ${return} ${scheduleId} Run Keyword And Ignore Error Set Variable ${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 ${policy} 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 + ... ELSE Evaluate list(map(int, re.split('[,]', '${appObjectIdArray}'))) re + Run Keyword If "${policyObjectVersion}"=="v1" Set To Dictionary ${policy} appObjectIdArray=${appObjectIdArrayV} + ... ELSE IF "${policyObjectVersion}"=="v2" Set To Dictionary ${policy} appIdObjects=${appObjectIdArrayV} + ${policyId} Run Keyword If "${opAction}"=="add" Set Variable ${EMPTY} + ... ELSE Get From Dictionary ${policy} policyId + # 固定值 + Set To Dictionary ${policy} policyId=${policyId} doBlacklist=${0} + # 分别处理EffectiveRange、UserRegion和ReferenceObject参数 + WxManageEffectiveRange ${policy} + #WxManageUserRegion ${policy} + Run Keyword If "${policyObjectVersion}"=="v1" WxManageReferenceObject ${policy} ELSE IF "${policyObjectVersion}"=="v2" WxManageObjectV2 ${policy} + #先取出useragion 再放回json + ${return} ${userRegion} Run Keyword And Ignore Error Get From Dictionary ${policy} userRegion + Set To Dictionary ${policy} 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 ${policy}[policyType] + Run Keyword If "${policyObjectVersion}"=="v1" and "${policyType}"=="active_defence" Set To Dictionary ${policy} referenceObject=${active_defence_emptyList} + Run Keyword If "${policyObjectVersion}"=="v1" and "${policyType}"=="active_defence" Set To Dictionary ${policy} appObjectIdArray=${active_defence_emptyList} + # 转为json结构并返回 + ${json} json.Dumps ${policy} ensure_ascii=False + ${json} Replace String ${json} "method:rst" ${userRegion} + #${json} Replace String ${json} "effectiveRange:Empty" {} + Log Policy-${json} + [Return] ${json} + +WxManageEffectiveRange + [Documentation] + ... 处理EffectiveRange + ... 加入effectiveRange={}的处理支持 + [Arguments] ${policyList} + Log To Console Call WxManageEffectiveRange + ${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 ${policyList} effectiveRange=${value} +WxManageReferenceObject + [Documentation] + ... 处理引用对象字符串 + ... v1版本接口使用 + [Arguments] ${policy} + Log To Console Call WxManageReferenceObject + ${emptyList} Create List + #默认客户端条件类型:clientip or clientsubid + ${return} ${defaultClient} Run Keyword And Ignore Error Set Variable ${policy}[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 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 ${policy} referenceObject=${emptyList} + +ObjectLoop + [Arguments] ${value} ${valueList} + # 若参数为空,设置默认结构 + FOR ${var} IN @{value} + Run Keyword If ${var}!={} Append To List ${valueList} ${var} + END + [Return] ${valueList} +WxManageObjectV2 + [Documentation] + ... 处理引用对象字符串 + ... v2版本接口使用 + ... source,destination,filterList + # 处理引用对象字符串 + [Arguments] ${policy} + Log To Console Call WxManageObjectV2 + #默认客户端条件类型:clientip or clientsubid + ${return} ${defaultClient} Run Keyword And Ignore Error Get From Dictionary ${policy} defalutClient + ${defaultClient} Run Keyword If "${return}"=="FAIL" or "${defaultClient}"=="${EMPTY}" Set Variable ${Default_Client_Type} + ... ELSE Set Variable ${defaultClient} + + ${sourceList} Create List + ${destinationList} Create List + ${filterList} Create List + Run Keyword If '${addTestClentIPFlag}'=='1' and '${defaultClient}'=='clientip' ManageClientIPObjectV2 ${sourceList} + Run Keyword If '${addTestClentIPFlag}'=='1' and '${defaultClient}'=='clientsubid' ManageClientSubIDObjectV2 ${sourceList} + AnalysisObjectV2 ${policy} source ${sourceList} + AnalysisObjectV2 ${policy} destination ${destinationList} + AnalysisObjectV2 ${policy} filterList ${filterList} + + Set To Dictionary ${policy} source=${sourceList} destination=${destinationList} filterList=${filterList} + + Log ${policy} +ManageClientIPObjectV2 + [Arguments] ${emptyList} + # 增加引用测试终端IP策略对象 + ${obj1} Create Dictionary objectId=${testClentID} protocolField=TSG_SECURITY_SOURCE_ADDR + Append To List ${emptyList} ${obj1} +ManageClientSubIDObjectV2 + [Arguments] ${emptyList} + # 增加引用测试终端IP策略对象 + ${protocolField} Set Variable + ${obj1} Create Dictionary objectId=${testClentSubID} protocolField=${protocolField} + Append To List ${emptyList} ${obj1} +AnalysisObjectV2 + [Arguments] ${policy} ${objectType} ${objList} + Log To Console Call AnalysisObjectV2 + ${policyObjectDefault} Run Keyword If "${objectType}"=="source" Set Variable ${Default_v2_SourceObject} + ... ELSE IF "${objectType}"=="destination" Set Variable ${Default_v2_DestinationObject} + ... ELSE IF "${objectType}"=="filterList" Set Variable ${Default_v2_FilterObject} + + ${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('[,]', '${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 + [Documentation] + ... source,destination处理 + [Arguments] ${object} + Log To Console Call ManageObject + ${objectList} Create List + #截取objectId + ${objectId} Evaluate '${object}'[0:'${object}'.find('|')] + #截取protocolField + ${protocolField} Evaluate '${object}'['${object}'.find('|')+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 + [Documentation] + ... filterList处理 + [Arguments] ${filter} + Log To Console Call ManageFilter + ${filterObjectList} Create List + #截取objectId + ${objectIds} Evaluate '${filter}'[0:'${filter}'.find(':')] + #截取protocolField + ${protocolField} Evaluate '${filter}'['${filter}'.find(':')+1:] + #遍历 objectId + ${list} Evaluate re.split('[|]', '${objectIds}') re + 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} + +WxGet-PolicyIds + [Documentation] + ... 获取结果中的策略ID + [Arguments] ${value} + ${policyIds} Create List + + FOR ${policy} IN @{value['data']['policyList']} + ${policyType} = Evaluate type(${policy}) + ${policyIdList} Create List ${policy['policyId']} + ${policyObj} Create Dictionary policyType=${policy['policyType']} policyIds=${policyIdList} + Append To List ${policyIds} ${policyObj} + #Log To Console ${policy['referenceObject']} + #${objectType} Evaluate type(${policy['referenceObject']}) + #Log To Console ${objectType} + + END + [Return] ${policyIds} \ No newline at end of file diff --git a/03-Variable/PolicyObjectDefault.txt b/03-Variable/PolicyObjectDefault.txt index 09dd950..ed922e2 100644 --- a/03-Variable/PolicyObjectDefault.txt +++ b/03-Variable/PolicyObjectDefault.txt @@ -14,7 +14,10 @@ ${Default_AppObjectIdArray} 2,3,4,5,6 ${Default_UserTags} ${EMPTY} ${Default_DoLog} ${1} ${Default_ScheduleId} ${EMPTY} - +#策略v2 +${Default_v2_SourceObject} ${EMPTY} +${Default_v2_DestinationObject} ${EMPTY} +${Default_v2_FilterObject} ${EMPTY} # 对象 ${Default_ObjectType} ip ${Default_ObjectSubType} ${EMPTY} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..db85ed3 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,58 @@ +pip>=19.3.0 +bcrypt>=3.1.7 +certifi>=2019.11.28 +cffi>=1.14.0 +chardet>=3.0.4 +Click>=7.0 +cryptography>=2.8 +decorator>=4.4.1 +docutils>=0.16 +flex>=6.14.1 +genson>=1.1.0 +get>=2019.4.13 +idna>=2.9 +importlib-metadata>=1.5.0 +jsonpath-ng>=1.4.3 +jsonpointer>=2.0 +jsonschema>=3.2.0 +numpy>=1.18.1 +paramiko>=2.7.1 +Pillow>=7.0.0 +ply>=3.11 +post>=2019.4.13 +public>=2019.4.13 +pyasn1>=0.4.8 +pycparser>=2.20 +pycryptodomex>=3.9.7 +Pygments>=2.5.2 +PyNaCl>=1.3.0 +Pypubsub>=4.0.3 +pyrsistent>=0.15.7 +pysmi>=0.3.4 +pysnmp>=4.4.12 +pytz>=2019.3 +pywin32>=227 +PyYAML>=5.3 +query-string>=2019.4.13 +request>=2019.4.13 +requests>=2.23.0 +RESTinstance>=1.0.2 +rfc3987>=1.3.8 +robotframework>=3.1.2 +robotframework-ftplibrary>=1.8 +robotframework-requests>=0.6.4 +robotframework-ride>=1.7.4.1 +robotframework-selenium2library>=3.0.0 +robotframework-seleniumlibrary>=4.3.0 +robotframework-snmplibrary>=0.2.1 +robotframework-sshlibrary>=3.4.0 +scp>=0.13.2 +selenium>=3.141.0 +setuptools>=40.6.2 +six>=1.14.0 +strict-rfc3339>=0.7 +tzlocal>=2.0.0 +urllib3>=1.25.8 +validate-email>=1.3 +wxPython>=4.0.7.post2 +zipp>=3.0.0