diff --git a/01-TestCase/tsg_bfapi/Object/Manage.robot b/01-TestCase/tsg_bfapi/Object/Manage.robot new file mode 100644 index 0000000..a764431 --- /dev/null +++ b/01-TestCase/tsg_bfapi/Object/Manage.robot @@ -0,0 +1,44 @@ +*** Settings *** +# Test Teardown DeletePolicyAndGroupObject ${policyIds} ${objectIds} +Resource ../../../02-Keyword/tsg_bfapi/PolicyObject.robot +Resource ../../../02-Keyword/tsg_bfapi/policy_object/Policy.robot +Resource ../../../02-Keyword/tsg_bfapi/policy_object/Object.robot +Resource ../../../02-Keyword/tsg_bfapi/policy_object/Log.robot +Resource ../../../02-Keyword/tsg_bfapi/Common.robot +Resource ../../../03-Variable/ApplicationID.txt +Library ../../../04-CustomLibrary/Library/delUseless.py +Library ../../../04-CustomLibrary/Custometest/JsonDiff.py +Library json +Library DateTime +*** Variables *** +@{policyIds} +@{profiles} +${objectIds} ${EMPTY} +${applicationDictUrl} /application/update/dict +${fileUploaduRL} /system/feature/update/ +*** Test Cases *** +update_applicationDict + ImportApplication uploadFiles applicationDict.exe ${EMPTY} 200 + +update_fileUpload_appSignature + ImportApplication uploadFiles appSignature.exe app_signature 200 + +update_fileUpload_app_library + ImportApplication uploadFiles applibrary.exe app_library 200 + +update_install1 + ${updateDict} Create Dictionary profileId=123456 feature=app_signature + UpdateInstall ${updateDict} +update_install2 + ${updateDict} Create Dictionary profileId=223 feature=app_library + UpdateInstall ${updateDict} +QueryUpadateRecord1 + QueryUpadateRecord pageSize=20&pageNo=1&orderBy=opTime desc,contentType asc&profileId=&profileIds=&version=&fileName=&feature=app_signature 200 +QueryUpadateRecord2 + QueryUpadateRecord pageSize=10000&pageNo=3&orderBy=opTime asc,contentType asc&feature=app_library 200 + + + + + + \ No newline at end of file diff --git a/02-Keyword/tsg_bfapi/policy_object/Object.robot b/02-Keyword/tsg_bfapi/policy_object/Object.robot index 1ea7b4c..e852fe9 100644 --- a/02-Keyword/tsg_bfapi/policy_object/Object.robot +++ b/02-Keyword/tsg_bfapi/policy_object/Object.robot @@ -11,6 +11,9 @@ Library DatabaseLibrary *** Variables *** ${objectUrl} /policy/object +${categoryUrl} /category/dict +${applicationDictUrl} /application/update/dict +${fileUploaduRL} /system/feature/update/ *** Keywords *** AddObjects @@ -61,6 +64,25 @@ UpdateObjects ${rescode} Set Variable ${response['code']} Should Be Equal As Strings ${rescode} 200 [Return] ${rescode} + +UpdateInstall + [Arguments] ${updateDict} + [Documentation] 更新策略对象 + ... objectList,策略对象,可为list类型与dict类型 + ... addItemList自动过滤itemId + ... updateItemList自动过滤isInitialize(update时该字段引发异常) + ... ipItem格式为dict,自动过滤空的字段 + ... stringItem格式为dict,需要注意keywordArray字段应传入逗号分隔的字符串eg: keyword1,keyword2 + ... http_signature为代表的拓展关键字keywordArray字段也是以逗号分隔的 + ... returnData,是否返回数据,固定为1 + ... opAction,可为update,enable,disable + #必选参数判定 + Should Not Be Empty ${updateDict} + ${bodyJson} json.Dumps ${updateDict} ensure_ascii=False + ${response} BaseEditRequestForV2 ${fileUploaduRL} ${body} ${version} + ${rescode} Set Variable ${response['code']} + Should Be Equal As Strings ${rescode} 200 + [Return] ${rescode} GetObjectItems [Arguments] ${params} @@ -154,7 +176,28 @@ ImportObject ${rescode} Set Variable ${response['code']} Should Be Equal As Strings ${rescode} 200 [Return] ${rescode} ${objectType} ${response} - + +ImportApplication + [Arguments] ${filePath} ${fileName} ${feature} ${code} + [Documentation] 策略对象导入 + ... filePath文件路径 + ... fileName文件名称 + ... feature是特征 + 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} Run Keyword If "${feature}"=="${EMPTY}" Evaluate (r'${fileName}',open(r"${path}/${filePath}/${fileName}",'rb'),'application/xml') + ... ELSE IF "${feature}"=="app_library" or "${feature}"=="app_signature" Evaluate (r'${fileName}',open(r"${path}/${filePath}/${fileName}",'rb'),'application/octet-stream') + ... ELSE ${EMPTY} + ${file} Create Dictionary file=${binFile} + # ${response} BaseMultipartPostRequest ${objectUrl}/batch ${EMPTY} ${file} ${version} + ${response} Run Keyword If "${feature}"=="${EMPTY}" BaseMultipartPostRequest ${applicationDictUrl} ${EMPTY} ${file} ${version} + ... ELSE IF "${feature}"=="app_library" or "${feature}"=="app_signature" BaseMultipartPostRequest ${fileUploaduRL} ${EMPTY} ${file} ${version} + ${rescode} Set Variable ${response['code']} + Should Be Equal As Strings ${rescode} ${code} + + ExportObject [Arguments] ${objectType} ${objectSubType} ${objectIds} ${objectName} [Documentation] 策略对象导出 @@ -240,3 +283,37 @@ AppIdTreeSearch ${rescode} Set Variable ${response['code']} Should Be Equal As Strings ${rescode} 200 [Return] ${response['data']} + +AddCategories + [Arguments] ${returnData} ${categoryList} + [Documentation] 新增策略对象 + ... objectList,策略对象,可为list类型与dict类型 + ... addItemList自动过滤itemId + ... updateItemList自动过滤isInitialize(update时该字段引发异常) + ... ipItem格式为dict,自动过滤空的字段 + ... stringItem格式为dict,需要注意keywordArray字段应传入逗号分隔的字符串eg: keyword1,keyword2 + ... http_signature为代表的拓展关键字keywordArray字段也是以逗号分隔的 + ... returnData,是否返回数据,固定为1 + Comment 此处思路给category单独的另一套关键字,原因:地址与json串名称与Object部分不同了 + ${returnData}= Run Keyword If '${returnData}' == '${EMPTY}' Set Variable 1 + ... ELSE Set Variable ${returnData} + #必选参数判定 + Should Not Be Empty ${categoryList} + ${dictType} = Evaluate type(${categoryList}) + ${body} Run Keyword If "${dictType}" == "" CategoryListOperation ${returnData} ${categoryList} add + ... ELSE IF "${dictType}" == "" CategoryOperation ${returnData} ${categoryList} add + ... ELSE Set Variable ${EMPTY} + ${response} BasePostRequestForV2 ${categoryUrl} ${body} ${version} + ${CategoryIds} Run Keyword If "${returnData}" == "1" Get-CategoryIds ${response} + ... ELSE Create List + ${rescode} Set Variable ${response['code']} + Should Be Equal As Strings ${rescode} 200 + [Return] ${rescode} ${CategoryIds} + +QueryUpadateRecord + [Arguments] ${body} ${code} + ${response} BaseGetRequestOK /${version}/system/feature/update body=${body} + log ${response} + ${rescode} Set Variable ${response['code']} + Shoule Be Equal As Strings ${rescode} ${code} + [Return] ${rescode} diff --git a/02-Keyword/tsg_bfapi/policy_object/ProcessObjectBody.robot b/02-Keyword/tsg_bfapi/policy_object/ProcessObjectBody.robot index 430845c..858ce76 100644 --- a/02-Keyword/tsg_bfapi/policy_object/ProcessObjectBody.robot +++ b/02-Keyword/tsg_bfapi/policy_object/ProcessObjectBody.robot @@ -28,6 +28,37 @@ ObjectListOperation ${json} Replace String ${bodyJson} "replace:objectList" ${objectListJson} Log Object_Request_Body-${json} [Return] ${json} + +CategoryListOperation + [Documentation] + ... 描述:入口,opAction参数可为'add','update','disable','enable' + ... 参数:returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。 + ... objectList: 必传,字典类型。字典内可选参数信息: + ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt + ... 多个对象处理 + + [Arguments] ${returnData} ${objectList} ${opAction} + Log Call ObjectListOperation + ${objectListJson} Set Variable [ + FOR ${object} IN @{objectList} + ${json} CategoryOrganize ${object} ${opAction} + ${objectListJson} Set Variable ${objectListJson}${json}, + END + ${objectListJson}= Replace String Using Regexp ${objectListJson} ,$ ] + + # 转为json结构并返回 + ${dict} Create Dictionary opAction=${opAction} returnData=${returnData} categoryList=replace:objectList + ${bodyJson} json.Dumps ${dict} ensure_ascii=False + ${json} Replace String ${bodyJson} "replace:objectList" ${json} + + Log Category_Request_Body-${json} + + # 转为json结构并返回 + # ${dict} Create Dictionary opAction=${opAction} returnData=${returnData} objectList=replace:objectList + # ${bodyJson} json.Dumps ${dict} ensure_ascii=False + # ${json} Replace String ${bodyJson} "replace:objectList" ${objectListJson} + # Log Object_Request_Body-${json} + [Return] ${json} ObjectOperation [Documentation] @@ -47,6 +78,65 @@ ObjectOperation Log Object_Request_Body-${json} [Return] ${json} + +InstallOperation + [Documentation] + ... 描述:入口,opAction参数可为'add','update','disable','enable' + ... 参数:returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。 + ... object: 必传,字典类型。字典内可选参数信息: + ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt + ... 单个策略处理 + + [Arguments] ${object} + Log Call ObjectOperation + ${json} ObjectOrganize ${object} + # 转为json结构并返回 + ${dict} Create Dictionary opAction=${opAction} returnData=${returnData} objectList=replace:objectList + ${bodyJson} json.Dumps ${dict} ensure_ascii=False + ${json} Replace String ${bodyJson} "replace:objectList" ${json} + + Log Object_Request_Body-${json} + [Return] ${json} + +FeatureOperation + [Documentation] + ... 描述:入口,opAction参数可为'add','update','disable','enable' + ... 参数:returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。 + ... object: 必传,字典类型。字典内可选参数信息: + ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt + ... 单个策略处理 + + [Arguments] ${returnData} ${object} ${opAction} + Log Call ObjectOperation + ${json} ObjectOrganize ${object} ${opAction} + # 转为json结构并返回 + ${dict} Create Dictionary opAction=${opAction} returnData=${returnData} objectList=replace:objectList + ${bodyJson} json.Dumps ${dict} ensure_ascii=False + ${json} Replace String ${bodyJson} "replace:objectList" ${json} + + Log Object_Request_Body-${json} + [Return] ${json} + +CategoryOperation + [Documentation] + ... 描述:入口,opAction参数可为'add','update','disable','enable' + ... 参数:returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。 + ... object: 必传,字典类型。字典内可选参数信息: + ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt + ... 单个策略处理 + + [Arguments] ${returnData} ${category} ${opAction} + Log Call ObjectOperation + ${json} CategoryOrganize ${category} ${opAction} + + # 转为json结构并返回 + ${dict} Create Dictionary opAction=${opAction} returnData=${returnData} categoryList=replace:objectList + ${bodyJson} json.Dumps ${dict} ensure_ascii=False + ${json} Replace String ${bodyJson} "replace:objectList" ${json} + + Log Category_Request_Body-${json} + [Return] ${json} + listorone [Arguments] ${object} ${addItemList} Evaluate str('addItemList'in${object}.keys()) @@ -147,6 +237,81 @@ ObjectOrganize ${json} json.Dumps ${returnDict} ensure_ascii=False Log Object-${json} [Return] ${json} +Categorylistorone + [Arguments] ${category} + ${addItemList} Evaluate str('fqdnList'in${category}.keys()) + log ${addItemList} + ${objectparm} set variable ${addItemList} + should contain x times ${objectparm} True 1 + # Should Not Be Empty ${object}[addItemList] or Should Not Be Empty ${object}[subObjectIds] + +CategoryOrganize + [Documentation] + ... 描述:入口,opAction参数可为'add','update','disable','enable' + ... object: 必传,字典类型。字典内可选参数信息: + ... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt + ... 单个策略转换为json + [Arguments] ${category} ${opAction} + Log Call CategoryOrganize + ${emptyList} Create List + ${returnDict} Create Dictionary + # 断言必传参数 + # Should Not Be Empty ${object}[objectType] + # Set To Dictionary ${returnDict} objectType=${object}[objectType] + #新增时addItemList不能为空 + Run Keyword If "${opAction}"=="add" Categorylistorone ${category} + Run Keyword If "${opAction}"=="update" Should Not Be Empty ${category}[categoryId] + ${return} ${objectId} Run Keyword And Ignore Error Get From Dictionary ${category} objectId + Run Keyword If "${return}"=="FAIL" or "${objectId}"=="${EMPTY}" Set To Dictionary ${returnDict} objectId=${EMPTY} + ... ELSE Set To Dictionary ${returnDict} objectId=${objectId} + ${return} ${categoryId} Run Keyword And Ignore Error Get From Dictionary ${category} categoryId + Run Keyword If "${return}"=="FAIL" or "${categoryId}"=="${EMPTY}" Set To Dictionary ${returnDict} categoryId=${EMPTY} + ... ELSE Set To Dictionary ${returnDict} categoryId=${categoryId} + + ${return} ${categoryType} Run Keyword And Ignore Error Get From Dictionary ${category} categoryType + ${categoryTypeV} Run Keyword If "${return}"!="FAIL" and "${categoryType}"!="${EMPTY}" Evaluate '${categoryType}'.lower() + ... ELSE Evaluate '${Default_CategoryType}'.lower() + Set To Dictionary ${returnDict} categoryType=${categoryTypeV} + # 取可选参数,为传入设置默认值 + Set To Dictionary ${returnDict} categoryType=${categoryTypeV} + # ${return} ${isDelete} Run Keyword And Ignore Error Get From Dictionary ${category} isDelete + # Run Keyword If "${return}"=="FAIL" or "${isDelete}"=="${EMPTY}" Set To Dictionary ${returnDict} isDelete=${Default_IsDelete} + # ... ELSE Set To Dictionary ${returnDict} isDelete=${isDelete} + ${return} ${categoryDimension} Run Keyword And Ignore Error Get From Dictionary ${category} categoryDimension + Run Keyword If "${return}"=="FAIL" or "${categoryDimension}"=="${EMPTY}" Set To Dictionary ${returnDict} categoryDimension=${Default_Dimension} + ... ELSE Set To Dictionary ${returnDict} categoryDimension=${categoryDimension} + ${return} ${categoryOrigin} Run Keyword And Ignore Error Get From Dictionary ${category} categoryOrigin + Run Keyword If "${return}"=="FAIL" or "${categoryOrigin}"=="${EMPTY}" Set To Dictionary ${returnDict} categoryOrigin=${Default_Origin} + ... ELSE Set To Dictionary ${returnDict} categoryOrigin=${categoryOrigin} + ${return} ${isInitialize} Run Keyword And Ignore Error Get From Dictionary ${category} isInitialize + Run Keyword If "${return}"=="FAIL" or "${isInitialize}"=="${EMPTY}" Set To Dictionary ${returnDict} isInitialize=${Default_IsInitialize} + ... ELSE Set To Dictionary ${returnDict} isInitialize=${isInitialize} + ${return} ${categoryName} Run Keyword And Ignore Error Get From Dictionary ${category} categoryName + Run Keyword If "${return}"=="FAIL" or "${categoryName}"=="${EMPTY}" Set To Dictionary ${returnDict} categoryName=${Default_ObjectName} + ... ELSE Set To Dictionary ${returnDict} categoryName=${categoryName} + ${return} ${categoryDesc} Run Keyword And Ignore Error Get From Dictionary ${category} categoryDesc + Run Keyword If "${return}"!="FAIL" and "${categoryDesc}"!="${EMPTY}" Set To Dictionary ${returnDict} categoryDesc=${categoryDesc} + ... ELSE Set To Dictionary ${returnDict} categoryDesc=${Default_ObjectDesc} + ${return} ${objectSubType} Run Keyword And Ignore Error Get From Dictionary ${category} objectSubType + Run Keyword If "${return}"!="FAIL" and "${objectSubType}"!="${EMPTY}" Set To Dictionary ${returnDict} objectSubType=${objectSubType} + ... ELSE Set To Dictionary ${returnDict} objectSubType=${Default_ObjectSubType} + # 处理AddItemList + ${return} ${addItemList} Run Keyword And Ignore Error Get From Dictionary ${category} fqdnList + Run Keyword If "${return}"!="FAIL" and "${addItemList}"!="${EMPTY}" ManageAddItemListNew ${addItemList} ${returnDict} ${categoryTypeV} ${objectSubType} + + # 处理UpdateItemList + ${return} ${updateItemList} Run Keyword And Ignore Error Get From Dictionary ${category} updateItemList + Run Keyword If "${opAction}"=="update" and "${return}"!="FAIL" and "${updateItemList}"!="${EMPTY}" ManageUpdateItemList ${updateItemList} ${returnDict} ${objectTypeV} ${objectSubType} + # 处理deleteItemIds + ${return} ${deleteItemIds} Run Keyword And Ignore Error Get From Dictionary ${category} deleteItemIds + Run Keyword If "${opAction}"=="update" and "${return}"!="FAIL" and "${deleteItemIds}"!="${EMPTY}" ManageDeleteItemIds ${deleteItemIds} ${returnDict} + # 删除无用判断key值objectSubType + Remove From Dictionary ${returnDict} objectSubType + # 转为json结构并返回 + ${json} json.Dumps ${returnDict} ensure_ascii=False + Log Object-${json} + [Return] ${json} + ManageEnableAndDisable [Documentation] ... 启用与禁用时调用 @@ -164,15 +329,19 @@ ManageAddItemListNew FOR ${item} IN @{addItemList} ${itemNew} Run Keyword If '${type}'=='ip' and '${subType}'=="geo_location" ManageGeoItem ${item} ${subType} add ... ELSE IF '${type}'=='ip' ManageIpItem ${item} ${subType} add - ... ELSE IF '${type}'=='url' or '${type}'=='fqdn' or '${type}'=='keywords' or '${type}'=='subscriberid' or '${type}'=='fqdn_category' or '${type}'=='account' or '${type}'=='app_id' + ... ELSE IF '${type}'=='url' or ('${type}'=='fqdn' and '${subType}'!='category') or '${type}'=='keywords' or '${type}'=='subscriberid' or '${type}'=='fqdn_category' or '${type}'=='account' + # ... or '${type}'=='app_id' or '${type}'=='mobile_identity' or '${type}'=='apn' ... ManageStrItem ${item} ${type} add ... ELSE IF '${type}'=='file_type' ManageFileItem ${item} ${type} add + ... ELSE IF '${type}'=='fqdn' and '${subType}'=='category' ManageCategory ${item} ${type} add ... ELSE IF '${type}'=='http_signature' ManageExtensionStrItem ${item} ${type} add ... ELSE IF '${type}'=='file_size' or '${type}'=='file_integrity_rate' ManageNumberItem ${item} ${type} add ... ELSE Fail Append To List ${itemList} ${itemNew} END - Set To Dictionary ${returnDict} addItemList=${itemList} + Run Keyword If '${subType}'=='category' Set To Dictionary ${returnDict} fqdnList=${itemList} + ... ELSE Set To Dictionary ${returnDict} addItemList=${itemList} + ManageUpdateItemList [Documentation] @@ -281,6 +450,28 @@ ManageStrItem Run Keyword If "${itemName}"!="${EMPTY}" Set To Dictionary ${itemNew} itemName=${itemName} Run Keyword If "${itemDesc}"!="${EMPTY}" Set To Dictionary ${itemNew} itemDesc=${itemDesc} [Return] ${itemNew} + +ManageCategory + [Documentation] + ... 字符串item处理 + [Arguments] ${item} ${type} ${action} + Log Call ManageStrItem + ${return} ${fqdn} Run Keyword And Ignore Error Set Variable ${item['fqdn']} + ${fqdn} Run Keyword If "${return}"!="FAIL" Set Variable ${fqdn} ELSE Set Variable ${EMPTY} + Run Keyword If "${action}"=="add" Should Not Be Empty ${fqdn} + ${fqdn} Evaluate re.split('[,]', '${fqdn}') re + + # ${return} ${isInitialize} Run Keyword And Ignore Error Set Variable ${item['isInitialize']} + # ${isInitialize} Run Keyword If "${return}"!="FAIL" Set Variable ${isInitialize} + # ... ELSE Set Variable ${EMPTY} + # ${return} ${itemName} Run Keyword And Ignore Error Set Variable ${item['isDelete']} + # ${itemName} Run Keyword If "${return}"!="FAIL" Set Variable ${isDelete} + ${itemNew} Create Dictionary + Run Keyword If "${fqdn}"!="${EMPTY}" Set To Dictionary ${itemNew} fqdn=${fqdn} + # Run Keyword If "${isInitialize}"!="${EMPTY}" Set To Dictionary ${itemNew} isInitialize=${isInitialize} + # Run Keyword If "${isDelete}"!="${EMPTY}" Set To Dictionary ${itemNew} isDelete=${isDelete} + [Return] ${itemNew} + ManageFileItem [Documentation] ... 接口未说明,待接口说明字段类型之后再完善 @@ -333,4 +524,22 @@ Get-ObjectIds ${json} json.Dumps ${objectIds} ensure_ascii=False ${json} Remove String ${json} [ ${json} Remove String ${json} ] + [Return] ${json} + +Get-CategoryIds + [Documentation] + ... 获取结果中的对象ID + [Arguments] ${value} + Log Call Get-ObjectIds + ${CategoryIds} Create List + ${CategoryTemp} Set Variable ${EMPTY} + ${return} ${data} Run Keyword And Ignore Error Get From Dictionary ${value} data + Return From Keyword If "${return}"=="FAIL" ${CategoryTemp} + + FOR ${category} IN @{value['data']['list']} + Append To List ${CategoryIds} ${category['categoryId']} + END + ${json} json.Dumps ${CategoryIds} ensure_ascii=False + ${json} Remove String ${json} [ + ${json} Remove String ${json} ] [Return] ${json} \ No newline at end of file