diff --git a/01-TestCase/tsg_adc/selfserver/DenyAllTests.robot b/01-TestCase/tsg_adc/selfserver/DenyAllTests.robot index 176850d..e0fc2ca 100644 --- a/01-TestCase/tsg_adc/selfserver/DenyAllTests.robot +++ b/01-TestCase/tsg_adc/selfserver/DenyAllTests.robot @@ -26,8 +26,6 @@ SecurityPolicy-Deny-AllProtol-00001 # ... Comment 创建目标IP ${objectDict} Create Dictionary - ... objectType=ip - ... isValid=${1} ... addItemList=CIDR|192.168.100.5|32|0/0 ${rescode} ${objectId} AddObject2 ${1} ${objectDict} ${objectids} set Variable ${objectId} @@ -35,17 +33,7 @@ SecurityPolicy-Deny-AllProtol-00001 Comment 创建安全策略,针对所有协议,相当于BlackIP ${policyDict} Create Dictionary ... policyName=SecurityPolicy-Deny-AllProtol-00001 - ... policyType=tsg_security - ... policyDesc=autotest - ... action=deny - ... effectiveRange=${effectiveRange} - ... userRegion=method:rst ... referenceObject=${objectId}|TSG_SECURITY_DESTINATION_ADDR - ... isValid=${1} - ... appObjectIdArray=2,3,4,5,6 - ... userTags=${userTags} - ... doLog=${2} - ... scheduleId=${referenceObject} ${rescode} ${policyId} AddPolicy2 ${1} ${policyDict} ${policyId} set Variable {"policyType":"tsg_security","policyIds":[${policyId}]} diff --git a/02-Keyword/tsg_common/ManageObjectBody.robot b/02-Keyword/tsg_common/ManageObjectBody.robot index 0c4216c..4f35672 100644 --- a/02-Keyword/tsg_common/ManageObjectBody.robot +++ b/02-Keyword/tsg_common/ManageObjectBody.robot @@ -2,47 +2,56 @@ Library json Library Collections Resource ../../03-Variable/BifangApiVariable.txt +Resource ../../03-Variable/PolicyObjectDefault.txt Resource ../../02-Keyword/tsg_bfapi/PolicyObject.robot *** Keywords *** ObjectParamsOpertion [Documentation] ... 描述:入口,opAction参数固定为'add' + ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt [Arguments] ${returnData} ${objectList} ${emptyList} Create List ${returnDict} Create Dictionary # 断言必传参数 - Should Not Be Empty ${objectList}[objectType] + # Should Not Be Empty ${objectList}[objectType] + # Set To Dictionary ${returnDict} objectType=${objectList}[objectType] Should Not Be Empty ${objectList}[addItemList] - Set To Dictionary ${returnDict} objectType=${objectList}[objectType] # 取可选参数,为传入设置默认值 + ${return} ${objectType} Run Keyword And Ignore Error Set Variable ${objectList}[objectType] + ${objectTypeV} Run Keyword If "${return}"!="FAIL" and "${objectType}"!="${EMPTY}" Set Variable ${objectType} + ... ELSE Set Variable ${Default_ObjectType} + Set To Dictionary ${objectList} objectType=${objectTypeV} + Set To Dictionary ${returnDict} objectType=${objectTypeV} ${return} ${objectSubType} Run Keyword And Ignore Error Set Variable ${objectList}[objectSubType] Run Keyword If "${return}"!="FAIL" and "${objectSubType}"!="${EMPTY}" Set To Dictionary ${returnDict} objectSubType=${objectSubType} + ... ELSE Set To Dictionary ${returnDict} objectSubType=${Default_ObjectSubType} ${return} ${isValid} Run Keyword And Ignore Error Set Variable ${objectList}[isValid] - Run Keyword If "${return}"=="FAIL" or "${isValid}"=="${EMPTY}" Set To Dictionary ${returnDict} isValid=${0} + Run Keyword If "${return}"=="FAIL" or "${isValid}"=="${EMPTY}" Set To Dictionary ${returnDict} isValid=${Default_IsValid} ... ELSE Set To Dictionary ${returnDict} isValid=${isValid} ${return} ${isInitialize} Run Keyword And Ignore Error Set Variable ${objectList}[isInitialize] - Run Keyword If "${return}"=="FAIL" or "${isInitialize}"=="${EMPTY}" Set To Dictionary ${returnDict} isInitialize=${0} + Run Keyword If "${return}"=="FAIL" or "${isInitialize}"=="${EMPTY}" Set To Dictionary ${returnDict} isInitialize=${Default_IsInitialize} ... ELSE Set To Dictionary ${returnDict} isInitialize=${isInitialize} ${return} ${isExclusion} Run Keyword And Ignore Error Set Variable ${objectList}[isExclusion] - Run Keyword If "${return}"=="FAIL" or "${isExclusion}"=="${EMPTY}" Set To Dictionary ${returnDict} isExclusion=${0} + Run Keyword If "${return}"=="FAIL" or "${isExclusion}"=="${EMPTY}" Set To Dictionary ${returnDict} isExclusion=${Default_IsExclusion} ... ELSE Set To Dictionary ${returnDict} isExclusion=${isExclusion} ${return} ${objectName} Run Keyword And Ignore Error Set Variable ${objectList}[objectName] - Run Keyword If "${return}"=="FAIL" or "${objectName}"=="${EMPTY}" Set To Dictionary ${returnDict} objectName=test_object_add + Run Keyword If "${return}"=="FAIL" or "${objectName}"=="${EMPTY}" Set To Dictionary ${returnDict} objectName=${Default_ObjectName} ... ELSE Set To Dictionary ${returnDict} objectName=${objectName} ${return} ${objectDesc} Run Keyword And Ignore Error Set Variable ${objectList}[objectDesc] Run Keyword If "${return}"!="FAIL" and "${objectDesc}"!="${EMPTY}" Set To Dictionary ${returnDict} objectDesc=${objectDesc} + ... ELSE Set To Dictionary ${returnDict} objectDesc=${Default_ObjectDesc} ${return} ${subObjectIds} Run Keyword And Ignore Error Set Variable ${objectList}[subObjectIds] Run Keyword If "${return}"!="FAIL" and "${subObjectIds}"!="${EMPTY}" Set To Dictionary ${returnDict} subObjectIds=${subObjectIds} - + ... ELSE Set To Dictionary ${returnDict} subObjectIds=${emptyList} # 处理AddItemList ManageAddItemList ${objectList} ${returnDict} # 转为json结构并返回 ${dict} Create Dictionary opAction=add returnData=${returnData} objectList=${returnDict} ${json} json.Dumps ${dict} ensure_ascii=False - Log ${json} + Log Object_Request_Body-${json} [Return] ${json} ManageAddItemList @@ -136,8 +145,8 @@ IpItemType3 ${obj} Create Dictionary # 设置默认值 Run Keyword If ':' in '${str}' Set To Dictionary ${obj} addrType=${6} - ... ELSE Set To Dictionary ${obj} addrType=${4} - Set To Dictionary ${obj} protocol=${0} direction=${0} isSession=endpoint + ... ELSE Set To Dictionary ${obj} addrType=${Default_AddItem_AddrType} + Set To Dictionary ${obj} protocol=${Default_AddItem_Protocol} direction=${Default_AddItem_Direction} isSession=${Default_AddItem_IsSession} ${cfgs} Evaluate re.split('[&]', '${str}') re ${client} Set Variable ${cfgs}[0] diff --git a/02-Keyword/tsg_common/ManagePolicyBody.robot b/02-Keyword/tsg_common/ManagePolicyBody.robot index c3b19b6..7d16399 100644 --- a/02-Keyword/tsg_common/ManagePolicyBody.robot +++ b/02-Keyword/tsg_common/ManagePolicyBody.robot @@ -2,6 +2,7 @@ Library json Library Collections Resource ../../03-Variable/BifangApiVariable.txt +Resource ../../03-Variable/PolicyObjectDefault.txt Resource ../../02-Keyword/tsg_bfapi/PolicyObject.robot *** Keywords *** @@ -30,42 +31,35 @@ PolicyParamsOpertion ... 描述:入口,opAction参数固定为'add' ... 参数:returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。 ... policyList: 必传,字典类型。字典内可选参数信息: - ... action: 必传,无默认值 - ... policyType: 必传,无默认值 - ... policyName: 可选,默认为'test_policy_add' - ... policyDesc: 可选,无默认值 - ... userTags: 可选,无默认值 - ... doLog: 可选,是否生成日志,${0}(不需要),${1}(需要),${2}(只记录结构化日志)。默认为${2} - ... isValid: 可选,${0}(无效),${1}(生效) - ... effectiveRange: 可选 - ... userRegion: 可选 - ... referenceObject: 可选 - ... scheduleId: 可选 - ... appObjectIdArray: 可选 + ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt [Arguments] ${returnData} ${policyList} ${emptyList} Create List # 断言必传参数 - Should Not Be Empty ${policyList}[policyType] - Should Not Be Empty ${policyList}[action] + # 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=test_policy_add + 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= + 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= + 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=${2} + 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=${0} + 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}" Set Variable ${emptyList} - ... ELSE Evaluate re.split('[,]', '${scheduleId}') re + ${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 ${return} ${appObjectIdArray} Run Keyword And Ignore Error Set Variable ${policyList}[appObjectIdArray] - ${appObjectIdArrayV} Run Keyword If "${return}"=="FAIL" or "${appObjectIdArray}"=="${EMPTY}" Set Variable ${emptyList} - ... ELSE Evaluate re.split('[,]', '${appObjectIdArray}') re - Set To Dictionary ${policyList} scheduleId=${scheduleIdV} + ${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} scheduleId=${scheduleIdV} Set To Dictionary ${policyList} appObjectIdArray=${appObjectIdArrayV} # 固定值 Set To Dictionary ${policyList} policyId= doBlacklist=${0} @@ -76,7 +70,7 @@ PolicyParamsOpertion # 转为json结构并返回 ${dict} Create Dictionary opAction=add returnData=${returnData} policyList=${policyList} ${json} json.Dumps ${dict} ensure_ascii=False - Log ${json} + Log Policy_Request_Body-${json} [Return] ${json} ManageEffectiveRange @@ -86,7 +80,10 @@ ManageEffectiveRange ${emptyListDouble} Create List ${emptyList} ${return} ${effectiveRange} Run Keyword And Ignore Error Set Variable ${policyList}[effectiveRange] - ${value} Run Keyword If "${return}"=="FAIL" or "${effectiveRange}"=="${EMPTY}" Create Dictionary tag_sets=${emptyListDouble} + ${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} @@ -160,7 +157,10 @@ ManageUserRegion ${emptyObj} Create Dictionary ${return} ${userRegion} Run Keyword And Ignore Error Set Variable ${policyList}[userRegion] - ${value} Run Keyword If "${return}"=="FAIL" or "${userRegion}"=="${EMPTY}" Create Dictionary + ${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} @@ -189,7 +189,9 @@ ManageReferenceObject ${defaultObj} Create Dictionary ${return} ${referenceObject} Run Keyword And Ignore Error Set Variable ${policyList}[referenceObject] - ${value} Run Keyword If "${return}"=="FAIL" or "${referenceObject}"=="${EMPTY}" Create List ${defaultObj} + ${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} diff --git a/03-Variable/PolciyObjectDefault.txt b/03-Variable/PolciyObjectDefault.txt deleted file mode 100644 index 2b1af9b..0000000 --- a/03-Variable/PolciyObjectDefault.txt +++ /dev/null @@ -1,22 +0,0 @@ -*** Variables *** -#策略 -policyName autotest_policy -policyType tsg_security -policyDesc autotest -action deny -effectiveRange Nursurtan|Transtelecom&Astel,|Astel&Transtelecom -userRegion method:rst -referenceObject 1|TSG_SECURITY_DESTINATION_ADDR -isValid ${1} -appObjectIdArray 2,3,4,5,6 -userTags 3 -doLog 2 -scheduleId 7 -#对象 -objectSubType ${objectSubType} -isValid ${isValid} -isInitialize ${isInitialize} -isExclusion ${isExclusion} -objectName ${objectName} -objectDesc ${objectDesc} -subObjectIds ${subObjectIds} diff --git a/03-Variable/PolicyObjectDefault.txt b/03-Variable/PolicyObjectDefault.txt new file mode 100644 index 0000000..3ae4b1e --- /dev/null +++ b/03-Variable/PolicyObjectDefault.txt @@ -0,0 +1,31 @@ +*** Variables *** +# 通用 +${Default_IsValid} ${1} + +# 策略 +${Default_PolicyName} autotest_policy +${Default_PolicyType} tsg_security +${Default_PolicyDesc} autotest +${Default_Action} deny +${Default_EffectiveRange} Nursurtan|Transtelecom&Astel,|Astel&Transtelecom +${Default_UserRegion} method:rst +${Default_ReferenceObject} 1|TSG_SECURITY_DESTINATION_ADDR +${Default_AppObjectIdArray} 2,3,4,5,6 +${Default_UserTags} 3 +${Default_DoLog} ${2} +${Default_ScheduleId} 7 + +# 对象 +${Default_ObjectType} ip +${Default_ObjectSubType} endpoint +${Default_IsInitialize} ${0} +${Default_IsExclusion} ${0} +${Default_ObjectName} autotestobj +${Default_ObjectDesc} autotestobj +${Default_AddItem_AddrType} ${4} +${Default_AddItem_Protocol} ${0} +${Default_AddItem_Direction} ${0} +${Default_AddItem_IsSession} endpoint + + +