This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
dongxiaoyan-tsg-autotest/02-Keyword/tsg_common/ManagePolicyBody.robot
wangxin 3e390386c3 fix:(v1版本接口分隔符)引用对象使用变量分隔符
feat:(策略对象)1.策略对象相关性查询;2.App ID对象树查询;
2020-07-01 12:03:01 +08:00

279 lines
15 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

*** Settings ***
Library json
Library Collections
Resource ../../03-Variable/BifangApiVariable.txt
Resource ../../03-Variable/PolicyObjectDefault.txt
Resource ../../02-Keyword/tsg_bfapi/PolicyObject.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&Astellocation和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值类型2location|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=location 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=location 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
${obj1} Create Dictionary objectId=${testClentID} 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}