From c24acb6bc35eda53ec95cd1e11c7d8ac7bf274fe Mon Sep 17 00:00:00 2001 From: wangxin Date: Fri, 19 Jun 2020 19:13:50 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A(=E7=AD=96=E7=95=A5=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=AF=BC=E5=87=BA)=E4=B8=8A=E4=BC=A0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E6=A0=B7=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../policy_object/PolicyObjectTests.robot | 11 +++- 02-Keyword/tsg_bfapi/Common.robot | 26 ++++++++++ .../tsg_bfapi/policy_object/Policy.robot | 36 ++++++++++++- 05-Other/uploadFiles/tsg_security_imp.json | 52 +++++++++++++++++++ 4 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 05-Other/uploadFiles/tsg_security_imp.json diff --git a/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot b/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot index ff2723f..b63fdac 100644 --- a/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot +++ b/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot @@ -425,4 +425,13 @@ Policy-Delete-v1-00017 Comment 删除安全策略 ${rescode} DeletePolicies ${policyIds} ${policyIds} Create List - Log ${rescode} \ No newline at end of file + Log ${rescode} +Policy-Import-v1-00018 + Comment 导入json + ${objectIds} Set Variable ${EMPTY} + ${rescode} ${policyIds} ImportPolicy uploadFiles tsg_security_imp.json tsg_security +Policy-Export-v1-00019 + Comment 导 出json + ${objectIds} Set Variable ${EMPTY} + ${response} ExportPolicy tsg_security ${EMPTY} ${EMPTY} + WriteFile downloads download.json ${response} \ No newline at end of file diff --git a/02-Keyword/tsg_bfapi/Common.robot b/02-Keyword/tsg_bfapi/Common.robot index 3f80b9c..009b144 100644 --- a/02-Keyword/tsg_bfapi/Common.robot +++ b/02-Keyword/tsg_bfapi/Common.robot @@ -3,6 +3,7 @@ Resource ../../03-Variable/BifangApiVariable.txt Library REST http://${host}:${port} Library Collections Library RequestsLibrary +Library json *** Keywords *** ManageApistr @@ -142,4 +143,29 @@ BaseFormRequest log return data =${response} Should Be Equal As Strings ${response.status_code} 200 ${response} to json ${response.content} + [Return] ${response} +BaseFormRequest1 + [Documentation] + ... 下载文件专用 + ... 由于下载的json存在特殊字符 + ... 隐藏需要设置response.encoding='utf-8-sig' + [Arguments] ${requestUri} ${data} ${apiVersion} + ${headers} set variable {"Authorization":"${token}","Content-Type":"application/x-www-form-urlencoded"} + create session api http://${host}:${port}/${apiVersion} ${headers} + ${response} Run Keyword If "${data}"=="${EMPTY}" Get Request api ${requestUri} + ... ELSE Get Request api ${requestUri}?${data} + log return data =${response} + ${response.encoding} set variable utf-8-sig + Should Be Equal As Strings ${response.status_code} 200 + ${response} json.Loads ${response.content} + [Return] ${response} +BaseMultipartPostRequest + [Arguments] ${requestUri} ${data} ${files} ${apiVersion} + ${headers} set variable {"Authorization":"${token}"} + ${dataString} Dictionary-To-QueryParams ${data} + create session api http://${host}:${port}/${apiVersion} ${headers} + ${response}= Post Request api ${requestUri}?${dataString} files=${files} + log return data =${response} + Should Be Equal As Strings ${response.status_code} 200 + ${response} to json ${response.content} [Return] ${response} \ No newline at end of file diff --git a/02-Keyword/tsg_bfapi/policy_object/Policy.robot b/02-Keyword/tsg_bfapi/policy_object/Policy.robot index 92b58c3..e40c59b 100644 --- a/02-Keyword/tsg_bfapi/policy_object/Policy.robot +++ b/02-Keyword/tsg_bfapi/policy_object/Policy.robot @@ -107,4 +107,38 @@ WxDeletePolicy1 ${response} BaseDeleteRequest /${version}${policyUrl} ${params} ${rescode} Set Variable ${response['code']} Should Be Equal As Strings ${rescode} 200 - [Return] ${rescode} \ No newline at end of file + [Return] ${rescode} +ImportPolicy + [Documentation] + ... 策略导入 + [Arguments] ${filePath} ${fileName} ${policyType} + Directory Should Exist ${path} + File Should Exist ${path}/${filePath}/${fileName} + File Should Not Be Empty ${path}/${filePath}/${fileName} + ${size} Get File Size ${path}/${filePath}/${fileName} + ${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} ${version} + ${rescode} Set Variable ${response['code']} + Should Be Equal As Strings ${rescode} 200 + [Return] ${rescode} +ExportPolicy + [Documentation] + ... 策略导出 + [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} Dictionary-To-QueryParams ${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}" == "" json.Dumps ${content} + ... ELSE Set Variable ${content} + Append To File ${path}/${filePath}/${fileName} ${content} \ No newline at end of file diff --git a/05-Other/uploadFiles/tsg_security_imp.json b/05-Other/uploadFiles/tsg_security_imp.json new file mode 100644 index 0000000..cdf109c --- /dev/null +++ b/05-Other/uploadFiles/tsg_security_imp.json @@ -0,0 +1,52 @@ +{ + "list": [ + { + "action": "deny", + "appObjectIdArray": [ + 2 + ], + "doLog": 1, + "evaluationLayer": "any_layer", + "evaluationOrder": 0, + "evaluationStage": 0, + "filterInfo": "2537:TSG_FIELD_HTTP_REQ_HDR;3002:TSG_SECURITY_SOURCE_ADDR;2723:TSG_SECURITY_DESTINATION_ADDR;2:app_id", + "isValid": 0, + "opTime": "2020-06-15 13:31:39", + "opUser": 353, + "policyDesc": "", + "policyId": 1231, + "policyName": "zw_test", + "policyType": "tsg_security", + "protocol": "HTTP", + "referenceObject": [ + { + "objectId": 2723, + "protocolFields": [ + "TSG_SECURITY_DESTINATION_ADDR" + ] + }, + { + "objectId": 2537, + "protocolFields": [ + "TSG_FIELD_HTTP_REQ_HDR" + ] + }, + { + "objectId": 3002, + "protocolFields": [ + "TSG_SECURITY_SOURCE_ADDR" + ] + } + ], + "scheduleId": [], + "userRegion": { + "protocol": "HTTP", + "code": 200, + "method": "alert", + "message": "aaaa" + }, + "userTags": "" + } + ], + "totalNum": 1 +} \ No newline at end of file