Test case design based on encryption interface

1. Environmental preparation

1. Interface for encrypting responses. After issuing a get request to it, an encrypted response message is obtained. (If there is an encrypted interface available and you know its decryption method, you can skip it)
2. Prepare an encrypted file
Insert image description here
and encrypted fields
Insert image description here

3. Use the python command to start a service in the directory where the encrypted file is located.
Insert image description here

4. Visit the website

Insert image description here

2. Principle

After getting the encrypted response information, decrypt the response:

1. If you know which common encryption algorithm is used, you can solve it yourself.
2. If you don’t know the corresponding encryption algorithm, you can ask R&D to provide the encryption and decryption lib.
3. If it is neither a universal encryption algorithm nor R&D nor can it provide encryption and decryption libs, the encryption party can provide remote analysis services so that the algorithm remains confidential.

3. Practical exercises

1. Call the base64 that comes with python and directly decrypt the returned response to get the decrypted response.

import requests
import base64
import json

def test_encode():
    url = 'http://127.0.0.1:9999/demo.txt'
    r = requests.get(url=url)
    print(r.text)
    res = json.loads(base64.b64decode(r.content))
    print(res)

2. Encapsulate the processing methods for different algorithms.
base_api.py

class ApiRequest:


    def send(self,data:dict):
        res=requests.request(data['method'],data['url'],headers=data['headers'])
        if data['encoding']== "base64":
            return json.loads(base64.b64decode(res.content))
        elif data['encoding']== "md5":
            return
        # 把加密后响应值发给第三方服务i,让第三方服务解密返回
        elif data['encoding'] == "第三方":
            return requests.post("url",data=res.content)

testcase.py

from unittest import TestCase
from mima import test_requests

class TestApiRequest(TestCase):
    req_data = {
    
    
        "method": "get",
        "url": "http://127.0.0.1:8080/demo.txt",
        "headers": None,
        "encoding": "base64"
    }

    def test_send(self):
        ar=test_requests.ApiRequest()
        print(ar.send(self.req_data))


Guess you like

Origin blog.csdn.net/YZL40514131/article/details/132481956