How to test log encryption?

Recently received a log encryption test task.
The requirements are roughly as follows: Encrypt the corresponding values ​​according to the called keyword output and input parameters.
Keywords:

'mobileNo|custName|money|mobile|userNo|fullName|idNo|panNo|aadhaarNo|registerMobileNo|applyMobile|phone|name|aadhaarCardNo|aadhaarCardName|custRegisterPhoneNum|phoneNumber|idNumber|mobilePhone|middleName|firstName|number|surname|pan|oriPan|userId|password|cardNo|lastName|panCode|additionalMiddleName|PANNumber|panCard|PANId|pan_code'

Example: For
example, a request log is as follows:

2020-05-16 16:22:31.195 DEBUG [apv-workflow-pool-pool-20] [e9f469a5cf79451a97589795563f0cde#14|10.11.2.126||10.11.0.8] [in.qihoo.finance.apv.modules.credit.component.creditnodeflow.impl.AbstractCreditNodeFlowProvider:239] - start checkWhetherDecisionCredit,传入参数str={'isDecisionNode':'Y','creditAdapter':'Pboc'},request={~~idNo=大大大撒21~~ , rejectReasonCode3=, rejectReasonCode2=, rejectReasonCode1=,, id=1335, state=CRING, custNameMd5x=, creditOrg=, phaseNo=AP_CREDIT, idType=P, updatedBy=SYSTEM, applyChannel=APKKR_CH_00001, , priority=, decisionCode=APPROVED, rejectMsg3=, rejectMsg2=, , rejectMsg1=, idNoMd5x=, origState=, flowNo=CREDIT_APPROVE, ,  rejectMsg=, contractNo=, dateFinished=, ~~userNo=UR121212121212121,~~  remark=, dateApplSubmit=2020-05-16T16:21:01.000+0800, dateCreated=2020-05-16T16:21:01.000+0800, eventTypeList=, taskNo=5980494681853657088, apprAutoAmt=, applNo=2020051600000201, dateAppl=2020-05-16T16:21:01.000+0800, ~~mobileNo=6212121212, custName=H162616261621~~ },creditType=EquifaxLesseePboc

In order to show that the keywords are similar before encryption: idNo=大大撒21 mobileNo=6212121212 userNo=UR121212121212121,~~ It
should be similar after encryption: idNo=大*****1 mobileNo=6******2 userNo =U****** 1,~
Logs are relatively small. It is easy to judge whether keywords are encrypted according to the naked eye, but there are often many logs and there are many keywords, and the naked eye test will inevitably miss.
Idea: Take the log out of the service, and then find the string containing the keyword = according to the keyword comparison, and take it out. If it contains
it, it will be encrypted, otherwise it will not be encrypted. And write them into files separately as records.
code show as below:

import numpy as np
import main
#按行件文件保存到list
def read_txt(filename):
    file = open(filename, "r",encoding='UTF-8')
    list = file.readlines()  # 每一行数据写入到list中
    print(list)
    lists = []
    # 将txt文件转换成数组形式保存
    for fields in list:
        fields = fields.strip();  # fields.strip()用来删除字符串两端的空白字符。
        # fields = fields.strip("\n");  # fields.strip("[]")用来删除字符串两端方括号。
        # fields = fields.split(",");  # fields.split(",")的作用是以逗号为分隔符,将字符串进行分隔。
        lists.append(fields)
    print(lists)
    return lists
#按关键字模糊匹配,匹中的写入文件
def write_txt(keyword,filename1,filename2,filename):
    # file = open(filename, 'a',encoding='UTF-8')
    lis=read_txt(filename1)

    for i in lis:
        j = i.split(',')
        for b in j:
        #关键字加密的
            if (keyword in b) and ('*'  in b):
                with open(filename, "a", encoding='UTF-8') as f:
                    f.write(b+"\n")
                #关键字未加密的
            elif (keyword in b) and ('*' not in b):
                with open(filename2, "a", encoding='UTF-8') as f:
                    # if keyword in str(i) :
                    f.write(b + "\n")
       
if __name__=='__main__':
    filename1=f'{main.BASE_DIR}/dataCenter/源文件.txt'
    filename=f'{main.BASE_DIR}/dataCenter/加密.txt'
    filename2=f'{main.BASE_DIR}/dataCenter/未加密.txt'
    keyword='mobileNo|custName|money|mobile|userNo|fullName|idNo|panNo|aadhaarNo|registerMobileNo|applyMobile|phone|name|aadhaarCardNo|aadhaarCardName|custRegisterPhoneNum|phoneNumber|idNumber|mobilePhone|middleName|firstName|number|surname|pan|oriPan|userId|password|cardNo|lastName|panCode|additionalMiddleName|PANNumber|panCard|PANId|pan_code'
    for keyword in keyword.split('|'):
        keyword=keyword+'='
        write_txt(keyword,filename1,filename2,filename)

Guess you like

Origin blog.csdn.net/kairui_guxiaobai/article/details/106190823