feat(API):增加策略验证关键字
This commit is contained in:
98
02-Keyword/tsg_adc/PolicyVertify.robot
Normal file
98
02-Keyword/tsg_adc/PolicyVertify.robot
Normal file
@@ -0,0 +1,98 @@
|
||||
*** Settings ***
|
||||
Library OperatingSystem
|
||||
Library Selenium2Library
|
||||
Library RequestsLibrary
|
||||
Library Collections
|
||||
Library json
|
||||
Resource ../tsg_bfapi/Common.robot
|
||||
Resource ../../03-Variable/BifangApiVariable.txt
|
||||
|
||||
*** Keywords ***
|
||||
PolicyVertify
|
||||
[Arguments] ${dict}
|
||||
Should Not Be Empty ${dict}[policyType]
|
||||
Should Not Be Empty ${dict}[appId]
|
||||
Should Not Be Empty ${dict}[cfg]
|
||||
|
||||
# APP ID
|
||||
${appId} Evaluate '${dict}[appId]'.lower()
|
||||
${attrVDict1} Create Dictionary string=${appId}.
|
||||
${attrDict1} Create Dictionary attributeType=string attributeName=app_id attributeValue=${attrVDict1}
|
||||
|
||||
# IP/Str
|
||||
${attributes} Create List ${attrDict1}
|
||||
${unCfg} Set Variable ${dict}[cfg]
|
||||
${cfgList} Evaluate re.split('[|]', '${unCfg}') re
|
||||
|
||||
# 区分 IP/String/Signature
|
||||
${type} Evaluate '${cfgList}[0]'.lower()
|
||||
Run Keyword If '${type}' == 'ip' ManageIpCfg ${cfgList} ${attributes}
|
||||
... ELSE IF '${type}' == 'str' ManageStrCfg ${cfgList} ${attributes} ${appId}
|
||||
... ELSE ManageSignatureCfg ${cfgList} ${attributes} ${appId}
|
||||
|
||||
${vsDict} Create Dictionary attributes=${attributes}
|
||||
${verify1} Create Dictionary policyType=${dict}[policyType] verifySession=${vsDict}
|
||||
${verifyList} Create List ${verify1}
|
||||
${resultObj} Create Dictionary verifyList=${verifyList}
|
||||
|
||||
${json} json.Dumps ${resultObj} ensure_ascii=False
|
||||
${response} BasePostRequest /v1/policy/verify body=${json}
|
||||
Log REQ = ${json}
|
||||
Log RES = ${response}
|
||||
Should Be True ${response['code']} == 200
|
||||
Should Not Be Empty ${response['data']['hitPolicyList']}
|
||||
Should Not Be Empty ${response['data']['verifySession']}
|
||||
|
||||
ManageIpCfg
|
||||
[Arguments] ${cfgList} ${attributes}
|
||||
# IP CFG
|
||||
${addrType} Evaluate int('${cfgList}[1]'[1:])
|
||||
${protocolDict} Create Dictionary Any=0 TCP=6 UDP=17
|
||||
${protocolkey} Set Variable ${cfgList}[6]
|
||||
${protocol} Evaluate int(${protocolDict}[${protocolkey}])
|
||||
${attrValueDict} Create Dictionary addrType=${addrType} clientIp=${cfgList}[2] clientPort=${cfgList}[3] serverIp=${cfgList}[4] serverPort=${cfgList}[5] protocol=${protocol}
|
||||
${attrDict} Create Dictionary attributeType=ip attributeName=ip attributeValue=${attrValueDict}
|
||||
Append To List ${attributes} ${attrDict}
|
||||
|
||||
ManageStrCfg
|
||||
[Arguments] ${cfgList} ${attributes} ${appId}
|
||||
# Subscriber ID
|
||||
${attrValueDict} Create Dictionary string=${cfgList}[1]
|
||||
${attrDict} Create Dictionary attributeType=string attributeName=subscriberid attributeValue=${attrValueDict}
|
||||
Append To List ${attributes} ${attrDict}
|
||||
|
||||
# APP CFG
|
||||
${list} Evaluate re.split('[&]', '${cfgList}[2]') re
|
||||
FOR ${var} IN @{list}
|
||||
${i} Evaluate '${var}'.find('=')
|
||||
${name} Evaluate '${var}'[:${i}]
|
||||
${value} Evaluate '${var}'[${i}+1:]
|
||||
${attributeValue} Create Dictionary string=${value}
|
||||
${obj} Create Dictionary attributeType=string attributeName=${name} protocol=${appId} attributeValue=${attributeValue}
|
||||
Append To List ${attributes} ${obj}
|
||||
END
|
||||
|
||||
ManageSignatureCfg
|
||||
[Documentation]
|
||||
... cfg=dstr|$jwctest|account=User-Agent#anony*&url=added&content=added
|
||||
[Arguments] ${cfgList} ${attributes} ${appId}
|
||||
# Subscriber ID
|
||||
${attrValueDict} Create Dictionary string=${cfgList}[1]
|
||||
${attrDict} Create Dictionary attributeType=string attributeName=subscriberid attributeValue=${attrValueDict}
|
||||
Append To List ${attributes} ${attrDict}
|
||||
|
||||
# APP CFG
|
||||
${list} Evaluate re.split('[&]', '${cfgList}[2]') re
|
||||
FOR ${var} IN @{list}
|
||||
${i} Evaluate '${var}'.find('=')
|
||||
${name} Evaluate '${var}'[:${i}]
|
||||
${value} Evaluate '${var}'[${i}+1:]
|
||||
${y} Evaluate '${value}'.find('#')
|
||||
${district} Evaluate '${value}'[:${y}]
|
||||
${string} Evaluate '${value}'[${y}+1:]
|
||||
${attributeValue} Create Dictionary string=${string} district=${district}
|
||||
${obj} Create Dictionary attributeType=signature attributeName=${name} protocol=${appId} attributeValue=${attributeValue}
|
||||
Append To List ${attributes} ${obj}
|
||||
END
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ Resource ../../02-Keyword/tsg_adc/SystemCommand.robot
|
||||
Resource ../../02-Keyword/tsg_bfapi/PolicyObject.robot
|
||||
Resource ../../02-Keyword/tsg_bfapi/LogVariable.robot
|
||||
Resource ../../02-Keyword/tsg_bfapi/LogSchema.robot
|
||||
Resource ../../02-Keyword/tsg_adc/PolicyVertify.robot
|
||||
|
||||
*** Test Cases ***
|
||||
case01
|
||||
@@ -16,37 +17,70 @@ case01
|
||||
# [isInitialize]|[itemName]|[itemDesc], 第四部分(可省略)
|
||||
# ...
|
||||
${objectDict} Create Dictionary
|
||||
... objectType=ip
|
||||
... isValid=${1}
|
||||
... addItemList=range|192.168.40.51|192.168.40.120|80/88
|
||||
... objectType=ip
|
||||
... isValid=${1}
|
||||
... addItemList=range|192.168.40.51|192.168.40.120|80/88
|
||||
${rescode} ${objectId} AddObject2 ${1} ${objectDict}
|
||||
|
||||
# 创建对象-http_signature
|
||||
# addItemList全参数:(参数不可跳跃,[keywordArray]|[district]为必填,其它可省略)
|
||||
# [keywordArray]|[district]|[isHexbin]|[isInitialize]|[itemName]|[itemDesc],...
|
||||
${objectDict} Create Dictionary
|
||||
... objectType=http_signature
|
||||
... isValid=${1}
|
||||
... addItemList=abcd|Cookie
|
||||
... objectType=http_signature
|
||||
... isValid=${1}
|
||||
... addItemList=abcd|Cookie
|
||||
${rescode} ${objectId} AddObject2 ${1} ${objectDict}
|
||||
|
||||
# 创建对象-url/fqdn/keywords/subscriberid/fqdn_category/account
|
||||
# addItemList全参数:(参数不可跳跃,[keywordArray]为必填,其它可省略)
|
||||
# [keywordArray]|[isHexbin]|[isInitialize]|[itemName]|[itemDesc],...
|
||||
${objectDict} Create Dictionary
|
||||
... objectType=url
|
||||
... isValid=${1}
|
||||
... addItemList=abcd&def
|
||||
... objectType=url
|
||||
... isValid=${1}
|
||||
... addItemList=abcd&def
|
||||
${rescode} ${objectId} AddObject2 ${1} ${objectDict}
|
||||
|
||||
# 创建策略
|
||||
${policyDict} Create Dictionary
|
||||
... policyName=test_policy_add
|
||||
... policyType=tsg_security
|
||||
... action=intercept
|
||||
... effectiveRange=Nursurtan|Transtelecom&Astel,|Astel&Transtelecom
|
||||
... userRegion=protocol:HTTP,keyring:${1}
|
||||
... referenceObject=${objectId}|TSG_SECURITY_DESTINATION_ADDR
|
||||
... isValid=${0}
|
||||
... policyName=test_policy_add
|
||||
... policyType=tsg_security
|
||||
... action=intercept
|
||||
... effectiveRange=Nursurtan|Transtelecom&Astel,|Astel&Transtelecom
|
||||
... userRegion=protocol:HTTP,keyring:${1}
|
||||
... referenceObject=${objectId}|TSG_SECURITY_DESTINATION_ADDR
|
||||
... isValid=${0}
|
||||
${rescode} ${policyId} AddPolicy2 ${1} ${policyDict}
|
||||
|
||||
case0x
|
||||
[Documentation]
|
||||
... 字典说明(所有参数均不可省略):
|
||||
... policyType tsg_security/pxy_manipulation
|
||||
... appId HTTP/SSL/DNS/MAIL/FTP
|
||||
... cfg (IP) ip|[v4/v6]|[ClientIP*]|[ClientPort*]|[ServerIP*]|[ServerPort*]|[Any/TCP/UDP]
|
||||
... (String) str|[SubscriberID*]|[key*]=[value*]&...
|
||||
... (Signature) dstr|[SubscriberID*]|[req_hdr/res_hdr]=[User-Agent/Cookie/Set-Cookie/Content-Type]#[value*]&...
|
||||
... ps: '&'配置多条时以最后一个'|'后开始
|
||||
... 可参考下面例1-3
|
||||
|
||||
# 例1:IP类策略验证
|
||||
${dict1} Create Dictionary
|
||||
... policyType=tsg_security
|
||||
... appId=HTTP
|
||||
... cfg=ip|v4|192.168.50.24|10000|172.16.0.1|80|UDP
|
||||
PolicyVertify ${dict1}
|
||||
|
||||
# 例2:String类策略验证
|
||||
${dict2} Create Dictionary
|
||||
... policyType=tsg_security
|
||||
... appId=FTP
|
||||
... cfg=str|$jwctest|account=anony*
|
||||
PolicyVertify ${dict2}
|
||||
|
||||
# 例3:Signature类策略验证
|
||||
${dict} Create Dictionary
|
||||
... policyType=tsg_security
|
||||
... appId=FTP # HTTP/SSL/DNS/MAIL/FTP
|
||||
... cfg=dstr|$test|req_hdr=User-Agent#aa&res_hdr=Content-Type#bb
|
||||
PolicyVertify ${dict}
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ ObjectParamsOpertion
|
||||
Should Not Be Empty ${objectList}[addItemList]
|
||||
# 取可选参数,为传入设置默认值
|
||||
${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}
|
||||
${objectTypeV} Run Keyword If "${return}"!="FAIL" and "${objectType}"!="${EMPTY}" Evaluate '${objectType}'.lower()
|
||||
... ELSE Evaluate '${Default_ObjectType}'.lower()
|
||||
Set To Dictionary ${objectList} objectType=${objectTypeV}
|
||||
Set To Dictionary ${returnDict} objectType=${objectTypeV}
|
||||
${return} ${objectSubType} Run Keyword And Ignore Error Set Variable ${objectList}[objectSubType]
|
||||
|
||||
Reference in New Issue
Block a user