ApiServer: add support MD5 authentication

This commit is contained in:
httprunner
2017-06-22 18:37:48 +08:00
parent 50f5373c41
commit 567eec21fd
2 changed files with 60 additions and 4 deletions

View File

@@ -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