From b1809c8083f03e8fda5bb4339c2a010bd603fbe5 Mon Sep 17 00:00:00 2001 From: wangxin Date: Wed, 24 Jun 2020 17:37:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:(=E6=97=A5=E5=BF=97=E5=8A=9F=E8=83=BD)1?= =?UTF-8?q?=EF=BC=9Aschema=E8=8E=B7=E5=8F=96;2:=E6=97=A5=E5=BF=97=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../policy_object/PolicyObjectTests.robot | 46 ++++++- 02-Keyword/tsg_bfapi/policy_object/Log.robot | 114 ++++++++++++++++++ 2 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 02-Keyword/tsg_bfapi/policy_object/Log.robot diff --git a/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot b/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot index 9a6cf7f..55d7f34 100644 --- a/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot +++ b/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot @@ -3,6 +3,7 @@ Test Teardown DeletePolicyAndObjectAndProfile ${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 Library json *** Variables *** @@ -494,4 +495,47 @@ Policy-Verify-v1-00023 ${attributes} Create List ${ipObj} ${stringObj} ${appIdObj} ${signatureObj} ${verifySession} Create Dictionary attributes=${attributes} ${verifyList} Create Dictionary policyType=tsg_security verifySession=${verifySession} - ${rescode} ${resData} VerifyPolicies ${verifyList} \ No newline at end of file + ${rescode} ${resData} VerifyPolicies ${verifyList} +Policy-log-v1-00024 + ${objectIds} Set Variable ${EMPTY} + Comment 查询schema + ${schema_query} ${schema_type} ${default_columns} ${fields} GetLogSchema security_event_log + ${queryFieldList} Create List + FOR ${field} IN @{fields} + ${return} ${doc} Run Keyword And Ignore Error Get From Dictionary ${field} doc + Continue For Loop If "${return}"=="FAIL" + ${return} ${allow_query} Run Keyword And Ignore Error Get From Dictionary ${doc} allow_query + Continue For Loop If "${allow_query}"=="false" or "${return}"=="FAIL" + ${fieldDict} Create Dictionary name=${field['name']} type=${field['type']} + Append To List ${queryFieldList} ${fieldDict} + END + Log ${queryFieldList} +Policy-log-v1-00025 + ${objectIds} Set Variable ${EMPTY} + Comment 查询schema + ${schema_query} ${schema_type} ${default_columns} ${fields} GetLogSchema security_event_log + + ${filters} Get From Dictionary ${schema_query} filters + Log ${filters} +Policy-log-v1-00026 + ${objectIds} Set Variable ${EMPTY} + Comment 查询schema + ${schema_query} ${schema_type} ${default_columns} ${fields} GetLogSchema security_event_log + Comment 处理schema,构造查询条件 + ${queryFieldList} Create List + FOR ${field} IN @{fields} + log ${field} + ${return} ${doc} Run Keyword And Ignore Error Get From Dictionary ${field} doc + Continue For Loop If "${return}"=="FAIL" + ${return} ${allow_query} Run Keyword And Ignore Error Get From Dictionary ${doc} allow_query + Continue For Loop If "${allow_query}"=="false" or "${return}"=="FAIL" + ${fieldDict} Create Dictionary name=${field['name']} type=${field['type']} + Append To List ${queryFieldList} ${fieldDict} + END + ${params} Create Dictionary pageSize=${10} logType=security_event_log + ... start_common_recv_time=2020-06-01 00:00:00 + ... end_common_recv_time=2020-06-24 00:00:00 + ... fields=common_log_id|long,http_url|string,common_client_ip|string,common_client_port|int,common_server_ip|string,common_server_port|int + ... conditions=common_server_port|int|in|${80}^${8080} + ... orderBy=common_server_ip|true + ${resData} QueryLogList ${params} \ No newline at end of file diff --git a/02-Keyword/tsg_bfapi/policy_object/Log.robot b/02-Keyword/tsg_bfapi/policy_object/Log.robot new file mode 100644 index 0000000..b4a79e9 --- /dev/null +++ b/02-Keyword/tsg_bfapi/policy_object/Log.robot @@ -0,0 +1,114 @@ +*** Settings *** +Library json +Library Collections +Library RequestsLibrary +Resource ../../../03-Variable/BifangApiVariable.txt +Resource ../../../02-Keyword/tsg_bfapi/policy_file_interface/FunctionalKeywords.robot +Resource ../Common.robot +*** Variables *** +${logUrl} /log +*** Keywords *** +GetLogSchema + [Documentation] + ... 日志schema查询 + ... logType 日志类型 + ... resData schema数据 + [Arguments] ${logType} + ${response} BaseFormRequest ${logUrl}/schema logType=${logType} ${version} + ${rescode} Set Variable ${response['code']} + Should Be Equal As Integers ${rescode} 200 + ${resData} Set Variable ${response['data']} + ${schema_query} Get From Dictionary ${resData['doc']} schema_query + ${schema_type} Get From Dictionary ${resData['doc']} schema_type + ${default_columns} Get From Dictionary ${resData['doc']} default_columns + [Return] ${schema_query} ${schema_type} ${default_columns} ${resData['fields']} +QueryLogList + [Documentation] + ... 日志列表查询 + ... params字典列表 + ... 注意如下字典字段格式 + ... orderBy=field名字1|true,field名字2|false + ... fields=name1|type,name2|type + ... conditions=field1|type|symbol|value1^value2,field2|type|symbol|value3^value4 + ... value1^value2是使用^分隔的字符串解析后为[value1,value2]格式的数组 + [Arguments] ${params} + Should Not Be Empty ${params} + ${return} ${pageSize} Run Keyword And Ignore Error Get From Dictionary ${params} pageSize + Run Keyword If "${return}"=="PASS" and "${pageSize}"=="${EMPTY}" Remove From Dictionary ${params} pageSize + ${return} ${pageNo} Run Keyword And Ignore Error Get From Dictionary ${params} pageNo + Run Keyword If "${return}"=="PASS" and "${pageNo}"=="${EMPTY}" Remove From Dictionary ${params} pageNo + Dictionary Should Contain Key ${params} logType + ${logType} Get From Dictionary ${params} logType + #处理排序 + ${return} ${orderBy} Run Keyword And Ignore Error Get From Dictionary ${params} orderBy + ${orderBy} Run Keyword If "${return}"=="FAIL" or "${orderBy}"=="${EMPTY}" Create List + ... ELSE ManageOrderBy ${orderBy} + Set To Dictionary ${params} orderBy=${orderBy} + + ${fields} Get From Dictionary ${params} fields + Should Not Be Empty ${fields} + ${fields} ManageFields ${fields} + Set To Dictionary ${params} fields=${fields} + + ${start_common_recv_time} Get From Dictionary ${params} start_common_recv_time + Should Not Be Empty ${start_common_recv_time} + ${end_common_recv_time} Get From Dictionary ${params} end_common_recv_time + Should Not Be Empty ${end_common_recv_time} + + ${return} ${userTags} Run Keyword And Ignore Error Get From Dictionary ${params} userTags + Run Keyword If "${return}"=="PASS" and "${userTags}"=="${EMPTY}" Remove From Dictionary ${params} userTags + ${return} ${conditions} Run Keyword And Ignore Error Get From Dictionary ${params} conditions + ${conditions} Run Keyword If "${return}"=="PASS" and "${conditions}"!="${EMPTY}" ManageConditions ${conditions} + ... ELSE Create List + Set To Dictionary ${params} conditions=${conditions} + ${bodyJson} json.Dumps ${params} ensure_ascii=False + ${response} BasePostRequestForV2 ${logUrl}/list ${bodyJson} ${version} + ${rescode} Set Variable ${response['code']} + Should Be Equal As Integers ${rescode} 200 + ${resData} Set Variable ${response['data']} + [Return] ${resData} + ManageOrderBy + [Documentation] + ... + [Arguments] ${orderBy} + ${orderByList} Create List + @{orderByArr} Split String ${orderBy} , + FOR ${order} IN @{orderByArr} + @{orderByArr} Split String ${order} | + ${dict} Create Dictionary field=${orderByArr}[0] asc=${orderByArr}[1] + Append To List ${orderByList} ${dict} + END + [Return] ${orderByList} + ManageFields + [Arguments] ${fields} + ${fieldsList} Create List + @{fieldsArr} Split String ${fields} , + FOR ${field} IN @{fieldsArr} + @{fieldsArr} Split String ${field} | + ${dict} Create Dictionary name=${fieldsArr}[0] type=${fieldsArr}[1] + Append To List ${fieldsList} ${dict} + END + [Return] ${fieldsList} + ManageConditions + [Arguments] ${conditions} + ${conditionsList} Create List + @{conditionsArr} Split String ${conditions} , + FOR ${condition} IN @{conditionsArr} + @{conditionArr} Split String ${condition} | + @{value} Split String ${conditionArr}[3] ^ + ${type} Set Variable ${conditionArr}[1] + ${value} Run Keyword If "${type}"=="int" or "${type}"=="long" toDigitList ${value} ${type} + ... ELSE Set Variable ${value} + ${dict} Create Dictionary field=${conditionArr}[0] type=${type} symbol=${conditionArr}[2] value=${value} + Append To List ${conditionsList} ${dict} + END + [Return] ${conditionsList} +toDigitList + [Arguments] ${values} ${type} + ${list} Create List + FOR ${var} IN @{values} + ${var} Run Keyword If "${type}"=="int" Evaluate int('${var}') + ... ELSE Evaluate long('${var}') + Append To List ${list} ${var} + END + [Return] ${list} \ No newline at end of file