mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-31 05:19:38 +08:00
ApiServer: add support MD5 authentication
This commit is contained in:
25
test/base.py
25
test/base.py
@@ -1,14 +1,22 @@
|
||||
import hashlib
|
||||
import multiprocessing
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
import unittest
|
||||
|
||||
from . import api_server
|
||||
|
||||
|
||||
class ApiServerUnittest(unittest.TestCase):
|
||||
""" Test case class that sets up an HTTP server which can be used within the tests
|
||||
"""
|
||||
Test case class that sets up an HTTP server which can be used within the tests
|
||||
"""
|
||||
|
||||
authentication = False
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
api_server.AUTHENTICATION = cls.authentication
|
||||
cls.api_server_process = multiprocessing.Process(
|
||||
target=api_server.app.run
|
||||
)
|
||||
@@ -18,3 +26,16 @@ class ApiServerUnittest(unittest.TestCase):
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.api_server_process.terminate()
|
||||
|
||||
def prepare_headers(self, data=""):
|
||||
token = api_server.TOKEN
|
||||
random_str = ''.join(
|
||||
random.choice(string.ascii_uppercase + string.digits) for _ in range(5))
|
||||
|
||||
authorization_str = "".join([token, data, random_str])
|
||||
authorization = hashlib.md5(authorization_str.encode('utf-8')).hexdigest()
|
||||
headers = {
|
||||
'authorization': authorization,
|
||||
'random': random_str
|
||||
}
|
||||
return headers
|
||||
|
||||
Reference in New Issue
Block a user