diff options
| author | 董晓燕 <[email protected]> | 2021-06-03 09:55:45 +0000 |
|---|---|---|
| committer | 董晓燕 <[email protected]> | 2021-06-03 09:55:45 +0000 |
| commit | ac68e65f508799a0e555a240ae374d313a0a8d75 (patch) | |
| tree | 2a339bbd8acd65e2fb235159cc9c5303ae5725b7 /keyword/policys | |
| parent | 2f39b56d617e5fba2b8d73d81cd5e6d894f85352 (diff) | |
| parent | 4667c668725ff7cb673c637a297c67283876d4d4 (diff) | |
Develop
See merge request dongxiaoyan/gap_tsg_api!4
Diffstat (limited to 'keyword/policys')
| -rw-r--r-- | keyword/policys/manage_policy_body.robot | 281 | ||||
| -rw-r--r-- | keyword/policys/policy.robot | 562 | ||||
| -rw-r--r-- | keyword/policys/process_policy_body.robot | 585 |
3 files changed, 1428 insertions, 0 deletions
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} |
