feat:(v2策略)支持update,enable,disable

This commit is contained in:
wangxin
2020-06-16 19:40:59 +08:00
parent e9893ac45d
commit ca22cc7ba7
4 changed files with 140 additions and 5 deletions

View File

@@ -150,3 +150,106 @@ Policy-Post-v2-00006
Append To List ${profiles} ${profile} ${profile1}
${objectIds} Set Variable ${EMPTY}
Log ${rescode} ${policyIds} ${objectIds}
Policy-Post-v2-00007
Comment 创建IP
${objectDict} Create Dictionary objectType=ip isValid=${1}
... isInitialize=0
... addItemList=range|192.168.41.68|192.168.41.68|0/0
${rescode} ${objectId1} AddObject2 ${1} ${objectDict}
${objectIds} Set Variable ${objectId1}
Log To Console Create IP Object1
Comment 创建IP1
${objectDict} Create Dictionary objectType=ip isValid=${1}
... isInitialize=0
... addItemList=range|192.168.41.67|192.168.41.67|0/0
${rescode} ${objectId2} AddObject2 ${1} ${objectDict}
${objectIds} Set Variable ${objectId2}
Log To Console Create IP Object2
Comment 创建url
${objectDict} Create Dictionary objectType=url isValid=${1} addItemList=*baidu.com
${rescode} ${objectId3} AddObject2 ${1} ${objectDict}
${objectIds} Set Variable ${objectId3},${objectIds}
Log To Console Create url Object3
Comment 创建url1
${objectDict} Create Dictionary objectType=url isValid=${1} addItemList=*google.com.com
${rescode} ${objectId4} AddObject2 ${1} ${objectDict}
${objectIds} Set Variable ${objectId4},${objectIds}
Log To Console Create url Object4
Comment 创建安全策略
${policy} Create Dictionary policyName=WX_AddPolicy-v2-00007 policyType=tsg_security
... policyDesc=wx-autotest
... action=deny effectiveRange={}
... userRegion={"protocol":"HTTP","method":"drop"}
... source=${objectId1}|TSG_SECURITY_SOURCE_ADDR
... destination=${objectId3}|TSG_FIELD_HTTP_URL
... isValid=${1} appIdObjects=2
${rescode} ${policyIds} AddPolicies 1 ${policy} v2
Log ${rescode}
${updatePolicyId} Set Variable ${policyIds}[0][policyIds][0]
Comment 更新安全策略
${policy} Create Dictionary policyName=WX_UpdatePolicy-v2-00007 policyType=tsg_security
... policyDesc=wx-autotest policyId=${updatePolicyId}
... action=monitor
... userRegion={"protocol":"HTTP","traffic_forward":{"enable":1}}
... source=${objectId2}|TSG_SECURITY_SOURCE_ADDR
... destination=${objectId4}|TSG_FIELD_HTTP_URL
... isValid=${1} appIdObjects=2
${rescode} UpdatePolicies 1 ${policy} v2 update
Policy-Post-v2-00008
Comment 创建IP
${objectDict} Create Dictionary objectType=ip isValid=${1}
... isInitialize=0
... addItemList=range|192.168.41.68|192.168.41.68|0/0
${rescode} ${objectId1} AddObject2 ${1} ${objectDict}
${objectIds} Set Variable ${objectId1}
Log To Console Create IP Object1
Comment 创建url
${objectDict} Create Dictionary objectType=url isValid=${1} addItemList=*baidu.com
${rescode} ${objectId3} AddObject2 ${1} ${objectDict}
${objectIds} Set Variable ${objectId3},${objectIds}
Log To Console Create url Object3
Comment 创建安全策略
${policy} Create Dictionary policyName=WX_AddPolicy-v2-00008 policyType=tsg_security
... policyDesc=wx-autotest
... action=deny effectiveRange={}
... userRegion={"protocol":"HTTP","method":"drop"}
... source=${objectId1}|TSG_SECURITY_SOURCE_ADDR
... destination=${objectId3}|TSG_FIELD_HTTP_URL
... isValid=${1} appIdObjects=2
${policy1} Copy Dictionary ${policy} true
${rescode} ${policyIds} AddPolicies 1 ${policy} v2
Log ${rescode}
${updatePolicyId} Set Variable ${policyIds}[0][policyIds][0]
Comment 更新安全策略
Set To Dictionary ${policy1} policyId=${updatePolicyId}
${rescode} UpdatePolicies 1 ${policy1} v2 disable
Policy-Post-v2-00009
Comment 创建IP
${objectDict} Create Dictionary objectType=ip isValid=${1}
... isInitialize=0
... addItemList=range|192.168.41.68|192.168.41.68|0/0
${rescode} ${objectId1} AddObject2 ${1} ${objectDict}
${objectIds} Set Variable ${objectId1}
Log To Console Create IP Object1
Comment 创建url
${objectDict} Create Dictionary objectType=url isValid=${1} addItemList=*baidu.com
${rescode} ${objectId3} AddObject2 ${1} ${objectDict}
${objectIds} Set Variable ${objectId3},${objectIds}
Log To Console Create url Object3
Comment 创建安全策略
${policy} Create Dictionary policyName=WX_AddPolicy-v2-00009 policyType=tsg_security
... policyDesc=wx-autotest
... action=deny effectiveRange={}
... userRegion={"protocol":"HTTP","method":"drop"}
... source=${objectId1}|TSG_SECURITY_SOURCE_ADDR
... destination=${objectId3}|TSG_FIELD_HTTP_URL
... isValid=${0} appIdObjects=2
${policy1} Copy Dictionary ${policy} true
${rescode} ${policyIds} AddPolicies 1 ${policy} v2
Log ${rescode}
${updatePolicyId} Set Variable ${policyIds}[0][policyIds][0]
Comment 更新安全策略
Set To Dictionary ${policy1} policyId=${updatePolicyId}
${rescode} UpdatePolicies 1 ${policy1} v2 enable

View File

@@ -83,3 +83,10 @@ BaseEditRequest
Should Be Equal As Strings ${response.status_code} 200
${response} to json ${response.content}
[Return] ${response}
BaseEditRequestForV2
[Arguments] ${requestUri} ${data} ${apiVersion}
${apiStart} Evaluate '${requestUri}'[0:1]
${requestUri} Run Keyword If "${apiStart}"=="/" set variable /${apiVersion}${requestUri}
... ELSE set variable /${apiVersion}/${requestUri}
${response} BaseEditRequest ${requestUri} ${data}
[Return] ${response}

View File

@@ -75,3 +75,17 @@ AddPolicies
... ELSE Create List
${rescode} Set Variable ${response['code']}
[Return] ${rescode} ${policyIds}
UpdatePolicies
[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'>" WxPolicyListOperation ${returnData} ${policyList} ${opAction} ${version}
... ELSE IF "${dictType}" == "<class 'dict'>" WxPolicyOperation ${returnData} ${policyList} ${opAction} ${version}
... ELSE Set Variable ${EMPTY}
${response} BaseEditRequestForV2 ${url} ${body} ${version}
${rescode} Set Variable ${response['code']}
[Return] ${rescode}

View File

@@ -33,7 +33,7 @@ Resource ../../tsg_common/ManagePolicyBody.robot
# ... 一个filter中的protocolFiled是确定的一个protocolFiled对应多个objectId
WxPolicyListOperation
[Documentation]
... 描述入口opAction参数固定为'add'
... 描述入口opAction参数为'add','update','disable','enable'
... 参数returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。
... policyList: 必传,字典类型。字典内可选参数信息:
... policyObjectVersion: 必传v1,v2,涉及策略版本
@@ -57,7 +57,7 @@ WxPolicyListOperation
WxPolicyOperation
[Documentation]
... 描述入口opAction参数固定为'add'
... 描述入口opAction参数为'add','update','disable','enable'
... 参数returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。
... policyList: 必传,字典类型。字典内可选参数信息:
... policyObjectVersion: 必传v1,v2,涉及策略版本
@@ -77,7 +77,7 @@ WxPolicyOperation
WxPolicyOrganize
[Documentation]
... 描述入口opAction参数固定为'add'
... 描述入口opAction参数为'add','update','disable','enable'
... policyList: 必传,字典类型。字典内可选参数信息:
... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt
... policyObjectVersion: 必传v1,v2,涉及策略版本
@@ -93,6 +93,14 @@ WxPolicyOrganize
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
# 取可选参数,为传入设置默认值
${return} ${policyName} Run Keyword And Ignore Error Get From Dictionary ${policy} policyName
@@ -116,6 +124,9 @@ WxPolicyOrganize
Run Keyword If "${return}"=="FAIL" or "${isValid}"=="${EMPTY}" Set To Dictionary ${policy} isValid=${Default_IsValid}
${return} ${scheduleId} Run Keyword And Ignore Error Set Variable ${policy}[scheduleId]
Run Keyword If "${opAction}"=="enable" Set To Dictionary ${policy} isValid=1
Run Keyword If "${opAction}"=="disable" Set To Dictionary ${policy} isValid=0
${scheduleIdV} Run Keyword If "${return}"!="FAIL" and "${scheduleId}"!="${EMPTY}" and "${scheduleId}"!="${None}" Evaluate list(map(int, re.split('[,]', '${scheduleId}'))) re
... ELSE Set Variable ${emptyList}
Set To Dictionary ${policy} scheduleId=${scheduleIdV}